-
-
Save tommcfarlin/059c23a274fe321896e7 to your computer and use it in GitHub Desktop.
[WordPress] Menu Pages and "Cheatin' Uh?"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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