diff --git a/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php b/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php index 7b414c895..c62dc8ece 100644 --- a/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php +++ b/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php @@ -4,90 +4,132 @@ * * @package WordPress * @subpackage Twenty Eleven + * @since Twenty Eleven 1.0 */ -add_action( 'admin_init', 'theme_options_init' ); -add_action( 'admin_menu', 'theme_options_add_page' ); - /** - * Add theme options page styles and scripts + * 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 + * + * @param string $hook_suffix The action passes the current page to the function. We don't + * do anything if we're not on our theme options page. */ -wp_register_style( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.css', '', '0.1' ); -wp_register_script( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.js' ); -if ( isset( $_GET['page'] ) && $_GET['page'] == 'theme_options' ) { - wp_enqueue_style( 'twentyeleven-theme-options' ); - wp_enqueue_script( 'twentyeleven-theme-options' ); - wp_enqueue_script( 'farbtastic' ); +function twentyeleven_admin_enqueue_scripts( $hook_suffix ) { + if ( $hook_suffix != 'appearance_page_theme_options' ) + return; + + wp_enqueue_style( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.css', '', '0.1' ); + wp_enqueue_script( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.js' ); wp_enqueue_style( 'farbtastic' ); + wp_enqueue_script( 'farbtastic' ); } +add_action( 'admin_enqueue_scripts', 'twentyeleven_admin_enqueue_scripts' ); /** - * Init plugin options to white list our options + * 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 */ -function theme_options_init(){ +function twentyeleven_theme_options_init() { register_setting( 'twentyeleven_options', 'twentyeleven_theme_options', 'twentyeleven_theme_options_validate' ); } +add_action( 'admin_init', 'twentyeleven_theme_options_init' ); /** - * Load up the menu page + * Add our theme options page to the admin menu. + * + * This function is attached to the admin_menu action hook. + * + * @since Twenty Eleven 1.0 */ -function theme_options_add_page() { - add_theme_page( __( 'Theme Options', 'twentyeleven' ), __( 'Theme Options', 'twentyeleven' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' ); +function twentyeleven_theme_options_add_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 + ); } +add_action( 'admin_menu', 'twentyeleven_theme_options_add_page' ); /** - * Return array for our color schemes + * Returns an array of color schemes registered for Twenty Eleven. + * + * @since Twenty Eleven 1.0 */ function twentyeleven_color_schemes() { $color_scheme_options = array( 'light' => array( 'value' => 'light', - 'label' => __( 'Light', 'twentyeleven' ) + 'label' => __( 'Light', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/theme-options/images/light.png', ), 'dark' => array( 'value' => 'dark', - 'label' => __( 'Dark', 'twentyeleven' ) + 'label' => __( 'Dark', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/theme-options/images/dark.png', ), ); - return $color_scheme_options; + return apply_filters( 'twentyeleven_color_schemes', $color_scheme_options ); } /** - * Return array for our layout options + * Returns an array of layout options registered for Twenty Eleven. + * + * @since Twenty Eleven 1.0 */ function twentyeleven_layouts() { $layout_options = array( 'content-sidebar' => array( 'value' => 'content-sidebar', 'label' => __( 'Content on left', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/theme-options/images/content-sidebar.png', ), 'sidebar-content' => array( 'value' => 'sidebar-content', - 'label' => __( 'Content on right', 'twentyeleven' ) + 'label' => __( 'Content on right', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/theme-options/images/sidebar-content.png', ), 'content' => array( 'value' => 'content', - 'label' => __( 'One-column, no Sidebar', 'twentyeleven' ) + 'label' => __( 'One-column, no Sidebar', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/theme-options/images/content.png', ), ); - return $layout_options; + return apply_filters( 'twentyeleven_layouts', $layout_options ); } /** - * Return the default Twenty Eleven theme option values + * Returns the default options for Twenty Eleven. + * + * @since Twenty Eleven 1.0 */ function twentyeleven_get_default_theme_options() { - return array( + $default_theme_options = array( 'color_scheme' => 'light', 'link_color' => '#1b8be0', 'theme_layout' => 'content-sidebar', ); + + return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options ); } /** - * Return the current Twenty Eleven theme options, with default values as fallback + * Returns the options array for Twenty Eleven. + * + * @since Twenty Eleven 1.0 */ function twentyeleven_get_theme_options() { $defaults = twentyeleven_get_default_theme_options(); @@ -97,54 +139,38 @@ function twentyeleven_get_theme_options() { } /** - * Create the options page + * Returns the options array for Twenty Eleven. + * + * @since Twenty Eleven 1.0 */ -function theme_options_do_page() { - if ( ! isset( $_REQUEST['settings-updated'] ) ) - $_REQUEST['settings-updated'] = false; - +function theme_options_render_page() { ?>
- " . get_current_theme() . __( ' Theme Options', 'twentyeleven' ) . ""; ?> - - -

- + +

+
- - + - - -
@@ -155,51 +181,30 @@ function theme_options_do_page() {
- +
- +
@@ -211,120 +216,102 @@ function theme_options_do_page() {
-

- -

+
- - + +