oFactory = $oFactory; $this->sClassName = $oFactory->oProp->sClassName; $this->sPageSlug = $sPageSlug; $this->sSectionID = $this->sTabSlug; $this->oFactory->addInPageTabs( $this->sPageSlug, array( 'tab_slug' => $this->sTabSlug, 'title' => 'Option', ) ); // load + page slug + tab slug add_action( 'load_' . $this->sPageSlug . '_' . $this->sTabSlug, array( $this, 'replyToLoadTab' ) ); } /** * Triggered when the tab starts loading. * * @callback add_action() load_{page slug}_{tab slug} */ public function replyToLoadTab( $oAdminPage ) { $oAdminPage->addSettingSection( array( 'section_id' => 'debug', ) ); /** * @var WP_Screen */ $_oWPScreen = get_current_screen(); $oAdminPage->addSettingFields( 'debug', array( 'field_id' => 'option_key', 'title' => 'Option Key', 'type' => 'text', 'description' => 'Enter an option key to inspect', ), array( 'field_id' => '_submit', 'save' => false, 'type' => 'submit', 'value' => 'Inspect' ), array( 'field_id' => 'option_keys', 'show_title_column' => false, 'type' => 'table', 'collapsible' => array( 'active' => false, ), 'caption' => 'Available Option Keys', ), array( 'field_id' => 'option_value', 'show_title_column' => false, 'type' => 'table', 'collapsible' => array( 'active' => true, ), 'caption' => 'Stored Option Value', ) ); add_filter( 'field_definition_' . $oAdminPage->oProp->sClassName . '_debug_option_keys', array( $this, 'replyToGetOptionKeys' ) ); add_filter( 'field_definition_' . $oAdminPage->oProp->sClassName . '_debug_option_value', array( $this, 'replyToGetOptionValue' ) ); } public function replyToGetOptionKeys( $aFieldset ) { /** * @var wpdb $_oWPDB */ $_oWPDB = $GLOBALS[ 'wpdb' ]; $_sQuery = <<options}` WHERE autoload='yes' UNION SELECT 'autoloaded data count', count(*) FROM `{$_oWPDB->options}` WHERE autoload='yes' UNION (SELECT option_name, length(option_value) FROM `{$_oWPDB->options}` WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 1000) SQLQUERY; $_aResults = $_oWPDB->get_results( $_sQuery, ARRAY_N ); $aFieldset[ 'data' ] = $_aResults; return $aFieldset; } /** * @param array $aFieldset * @return array */ public function replyToGetOptionValue( $aFieldset ) { $aFieldset[ 'caption' ] = 'Option Key: ' . $this->oFactory->getValue( 'debug', 'option_key' ) . ''; $aFieldset[ 'data' ] = get_option( $this->oFactory->getValue( 'debug', 'option_key' ) ); return $aFieldset; } }