Got a fix for this.
Get current user id and based on ID get current user info.From that user info get user role. If user role is not subscriber then only we can add menu page. This way editors/contributors can access plugin.
Below is the working code.
<?php
$userID = get_current_user_id();
$user = new WP_User($userID);
$userRole = $user->roles[0];
if($userRole!="subscriber")
{
$Access_Role =$userRole;
$UPCP_Menu_page = add_menu_page($page_title, $menu_title, $Access_Role, 'UPCP-options', 'UPCP_Output_Options',null , '50.5');
add_action("load-$UPCP_Menu_page", "UPCP_Screen_Options");
}
?>
Related Posts:
- What’s the preferred method of writing AJAX-enabled plugins?
- How to add a shortcode button to the TinyMCE editor?
- Redesigning Custom Post Type “Add New” page
- Is there any record of installed plugins in the database?
- Using require_once in a Plugin?
- How to call “page specific menu items” in template [closed]
- Custom headers for the WordPress plugin directory
- plugin wants to update to wrong plugin
- How can I add a custom header to a custom template in a plugin without using the theme folders
- Trying to avoid including wp-load.php
- AJAX Call Via Vanilla JavaScript In WordPress Plugin Development
- Understanding apply_filters
- Custom values are not translated
- Make the plugin directory recognize new version numbers
- Master menu item for multiple plugins?
- Change the name of an installed plugin
- Where do I add a new table’s name in wpdb?
- How to create popup same as wordpress popup feature
- How to customize user search
- Upgrade Private Plugin without Deleting
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- How to make first_name and last_name required fields in user profile?
- Making my plugin translation ready. Poedit not working
- Check if email address exists front end with AJAX in a plugin
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- Can we use a webservice with WordPress?
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- New User Form – Custom Menu Page
- Checking instances of scripts in wp_head
- Creating mySQL procedure with $wpdb
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- How can I prevent my plugin go development trunk [closed]
- Best way to maintain and update 3rd-party WP plugin when developer is unresponsive?
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Best place for if/else piece of code related to custom plugin?
- How do you assign a UUID to posts/products/comments/reviews?
- How to make a implement queue for scheduling tasks in WordPress?
- how to do login using woocommerce rest api From android
- How to create a code editor for my plugin .?
- Editable form for WordPress plugin options page
- Manually set a custom admin sub-menu selected?
- wp-pagenavi getting 404 page not found
- remove add new post, if there is already one post
- How to test ‘upgrader_process_complete’ hook in plugin development?
- Plugin Not Working After Being Uploaded To WordPress Plugin Repository
- Difference and examples of esc_attr__() and esc_attr_e()
- Change the display of Settings API (do_settings_sections)
- Issue running db create table query from static method
- How to make custom plugin run on demand?
- What is the easiest way to rename a plugin (and also avoid plugin updates)
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- Using WordPress to build membership Page
- Set WordPress Transient Expiration via Variable Value
- Sanitizing file & directory form input
- Override plugin class which has namespace
- Correct Plugin File Path
- strange shortcode error: does shortcodes requires any dependency?
- Plugin create pages and use templates
- Custom CSS not being added by plugin
- Quick press publish post hook
- How to display results from a data table with an encrypted user id?
- How do i specify a url to which to redirect the user after he logs out from facebook?
- I cannot include a file in my plugin settings page
- How to Add text value in Automatically in this conditions?
- Translation for a text that is not printed on the screen
- Two plugins using the same CSS id
- Activation flow of a plugin in a multisite environment
- Checkbox show / hide output result
- How to show multi line output from metabox
- force logged in user to stay in the dashboard
- Critical Error message of WordPress adming
- Clicking custom plugin admin menu redirects to “No Update Required” on live site
- Create new page in wordpress plugin which doesn’t exist
- Use WordPress Plugin without WP head
- The plugin generated 227 characters of unexpected output during activation. If you notice “headers already sent” messages
- How to call a function from class in wp table list button form
- 500 Internal server error wp_handle_upload_prefilter
- Installation failed, trying to install ANY plugin
- WordPress the_content Filter and GET Parameter
- Overwrite js code using WP_Footer
- Fatal error when activating my custom wordpress plugin
- How to access classes in theme of a plugin?
- Protect WordPress option value
- Help Code Review – I need to write on .htaccess file from theme’s function.php
- TinyMCE how to add css when inputing a text
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- How do i get all author posts on custom post type list
- Need to hide an element depending on date and post category
- How to add a handler for a button in plugin?
- Submit form stored in one plugin from another plugin?
- How to show an image popup when one clicks on an image thumbnail?
- Using Taxonomies with Vote It Up plugin chart [closed]
- wordpress last all added get meta value by post id
- Jquery post responses 500 error after some time and lastly an 503 error
- How can I delete the options from DB when the plugin is deleted?
- How to add custom html to the Media > Attachment Details modal?
- manage_{taxonomy}_custom_column not working
- How to be Variables and options must be escaped when echo’d?
- How to override plugin function in code snippets WordPress