X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/38ca813a0e312e2768e5b9519f0415cd0aa84781..refs/tags/wordpress-3.4:/wp-content/themes/twentyeleven/inc/theme-options.php diff --git a/wp-content/themes/twentyeleven/inc/theme-options.php b/wp-content/themes/twentyeleven/inc/theme-options.php index a2460b91..698f2a0b 100644 --- a/wp-content/themes/twentyeleven/inc/theme-options.php +++ b/wp-content/themes/twentyeleven/inc/theme-options.php @@ -31,21 +31,35 @@ add_action( 'admin_print_styles-appearance_page_theme_options', 'twentyeleven_ad * 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. - * * @since Twenty Eleven 1.0 */ function twentyeleven_theme_options_init() { - // If we have no options in the database, let's add them now. - if ( false === twentyeleven_get_theme_options() ) - add_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() ); - register_setting( - 'twentyeleven_options', // Options group, see settings_fields() call in theme_options_render_page() + '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() ); + + // Register our settings field group + add_settings_section( + '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() + ); + + // Register our individual settings fields + add_settings_field( + '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 + ); + + 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' ); } add_action( 'admin_init', 'twentyeleven_theme_options_init' ); @@ -77,30 +91,51 @@ add_filter( 'option_page_capability_twentyeleven_options', 'twentyeleven_option_ */ function twentyeleven_theme_options_add_page() { $theme_page = add_theme_page( - __( '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 - 'theme_options_render_page' // Function that renders the options page + __( '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 ); if ( ! $theme_page ) return; + add_action( "load-$theme_page", 'twentyeleven_theme_options_help' ); +} +add_action( 'admin_menu', 'twentyeleven_theme_options_add_page' ); + +function twentyeleven_theme_options_help() { + $help = '
' . __( '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' ) . '
' . '' . __( 'Remember to click "Save Changes" to save any changes you have made to the theme options.', 'twentyeleven' ) . '
' . - '' . __( 'For more information:', 'twentyeleven' ) . '
' . - '' . __( 'Documentation on Theme Options', 'twentyeleven' ) . '
' . - '' . __( 'Support Forums', 'twentyeleven' ) . '
'; - - add_contextual_help( $theme_page, $help ); + '' . __( 'Remember to click "Save Changes" to save any changes you have made to the theme options.', 'twentyeleven' ) . '
'; + + $sidebar = '' . __( 'For more information:', 'twentyeleven' ) . '
' . + '' . __( 'Documentation on Theme Options', 'twentyeleven' ) . '
' . + '' . __( 'Support Forums', 'twentyeleven' ) . '
'; + + $screen = get_current_screen(); + + if ( method_exists( $screen, 'add_help_tab' ) ) { + // WordPress 3.3 + $screen->add_help_tab( array( + 'title' => __( 'Overview', 'twentyeleven' ), + 'id' => 'theme-options-help', + 'content' => $help, + ) + ); + + $screen->set_help_sidebar( $sidebar ); + } else { + // WordPress 3.2 + add_contextual_help( $screen, $help . $sidebar ); + } } -add_action( 'admin_menu', 'twentyeleven_theme_options_add_page' ); /** * Returns an array of color schemes registered for Twenty Eleven. @@ -201,87 +236,88 @@ function twentyeleven_get_theme_options() { return get_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() ); } +/** + * Renders the Color Scheme setting field. + * + * @since Twenty Eleven 1.3 + */ +function twentyeleven_settings_field_color_scheme() { + $options = twentyeleven_get_theme_options(); + + foreach ( twentyeleven_color_schemes() as $scheme ) { + ?> +