%s
', wp_kses_post( $title ) ); if ( ! empty( $text ) ) { $html .= sprintf( '- ';
foreach ( $features as $feature ) {
$html .= sprintf(
'
- %s ', wp_kses_post( $feature ) ); } $html .= '
menu_title ) ) { $this->menu_title = $this->page_title; } $this->hooks(); } /** * Add hooks to register the page and output content. * * @return void */ public function hooks() { add_action( 'admin_menu', array( $this, 'add_page' ) ); $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Only load if we are actually on the desired page. if ( $this->page_slug !== $page ) { return; } if ( ! current_user_can( $this->capability ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'insert-headers-and-footers' ) ); } remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); add_action( 'wpcode_admin_page', array( $this, 'output' ) ); add_action( 'wpcode_admin_page', array( $this, 'output_footer' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'page_scripts' ) ); add_filter( 'admin_body_class', array( $this, 'page_specific_body_class' ) ); add_filter( 'wpcode_admin_js_data', array( $this, 'maybe_add_library_data' ) ); add_action( 'admin_init', array( $this, 'maybe_redirect_to_click' ) ); $this->setup_views(); $this->set_current_view(); $this->page_hooks(); } /** * Get the post type for this page. * * @return string */ public function get_post_type() { return wpcode_get_post_type(); } /** * Override in child class to define page-specific hooks that will run only * after checks have been passed. * * @return void */ public function page_hooks() { } /** * Add the submenu page. * * @return void */ public function add_page() { add_submenu_page( 'wpcode', $this->page_title, $this->menu_title, $this->capability, $this->page_slug, array( wpcode()->admin_page_loader, 'admin_menu_page', ) ); } /** * If the page has views, this is where you should assign them to $this->views. * * @return void */ protected function setup_views() { } /** * Set the current view from the query param also checking it's a registered view for this page. * * @return void */ protected function set_current_view() { // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( ! isset( $_GET['view'] ) ) { return; } $view = sanitize_text_field( wp_unslash( $_GET['view'] ) ); // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( array_key_exists( $view, $this->views ) ) { $this->view = $view; } } /** * Output the page content. * * @return void */ public function output() { $this->output_header(); ?>
' . wp_kses_post( $description ) . '
'; } return $markup; } /** * Get an email field. * * @param string $id The id of the text field. * @param string $value The value of the text field. * @param string $description The description of the text field. * @param bool $wide Whether the text field should be wide. * * @return string */ public function get_input_email( $id, $value = '', $description = '', $wide = false ) { return $this->get_input_text( $id, $value, $description, $wide, 'email' ); } /** * Get an admin URL. * * @param string $path The path to append to the admin URL. * * @return string */ public function admin_url( $path ) { return admin_url( $path ); } }