Subversion Repositories ZenDark

Rev

Rev 3 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 27
Line 2... Line 2...
2
/*
2
/*
3
 * Theme Options
3
 * Theme Options
4
 */
4
 */
5
 
5
 
6
/*
6
/*
7
 * Register the form setting for our sdt_options array.
7
 * Register the form setting for our zendark_options array.
8
 *
8
 *
9
 * This function is attached to the admin_init action hook.
9
 * This function is attached to the admin_init action hook.
10
 *
10
 *
11
 * This call to register_setting() registers a validation callback, sdt_theme_options_validate(),
11
 * This call to register_setting() registers a validation callback, zendark_theme_options_validate(),
12
 * which is used when the option is saved, to ensure that our option values are complete, properly
12
 * which is used when the option is saved, to ensure that our option values are complete, properly
13
 * formatted, and safe.
13
 * formatted, and safe.
14
 *
14
 *
15
 * We also use this function to add our theme option if it doesn't already exist.
15
 * We also use this function to add our theme option if it doesn't already exist.
16
 */
16
 */
17
function sdt_theme_options_init() {
17
function zendark_theme_options_init() {
18
18
19
        // If we have no options in the database, let's add them now.
19
        // If we have no options in the database, let's add them now.
20
        if (false === sdt_get_theme_options())
20
        if (false === zendark_get_theme_options())
21
                add_option('sdt_theme_options', sdt_get_default_theme_options());
21
                add_option('zendark_theme_options', zendark_get_default_theme_options());
22
22
23
        register_setting(
23
        register_setting(
24
                'sdt_options',       // Options group, see settings_fields() call in theme_options_render_page()
24
                'zendark_options',       // Options group, see settings_fields() call in theme_options_render_page()
25
                'sdt_theme_options', // Database option, see sdt_get_theme_options()
25
                'zendark_theme_options', // Database option, see zendark_get_theme_options()
26
                'sdt_theme_options_validate' // The sanitization callback, see sdt_theme_options_validate()
26
                'zendark_theme_options_validate' // The sanitization callback, see zendark_theme_options_validate()
27
        );
27
        );
28
}
28
}
29
add_action('admin_init', 'sdt_theme_options_init');
29
add_action('admin_init', 'zendark_theme_options_init');
30
30
31
/*
31
/*
32
 * Change the capability required to save the 'sdt_options' options group.
32
 * Change the capability required to save the 'zendark_options' options group.
33
 *
33
 *
34
 * @see sdt_theme_options_init() First parameter to register_setting() is the name of the options group.
34
 * @see zendark_theme_options_init() First parameter to register_setting() is the name of the options group.
35
 * @see sdt_theme_options_add_page() The edit_theme_options capability is used for viewing the page.
35
 * @see zendark_theme_options_add_page() The edit_theme_options capability is used for viewing the page.
36
 *
36
 *
37
 * By default, the options groups for all registered settings require the manage_options capability.
37
 * By default, the options groups for all registered settings require the manage_options capability.
38
 * This filter is required to change our theme options page to edit_theme_options instead.
38
 * This filter is required to change our theme options page to edit_theme_options instead.
39
 * By default, only administrators have either of these capabilities, but the desire here is
39
 * By default, only administrators have either of these capabilities, but the desire here is
40
 * to allow for finer-grained control for roles and users.
40
 * to allow for finer-grained control for roles and users.
41
 *
41
 *
42
 * @param string $capability The capability used for the page, which is manage_options by default.
42
 * @param string $capability The capability used for the page, which is manage_options by default.
43
 * @return string The capability to actually use.
43
 * @return string The capability to actually use.
44
 */
44
 */
45
function sdt_option_page_capability($capability) {
45
function zendark_option_page_capability($capability) {
46
        return 'edit_theme_options';
46
        return 'edit_theme_options';
47
}
47
}
48
add_filter('option_page_capability_sdt_options', 'sdt_option_page_capability');
48
add_filter('option_page_capability_zendark_options', 'zendark_option_page_capability');
49
49
50
/*
50
/*
51
 * Add our theme options page to the admin menu, including some help documentation.
51
 * Add our theme options page to the admin menu, including some help documentation.
52
 *
52
 *
53
 * This function is attached to the admin_menu action hook.
53
 * This function is attached to the admin_menu action hook.
54
 */
54
 */
55
function sdt_theme_options_add_page() {
55
function zendark_theme_options_add_page() {
56
        $theme_page = add_theme_page(
56
        $theme_page = add_theme_page(
57
                __('Theme Options', 'sdt'),            // Name of page
57
                __('Theme Options', 'zendark'),            // Name of page
58
                __('Theme Options', 'sdt'),            // Label in menu
58
                __('Theme Options', 'zendark'),            // Label in menu
59
                'edit_theme_options',                  // Capability required
59
                'edit_theme_options',                  // Capability required
60
                'theme_options',                       // Menu slug, used to uniquely identify the page
60
                'theme_options',                       // Menu slug, used to uniquely identify the page
61
                'sdt_theme_options_render_page'        // Function that renders the options page
61
                'zendark_theme_options_render_page'        // Function that renders the options page
62
        );
62
        );
63
63
64
        if (!$theme_page)
64
        if (!$theme_page)
65
                return;
65
                return;
66
66
67
        $help = '<p>'.__('Some themes provide customization options that are grouped together on a Theme Options screen. If you change themes, options may change or disappear, as they are theme-specific. Your current theme, Simple Dark Theme, provides the following Theme Options:', 'sdt').'</p>' .
67
        $help = '<p>'.__('Some themes provide customization options that are grouped together on a Theme Options screen. If you change themes, options may change or disappear, as they are theme-specific. Your current theme, Simple Dark Theme, provides the following Theme Options:', 'zendark').'</p>' .
68
                        '<ol>' .
68
                        '<ol>' .
69
                                '<li>'.__( '<strong>Zenphoto integration</strong>: You can insert the URL of your Zenphoto installation (if on the same domain of this WordPress installation) to integrate it on a WordPress page.', 'sdt').'</li>'.
69
                                '<li>'.__( '<strong>Zenphoto integration</strong>: You can insert the URL of your Zenphoto installation (if on the same domain of this WordPress installation) to integrate it on a WordPress page.', 'zendark').'</li>'.
70
                        '</ol>'.
70
                        '</ol>'.
71
                        '<p>'.__('Remember to click "Save Changes" to save any changes you have made to the theme options.', 'sdt').'</p>'.
71
                        '<p>'.__('Remember to click "Save Changes" to save any changes you have made to the theme options.', 'zendark').'</p>'.
72
                        '<p><strong>'.__('For more information:', 'sdt').'</strong></p>'.
72
                        '<p><strong>'.__('For more information:', 'zendark').'</strong></p>'.
73
                        '<p>'.__('<a href="http://codex.wordpress.org/Appearance_Theme_Options_Screen" target="_blank">Documentation on Theme Options</a>', 'sdt').'</p>'.
73
                        '<p>'.__('<a href="http://codex.wordpress.org/Appearance_Theme_Options_Screen" target="_blank">Documentation on Theme Options</a>', 'zendark').'</p>'.
74
                        '<p>'.__('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'sdt').'</p>';
74
                        '<p>'.__('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'zendark').'</p>';
75
75
76
        add_contextual_help($theme_page, $help);
76
        add_contextual_help($theme_page, $help);
77
}
77
}
78
add_action('admin_menu', 'sdt_theme_options_add_page');
78
add_action('admin_menu', 'zendark_theme_options_add_page');
79
79
80
/*
80
/*
81
 * Returns the default options
81
 * Returns the default options
82
 */
82
 */
83
function sdt_get_default_theme_options() {
83
function zendark_get_default_theme_options() {
84
        $default_theme_options = array(
84
        $default_theme_options = array(
85
                'zenphoto_url' => 'http://'
85
                'zenphoto_url' => 'http://'
86
        );
86
        );
87
}
87
}
88
88
89
/*
89
/*
90
 * Returns the options array
90
 * Returns the options array
91
 */
91
 */
92
function sdt_get_theme_options() {
92
function zendark_get_theme_options() {
93
        return get_option('sdt_theme_options', sdt_get_default_theme_options());
93
        return get_option('zendark_theme_options', zendark_get_default_theme_options());
94
}
94
}
95
95
96
/*
96
/*
97
 * Returns the options page
97
 * Returns the options page
98
 */
98
 */
99
function sdt_theme_options_render_page() {
99
function zendark_theme_options_render_page() {
100
        ?>
100
        ?>
101
        <div class="wrap">
101
        <div class="wrap">
102
                <?php screen_icon(); ?>
102
                <?php screen_icon(); ?>
103
                <h2><?php printf(__('%s Theme Options', 'sdt'), get_current_theme()); ?></h2>
103
                <h2><?php printf(__('%s Theme Options', 'zendark'), get_current_theme()); ?></h2>
104
                <?php settings_errors(); ?>
104
                <?php settings_errors(); ?>
105
105
106
                <form method="post" action="options.php" style="margin-top: 20px;">
106
                <form method="post" action="options.php" style="margin-top: 20px;">
107
                        <?php
107
                        <?php
108
                                settings_fields('sdt_options');
108
                                settings_fields('zendark_options');
109
                                $options = sdt_get_theme_options();
109
                                $options = zendark_get_theme_options();
110
                                $default_options = sdt_get_default_theme_options();
110
                                $default_options = zendark_get_default_theme_options();
111
                        ?>
111
                        ?>
112
                        <fieldset>
112
                        <fieldset>
113
        <label><?php _e('Zenphoto URL:', 'sdt'); ?></label>
113
        <label><?php _e('Zenphoto URL:', 'zendark'); ?></label>
114
        <legend class="screen-reader-text"><span><?php _e('Zenphoto URL', 'sdt'); ?></span></legend>
114
        <legend class="screen-reader-text"><span><?php _e('Zenphoto URL', 'zendark'); ?></span></legend>
115
                                <input type="text" name="sdt_theme_options[zenphoto_url]" id="zenphoto-url" value="<?php echo esc_attr( $options['zenphoto_url'] ); ?>" size="60" />
115
                                <input type="text" name="zendark_theme_options[zenphoto_url]" id="zenphoto-url" value="<?php echo esc_attr( $options['zenphoto_url'] ); ?>" size="60" />
116
                        </fieldset>
116
                        </fieldset>
117
                        <?php submit_button(); ?>
117
                        <?php submit_button(); ?>
118
                </form>
118
                </form>
119
        </div>
119
        </div>
120
        <?php
120
        <?php
121
}
121
}
122
122
123
/*
123
/*
124
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
124
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
125
 */
125
 */
126
function sdt_theme_options_validate($input) {
126
function zendark_theme_options_validate($input) {
127
        $output = $defaults = sdt_get_default_theme_options();
127
        $output = $defaults = zendark_get_default_theme_options();
128
128
129
        // Zenphoto URL must be in our array
129
        // Zenphoto URL must be in our array
130
        if (isset( $input['zenphoto_url']))
130
        if (isset( $input['zenphoto_url']))
131
                $output['zenphoto_url'] = $input['zenphoto_url'];
131
                $output['zenphoto_url'] = $input['zenphoto_url'];
132
132
133
        return apply_filters('sdt_theme_options_validate', $output, $input, $defaults);
133
        return apply_filters('zendark_theme_options_validate', $output, $input, $defaults);
134
}
134
}
135
?>
135
?>