52130

How to get a slug name for a page without creating an admin page menu

Question:

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

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

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' ); ...

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' );

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

Answer1:

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

The page can be accessed through 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' ); } }

Recommend

  • Using set() on an array
  • Passing Extended Class Method as a Call-Back Function in WordPress
  • How to create new page in wordpress plugin?
  • Get title from wordpress custom post type
  • CKEditor 4 Images and dataProcessor API
  • How can I pass a list of values as a parameter to a Visual Studio web performance test or load test
  • wordpress plugin redirect from page to page permisson error
  • How to prevent a nib from loading if already in instance is loaded?
  • javascript - change the Page source Reference File Path
  • Rails- Heroku - rake aborted! Please install the postgresql adapter: gem install activerecord-postgr
  • ListBox does not display the binding data
  • How can I set and get the values of a multiple select with the Wordpress settings API for a theme op
  • Problem while Building a Setup Project for a windows Service?
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • MVC3 Razor - ListBox pre-select not working
  • Django: Count of Group Elements
  • All Classes Conforming to Protocol Inherit Default Implementation
  • Using variable in a value field in jMeter
  • Adding a button at the bottom of a table view
  • Deleting and Updating values from a cusrsor adapter
  • Fetching methods from BroadcastReceiver to update UI
  • Is possible to count alias result on mysql
  • Symfony2: How to get request parameter
  • Importing jscolor library in angular 2
  • To display the title for the current loaction in map in iphone
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • GridView Sorting works once only
  • php design question - will a Helper help here?
  • KeystoneJS: Relationships in Admin UI not updating
  • WPF Applying a trigger on binding failure
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • JTable with a ScrollPane misbehaving
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?