4,35 → 4,35 |
*/ |
|
/* |
* Register the form setting for our sdt_options array. |
* Register the form setting for our zendark_options array. |
* |
* This function is attached to the admin_init action hook. |
* |
* This call to register_setting() registers a validation callback, sdt_theme_options_validate(), |
* This call to register_setting() registers a validation callback, zendark_theme_options_validate(), |
* which is used when the option is saved, to ensure that our option values are complete, properly |
* formatted, and safe. |
* |
* We also use this function to add our theme option if it doesn't already exist. |
*/ |
function sdt_theme_options_init() { |
function zendark_theme_options_init() { |
|
// If we have no options in the database, let's add them now. |
if (false === sdt_get_theme_options()) |
add_option('sdt_theme_options', sdt_get_default_theme_options()); |
if (false === zendark_get_theme_options()) |
add_option('zendark_theme_options', zendark_get_default_theme_options()); |
|
register_setting( |
'sdt_options', // Options group, see settings_fields() call in theme_options_render_page() |
'sdt_theme_options', // Database option, see sdt_get_theme_options() |
'sdt_theme_options_validate' // The sanitization callback, see sdt_theme_options_validate() |
'zendark_options', // Options group, see settings_fields() call in theme_options_render_page() |
'zendark_theme_options', // Database option, see zendark_get_theme_options() |
'zendark_theme_options_validate' // The sanitization callback, see zendark_theme_options_validate() |
); |
} |
add_action('admin_init', 'sdt_theme_options_init'); |
add_action('admin_init', 'zendark_theme_options_init'); |
|
/* |
* Change the capability required to save the 'sdt_options' options group. |
* Change the capability required to save the 'zendark_options' options group. |
* |
* @see sdt_theme_options_init() First parameter to register_setting() is the name of the options group. |
* @see sdt_theme_options_add_page() The edit_theme_options capability is used for viewing the page. |
* @see zendark_theme_options_init() First parameter to register_setting() is the name of the options group. |
* @see zendark_theme_options_add_page() The edit_theme_options capability is used for viewing the page. |
* |
* By default, the options groups for all registered settings require the manage_options capability. |
* This filter is required to change our theme options page to edit_theme_options instead. |
42,10 → 42,10 |
* @param string $capability The capability used for the page, which is manage_options by default. |
* @return string The capability to actually use. |
*/ |
function sdt_option_page_capability($capability) { |
function zendark_option_page_capability($capability) { |
return 'edit_theme_options'; |
} |
add_filter('option_page_capability_sdt_options', 'sdt_option_page_capability'); |
add_filter('option_page_capability_zendark_options', 'zendark_option_page_capability'); |
|
/* |
* Add our theme options page to the admin menu, including some help documentation. |
52,35 → 52,35 |
* |
* This function is attached to the admin_menu action hook. |
*/ |
function sdt_theme_options_add_page() { |
function zendark_theme_options_add_page() { |
$theme_page = add_theme_page( |
__('Theme Options', 'sdt'), // Name of page |
__('Theme Options', 'sdt'), // Label in menu |
__('Theme Options', 'zendark'), // Name of page |
__('Theme Options', 'zendark'), // Label in menu |
'edit_theme_options', // Capability required |
'theme_options', // Menu slug, used to uniquely identify the page |
'sdt_theme_options_render_page' // Function that renders the options page |
'zendark_theme_options_render_page' // Function that renders the options page |
); |
|
if (!$theme_page) |
return; |
|
$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>' . |
$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>' . |
'<ol>' . |
'<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>'. |
'<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>'. |
'</ol>'. |
'<p>'.__('Remember to click "Save Changes" to save any changes you have made to the theme options.', 'sdt').'</p>'. |
'<p><strong>'.__('For more information:', 'sdt').'</strong></p>'. |
'<p>'.__('<a href="http://codex.wordpress.org/Appearance_Theme_Options_Screen" target="_blank">Documentation on Theme Options</a>', 'sdt').'</p>'. |
'<p>'.__('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'sdt').'</p>'; |
'<p>'.__('Remember to click "Save Changes" to save any changes you have made to the theme options.', 'zendark').'</p>'. |
'<p><strong>'.__('For more information:', 'zendark').'</strong></p>'. |
'<p>'.__('<a href="http://codex.wordpress.org/Appearance_Theme_Options_Screen" target="_blank">Documentation on Theme Options</a>', 'zendark').'</p>'. |
'<p>'.__('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'zendark').'</p>'; |
|
add_contextual_help($theme_page, $help); |
} |
add_action('admin_menu', 'sdt_theme_options_add_page'); |
add_action('admin_menu', 'zendark_theme_options_add_page'); |
|
/* |
* Returns the default options |
*/ |
function sdt_get_default_theme_options() { |
function zendark_get_default_theme_options() { |
$default_theme_options = array( |
'zenphoto_url' => 'http://' |
); |
89,30 → 89,30 |
/* |
* Returns the options array |
*/ |
function sdt_get_theme_options() { |
return get_option('sdt_theme_options', sdt_get_default_theme_options()); |
function zendark_get_theme_options() { |
return get_option('zendark_theme_options', zendark_get_default_theme_options()); |
} |
|
/* |
* Returns the options page |
*/ |
function sdt_theme_options_render_page() { |
function zendark_theme_options_render_page() { |
?> |
<div class="wrap"> |
<?php screen_icon(); ?> |
<h2><?php printf(__('%s Theme Options', 'sdt'), get_current_theme()); ?></h2> |
<h2><?php printf(__('%s Theme Options', 'zendark'), get_current_theme()); ?></h2> |
<?php settings_errors(); ?> |
|
<form method="post" action="options.php" style="margin-top: 20px;"> |
<?php |
settings_fields('sdt_options'); |
$options = sdt_get_theme_options(); |
$default_options = sdt_get_default_theme_options(); |
settings_fields('zendark_options'); |
$options = zendark_get_theme_options(); |
$default_options = zendark_get_default_theme_options(); |
?> |
<fieldset> |
<label><?php _e('Zenphoto URL:', 'sdt'); ?></label> |
<legend class="screen-reader-text"><span><?php _e('Zenphoto URL', 'sdt'); ?></span></legend> |
<input type="text" name="sdt_theme_options[zenphoto_url]" id="zenphoto-url" value="<?php echo esc_attr( $options['zenphoto_url'] ); ?>" size="60" /> |
<label><?php _e('Zenphoto URL:', 'zendark'); ?></label> |
<legend class="screen-reader-text"><span><?php _e('Zenphoto URL', 'zendark'); ?></span></legend> |
<input type="text" name="zendark_theme_options[zenphoto_url]" id="zenphoto-url" value="<?php echo esc_attr( $options['zenphoto_url'] ); ?>" size="60" /> |
</fieldset> |
<?php submit_button(); ?> |
</form> |
123,13 → 123,13 |
/* |
* Sanitize and validate form input. Accepts an array, return a sanitized array. |
*/ |
function sdt_theme_options_validate($input) { |
$output = $defaults = sdt_get_default_theme_options(); |
function zendark_theme_options_validate($input) { |
$output = $defaults = zendark_get_default_theme_options(); |
|
// Zenphoto URL must be in our array |
if (isset( $input['zenphoto_url'])) |
$output['zenphoto_url'] = $input['zenphoto_url']; |
|
return apply_filters('sdt_theme_options_validate', $output, $input, $defaults); |
return apply_filters('zendark_theme_options_validate', $output, $input, $defaults); |
} |
?> |