2011-04-27 00:52:18 +02:00
< ? php
/**
* Twenty Eleven Theme Options
*
* @ package WordPress
2011-05-18 21:06:09 +02:00
* @ subpackage Twenty_Eleven
2011-04-28 10:06:57 +02:00
* @ since Twenty Eleven 1.0
2011-04-27 00:52:18 +02:00
*/
/**
2011-04-28 10:06:57 +02:00
* Properly enqueue styles and scripts for our theme options page .
*
* This function is attached to the admin_enqueue_scripts action hook .
*
* @ since Twenty Eleven 1.0
*
2013-09-25 18:50:11 +02:00
* @ param string $hook_suffix An admin page ' s hook suffix .
2011-04-27 00:52:18 +02:00
*/
2011-04-28 10:06:57 +02:00
function twentyeleven_admin_enqueue_scripts ( $hook_suffix ) {
2019-08-08 03:25:58 +02:00
wp_enqueue_style ( 'twentyeleven-theme-options' , get_template_directory_uri () . '/inc/theme-options.css' , false , '20110602' );
2019-08-08 03:29:58 +02:00
wp_enqueue_script ( 'twentyeleven-theme-options' , get_template_directory_uri () . '/inc/theme-options.js' , array ( 'farbtastic' ), '20110610' );
2011-04-27 00:52:18 +02:00
wp_enqueue_style ( 'farbtastic' );
}
2011-06-11 01:01:16 +02:00
add_action ( 'admin_print_styles-appearance_page_theme_options' , 'twentyeleven_admin_enqueue_scripts' );
2011-04-27 00:52:18 +02:00
/**
2011-04-28 10:06:57 +02:00
* Register the form setting for our twentyeleven_options array .
*
* This function is attached to the admin_init action hook .
*
* This call to register_setting () registers a validation callback , twentyeleven_theme_options_validate (),
* which is used when the option is saved , to ensure that our option values are complete , properly
* formatted , and safe .
*
* @ since Twenty Eleven 1.0
2011-04-27 00:52:18 +02:00
*/
2011-04-28 10:06:57 +02:00
function twentyeleven_theme_options_init () {
2011-04-28 10:52:37 +02:00
register_setting (
2020-01-29 01:45:18 +01:00
'twentyeleven_options' , // Options group, see settings_fields() call in twentyeleven_theme_options_render_page().
'twentyeleven_theme_options' , // Database option, see twentyeleven_get_theme_options().
'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate().
2011-04-28 10:52:37 +02:00
);
2011-07-21 23:37:31 +02:00
2020-01-29 01:45:18 +01:00
// Register our settings field group.
2011-12-02 05:31:01 +01:00
add_settings_section (
2020-01-29 01:45:18 +01:00
'general' , // Unique identifier for the settings section.
'' , // Section title (we don't want one).
'__return_false' , // Section callback (we don't want anything).
'theme_options' // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page().
2011-07-21 23:37:31 +02:00
);
2020-01-29 01:45:18 +01:00
// Register our individual settings fields.
2011-12-02 05:31:01 +01:00
add_settings_field (
2020-01-29 01:45:18 +01:00
'color_scheme' , // Unique identifier for the field for this section.
__ ( 'Color Scheme' , 'twentyeleven' ), // Setting field label.
'twentyeleven_settings_field_color_scheme' , // Function that renders the settings field.
'theme_options' , // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page().
'general' // Settings section. Same as the first argument in the add_settings_section() above.
2011-07-21 23:37:31 +02:00
);
2017-12-01 00:11:00 +01:00
add_settings_field ( 'link_color' , __ ( 'Link Color' , 'twentyeleven' ), 'twentyeleven_settings_field_link_color' , 'theme_options' , 'general' );
add_settings_field ( 'layout' , __ ( 'Default Layout' , 'twentyeleven' ), 'twentyeleven_settings_field_layout' , 'theme_options' , 'general' );
2011-04-27 00:52:18 +02:00
}
2011-04-28 10:06:57 +02:00
add_action ( 'admin_init' , 'twentyeleven_theme_options_init' );
2011-04-27 00:52:18 +02:00
2011-05-22 23:32:44 +02:00
/**
* Change the capability required to save the 'twentyeleven_options' options group .
*
2013-09-25 18:50:11 +02:00
* @ see twentyeleven_theme_options_init () First parameter to register_setting () is the name of the options group .
2011-05-22 23:32:44 +02:00
* @ see twentyeleven_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 .
* By default , only administrators have either of these capabilities , but the desire here is
* to allow for finer - grained control for roles and users .
*
* @ param string $capability The capability used for the page , which is manage_options by default .
* @ return string The capability to actually use .
*/
function twentyeleven_option_page_capability ( $capability ) {
return 'edit_theme_options' ;
}
add_filter ( 'option_page_capability_twentyeleven_options' , 'twentyeleven_option_page_capability' );
2011-04-27 00:52:18 +02:00
/**
2013-09-25 18:50:11 +02:00
* Add a theme options page to the admin menu , including some help documentation .
2011-04-28 10:06:57 +02:00
*
* This function is attached to the admin_menu action hook .
*
* @ since Twenty Eleven 1.0
2011-04-27 00:52:18 +02:00
*/
2011-04-28 10:06:57 +02:00
function twentyeleven_theme_options_add_page () {
2011-06-01 21:28:42 +02:00
$theme_page = add_theme_page (
2020-01-29 01:45:18 +01:00
__ ( 'Theme Options' , 'twentyeleven' ), // Name of page.
__ ( 'Theme Options' , 'twentyeleven' ), // Label in menu.
'edit_theme_options' , // Capability required.
'theme_options' , // Menu slug, used to uniquely identify the page.
'twentyeleven_theme_options_render_page' // Function that renders the options page.
2011-04-28 10:06:57 +02:00
);
2011-06-04 00:37:13 +02:00
2017-12-01 00:11:00 +01:00
if ( ! $theme_page ) {
2011-06-04 00:37:13 +02:00
return ;
2017-12-01 00:11:00 +01:00
}
2011-06-04 00:37:13 +02:00
2019-08-22 21:08:55 +02:00
add_action ( " load- { $theme_page } " , 'twentyeleven_theme_options_help' );
2011-11-10 15:01:46 +01:00
}
add_action ( 'admin_menu' , 'twentyeleven_theme_options_add_page' );
function twentyeleven_theme_options_help () {
2011-12-10 19:31:44 +01:00
$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, Twenty Eleven, provides the following Theme Options:' , 'twentyeleven' ) . '</p>' .
2011-06-01 21:28:42 +02:00
'<ol>' .
2011-06-10 19:13:23 +02:00
'<li>' . __ ( '<strong>Color Scheme</strong>: You can choose a color palette of "Light" (light background with dark text) or "Dark" (dark background with light text) for your site.' , 'twentyeleven' ) . '</li>' .
'<li>' . __ ( '<strong>Link Color</strong>: You can choose the color used for text links on your site. You can enter the HTML color or hex code, or you can choose visually by clicking the "Select a Color" button to pick from a color wheel.' , 'twentyeleven' ) . '</li>' .
'<li>' . __ ( '<strong>Default Layout</strong>: You can choose if you want your site’s default layout to have a sidebar on the left, the right, or not at all.' , 'twentyeleven' ) . '</li>' .
2011-06-01 21:28:42 +02:00
'</ol>' .
2011-12-10 19:31:44 +01:00
'<p>' . __ ( 'Remember to click "Save Changes" to save any changes you have made to the theme options.' , 'twentyeleven' ) . '</p>' ;
2011-06-01 21:28:42 +02:00
2011-12-10 19:31:44 +01:00
$sidebar = '<p><strong>' . __ ( 'For more information:' , 'twentyeleven' ) . '</strong></p>' .
2023-02-23 12:06:19 +01:00
'<p>' . __ ( '<a href="https://wordpress.org/documentation/article/customizer/" target="_blank">Documentation on Theme Customization</a>' , 'twentyeleven' ) . '</p>' .
'<p>' . __ ( '<a href="https://wordpress.org/support/forums/" target="_blank">Support forums</a>' , 'twentyeleven' ) . '</p>' ;
2011-12-10 19:31:44 +01:00
$screen = get_current_screen ();
if ( method_exists ( $screen , 'add_help_tab' ) ) {
2020-01-29 01:45:18 +01:00
// WordPress 3.3.0.
2017-12-01 00:11:00 +01:00
$screen -> add_help_tab (
array (
'title' => __ ( 'Overview' , 'twentyeleven' ),
'id' => 'theme-options-help' ,
'content' => $help ,
2011-12-10 19:31:44 +01:00
)
);
$screen -> set_help_sidebar ( $sidebar );
} else {
2020-01-29 01:45:18 +01:00
// WordPress 3.2.0.
2011-12-10 19:31:44 +01:00
add_contextual_help ( $screen , $help . $sidebar );
}
2011-04-27 00:52:18 +02:00
}
/**
2013-09-25 18:50:11 +02:00
* Return an array of color schemes registered for Twenty Eleven .
2011-04-28 10:06:57 +02:00
*
* @ since Twenty Eleven 1.0
2011-04-27 00:52:18 +02:00
*/
function twentyeleven_color_schemes () {
$color_scheme_options = array (
'light' => array (
2017-12-01 00:11:00 +01:00
'value' => 'light' ,
'label' => __ ( 'Light' , 'twentyeleven' ),
'thumbnail' => get_template_directory_uri () . '/inc/images/light.png' ,
2011-06-08 19:39:12 +02:00
'default_link_color' => '#1b8be0' ,
2011-04-27 00:52:18 +02:00
),
2017-12-01 00:11:00 +01:00
'dark' => array (
'value' => 'dark' ,
'label' => __ ( 'Dark' , 'twentyeleven' ),
'thumbnail' => get_template_directory_uri () . '/inc/images/dark.png' ,
2011-06-08 19:39:12 +02:00
'default_link_color' => '#e4741f' ,
2011-04-27 00:52:18 +02:00
),
);
2013-09-25 18:50:11 +02:00
/**
2020-08-11 02:34:08 +02:00
* Filters the Twenty Eleven color scheme options .
2013-09-25 18:50:11 +02:00
*
* @ since Twenty Eleven 1.0
*
* @ param array $color_scheme_options An associative array of color scheme options .
*/
2011-04-28 10:06:57 +02:00
return apply_filters ( 'twentyeleven_color_schemes' , $color_scheme_options );
2011-04-27 00:52:18 +02:00
}
/**
2013-09-25 18:50:11 +02:00
* Return an array of layout options registered for Twenty Eleven .
2011-04-28 10:06:57 +02:00
*
* @ since Twenty Eleven 1.0
2011-04-27 00:52:18 +02:00
*/
function twentyeleven_layouts () {
$layout_options = array (
'content-sidebar' => array (
2017-12-01 00:11:00 +01:00
'value' => 'content-sidebar' ,
'label' => __ ( 'Content on left' , 'twentyeleven' ),
2011-04-28 10:59:42 +02:00
'thumbnail' => get_template_directory_uri () . '/inc/images/content-sidebar.png' ,
2011-04-27 00:52:18 +02:00
),
'sidebar-content' => array (
2017-12-01 00:11:00 +01:00
'value' => 'sidebar-content' ,
'label' => __ ( 'Content on right' , 'twentyeleven' ),
2011-04-28 10:59:42 +02:00
'thumbnail' => get_template_directory_uri () . '/inc/images/sidebar-content.png' ,
2011-04-27 00:52:18 +02:00
),
2017-12-01 00:11:00 +01:00
'content' => array (
'value' => 'content' ,
'label' => __ ( 'One-column, no sidebar' , 'twentyeleven' ),
2011-04-28 10:59:42 +02:00
'thumbnail' => get_template_directory_uri () . '/inc/images/content.png' ,
2011-04-27 00:52:18 +02:00
),
);
2013-09-25 18:50:11 +02:00
/**
2020-08-11 02:34:08 +02:00
* Filters the Twenty Eleven layout options .
2013-09-25 18:50:11 +02:00
*
* @ since Twenty Eleven 1.0
*
* @ param array $layout_options An associative array of layout options .
*/
2011-04-28 10:06:57 +02:00
return apply_filters ( 'twentyeleven_layouts' , $layout_options );
2011-04-27 00:52:18 +02:00
}
/**
2013-09-25 18:50:11 +02:00
* Return the default options for Twenty Eleven .
2011-04-28 10:06:57 +02:00
*
* @ since Twenty Eleven 1.0
2013-09-25 18:50:11 +02:00
*
* @ return array An array of default theme options .
2011-04-27 00:52:18 +02:00
*/
2011-04-28 01:03:27 +02:00
function twentyeleven_get_default_theme_options () {
2011-04-28 10:06:57 +02:00
$default_theme_options = array (
2011-04-27 00:52:18 +02:00
'color_scheme' => 'light' ,
2011-06-08 19:39:12 +02:00
'link_color' => twentyeleven_get_default_link_color ( 'light' ),
2011-04-27 00:52:18 +02:00
'theme_layout' => 'content-sidebar' ,
);
2011-04-28 10:06:57 +02:00
2017-12-01 00:11:00 +01:00
if ( is_rtl () ) {
2015-01-22 01:42:23 +01:00
$default_theme_options [ 'theme_layout' ] = 'sidebar-content' ;
2017-12-01 00:11:00 +01:00
}
2011-06-25 22:24:07 +02:00
2013-09-25 18:50:11 +02:00
/**
2020-08-11 02:34:08 +02:00
* Filters the Twenty Eleven default options .
2013-09-25 18:50:11 +02:00
*
* @ since Twenty Eleven 1.0
*
* @ param array $default_theme_options An array of default theme options .
*/
2011-04-28 10:06:57 +02:00
return apply_filters ( 'twentyeleven_default_theme_options' , $default_theme_options );
2011-04-28 01:03:27 +02:00
}
2011-06-08 19:39:12 +02:00
/**
2013-09-25 18:50:11 +02:00
* Return the default link color for Twenty Eleven , based on color scheme .
2011-06-08 19:39:12 +02:00
*
* @ since Twenty Eleven 1.0
*
2013-09-25 18:50:11 +02:00
* @ param string $color_scheme Optional . Color scheme .
* Default null ( or the active color scheme ) .
* @ return string The default link color .
2017-12-01 00:11:00 +01:00
*/
2011-06-08 19:39:12 +02:00
function twentyeleven_get_default_link_color ( $color_scheme = null ) {
if ( null === $color_scheme ) {
2017-12-01 00:11:00 +01:00
$options = twentyeleven_get_theme_options ();
2011-06-08 19:39:12 +02:00
$color_scheme = $options [ 'color_scheme' ];
}
$color_schemes = twentyeleven_color_schemes ();
2017-12-01 00:11:00 +01:00
if ( ! isset ( $color_schemes [ $color_scheme ] ) ) {
2011-06-08 19:39:12 +02:00
return false ;
2017-12-01 00:11:00 +01:00
}
2011-06-08 19:39:12 +02:00
return $color_schemes [ $color_scheme ][ 'default_link_color' ];
}
2011-04-28 01:03:27 +02:00
/**
2013-09-25 18:50:11 +02:00
* Return the options array for Twenty Eleven .
2011-04-28 10:06:57 +02:00
*
* @ since Twenty Eleven 1.0
2011-04-28 01:03:27 +02:00
*/
function twentyeleven_get_theme_options () {
2011-06-05 21:53:31 +02:00
return get_option ( 'twentyeleven_theme_options' , twentyeleven_get_default_theme_options () );
2011-04-27 00:52:18 +02:00
}
2011-07-21 23:37:31 +02:00
/**
2013-09-25 18:50:11 +02:00
* Render the Color Scheme setting field .
2011-12-02 05:31:01 +01:00
*
2011-07-21 23:44:47 +02:00
* @ since Twenty Eleven 1.3
2011-07-21 23:37:31 +02:00
*/
function twentyeleven_settings_field_color_scheme () {
$options = twentyeleven_get_theme_options ();
foreach ( twentyeleven_color_schemes () as $scheme ) {
2018-08-17 03:51:36 +02:00
?>
2011-07-21 23:37:31 +02:00
< div class = " layout image-radio-option color-scheme " >
< label class = " description " >
< input type = " radio " name = " twentyeleven_theme_options[color_scheme] " value = " <?php echo esc_attr( $scheme['value'] ); ?> " < ? php checked ( $options [ 'color_scheme' ], $scheme [ 'value' ] ); ?> />
< input type = " hidden " id = " default-color-<?php echo esc_attr( $scheme['value'] ); ?> " value = " <?php echo esc_attr( $scheme['default_link_color'] ); ?> " />
< span >
< img src = " <?php echo esc_url( $scheme['thumbnail'] ); ?> " width = " 136 " height = " 122 " alt = " " />
2015-01-22 01:42:23 +01:00
< ? php echo esc_html ( $scheme [ 'label' ] ); ?>
2011-07-21 23:37:31 +02:00
</ span >
</ label >
</ div >
2018-08-17 03:51:36 +02:00
< ? php
2011-07-21 23:37:31 +02:00
}
}
/**
2013-09-25 18:50:11 +02:00
* Render the Link Color setting field .
2011-12-02 05:31:01 +01:00
*
2011-07-21 23:44:47 +02:00
* @ since Twenty Eleven 1.3
2011-07-21 23:37:31 +02:00
*/
function twentyeleven_settings_field_link_color () {
$options = twentyeleven_get_theme_options ();
?>
< input type = " text " name = " twentyeleven_theme_options[link_color] " id = " link-color " value = " <?php echo esc_attr( $options['link_color'] ); ?> " />
< a href = " # " class = " pickcolor hide-if-no-js " id = " link-color-example " ></ a >
< input type = " button " class = " pickcolor button hide-if-no-js " value = " <?php esc_attr_e( 'Select a Color', 'twentyeleven' ); ?> " />
< div id = " colorPickerDiv " style = " z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none; " ></ div >
< br />
2019-07-05 10:04:57 +02:00
< span >
< ? php
2019-09-03 02:41:05 +02:00
/* translators: %s: Link color. */
2019-07-05 10:04:57 +02:00
printf ( __ ( 'Default color: %s' , 'twentyeleven' ), '<span id="default-color">' . twentyeleven_get_default_link_color ( $options [ 'color_scheme' ] ) . '</span>' );
?>
</ span >
2011-07-21 23:37:31 +02:00
< ? php
}
/**
2013-09-25 18:50:11 +02:00
* Render the Layout setting field .
2011-12-02 05:31:01 +01:00
*
2011-07-21 23:44:47 +02:00
* @ since Twenty Eleven 1.3
2011-07-21 23:37:31 +02:00
*/
function twentyeleven_settings_field_layout () {
$options = twentyeleven_get_theme_options ();
foreach ( twentyeleven_layouts () as $layout ) {
?>
< div class = " layout image-radio-option theme-layout " >
< label class = " description " >
< input type = " radio " name = " twentyeleven_theme_options[theme_layout] " value = " <?php echo esc_attr( $layout['value'] ); ?> " < ? php checked ( $options [ 'theme_layout' ], $layout [ 'value' ] ); ?> />
< span >
< img src = " <?php echo esc_url( $layout['thumbnail'] ); ?> " width = " 136 " height = " 122 " alt = " " />
2015-01-22 01:42:23 +01:00
< ? php echo esc_html ( $layout [ 'label' ] ); ?>
2011-07-21 23:37:31 +02:00
</ span >
</ label >
</ div >
< ? php
}
}
2011-04-27 00:52:18 +02:00
/**
2014-05-02 02:43:16 +02:00
* Render the theme options page for Twenty Eleven .
2011-04-28 10:06:57 +02:00
*
2011-07-11 22:15:37 +02:00
* @ since Twenty Eleven 1.2
2011-04-27 00:52:18 +02:00
*/
2011-07-11 22:15:37 +02:00
function twentyeleven_theme_options_render_page () {
Twenty Eleven: Replace deprecated function calls on theme options page.
This includes:
* Removing the deprecated `screen_icon()` function call.
* Replacing the deprecated `get_current_theme()` function call with `get_option( 'current_theme' )`.
* Using `wp_get_theme()->display( 'Name' )` explicitly instead of relying on `WP_Theme`'s `__toString()` method, for clarity.
Follow-up to [6334], [20039], [20040], [20042], [20508], [26537], [41274].
Props Presskopp, cu121, viralsampat, costdev, tomjdv, sabernhardt, SergeyBiryukov.
Fixes #54833.
Built from https://develop.svn.wordpress.org/trunk@53626
git-svn-id: http://core.svn.wordpress.org/trunk@53185 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-01 16:26:15 +02:00
$theme_name = function_exists ( 'wp_get_theme' ) ? wp_get_theme () -> display ( 'Name' ) : get_option ( 'current_theme' );
2011-04-27 00:52:18 +02:00
?>
< div class = " wrap " >
2019-07-05 10:04:57 +02:00
< h2 >
< ? php
2019-09-03 02:41:05 +02:00
/* translators: %s: Theme name. */
2019-07-05 10:04:57 +02:00
printf ( __ ( '%s Theme Options' , 'twentyeleven' ), $theme_name );
?>
</ h2 >
2011-04-28 10:06:57 +02:00
< ? php settings_errors (); ?>
2011-04-27 00:52:18 +02:00
< form method = " post " action = " options.php " >
2011-04-28 10:06:57 +02:00
< ? php
settings_fields ( 'twentyeleven_options' );
2011-07-21 23:37:31 +02:00
do_settings_sections ( 'theme_options' );
submit_button ();
?>
2011-04-27 00:52:18 +02:00
</ form >
</ div >
< ? php
}
/**
2013-09-25 18:50:11 +02:00
* Sanitize and validate form input .
*
* Accepts an array , return a sanitized array .
2011-04-28 01:03:27 +02:00
*
2011-04-28 10:06:57 +02:00
* @ see twentyeleven_theme_options_init ()
* @ todo set up Reset Options action
*
2011-04-28 10:52:37 +02:00
* @ since Twenty Eleven 1.0
2013-09-25 18:50:11 +02:00
*
* @ param array $input An array of form input .
2011-04-27 00:52:18 +02:00
*/
function twentyeleven_theme_options_validate ( $input ) {
2019-07-01 10:23:57 +02:00
$defaults = twentyeleven_get_default_theme_options ();
$output = $defaults ;
2011-04-28 01:03:27 +02:00
2020-01-29 01:45:18 +01:00
// Color scheme must be in our array of color scheme options.
2017-12-01 00:11:00 +01:00
if ( isset ( $input [ 'color_scheme' ] ) && array_key_exists ( $input [ 'color_scheme' ], twentyeleven_color_schemes () ) ) {
2011-04-28 10:06:57 +02:00
$output [ 'color_scheme' ] = $input [ 'color_scheme' ];
2017-12-01 00:11:00 +01:00
}
2011-06-11 17:44:06 +02:00
// Our defaults for the link color may have changed, based on the color scheme.
2019-07-01 10:23:57 +02:00
$defaults [ 'link_color' ] = twentyeleven_get_default_link_color ( $output [ 'color_scheme' ] );
$output [ 'link_color' ] = $defaults [ 'link_color' ];
2011-04-28 01:03:27 +02:00
2020-01-29 01:45:18 +01:00
// Link color must be 3 or 6 hexadecimal characters.
2017-12-01 00:11:00 +01:00
if ( isset ( $input [ 'link_color' ] ) && preg_match ( '/^#?([a-f0-9]{3}){1,2}$/i' , $input [ 'link_color' ] ) ) {
2011-06-11 01:01:16 +02:00
$output [ 'link_color' ] = '#' . strtolower ( ltrim ( $input [ 'link_color' ], '#' ) );
2017-12-01 00:11:00 +01:00
}
2011-04-27 00:52:18 +02:00
2020-01-29 01:45:18 +01:00
// Theme layout must be in our array of theme layout options.
2017-12-01 00:11:00 +01:00
if ( isset ( $input [ 'theme_layout' ] ) && array_key_exists ( $input [ 'theme_layout' ], twentyeleven_layouts () ) ) {
2011-04-28 10:06:57 +02:00
$output [ 'theme_layout' ] = $input [ 'theme_layout' ];
2017-12-01 00:11:00 +01:00
}
2011-04-27 00:52:18 +02:00
2013-09-25 18:50:11 +02:00
/**
2020-08-11 02:34:08 +02:00
* Filters the Twenty Eleven sanitized form input array .
2013-09-25 18:50:11 +02:00
*
* @ since Twenty Eleven 1.0
*
* @ param array $output An array of sanitized form output .
* @ param array $input An array of un - sanitized form input .
* @ param array $defaults An array of default theme options .
*/
2011-04-28 10:52:37 +02:00
return apply_filters ( 'twentyeleven_theme_options_validate' , $output , $input , $defaults );
2011-04-27 00:52:18 +02:00
}
/**
2011-04-28 10:52:37 +02:00
* Enqueue the styles for the current color scheme .
*
* @ since Twenty Eleven 1.0
2011-04-27 00:52:18 +02:00
*/
2011-04-28 13:05:53 +02:00
function twentyeleven_enqueue_color_scheme () {
2017-12-01 00:11:00 +01:00
$options = twentyeleven_get_theme_options ();
2011-04-28 10:06:57 +02:00
$color_scheme = $options [ 'color_scheme' ];
2011-04-27 00:52:18 +02:00
2020-05-16 20:42:12 +02:00
if ( 'dark' === $color_scheme ) {
2019-08-08 03:25:58 +02:00
wp_enqueue_style ( 'dark' , get_template_directory_uri () . '/colors/dark.css' , array (), '20190404' );
2017-12-01 00:11:00 +01:00
}
2011-04-27 00:52:18 +02:00
2013-09-25 18:50:11 +02:00
/**
* Fires after the styles for the Twenty Eleven color scheme are enqueued .
*
* @ since Twenty Eleven 1.0
*
* @ param string $color_scheme The color scheme .
*/
2011-04-28 13:05:53 +02:00
do_action ( 'twentyeleven_enqueue_color_scheme' , $color_scheme );
2011-04-27 00:52:18 +02:00
}
2011-04-28 13:05:53 +02:00
add_action ( 'wp_enqueue_scripts' , 'twentyeleven_enqueue_color_scheme' );
2011-04-27 00:52:18 +02:00
/**
2011-04-28 10:06:57 +02:00
* Add a style block to the theme for the current link color .
*
* This function is attached to the wp_head action hook .
2011-04-27 00:52:18 +02:00
*
* @ since Twenty Eleven 1.0
*/
2011-04-28 13:05:53 +02:00
function twentyeleven_print_link_color_style () {
2017-12-01 00:11:00 +01:00
$options = twentyeleven_get_theme_options ();
2011-04-28 10:06:57 +02:00
$link_color = $options [ 'link_color' ];
$default_options = twentyeleven_get_default_theme_options ();
2011-04-28 21:01:51 +02:00
2011-04-28 10:06:57 +02:00
// Don't do anything if the current link color is the default.
2023-02-24 07:23:23 +01:00
if ( $default_options [ 'link_color' ] === $link_color ) {
2011-04-28 10:06:57 +02:00
return ;
2017-12-01 00:11:00 +01:00
}
2018-08-17 03:51:36 +02:00
?>
2011-04-28 10:06:57 +02:00
< style >
/* Link color */
a ,
2011-05-26 20:41:35 +02:00
#site-title a:focus,
#site-title a:hover,
#site-title a:active,
2011-04-29 00:04:39 +02:00
. entry - title a : hover ,
2011-05-26 20:41:35 +02:00
. entry - title a : focus ,
. entry - title a : active ,
2011-04-29 00:04:39 +02:00
. widget_twentyeleven_ephemera . comments - link a : hover ,
section . recent - posts . other - recent - posts a [ rel = " bookmark " ] : hover ,
2011-05-05 00:54:50 +02:00
section . recent - posts . other - recent - posts . comments - link a : hover ,
2011-05-13 01:13:56 +02:00
. format - image footer . entry - meta a : hover ,
#site-generator a:hover {
2011-04-28 10:06:57 +02:00
color : < ? php echo $link_color ; ?> ;
}
2011-04-29 00:04:39 +02:00
section . recent - posts . other - recent - posts . comments - link a : hover {
border - color : < ? php echo $link_color ; ?> ;
2011-06-11 17:44:06 +02:00
}
2011-05-30 03:29:55 +02:00
article . feature - image . small . entry - summary p a : hover ,
. entry - header . comments - link a : hover ,
. entry - header . comments - link a : focus ,
2011-06-07 23:28:56 +02:00
. entry - header . comments - link a : active ,
. feature - slider a . active {
2011-06-11 01:10:23 +02:00
background - color : < ? php echo $link_color ; ?> ;
2011-05-30 03:29:55 +02:00
}
2011-04-28 10:06:57 +02:00
</ style >
2018-08-17 03:51:36 +02:00
< ? php
2011-04-27 00:52:18 +02:00
}
2011-04-28 13:05:53 +02:00
add_action ( 'wp_head' , 'twentyeleven_print_link_color_style' );
2011-04-27 00:52:18 +02:00
/**
2013-09-25 18:50:11 +02:00
* Add Twenty Eleven layout classes to the array of body classes .
2011-04-27 00:52:18 +02:00
*
* @ since Twenty Eleven 1.0
2013-09-25 18:50:11 +02:00
*
* @ param array $existing_classes An array of existing body classes .
2011-04-27 00:52:18 +02:00
*/
2011-04-28 13:05:53 +02:00
function twentyeleven_layout_classes ( $existing_classes ) {
2017-12-01 00:11:00 +01:00
$options = twentyeleven_get_theme_options ();
2011-04-28 10:06:57 +02:00
$current_layout = $options [ 'theme_layout' ];
2020-04-05 05:02:11 +02:00
if ( in_array ( $current_layout , array ( 'content-sidebar' , 'sidebar-content' ), true ) ) {
2011-04-28 13:05:53 +02:00
$classes = array ( 'two-column' );
2017-12-01 00:11:00 +01:00
} else {
2011-04-28 13:05:53 +02:00
$classes = array ( 'one-column' );
2017-12-01 00:11:00 +01:00
}
2011-04-28 10:06:57 +02:00
2020-05-16 20:42:12 +02:00
if ( 'content-sidebar' === $current_layout ) {
2011-06-25 22:24:07 +02:00
$classes [] = 'right-sidebar' ;
2020-05-16 20:42:12 +02:00
} elseif ( 'sidebar-content' === $current_layout ) {
2011-06-25 22:24:07 +02:00
$classes [] = 'left-sidebar' ;
2017-12-01 00:11:00 +01:00
} else {
2011-06-25 22:24:07 +02:00
$classes [] = $current_layout ;
2017-12-01 00:11:00 +01:00
}
2011-04-28 10:06:57 +02:00
2013-09-25 18:50:11 +02:00
/**
2020-08-11 02:34:08 +02:00
* Filters the Twenty Eleven layout body classes .
2013-09-25 18:50:11 +02:00
*
* @ since Twenty Eleven 1.0
*
* @ param array $classes An array of body classes .
* @ param string $current_layout The current theme layout .
*/
2011-04-28 13:05:53 +02:00
$classes = apply_filters ( 'twentyeleven_layout_classes' , $classes , $current_layout );
2011-04-27 00:52:18 +02:00
2011-04-28 13:05:53 +02:00
return array_merge ( $existing_classes , $classes );
2011-04-27 00:52:18 +02:00
}
2012-05-25 23:50:01 +02:00
add_filter ( 'body_class' , 'twentyeleven_layout_classes' );
/**
2014-10-15 19:21:19 +02:00
* Implements Twenty Eleven theme options into Customizer
2012-05-25 23:50:01 +02:00
*
2013-09-25 18:50:11 +02:00
* @ since Twenty Eleven 1.3
*
2020-10-17 18:05:09 +02:00
* @ param WP_Customize_Manager $wp_customize Customizer object .
2012-05-25 23:50:01 +02:00
*/
function twentyeleven_customize_register ( $wp_customize ) {
2017-12-01 00:11:00 +01:00
$wp_customize -> get_setting ( 'blogname' ) -> transport = 'postMessage' ;
$wp_customize -> get_setting ( 'blogdescription' ) -> transport = 'postMessage' ;
2015-04-01 23:42:27 +02:00
$wp_customize -> get_setting ( 'header_textcolor' ) -> transport = 'postMessage' ;
2012-05-25 23:50:01 +02:00
2016-03-01 23:18:26 +01:00
if ( isset ( $wp_customize -> selective_refresh ) ) {
2017-12-01 00:11:00 +01:00
$wp_customize -> selective_refresh -> add_partial (
2018-08-17 03:51:36 +02:00
'blogname' ,
array (
2017-12-01 00:11:00 +01:00
'selector' => '#site-title a' ,
'container_inclusive' => false ,
'render_callback' => 'twentyeleven_customize_partial_blogname' ,
)
);
$wp_customize -> selective_refresh -> add_partial (
2018-08-17 03:51:36 +02:00
'blogdescription' ,
array (
2017-12-01 00:11:00 +01:00
'selector' => '#site-description' ,
'container_inclusive' => false ,
'render_callback' => 'twentyeleven_customize_partial_blogdescription' ,
)
);
2016-03-01 23:18:26 +01:00
}
2012-05-25 23:50:01 +02:00
$options = twentyeleven_get_theme_options ();
$defaults = twentyeleven_get_default_theme_options ();
2017-12-01 00:11:00 +01:00
$wp_customize -> add_setting (
2018-08-17 03:51:36 +02:00
'twentyeleven_theme_options[color_scheme]' ,
array (
2017-12-01 00:11:00 +01:00
'default' => $defaults [ 'color_scheme' ],
'type' => 'option' ,
'capability' => 'edit_theme_options' ,
)
);
2012-05-25 23:50:01 +02:00
$schemes = twentyeleven_color_schemes ();
$choices = array ();
foreach ( $schemes as $scheme ) {
$choices [ $scheme [ 'value' ] ] = $scheme [ 'label' ];
}
2017-12-01 00:11:00 +01:00
$wp_customize -> add_control (
2018-08-17 03:51:36 +02:00
'twentyeleven_color_scheme' ,
array (
2017-12-01 00:11:00 +01:00
'label' => __ ( 'Color Scheme' , 'twentyeleven' ),
'section' => 'colors' ,
'settings' => 'twentyeleven_theme_options[color_scheme]' ,
'type' => 'radio' ,
'choices' => $choices ,
'priority' => 5 ,
)
);
2012-05-25 23:50:01 +02:00
2020-01-29 01:45:18 +01:00
// Link Color (added to Color Scheme section in Customizer).
2017-12-01 00:11:00 +01:00
$wp_customize -> add_setting (
2018-08-17 03:51:36 +02:00
'twentyeleven_theme_options[link_color]' ,
array (
2017-12-01 00:11:00 +01:00
'default' => twentyeleven_get_default_link_color ( $options [ 'color_scheme' ] ),
'type' => 'option' ,
'sanitize_callback' => 'sanitize_hex_color' ,
'capability' => 'edit_theme_options' ,
)
);
$wp_customize -> add_control (
new WP_Customize_Color_Control (
2018-08-17 03:51:36 +02:00
$wp_customize ,
'link_color' ,
array (
2017-12-01 00:11:00 +01:00
'label' => __ ( 'Link Color' , 'twentyeleven' ),
'section' => 'colors' ,
'settings' => 'twentyeleven_theme_options[link_color]' ,
)
)
);
2012-05-25 23:50:01 +02:00
2020-01-29 01:45:18 +01:00
// Default Layout.
2017-12-01 00:11:00 +01:00
$wp_customize -> add_section (
2018-08-17 03:51:36 +02:00
'twentyeleven_layout' ,
array (
2017-12-01 00:11:00 +01:00
'title' => __ ( 'Layout' , 'twentyeleven' ),
'priority' => 50 ,
)
);
2012-05-25 23:50:01 +02:00
2017-12-01 00:11:00 +01:00
$wp_customize -> add_setting (
2018-08-17 03:51:36 +02:00
'twentyeleven_theme_options[theme_layout]' ,
array (
2017-12-01 00:11:00 +01:00
'type' => 'option' ,
'default' => $defaults [ 'theme_layout' ],
'sanitize_callback' => 'sanitize_key' ,
)
);
2012-05-25 23:50:01 +02:00
$layouts = twentyeleven_layouts ();
$choices = array ();
foreach ( $layouts as $layout ) {
2015-01-22 01:42:23 +01:00
$choices [ $layout [ 'value' ] ] = $layout [ 'label' ];
2012-05-25 23:50:01 +02:00
}
2017-12-01 00:11:00 +01:00
$wp_customize -> add_control (
2018-08-17 03:51:36 +02:00
'twentyeleven_theme_options[theme_layout]' ,
array (
2017-12-01 00:11:00 +01:00
'section' => 'twentyeleven_layout' ,
'type' => 'radio' ,
'choices' => $choices ,
)
);
2012-05-25 23:50:01 +02:00
}
add_action ( 'customize_register' , 'twentyeleven_customize_register' );
2016-03-01 23:18:26 +01:00
/**
* Render the site title for the selective refresh partial .
*
* @ since Twenty Eleven 2.4
2020-06-16 23:07:14 +02:00
*
2016-03-01 23:18:26 +01:00
* @ see twentyeleven_customize_register ()
*
* @ return void
*/
function twentyeleven_customize_partial_blogname () {
bloginfo ( 'name' );
}
/**
* Render the site tagline for the selective refresh partial .
*
* @ since Twenty Eleven 2.4
2020-06-16 23:07:14 +02:00
*
2016-03-01 23:18:26 +01:00
* @ see twentyeleven_customize_register ()
*
* @ return void
*/
function twentyeleven_customize_partial_blogdescription () {
bloginfo ( 'description' );
}
2012-05-25 23:50:01 +02:00
/**
2014-10-15 19:21:19 +02:00
* Bind JS handlers to make Customizer preview reload changes asynchronously .
2013-09-25 18:50:11 +02:00
*
2012-05-25 23:50:01 +02:00
* Used with blogname and blogdescription .
*
* @ since Twenty Eleven 1.3
*/
function twentyeleven_customize_preview_js () {
2023-09-06 23:23:20 +02:00
wp_enqueue_script ( 'twentyeleven-customizer' , get_template_directory_uri () . '/inc/theme-customizer.js' , array ( 'customize-preview' ), '20150401' , array ( 'in_footer' => true ) );
2012-05-25 23:50:01 +02:00
}
2015-04-12 23:29:32 +02:00
add_action ( 'customize_preview_init' , 'twentyeleven_customize_preview_js' );