page = $page_slug; $this->args = wp_parse_args( $args, array( 'parent' => 'options-general.php', 'title' => '', 'menu' => 'New Modern Page', 'callback' => array($this, 'not_set_callback'), 'validate' => array($this, 'validate_options'), 'permissions' => 'manage_options', 'tab_sections'=> null, 'columns' => 1, ) ); add_action('admin_menu', array($this,'_add_page')); add_action('admin_init', array($this,'register_option_page')); } function not_set_callback() { echo "Callback param not defined! @see more https://github.com/nikolays93/WPAdminPage"; } /** * Add page wordpress handle * * @see wordpress codex : add_submenu_page() */ function _add_page(){ $this->screen = add_submenu_page( $this->args['parent'], $this->args['title'], $this->args['menu'], $this->args['permissions'], $this->page, array($this,'render_page'), 10); add_action('load-'.$this->screen, array($this,'page_actions'),9); add_action('admin_footer-'.$this->screen, array($this,'footer_scripts')); } function _metabox(){ foreach ($this->metaboxes as $metabox) { extract($metabox); add_meta_box( $handle, $label, $render_cb, $this->screen, $position, $priority); } } public function add_metabox( $handle, $label, $render_cb, $position = 'normal', $priority = 'high'){ $this->metaboxes[] = array( 'handle' => $handle, 'label' => $label, 'render_cb' => $render_cb, 'position' => $position, 'priority' => $priority ); } public function set_metaboxes(){ add_action( 'add_meta_boxes', array($this, '_metabox') ); } /** * Init actions for created page */ function page_actions(){ add_action( $this->page . '_inside_page_content', array($this, 'page_render'), 10); add_action( $this->page . '_inside_side_container', array($this, 'side_render'), 10 ); add_action( $this->page . '_inside_normal_container', array($this, 'normal_render'), 10 ); add_action( $this->page . '_inside_advanced_container', array($this, 'advanced_render'), 10 ); do_action('add_meta_boxes_'.$this->screen, null); do_action('add_meta_boxes', $this->screen, null); add_screen_option('layout_columns', array( 'max' => $this->args['columns'], 'default' => $this->args['columns']) ); // Enqueue WordPress' script for handling the metaboxes wp_enqueue_script('postbox'); } function page_render(){ /** @ Experemental ! (tabs) */ if( is_array($this->args['callback']) && !empty($this->args['tab_sections']) ){ if (!empty($_GET['tab'])){ $current = $_GET['tab']; } else { reset($this->tab_sections); $current = key($this->tab_sections); } echo '