You could check the user role when loading your metabox.
//get user
$user_id = get_current_user_id();
$user = new WP_User($user_id);
//check user role
if($user->roles[0] == 'administrator' || $user->roles[0] == 'editor') {
//add your metabox here
}
That way the metabox is only added to the post for editor’s and users, you’ll probably want to wrap your save functionality in a similar condition so that it doesn’t try to run every time the post is saved.
EDIT: If you plan to use this on any other site or release it for others to use, I’d also recommend setting up an options page for your plug-in so that the user roles that are able to use this plug-in can be selected from a list of current user roles.
That way custom user roles can be accounted for, as well.
Related Posts:
- How does WooCommerce display a custom comment_type in Comment Admin?
- Plugin: How should I handle deleting comments?
- Override comments.php template with plugin
- How to change commenter links to /user/user_id?
- How can I get WordPress to save comments in markdown format?
- Creating a plugin to sanitize comment and the url field before display only
- Add a Custom Field in Comment Box next to the Text area
- How to remove WordPress Default Comment? not Facebook
- Why do I get this “plugin does not have a valid header” error?
- Edit plugin without hooks in functions.php
- WordPress Capabilities: edit_user vs edit_users
- Making plugin unique to not conflict with plugins with the same name
- How to find out if option exists but is empty?
- Is dynamic forms/entries possible in Widget?
- How to get posts by content?
- Trigger a custom wordpress plugin with a linux cron
- update_meta_user difference in i:1 and b:1, how to write b:1
- Add_rewrite_rule doesn’t add custom url in plugin
- How to add inline css/js inside a shortcode
- Can wp_script_is used in pluginA check if a script is being enqueued/registered from pluginB?
- Licensing of freemium plugin
- Way to hook into a sidebar call to replace it with a custom sidebar
- How to trigger an action with a URL
- Default Plugin Settings Not Writing to Database
- WP Plugin Developers – Accessing my wordpress site [closed]
- Create a custom page template inside my wordpress plugin
- How to pull code snippet from functionality plugin?
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- Best approach to fetch data from wp options to js file or php file
- Is it possible to create Custom Post plug-in?
- How to add Internationalization in WordPress using Javascript/React?
- why doesn’t this update part of this plugin work? it take me to nothing here page
- Using a custom plugin to capture input data via Ajax and PHP
- Display post lists in 2nd paragraph
- creating html reusable blocks via shortcodes
- I want to auto populate data in three fields if one drop down is selected
- How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
- Session destroyed on page redirect
- Is there a way to test that readme looks in other language before submitting translation?
- How can I change the meta_key for a particular piece of information?
- Can I load the textdomain before a plugin is activated?
- Create tabs in admin options page from custom post type loop
- ob_start() combined with wp_query
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- Settings API saved values not getting shown in the dropdownbox
- populating a form field with output from a custom plugin function
- Why Does The `auto_update_plugin` Hook Disable Management?
- Is there a way to add custom endpoint to specific page only
- IF condition based on wp_remote_get output
- Add User Role: Pre-saved in User-Meta [SOLVED]
- get_comments_number() giving wrong results! What are alternatives?
- Is there a script to collect all hooks and filters provided by a plugin?
- How WordPress core manage the plugin installation
- Post status doesn’t update to ‘future’ every time?
- Unable to give correct path in wordpress
- Disable variations on woo commerce if out of stock
- How to add img into a plugin?
- How to log custom plugin error to debug.log file
- Error: Can´t access facebook comment plugin admin page
- count the number of views of a post excluding own views
- How to hide plugin submenu title in drop down in admin panel in wordpress?
- How to create admin setting for this small plugin
- How to set Google Analytics tracking code on WordPress plugin directory page?
- How to fix caching issue in PHP data from database
- Show Custom Post on Frontend
- SASS not showing in customized preloader plugin
- How to securely controlling data without keeping it in postmeta?
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- Load my Inline js footer area
- Remove action added in plugin class from theme
- wc_get_product_terms() throws “Notice: Undefined offset: 0”
- Using multi-dimensional array with filter
- WordPress Admin sub-level menu issue
- How do I add a textarea (multirow) option to my WordPress plugin?
- PHP header() not available to use in my plugin
- Passing ajax variable to more than one wordpress plugin function
- wordpress ajax pagination object value does not change
- Custom pages with plugin
- How to insert category name above post title in a featured pages plugin?
- Displaying friend’s posts only
- Why isn’t my plugin seeing other classes?
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- How to add jquery to my custom post type wp plugin
- Update post meta not working on wp_postmeta
- Check if user is in a group of another site within multisite network [closed]
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- Redirect url in plugin to somewhere else?
- How to set-up multiple cron task with wp_schedule_event so that they do not overlap?
- wp_insert_post_data filter to set category
- Site is setup statically – how to make it content managable?
- is there a way I can add or remove some plugin options?
- Modifying lightbox plugin to allow for quoting, Does this exist? [closed]
- What can I do to customize a widget provided with this plugin? from where have I to start?
- Plugin version number after code rewrite [closed]
- How to escape html code?
- add_meta_box showing blank screen in my page
- Plugin translations are not loaded from translate.wordpress.org
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- How do i fix this error?