cmb = $cmb; $this->option_key = $option_key; } public function hooks() { if ( empty( $this->option_key ) ) { return; } if ( ! $this->cmb->prop( 'autoload', true ) ) { // Disable option autoload if requested. add_filter( "cmb2_should_autoload_{$this->option_key}", '__return_false' ); } /** * For WP < 4.7. Ensure the register_setting function exists. */ if ( ! CMB2_Utils::wp_at_least( '4.7' ) && ! function_exists( 'register_setting' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // Register setting to cmb2 group. register_setting( 'cmb2', $this->option_key ); // Handle saving the data. add_action( 'admin_post_' . $this->option_key, array( $this, 'save_options' ) ); // Optionally network_admin_menu. $hook = $this->cmb->prop( 'admin_menu_hook' ); // Hook in to add our menu. add_action( $hook, array( $this, 'options_page_menu_hooks' ), $this->get_priority() ); // If in the network admin, need to use get/update_site_option. if ( 'network_admin_menu' === $hook ) { // Override CMB's getter. add_filter( "cmb2_override_option_get_{$this->option_key}", array( $this, 'network_get_override' ), 10, 2 ); // Override CMB's setter. add_filter( "cmb2_override_option_save_{$this->option_key}", array( $this, 'network_update_override' ), 10, 2 ); } } /** * Hook up our admin menu item and admin page. * * @since 2.2.5 * * @return void */ public function options_page_menu_hooks() { $parent_slug = $this->cmb->prop( 'parent_slug' ); $title = $this->cmb->prop( 'title' ); $menu_title = $this->cmb->prop( 'menu_title', $title ); $capability = $this->cmb->prop( 'capability' ); $callback = array( $this, 'options_page_output' ); if ( $parent_slug ) { $page_hook = add_submenu_page( $parent_slug, $title, $menu_title, $capability, $this->option_key, $callback ); } else { $page_hook = add_menu_page( $title, $menu_title, $capability, $this->option_key, $callback, $this->cmb->prop( 'icon_url' ), $this->cmb->prop( 'position' ) ); } if ( $this->cmb->prop( 'cmb_styles' ) ) { // Include CMB CSS in the head to avoid FOUC. add_action( "admin_print_styles-{$page_hook}", array( 'CMB2_Hookup', 'enqueue_cmb_css' ) ); } $this->maybe_register_message(); } /** * If there is a message callback, let it determine how to register the message, * else add a settings message if on this settings page. * * @since 2.2.6 * * @return void */ public function maybe_register_message() { $is_options_page = self::is_page( $this->option_key ); $should_notify = ! $this->cmb->prop( 'disable_settings_errors' ) && isset( $_GET['settings-updated'] ) && $is_options_page; $is_updated = $should_notify && 'true' === $_GET['settings-updated']; $setting = "{$this->option_key}-notices"; $code = ''; $message = __( 'Nothing to update.', 'cmb2' ); $type = 'notice-warning'; if ( $is_updated ) { $message = __( 'Settings updated.', 'cmb2' ); $type = 'updated'; } // Check if parameter has registered a callback. if ( $cb = $this->cmb->maybe_callback( 'message_cb' ) ) { /** * The 'message_cb' callback will receive the following parameters. * Unless there are other reasons for notifications, the callback should only * `add_settings_error()` if `$args['should_notify']` is truthy. * * @param CMB2 $cmb The CMB2 object. * @param array $args { * An array of message arguments * * @type bool $is_options_page Whether current page is this options page. * @type bool $should_notify Whether options were saved and we should be notified. * @type bool $is_updated Whether options were updated with save (or stayed the same). * @type string $setting For add_settings_error(), Slug title of the setting to which * this error applies. * @type string $code For add_settings_error(), Slug-name to identify the error. * Used as part of 'id' attribute in HTML output. * @type string $message For add_settings_error(), The formatted message text to display * to the user (will be shown inside styled `
` tags). * Will be 'Settings updated.' if $is_updated is true, else 'Nothing to update.' * @type string $type For add_settings_error(), Message type, controls HTML class. * Accepts 'error', 'updated', '', 'notice-warning', etc. * Will be 'updated' if $is_updated is true, else 'notice-warning'. * } */ $args = compact( 'is_options_page', 'should_notify', 'is_updated', 'setting', 'code', 'message', 'type' ); $this->cmb->do_callback( $cb, $args ); } elseif ( $should_notify ) { add_settings_error( $setting, $code, $message, $type ); } } /** * Display options-page output. To override, set 'display_cb' box property. * * @since 2.2.5 */ public function options_page_output() { $this->maybe_output_settings_notices(); $callback = $this->cmb->prop( 'display_cb' ); if ( is_callable( $callback ) ) { return call_user_func( $callback, $this ); } ?>
get_tab_group_tabs(); if ( empty( $tabs ) ) { return; } ?>