public function admin_menu()
 {
     $this->user_created_pages = SerializeStringToArray(get_option($this->prefix('user_created_pages')));
     if ($this->user_created_pages && count($this->user_created_pages) >= 1) {
         foreach ($this->user_created_pages as $page) {
             if (isset($page['page_slug']) && isset($page['page_title']) && isset($page['parent_menu'])) {
                 if ($page['parent_menu'] == 'new_menu') {
                     add_menu_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'dashboard') {
                     add_dashboard_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'posts') {
                     add_posts_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'media') {
                     add_media_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'pages') {
                     add_pages_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'comments') {
                     add_comments_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'theme') {
                     add_theme_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'plugins') {
                     add_plugins_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'users') {
                     add_users_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'management') {
                     add_management_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif ($page['parent_menu'] == 'options') {
                     add_options_page($page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 } elseif (array_key_exists($page['parent_menu'], $user_pages)) {
                     add_submenu_page($page['parent_menu'], $page['page_title'], $page['page_title'], 'manage_options', $page['page_slug'], array($this, 'user_created_menu_pages'));
                 }
             }
         }
     }
 }
	function test_menu_page_url() {
		$current_user = get_current_user_id();
		wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
		update_option( 'siteurl', 'http://example.com' );

		// add some pages
		add_options_page( 'Test Settings', 'Test Settings', 'manage_options', 'testsettings', 'mt_settings_page' );
		add_management_page( 'Test Tools', 'Test Tools', 'manage_options', 'testtools', 'mt_tools_page' );
		add_menu_page( 'Test Toplevel', 'Test Toplevel', 'manage_options', 'mt-top-level-handle', 'mt_toplevel_page' );
		add_submenu_page( 'mt-top-level-handle', 'Test Sublevel', 'Test Sublevel', 'manage_options', 'sub-page', 'mt_sublevel_page' );
		add_submenu_page( 'mt-top-level-handle', 'Test Sublevel 2', 'Test Sublevel 2', 'manage_options', 'sub-page2', 'mt_sublevel_page2' );
		add_theme_page( 'With Spaces', 'With Spaces', 'manage_options', 'With Spaces', 'mt_tools_page' );
		add_pages_page( 'Appending Query Arg', 'Test Pages', 'edit_pages', 'testpages', 'mt_pages_page' );

		$expected['testsettings'] = 'http://example.com/wp-admin/options-general.php?page=testsettings';
		$expected['testtools'] = 'http://example.com/wp-admin/tools.php?page=testtools';
		$expected['mt-top-level-handle'] = 'http://example.com/wp-admin/admin.php?page=mt-top-level-handle';
		$expected['sub-page'] = 'http://example.com/wp-admin/admin.php?page=sub-page';
		$expected['sub-page2'] = 'http://example.com/wp-admin/admin.php?page=sub-page2';
		$expected['not_registered'] = '';
		$expected['With Spaces'] = 'http://example.com/wp-admin/themes.php?page=WithSpaces';
		$expected['testpages'] = 'http://example.com/wp-admin/edit.php?post_type=page&page=testpages';

		foreach ($expected as $name => $value) {
			$this->assertEquals( $value, menu_page_url( $name, false ) );
		}

		wp_set_current_user( $current_user );
	}
 public function addMenuItem()
 {
     switch ($this->pageType) {
         case "top":
             if ($this->actionHookIsValid($this->menuSlug, '')) {
                 add_menu_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "custom":
             if ($this->actionHookIsValid($this->menuSlug, "edit.php?post_type={$this->targetPostType}")) {
                 add_submenu_page("edit.php?post_type={$this->targetPostType}", $this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
                 //add_posts_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array( &$this, 'render' ));
             }
             break;
         case "dashboard":
             if ($this->actionHookIsValid($this->menuSlug, 'index.php')) {
                 add_dashboard_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "posts":
             if ($this->actionHookIsValid($this->menuSlug, 'edit.php')) {
                 add_posts_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "pages":
             if ($this->actionHookIsValid($this->menuSlug, 'edit.php?post_type=page')) {
                 add_pages_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "settings":
             if ($this->actionHookIsValid($this->menuSlug, 'options-general.php')) {
                 add_options_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "users":
             if ($this->actionHookIsValid($this->menuSlug, 'user.php') || $this->actionHookIsValid($this->menuSlug, 'profile.php')) {
                 add_users_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "plugins":
             if ($this->actionHookIsValid($this->menuSlug, 'plugins.php')) {
                 add_plugins_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         case "theme":
             if ($this->actionHookIsValid($this->menuSlug, 'themes.php')) {
                 add_theme_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
         default:
             // Defaults to Tools Menu
             if ($this->actionHookIsValid($this->menuSlug, 'tools.php')) {
                 add_management_page($this->pageTitle, $this->menuTitle, $this->userCapabilities, $this->menuSlug, array(&$this, 'render'));
             }
             break;
     }
     return $this;
 }
function oaf_create_submenu()
{
    add_dashboard_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_posts_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_media_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_pages_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_comments_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_theme_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_users_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_management_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
    add_options_page('OAF Settings', 'OAF Settings', 'manage_options', 'oaf_create_submenu_plugin', 'oaf_create_submenu_function');
}
 function my_admin_menu()
 {
     //create a main admin panel
     //create a sub admin panel link above
     add_menu_page('Bandi Summary', 'Bandi Summary', 'administrator', 9, array(&$this, 'overview'));
     //These functions adds sub menu for different kinds of admin panel on back end
     add_options_page('Mahesh Options', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_options'));
     add_posts_page('Mahesh posts', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_posts'));
     add_media_page('Mahesh media', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_media'));
     add_pages_page('Mahesh pages', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_pages'));
     add_users_page('Mahesh users', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_users'));
     add_management_page('Bandi', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_tools'));
     add_theme_page('Bandi', 'Mahesh  Plugin', 'administrator', basename(__FILE__), array(&$this, 'my_plugin_themes'));
 }
Exemple #6
0
function mailusers_add_pages()
{
    global $mailusers_user_custom_meta_filters;
    global $mailusers_group_custom_meta_filters;
    mailusers_init_i18n();
    add_posts_page(__('Notify Users', MAILUSERS_I18N_DOMAIN), __('Notify Users', MAILUSERS_I18N_DOMAIN), MAILUSERS_NOTIFY_USERS_CAP, 'mailusers-send-notify-mail-post', 'mailusers_send_notify_mail');
    add_pages_page(__('Notify Users', MAILUSERS_I18N_DOMAIN), __('Notify Users', MAILUSERS_I18N_DOMAIN), MAILUSERS_NOTIFY_USERS_CAP, 'mailusers-send-notify-mail-page', 'mailusers_send_notify_mail');
    add_options_page(__('Email Users', MAILUSERS_I18N_DOMAIN), __('Email Users', MAILUSERS_I18N_DOMAIN), 'manage_options', 'mailusers-options-page', 'mailusers_options_page');
    add_menu_page(__('Email Users', MAILUSERS_I18N_DOMAIN), __('Email Users', MAILUSERS_I18N_DOMAIN), MAILUSERS_EMAIL_SINGLE_USER_CAP, plugin_basename(__FILE__), 'mailusers_overview_page', plugins_url('images/email.png', __FILE__));
    //  Send to User(s) Menu
    add_submenu_page(plugin_basename(__FILE__), __('Send to User(s)', MAILUSERS_I18N_DOMAIN), __('Send to User(s)', MAILUSERS_I18N_DOMAIN), MAILUSERS_EMAIL_SINGLE_USER_CAP, 'mailusers-send-to-user-page', 'mailusers_send_to_user_page');
    /**
     * Do we need to deal with a user custom meta filter?
     *
     */
    //  Load any custom meta filters
    do_action('mailusers_user_custom_meta_filter');
    foreach ($mailusers_user_custom_meta_filters as $mf) {
        $slug = strtolower($mf['label']);
        $slug = preg_replace("/[^a-z0-9\\s-]/", "", $slug);
        $slug = trim(preg_replace("/[\\s-]+/", " ", $slug));
        $slug = trim(substr($slug, 0));
        $slug1 = preg_replace("/\\s/", "-", $slug);
        $slug2 = preg_replace("/\\s/", "_", $slug);
        //  Need to create the function to call the custom filter email script
        $fn = create_function('', 'global $mailusers_mf, $mailusers_mv, $mailusers_mc; $mailusers_mf = \'' . $mf['meta_filter'] . '\' ; $mailusers_mv = \'' . $mf['meta_value'] . '\' ; $mailusers_mc = \'' . $mf['meta_compare'] . '\' ; require(\'email_users_send_custom_filter_mail.php\') ;');
        add_submenu_page(plugin_basename(__FILE__), sprintf(__('Send to %s'), $mf['label'], MAILUSERS_I18N_DOMAIN), sprintf(__('Send to %s'), $mf['label'], MAILUSERS_I18N_DOMAIN), MAILUSERS_EMAIL_USER_GROUPS_CAP, 'mailusers-send-to-custom-filter-page-' . $slug1, $fn);
        //'mailusers_send_to_custom_filter_page_' . $slug2) ;
    }
    //  Send to Group(s) Menu
    add_submenu_page(plugin_basename(__FILE__), __('Send to Group(s)', MAILUSERS_I18N_DOMAIN), __('Send to Group(s)', MAILUSERS_I18N_DOMAIN), MAILUSERS_EMAIL_USER_GROUPS_CAP, 'mailusers-send-to-group-page', 'mailusers_send_to_group_page');
    /**
     * Do we need to deal with a user custom meta filter?
     *
     */
    //  Load any custom meta key filters
    do_action('mailusers_group_custom_meta_key_filter');
    //  Load any custom meta filters
    do_action('mailusers_group_custom_meta_filter');
    /**
        if (!empty($mailusers_group_custom_meta_filters))
        {
            //  Send to Group(s) Menu
            add_submenu_page(plugin_basename(__FILE__),
    	        __('Send to Meta Group(s)', MAILUSERS_I18N_DOMAIN), 
    	        __('Send to Meta Group(s)', MAILUSERS_I18N_DOMAIN), 
    	        MAILUSERS_EMAIL_USER_GROUPS_CAP,
                'mailusers-send-to-group-custom-meta-page',
       	        'mailusers_send_to_group_custom_meta_page') ;
        }
        **/
    //  User Settings Menu
    add_submenu_page(plugin_basename(__FILE__), __('User Settings', MAILUSERS_I18N_DOMAIN), __('User Settings', MAILUSERS_I18N_DOMAIN), 'edit_users', 'mailusers-user-settings', 'mailusers_user_settings_page');
}
function mypageorder_menu()
{
    add_pages_page(__('My Page Order', 'mypageorder'), __('My Page Order', 'mypageorder'), 'edit_pages', 'mypageorder', 'mypageorder');
}
Exemple #8
0
 /**
  * Adds the current page to the admin.
  */
 function add_page($type = "options")
 {
     if ("presentation" == $type) {
         add_theme_page($this->page_title, $this->menu_title, 8, $this->get_short_name(), array($this, 'page'));
     } else {
         if ("management" == $type) {
             add_management_page($this->page_title, $this->menu_title, 8, $this->get_short_name(), array($this, 'page'));
         } else {
             if ("pages" == $type) {
                 add_pages_page($this->page_title, $this->menu_title, 8, $this->get_short_name(), array($this, 'page'));
             } else {
                 if ("posts" == $type) {
                     add_posts_page($this->page_title, $this->menu_title, 8, $this->get_short_name(), array($this, 'page'));
                 } else {
                     add_options_page($this->page_title, $this->menu_title, 8, $this->get_short_name(), array($this, 'page'));
                 }
             }
         }
     }
     add_action("admin_head", array($this, 'head'));
 }
 /**
  * Create a WP Settings Page in the Pages section
  * @todo Allow both menu page and options page?
  * @param string $page_title
  * @param string $page_subtitle
  * @param string $menu_title
  * @param string $capability
  * @param string $menu_slug
  * @param string|array $function
  * @param string $icon_url Optional
  * @param int|null $position Optional
  * @return WPSettingsPage
  */
 public function __construct($page_title, $page_subtitle, $menu_title, $capability, $menu_slug, $function)
 {
     // Call parent constructor to setup everything
     parent::__construct($page_title, $page_subtitle, $menu_title, $capability, $menu_slug, $function, null, null);
     // Add pages page
     add_pages_page($page_title, $menu_title, $capability, $menu_slug, $function);
     return $this;
 }
 /**
  * Loads the admin menu with user-defined flags.
  */
 function load_admin_menu()
 {
     switch ($this->menu_type) {
         case 'page':
             $hook = add_pages_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'link':
             $hook = add_links_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'comment':
             $hook = add_comments_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'management':
             $hook = add_management_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'option':
             $hook = add_options_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'theme':
             $hook = add_theme_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'plugin':
             $hook = add_plugins_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'user':
             $hook = add_users_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'dashboard':
             $hook = add_dashboard_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'post':
             $hook = add_posts_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         case 'media':
             $hook = add_media_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'));
             break;
         default:
             $hook = add_menu_page($this->plugin_title, $this->menu_title, $this->cap, $this->slug, array(&$this, 'render_options_page'), $this->icon, isset($this->menu_pos) ? $this->menu_pos : null);
             break;
     }
     $this->hook = $hook;
 }
Exemple #11
0
function myeasydb_add_pages()
{
    #
    #	settings submenu
    #
    add_options_page(__('myEASYdb', MED_LOCALE), __('myEASYdb', MED_LOCALE), 'administrator', 'med_options', 'myeasydb_options_page');
    #
    #	tools submenu
    #
    add_management_page(__('myEASYdb', MED_LOCALE), __('myEASYdb', MED_LOCALE), 'administrator', 'med_tools', 'myeasydb_manage_page');
    #
    #	top level menu
    #
    add_menu_page(__('myEASYdb', MED_LOCALE), __('myEASYdb', MED_LOCALE), 'administrator', 'med_admin', 'myeasydb_toplevel_page', PLUGIN_LINK . 'img/myEASYdb-16.png');
    //$page_ref = add_menu_page( '', 'Menu Test', 10, 'menu-test', 'menu_test_index' );
    //add_action( 'load-' . $page_ref, 'menu_test_set_title' );
    //	$page_ref =  add_menu_page('', __( 'MySQL Admin', MED_LOCALE ), 'administrator', 'med_adminAAA', 'myeasydb_toplevel_page', PLUGIN_LINK.'img/mysql.png');
    //	add_action( 'load-' . $page_ref, 'set_title' );
    //    function set_title() {
    //        global $title;
    //        $title = 'Menu Test';
    //    }
    //add_submenu_page( 'my-top-level-handle', 'Page title', 'Sub-menu title', 'administrator', 'my-submenu-handle', 'my_magic_function');
    //add_submenu_page('med_admin', __( 'Sublevel', MED_LOCALE ), __( 'Sublevel', MED_LOCALE ), 'administrator', 'med_sub-page', 'myeasydb_toplevel_page');
    //add_menu_page(__( 'MySQL Admin', MED_LOCALE ), '', 'administrator', 'med_admin', 'myeasydb_toplevel_page', PLUGIN_LINK.'img/mysql.png');
    //add_menu_page(__( 'Start Here', MED_LOCALE ), 'myeasydb', 'administrator', 'med_admin', 'myeasydb_toplevel_page', PLUGIN_LINK.'img/mysql.png');
    //$this->_pageRef = add_menu_page( 'Start Here', $wp_theme_name, 'edit_themes', $this->_page, array( &$this, 'index' ) );
    //add_submenu_page( $this->_page, 'Start Here', 'Start Here', 'edit_themes', $this->_page, array( &$this, 'index' ) );
    #
    #	edit page
    #
    add_pages_page(__('myEASYdb Edit', MED_LOCALE), '', 'administrator', 'med_edit', 'myeasydb_edit_page');
    //// Add a submenu to the custom top-level menu:
    //add_submenu_page('med_admin', __( 'Sublevel', MED_LOCALE ), __( 'Sublevel', MED_LOCALE ), 'administrator', 'med_sub-page', 'myeasydb_sublevel_page');
    //
    //// Add a second submenu to the custom top-level menu:
    //add_submenu_page('med_admin', __( 'Sublevel 2', MED_LOCALE ), __( 'Sublevel 2', MED_LOCALE ), 'administrator', 'med_sub-page2', 'myeasydb_sublevel_page2');
    #
    #	available tables
    #
    if (defined('MAINSITE_DB') && MAINSITE_DB != '') {
        $rows = table_get_tables(MAINSITE_DB);
        $t = count($rows);
        for ($i = 0; $i < $t; $i++) {
            //var_dump($rows[$i]);echo '<hr>';
            if ($rows[$i]['Comment'] != '' && substr($rows[$i]['Comment'], 0, 8) != '*PRIVATE') {
                //echo $rows[$i]['Name'].' => '.$rows[$i]['Comment'].'<br>';
                //echo '<a href="'.PLUGIN_LINK.'table_editor_adm.php?table='.$rows[$i]['Name'].'">'.$rows[$i]['Name'].' => '.$rows[$i]['Comment'].'</a><br>';
                add_submenu_page('med_admin', $rows[$i]['Comment'], $rows[$i]['Comment'], 'administrator', $rows[$i]['Name'], 'myeasydb_table_handler_page');
            } else {
                add_submenu_page('med_admin', $rows[$i]['Name'], $rows[$i]['Name'], 'administrator', $rows[$i]['Name'], 'myeasydb_table_handler_page');
            }
        }
        /*
        	#	0.0.6
        
        		//if(!isset($_SESSION['myeasydbVersion']) && (!defined('AJAX_CALLER') || AJAX_CALLER==false))
        		//{
        		//	#	check the myEASYdb version only once per session
        		//	#
        		//	?><script type="text/javascript">function get_med_information() {
        		//		sndReq('get_med_information','med','<?php echo 'username' . AJAX_PARMS_SPLITTER . 'pwd'; ?>');
        		//		}
        		//		setTimeout('get_med_information()', 500);
        		//	</script><?php
        		//}
        */
    }
}
<?php

/**
 * This test helper creates a bunch of admin menus in different locations.
 * Useful for testing the editor's ability to move/copy/add plugin menus.
 */
add_action('admin_menu', function () {
    add_options_page('Dummy Settings', 'Dummy Settings', 'read', 'dummy-settings', 'amt_output_page');
    add_comments_page('Dummy Comments', 'Dummy Comments', 'read', 'dummy-comments', 'amt_output_page');
    add_menu_page('Dummy Top Menu', 'Dummy Top Menu', 'read', 'dummy-top-menu', 'amt_output_page');
    add_submenu_page('dummy-top-menu', 'Dummy Submenu #1', 'Dummy Submenu #1', 'read', 'dummy-submenu-1', 'amt_output_page');
    add_submenu_page('dummy-top-menu', 'Dummy Submenu #2', 'Dummy Submenu #2', 'read', 'dummy-submenu-2', 'amt_output_page');
    add_dashboard_page('Dummy Dashboard', 'Dummy Dashboard', 'read', 'dummy-dashboard-page', 'amt_output_page');
    //A top-level menu with no submenus.
    add_menu_page('The Dummy', 'The Dummy', 'read', 'dummy-menu-with-no-items', 'amt_output_page');
    //A top-level menu with no hook callback!
    add_menu_page('No Hook', 'No Hook', 'read', 'dummy-menu-with-no-hook', null, 'dashicons-dismiss');
    add_submenu_page('dummy-menu-with-no-hook', 'NH Submenu #1', 'NH Submenu #1', 'read', 'dummy-nh-submenu-1', function () {
        amt_output_page('nh-submenu-1-content');
    });
    add_submenu_page('dummy-menu-with-no-hook', 'NH Submenu #2', 'NH Submenu #2', 'read', 'dummy-nh-submenu-2', 'amt_output_page');
    //A submenu with special character(s) in the slug. Tests query parameter encoding.
    add_options_page('Special Slug', 'Special Slug', 'read', 'dummy/special-characters-in-slug.php', 'amt_output_page');
    //Add a page to a parent menu that includes a query parameter (edit.php?post_type=page)
    add_pages_page('Pages Submenu', 'Pages Submenu', 'read', 'dummy-pages-submenu', 'amt_output_page');
});
function amt_output_page($content_id = 'ame-test-page-content')
{
    printf('<span id="%s">This is a dummy page.</span>', htmlentities($content_id));
}
Exemple #13
0
 /**
  * Displays the menu entry on the WordPress Dashboard
  *
  * @return bool Returns `true` if successful, `false` otherwise.
  * @throws \Exception if the no title or callback function was specified
  */
 public function display()
 {
     if (empty($this->title) || empty($this->_properties['callback'])) {
         throw new \Exception('No title or callback function specified for menu entry');
     }
     $title = $this->title;
     $page_title = $this->page_title;
     $icon = $this->icon;
     $capability = $this->capability;
     $parent = $this->_properties['parent_slug'];
     $slug = $this->_properties['slug'];
     if (empty($slug)) {
         $_cb = $this->_properties['callback'];
         $slug = Helpers::makeSlug(is_array($_cb) ? $_cb[1] : (string) $_cb);
         // Since 1.0.5, slug is based on callback function name
         unset($_cb);
     }
     if (empty($page_title)) {
         $page_title = $title;
     }
     // Sanitize and add count to the title here (prior operations use a "clean" title)
     if ($this->count !== false) {
         $title = htmlspecialchars($title) . ' <span class="awaiting-mod"><span class="pending-count">' . $this->count . '</span></span>';
     } else {
         $title = htmlspecialchars($title);
     }
     // We call our own callback first
     $callback = array($this, 'onMenuCallback');
     switch ($this->_properties['type']) {
         case self::MT_CUSTOM:
             if (empty($capability)) {
                 $capability = 'read';
             }
             $this->hook = add_menu_page($page_title, $title, $capability, $slug, $callback, $icon);
             break;
         case self::MT_SUBMENU:
             if (empty($capability)) {
                 $capability = 'read';
             }
             if (!$this->_properties['use_subheaders']) {
                 $this->hook = add_submenu_page($parent, $page_title, $title, $capability, $slug, $callback);
             } else {
                 $this->hook = '';
             }
             break;
         case self::MT_COMMENTS:
             if (empty($capability)) {
                 $capability = 'moderate_comments';
             }
             $this->hook = add_comments_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_DASHBOARD:
             if (empty($capability)) {
                 $capability = 'read';
             }
             $this->hook = add_dashboard_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_LINKS:
             if (empty($capability)) {
                 $capability = 'manage_links';
             }
             $this->hook = add_links_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_TOOLS:
             if (empty($capability)) {
                 $capability = 'import';
             }
             $this->hook = add_management_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_MEDIA:
             if (empty($capability)) {
                 $capability = 'upload_files';
             }
             $this->hook = add_media_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_SETTINGS:
             if (empty($capability)) {
                 $capability = 'manage_options';
             }
             $this->hook = add_options_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_PAGES:
             if (empty($capability)) {
                 $capability = 'edit_pages';
             }
             $this->hook = add_pages_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_PLUGINS:
             if (empty($capability)) {
                 $capability = 'update_plugins';
             }
             $this->hook = add_plugins_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_POSTS:
             if (empty($capability)) {
                 $capability = 'edit_posts';
             }
             $this->hook = add_posts_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_THEMES:
             if (empty($capability)) {
                 $capability = 'edit_theme_options';
             }
             $this->hook = add_theme_page($page_title, $title, $capability, $slug, $callback);
             break;
         case self::MT_USERS:
             if (empty($capability)) {
                 $capability = 'edit_users';
             }
             $this->hook = add_users_page($page_title, $title, $capability, $slug, $callback);
             break;
         default:
             $this->hook = false;
             break;
     }
     $this->displayed = $this->hook !== false;
     if ($this->displayed) {
         // Write back any changes for future reference
         $this->_properties['slug'] = $slug;
         $this->capability = $capability;
         $this->page_title = $page_title;
     }
     return $this->displayed;
 }
Exemple #14
0
 /** ====================================================================================================================================================
  * Add menu
  *
  * @return void
  */
 public function admin_menu_local()
 {
     if ($this->get_param('show_order_in_page_edit')) {
         add_pages_page(__('Order pages', 'SL_framework'), __('Order', 'SL_framework'), 'edit_pages', 'edit_pages-order/pages-order', array($this, 'pages_order_edit'));
     }
 }