How can I pass value to function in add_menu_page?

Don’t use a function for the callback, use a class. Something like this: class Competition_Manager_Page { private $extra; public function set_extra( $value ) { $this->extra = $value; } public function render() { // show you page content, then: print $this->extra; } } You can extend the class’ functionality later. Now, when you register the menu, … Read more

Link to a admin submenu item using a custom link

If I understand correctly what you are asking, you need the $menu_slug used when adding your menu pages: //add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); //add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); $your_link_url = admin_url( ‘admin.php?page=”.$menu_slug, “http’ ); OR SPECIFICALLY FOR YOU $your_link_url = admin_url( ‘admin.php?page=nes_vendor_new’, ‘http’ ); You can always verify … Read more

Execute certain function on GET request

One of the earlier hooks that is aware of the page (I think) is load-{$slug}: add_action( ‘load-_my-plugin’, ‘wpse143915_maybe_trigger_export’ ); function wpse143915_maybe_trigger_export(){ if( isset( $_GET[‘export’] ) && ( $_GET[‘export’] == ‘data’ ) ){ //… } } If you want to find out what your page slug is, checkout this plug-in by Kaiser: https://github.com/franz-josef-kaiser/current-admin-info But personally, I … Read more

Plugin capabilities

public function myplugin_role_has_cap($capabilities, $cap, $args) { if(!isset($capabilities[‘myplugin_access’])) { unset($capabilities[‘myplugin_delete_item’]); } return $capabilities; }add_filter(‘user_has_cap’, array($this, ‘myplugin_role_has_cap’), 0 , 3); Here is a better answer, that corresponds to my example. Let’s say the plugin, on activation, adds the 2 caps to a role, and that after that for some reasons, the access cap is revoked. Then, even … Read more