* @license GPL-2.0+ * @link http://wptheming.com * @copyright 2013 WP Theming */ class Options_Framework_Admin { /** * Page hook for the options screen * * @since 1.7.0 * @type string */ protected $options_screen = null; /** * Hook in the scripts and styles * * @since 1.7.0 */ public function init() { // Gets options to load $options = & Options_Framework::_optionsframework_options(); // Checks if options are available if ( $options ) { // Add the options page and menu item. add_action( 'admin_menu', array( $this, 'add_dashboard_options_page' ) ); // Add the required scripts and styles add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); // Settings need to be registered after admin_init add_action( 'admin_init', array( $this, 'settings_init' ) ); // Adds options menu to the admin bar add_action( 'wp_before_admin_bar_render', array( $this, 'optionsframework_admin_bar' ) ); } } /** * Registers the settings * * @since 1.7.0 */ function settings_init() { // Load Options Framework Settings $optionsframework_settings = get_option( 'optionsframework' ); // Registers the settings fields and callback register_setting( 'optionsframework', $optionsframework_settings['id'], array ( $this, 'validate_options' ) ); // Displays notice after options save add_action( 'optionsframework_after_validate', array( $this, 'save_options_notice' ) ); } /* * Define menu options (still limited to appearance section) * * Examples usage: * * add_filter( 'optionsframework_menu', function( $menu ) { * $menu['page_title'] = 'The Options'; * $menu['menu_title'] = 'The Options'; * return $menu; * }); * * @since 1.7.0 * */ static function menu_settings() { $menu = array( 'page_title' => esc_html__( 'Theme Options', 'responsivo' ), 'menu_title' => esc_html__( 'Theme Options', 'responsivo' ), 'capability' => 'edit_theme_options', 'menu_slug' => 'options-framework' ); return apply_filters( 'optionsframework_menu', $menu ); } /** * Add a subpage called "Theme Options" to the appearance menu. * * @since 1.7.0 */ function add_dashboard_options_page() { $menu = $this->menu_settings(); $this->options_screen = add_theme_page( $menu['page_title'], $menu['menu_title'], $menu['capability'], $menu['menu_slug'], array( $this, 'options_page' ) ); } /** * Loads the required stylesheets * * @since 1.7.0 */ function enqueue_admin_styles() { wp_enqueue_style( 'optionsframework', OPTIONS_FRAMEWORK_DIRECTORY . 'css/optionsframework.css', array(), Options_Framework::VERSION ); wp_enqueue_style( 'wp-color-picker' ); } /** * Loads the required javascript * * @since 1.7.0 */ function enqueue_admin_scripts( $hook ) { $menu = $this->menu_settings(); if ( 'appearance_page_' . $menu['menu_slug'] != $hook ) return; // Enqueue custom option panel JS wp_enqueue_script( 'options-custom', OPTIONS_FRAMEWORK_DIRECTORY . 'js/options-custom.js', array( 'jquery','wp-color-picker' ), Options_Framework::VERSION ); // Inline scripts from options-interface.php add_action( 'admin_head', array( $this, 'of_admin_head' ) ); } function of_admin_head() { // Hook to add custom scripts do_action( 'optionsframework_custom_scripts' ); } /** * Builds out the options panel. * * If we were using the Settings API as it was intended we would use * do_settings_sections here. But as we don't want the settings wrapped in a table, * we'll call our own custom optionsframework_fields. See options-interface.php * for specifics on how each individual field is generated. * * Nonces are provided using the settings_fields() * * @since 1.7.0 */ function options_page() { ?>