Subversion Repositories ZenDark

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 iacchi 1
<?php
2
/*
3
 * Theme Options
4
 */
5
 
6
/*
27 iacchi 7
 * Register the form setting for our zendark_options array.
3 iacchi 8
 *
9
 * This function is attached to the admin_init action hook.
10
 *
27 iacchi 11
 * This call to register_setting() registers a validation callback, zendark_theme_options_validate(),
3 iacchi 12
 * which is used when the option is saved, to ensure that our option values are complete, properly
13
 * formatted, and safe.
14
 *
15
 * We also use this function to add our theme option if it doesn't already exist.
16
 */
27 iacchi 17
function zendark_theme_options_init() {
3 iacchi 18
 
19
        // If we have no options in the database, let's add them now.
27 iacchi 20
        if (false === zendark_get_theme_options())
21
                add_option('zendark_theme_options', zendark_get_default_theme_options());
3 iacchi 22
 
23
        register_setting(
27 iacchi 24
                'zendark_options',       // Options group, see settings_fields() call in theme_options_render_page()
25
                'zendark_theme_options', // Database option, see zendark_get_theme_options()
26
                'zendark_theme_options_validate' // The sanitization callback, see zendark_theme_options_validate()
3 iacchi 27
        );
28
}
27 iacchi 29
add_action('admin_init', 'zendark_theme_options_init');
3 iacchi 30
 
31
/*
27 iacchi 32
 * Change the capability required to save the 'zendark_options' options group.
3 iacchi 33
 *
27 iacchi 34
 * @see zendark_theme_options_init() First parameter to register_setting() is the name of the options group.
35
 * @see zendark_theme_options_add_page() The edit_theme_options capability is used for viewing the page.
3 iacchi 36
 *
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.
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.
41
 *
42
 * @param string $capability The capability used for the page, which is manage_options by default.
43
 * @return string The capability to actually use.
44
 */
27 iacchi 45
function zendark_option_page_capability($capability) {
3 iacchi 46
        return 'edit_theme_options';
47
}
27 iacchi 48
add_filter('option_page_capability_zendark_options', 'zendark_option_page_capability');
3 iacchi 49
 
50
/*
51
 * Add our theme options page to the admin menu, including some help documentation.
52
 *
53
 * This function is attached to the admin_menu action hook.
54
 */
27 iacchi 55
function zendark_theme_options_add_page() {
3 iacchi 56
        $theme_page = add_theme_page(
27 iacchi 57
                __('Theme Options', 'zendark'),            // Name of page
58
                __('Theme Options', 'zendark'),            // Label in menu
3 iacchi 59
                'edit_theme_options',                  // Capability required
60
                'theme_options',                       // Menu slug, used to uniquely identify the page
27 iacchi 61
                'zendark_theme_options_render_page'        // Function that renders the options page
3 iacchi 62
        );
63
 
64
        if (!$theme_page)
65
                return;
66
 
27 iacchi 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>' .
3 iacchi 68
                        '<ol>' .
27 iacchi 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>'.
3 iacchi 70
                        '</ol>'.
27 iacchi 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:', 'zendark').'</strong></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>', 'zendark').'</p>';
3 iacchi 75
 
76
        add_contextual_help($theme_page, $help);
77
}
27 iacchi 78
add_action('admin_menu', 'zendark_theme_options_add_page');
3 iacchi 79
 
80
/*
81
 * Returns the default options
82
 */
27 iacchi 83
function zendark_get_default_theme_options() {
3 iacchi 84
        $default_theme_options = array(
85
                'zenphoto_url' => 'http://'
86
        );
87
}
88
 
89
/*
90
 * Returns the options array
91
 */
27 iacchi 92
function zendark_get_theme_options() {
93
        return get_option('zendark_theme_options', zendark_get_default_theme_options());
3 iacchi 94
}
95
 
96
/*
97
 * Returns the options page
98
 */
27 iacchi 99
function zendark_theme_options_render_page() {
3 iacchi 100
        ?>
101
        <div class="wrap">
102
                <?php screen_icon(); ?>
27 iacchi 103
                <h2><?php printf(__('%s Theme Options', 'zendark'), get_current_theme()); ?></h2>
3 iacchi 104
                <?php settings_errors(); ?>
105
 
106
                <form method="post" action="options.php" style="margin-top: 20px;">
107
                        <?php
27 iacchi 108
                                settings_fields('zendark_options');
109
                                $options = zendark_get_theme_options();
110
                                $default_options = zendark_get_default_theme_options();
3 iacchi 111
                        ?>
112
                        <fieldset>
27 iacchi 113
        <label><?php _e('Zenphoto URL:', 'zendark'); ?></label>
114
        <legend class="screen-reader-text"><span><?php _e('Zenphoto URL', 'zendark'); ?></span></legend>
115
                                <input type="text" name="zendark_theme_options[zenphoto_url]" id="zenphoto-url" value="<?php echo esc_attr( $options['zenphoto_url'] ); ?>" size="60" />
3 iacchi 116
                        </fieldset>
117
                        <?php submit_button(); ?>
118
                </form>
119
        </div>
120
        <?php
121
}
122
 
123
/*
124
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
125
 */
27 iacchi 126
function zendark_theme_options_validate($input) {
127
        $output = $defaults = zendark_get_default_theme_options();
3 iacchi 128
 
129
        // Zenphoto URL must be in our array
130
        if (isset( $input['zenphoto_url']))
131
                $output['zenphoto_url'] = $input['zenphoto_url'];
132
 
27 iacchi 133
        return apply_filters('zendark_theme_options_validate', $output, $input, $defaults);
3 iacchi 134
}
135
?>