option_key = get_stylesheet() . '_theme_options'; add_action( 'admin_init', array( $this, 'options_init' ) ); add_action( 'admin_menu', array( $this, 'add_page' ) ); add_action( 'customize_register', array( $this, 'customize_register' ) ); } /** * Register the form setting for our options array. * * This function is attached to the admin_init action hook. * * This call to register_setting() registers a validation callback, validate(), * which is used when the option is saved, to ensure that our option values are properly * formatted, and safe. * * @access public * * @return void */ public function options_init() { // Load our options for use in any method. $this->options = $this->get_theme_options(); // Register our option group. register_setting( 'twentytwelve_options', // Options group, see settings_fields() call in render_page() $this->option_key, // Database option, see get_theme_options() array( $this, 'validate' ) // The sanitization callback, see 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 add_page() ); // Register our individual settings fields. add_settings_field( 'enable_fonts', // Unique identifier for the field for this section __( 'Enable Web Fonts', 'twentytwelve' ), // Setting field label array( $this, 'settings_field_enable_fonts' ), // Function that renders the settings field 'theme_options', // Menu slug, used to uniquely identify the page; see add_page() 'general' // Settings section. Same as the first argument in the add_settings_section() above ); } /** * Add our theme options page to the admin menu. * * This function is attached to the admin_menu action hook. * * @access public * * @return void */ public function add_page() { $theme_page = add_theme_page( __( 'Theme Options', 'twentytwelve' ), // Name of page __( 'Theme Options', 'twentytwelve' ), // Label in menu 'edit_theme_options', // Capability required 'theme_options', // Menu slug, used to uniquely identify the page array( $this, 'render_page' ) // Function that renders the options page ); } /** * Returns the default options. * * @access public * * @return array */ public function get_default_theme_options() { $default_theme_options = array( 'enable_fonts' => false, ); return apply_filters( 'twentytwelve_default_theme_options', $default_theme_options ); } /** * Returns the options array. * * @access public * * @return array */ public function get_theme_options() { return get_option( $this->option_key, $this->get_default_theme_options() ); } /** * Renders the enable fonts checkbox setting field. * * @access public * * @return void */ public function settings_field_enable_fonts() { $options = $this->options; ?>