0

I am making a custom plugin with custom user role:

add_role('lln_assessor', 'LLN Assessor', array(

'read' => true, // true allows this capability
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
));

this role will be created when I activate my custom plugin.

Now, in the wp-admin or its dashboard when it logged, how can I create its own menu and page?

gadss
  • 21,687
  • 41
  • 104
  • 154

1 Answers1

0

Here custom_cap is custom capability added to new role and while adding new admin menu this capability is added.

  add_role('lln_assessor', 'LLN Assessor', array(

    'read' => true, // true allows this capability
    'edit_posts' => true, // Allows user to edit their own posts
    'edit_pages' => true, // Allows user to edit pages
    'edit_others_posts' => true, // Allows user to edit others posts not just their own
    'create_posts' => true, // Allows user to create new posts
    'manage_categories' => true, // Allows user to manage post categories
    'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
    'custom_cap'=>true
    ));

        add_menu_page( 'Custom Menu', 'Custom Menu', 'custom_cap', 'menu-slug', 'menu_function', plugins_url( 'icon.png' ), '1.0' );

    function menu_function(){

      // do code for menu here

    }

   }
Gaurav Srivastav
  • 2,381
  • 1
  • 15
  • 18
  • thanks for the response Gaurav but I got this error: `Fatal error: Call to undefined function wp_get_current_user() in C:\xampp\htdocs\tide\wp-includes\capabilities.php on line 1441` – gadss Dec 02 '15 at 03:51
  • Where are you're using this wp_get_current_user() in plugin or theme. If you using any hook please specify. – Gaurav Srivastav Dec 02 '15 at 05:37
  • now I got `You do not have sufficient permissions to access this page.` Error.. this is my current code `add_menu_page('Axcelerate LLN','LLN Datas','assess_lln', 'Axcelerate_Link_Admin_lln_data','axcelerate_link_admin_lln_data_fn','','1.0' );` where the `assess_lln` is my `custom_cap` I think the error is on the custom capabilities.. please help – gadss Dec 03 '15 at 01:30
  • You should try `code` $currentuser= wp_get_current_user(); $role=get_user_role($currentuser->ID); if($role=='lln_assessor'){ add_menu_page('Axcelerate LLN','LLN Datas','manage_categories', 'Axcelerate_Link_Admin_lln_data','axcelerate_link_admin_lln_data_fn','','1.0' ); function get_user_role($uid) { global $wpdb; $role = $wpdb->get_var("SELECT meta_value FROM {$wpdb->usermeta} WHERE meta_key = 'wp_capabilities' AND user_id = {$uid}"); if(!$role) return 'non-user'; $rarr = unserialize($role); $roles = is_array($rarr) ? array_keys($rarr) : array('non-user'); return $roles[0]; } } `code` – Gaurav Srivastav Dec 03 '15 at 02:18
  • `manage_categories` wont work.. now I try `manage_options` then it works.. then I add some CSS to hide unwanted admin menu page and shows what I want to show – gadss Dec 03 '15 at 03:00