如何在不创建管理页面菜单的情况下获取页面的名字 [英] How to get a slug name for a page without creating an admin page menu

查看:149
本文介绍了如何在不创建管理页面菜单的情况下获取页面的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在使用add_submenu_page()函数,但是我不希望编辑页面出现在管理菜单中。

I now use the add_submenu_page() function, but I don't want the edit page to appear in the admin menu.

我想访问编辑页面直接从列表(另一页)中获取。但是我需要把它作为一个hook_suffix。

I want to access the edit page from a list (another page) directly. But I need the slug as a hook_suffix.

我在my-edit.php中

I have in my-edit.php

/* Set up the administration functionality. */
add_action( 'admin_menu', 'my_edit_setup' );

function my_edit_setup() {
...
/* Add Edit Actionlist page. */
$myplugin->my_edit = add_submenu_page( 'myplugin', esc_attr__( 'Edit', 'myplugin' ), esc_attr__( 'Edit', 'myplugin' ), 7, 'my-edit', 'my_edit' );
...

在admin.php中,我有:

In admin.php I have:

function my_admin_enqueue_style( $hook_suffix ) {

  $pages = array(
    'admin_page_projects',
        '...my-edit'
  );

  if ( in_array( $hook_suffix, $pages ) ) {
    wp_enqueue_style( 'myplugin-admin', trailingslashit( MYPLUGIN_URI ) . 'css/admin.css', false, '20110525', 'screen' );

您看到我需要$ hook_suffix,但是我不知道如何获得它创建管理菜单项。

You see I need the $hook_suffix, but I can't find out how to get this, without creating the admin menu item.

推荐答案

如何创建不可见子菜单的示例(将其附加到仪表板 index.php )和对应的 $ hook_suffix

Example of how to create an invisible sub menu (it gets attached to the Dashboard, index.php) and the correspondent $hook_suffix.

可以通过 http://example.com/wp-admin/index.php?page=sample_page_hidden

add_action(  'admin_menu', 'admin_menu_so_11593510' );
add_action( 'admin_enqueue_scripts', 'admin_enqueue_scripts_so_11593510' );

function admin_menu_so_11593510() 
{
    add_submenu_page(
        null, // doesn't shows up in the menu, submenu is attached to "index.php"
        'Test', 
        'Test', 
        'edit_pages', 
        'sample_page_hidden', 
        'menu_options_so_11593510'
    );
}

function menu_options_so_11593510() { echo 'Hello!'; }

function admin_enqueue_scripts_so_11593510( $hook_suffix )
{
    if ( 'dashboard_page_sample_page_hidden' == $hook_suffix ) {
        wp_enqueue_script( 'swfobject' );
    }
}

这篇关于如何在不创建管理页面菜单的情况下获取页面的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆