Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created May 18, 2015 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/059c23a274fe321896e7 to your computer and use it in GitHub Desktop.
Save tommcfarlin/059c23a274fe321896e7 to your computer and use it in GitHub Desktop.
[WordPress] Menu Pages and "Cheatin' Uh?"
<?php
add_menu_page(
'Acme Place',
'Acme Place',
'edit_posts',
'acme_page',
'display_all_acme_places',
'dashicons-location',
3
);
<?php
/* Note that the 'acme_places_group' is part of what's defined
* when setting up the options using the Settings API.
*/
add_filter(
'option_page_capability_acme_places_group',
'acme_places_capability'
);
<?php
/**
* Defines a custom filter so that editors can save options with the 'Acme Places'
* menu page and subpages
*
* @since 1.0.0
*
* @param string $capability The default capability.
* @return string The capability needed to edit the post.
*/
function acme_places_capability( $capability ) {
return 'edit_posts';
}
<?php
/**
* Defines the hooks that are necessary to get the dependencies of this class loaded.
*
* @since 1.0.0
*/
public function initialize() {
add_filter(
'option_page_capability_acme_places_group',
array( $this, 'acme_places_capability' )
);
}
/**
* Defines a custom filter so that editors can save options with the 'Acme Places'
* menu page and subpages.
*
* @since 1.0.0
*
* @param string $capability The default capability.
* @return string The capability needed to edit the post.
*/
public function acme_places_capability( $capability ) {
return 'edit_posts';
}
/**
* Adds the menu items and the submenus for Acme Places.
*
* @since 1.0.0
*/
public function add_menu_items() {
add_menu_page(
'Acme Places',
'Acme Places',
'edit_posts',
'acme_places',
array( $this, 'display_all_acme_places' ),
'dashicons-location',
3
);
add_submenu_page(
'acme_places',
'Acme Places',
'Add New Place',
'edit_posts',
'add_new_place',
array( $this, 'display_add_place' )
);
add_submenu_page(
'acme_places',
'View All Places',
'View All Places',
'edit_posts',
'view_all_places',
array( $this, 'display_all_places' )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment