'', 'menu_title' => '', ); /** * Messages shown to the user. * * @var array */ protected $messages = array( 'warning_message' => '', ); /** * Actions used in this page. * * @var array */ protected $actions = array(); /** * Should the link to this page be displayed in the plugin list. Default false. * * @var bool */ protected $show_link_in_plugin_list = false; /** * Initialize and setup variables and attributes of the page. * * @return void */ abstract protected function initialize(); /** * Render body content. * * @return void */ abstract protected function render_body(); /** * BasePage constructor. * * @param string $plugin_file Path to the main plugin file. */ public function __construct( $plugin_file ) { $this->plugin_file = $plugin_file; $this->initialize(); } /** * Register the page. * * This function will be called in the `admin_menu` hook. */ public function register() { $this->register_page(); $this->register_hooks(); } /** * Register page as a submenu to the Bulk WP Menu. */ protected function register_page() { $hook_suffix = add_submenu_page( self::BULK_WP_MENU_SLUG, $this->label['page_title'], $this->label['menu_title'], $this->capability, $this->page_slug, array( $this, 'render_page' ) ); if ( false !== $hook_suffix ) { $this->hook_suffix = $hook_suffix; } } /** * Register hooks. */ protected function register_hooks() { add_filter( 'bd_action_nonce_check', array( $this, 'verify_nonce' ), 10, 2 ); add_action( "load-{$this->hook_suffix}", array( $this, 'setup_contextual_help' ) ); add_filter( 'bd_admin_help_tabs', array( $this, 'render_help_tab' ), 10, 2 ); add_action( "bd_admin_footer_for_{$this->page_slug}", array( $this, 'modify_admin_footer' ) ); if ( $this->show_link_in_plugin_list ) { add_filter( 'bd_plugin_action_links', array( $this, 'append_to_plugin_action_links' ) ); } } /** * Check for nonce before executing the action. * * @param bool $result The current result. * @param string $action Action name. * * @return bool True if nonce is verified, False otherwise. */ public function verify_nonce( $result, $action ) { /** * List of actions for page. * * @param array $actions Actions. * @param BasePage $page Page objects. * * @since 6.0.0 */ $page_actions = apply_filters( 'bd_page_actions', $this->actions, $this ); if ( in_array( $action, $page_actions, true ) ) { if ( check_admin_referer( "bd-{$this->page_slug}", "bd-{$this->page_slug}-nonce" ) ) { return true; } } return $result; } /** * Setup hooks for rendering contextual help. */ public function setup_contextual_help() { /** * Add contextual help for admin screens. * * @since 5.1 * * @param string Hook suffix of the current page. */ do_action( 'bd_add_contextual_help', $this->hook_suffix ); } /** * Modify help tabs for the current page. * * @param array $help_tabs Current list of help tabs. * @param string $hook_suffix Hook Suffix of the page. * * @return array Modified list of help tabs. */ public function render_help_tab( $help_tabs, $hook_suffix ) { if ( $this->hook_suffix === $hook_suffix ) { $help_tabs = $this->add_help_tab( $help_tabs ); } return $help_tabs; } /** * Add help tabs. * * Help tabs can be added by overriding this function in the child class. * * @param array $help_tabs Current list of help tabs. * * @return array List of help tabs. */ protected function add_help_tab( $help_tabs ) { return $help_tabs; } /** * Render the page. */ public function render_page() { ?>
messages['warning_message'] ); ?>