The wp_dropdown_roles()
function internally uses get_editable_roles()
to fetch the needed roles. It does nothing else than fetching the roles from the global:
$all_roles = $GLOBALS['wp_roles']->roles;
and filter it afterwards:
return apply_filters( 'editable_roles', $all_roles );
So you can simply add the following function to a plugin or your functions.php
file of your theme:
function wpse137935_filter_editable_roles( Array $roles )
{
// Don't conflict and remove immediately
remove_filter( current_filter(), __FUNCTION__ );
// Do any logic in here that appends or removes roles
return $roles;
}
Then, right before the call to wp_dropdown_roles()
, you add:
add_filter( 'editable_roles', 'wpse137935_filter_editable_roles' );
It’s important that you add the filter as late as possible to not crash into other plugins or your theme if they/it calls the same function elsewhere.
Related Posts:
- what’s the meaning of the field wp_capabilities in table wp_usermeta
- Send user activation email when programmatically creating user
- Change default admin page for specific role(s)
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- How to Change the Entire WordPress Admin panel Look and Feel?
- How to Structure a New Role/Capability Scheme?
- How to add more than 1 user role to sub-menu pages
- How to allow Unfiltered HTML in a wordpress multisite install
- How to restrict plugin’s sub-menu pages to admin/subscribers?
- How to not let a user with a new role edit users that have administrator role?
- Execute plugin for specific user role(s) only
- query users by role
- Hide plugin dashboard menu item for specific roles
- get_posts() not working when accessing with a custom user role
- Limit role to one plugin [duplicate]
- Logout users upon login, based on caps/role?
- Set different custom menu items for different user roles
- Prevent third party plugin’s admin page access based on user type
- Hide custom post type by user roles
- Check user’s role and store in variable
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- How can I change my assigned user role in WordPress 3.5.1?
- How to determine which capability to use?
- Allow contributor user role to perform copy operation PHP
- Enable a role named ‘backend_user’ to access my plugin pages
- Add custom parameter for custom user role
- Buddy Press restrict the capability to edit users
- How I can give access to my custom plugin for editor roles user?
- Remove all capabilities in separate method fails versus included in method
- Remove from a div by class name from post page if post author role is not administrator
- Adding admin for specific users
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- New Users are saved with no role selected
- WordPress User Management Departmental Managers
- Remove default wordpress roles
- How Do I Use jQuery UI In My Plugin
- Checking if a file is already in the Media Library
- How to implement add_image_size in a plugin
- How to make dynamically-generated content searchable in WordPress?
- Nav Menu meta failing to import
- Custom Rewriting to Plugin with Parameters
- ERROR: Options page not found – saving settings page with tabs
- Script won’t load via plugin class
- How to override a function call in functions.php?
- Is there a need to do apply_filter(‘widget_title’, $instance[‘title’]) or any other ‘widget_xxx’ filters?
- Passing array of strings to a SQL statement in a WordPress plugin
- Sidebar widget to show popular post not working?
- WP_Query returns no results
- Will setcookie work if there is a cache plugin installed?
- Adding settings link to plugin doesn’t work
- Check Paypal Purchase is Success or Not in Easy Digital Download Plugin
- Dashboard – get status and position of metaboxes and pass them to ajax method
- Is it possible to install a theme via a plugin?
- Form doesnt save to database
- Wp_list_table search box not working for custom value from database
- Notice: Trying to get property ‘term_id’ of non-object
- How to add user details to different tables immediately after user registration
- Including comments meta box on a plugin page
- How to Control CSS of Admin On Creating only a Specific Custom Post Type
- Run JavaScript validation script on form submit in plugin
- Bypass product key [closed]
- Return conditional category in load_posts_by_ajax
- How to format custom fields when editing an attachment?
- Woocommerce – Provide Associated Category Link for Product List Plugin [closed]
- How can I call wp-load.php in my plugin file
- How to create new content type and flushes rewrite rules without visiting the permalinks page?
- About a programming language starts with [closed]
- How to Get Last ID?
- How to display specific data from a custom table to logged in users with a custom role
- How to add quick edit on the list of users to edit custom fields?
- How to Run Plugin on Server Without Web Browser
- Unit Testing action hook
- 400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true
- Integrate separate web app inside wordpress [closed]
- PHP includes with AJAX actions
- Custom Post Type and Functions
- WordPress custom plugin developement
- Google does not index data from custom table used for a plugin
- Best practice: What belongs in theme and what in plugin for large eCommerce website
- I can install my plugin in localhost but not in my server
- What is the Timeline for the Active Version Pie Chart in the Repository?
- Email verification feature in wordpress social login plugin
- Custom Pin it button is not showing over the image instead it shows as block top_left
- check wp_login into a plugin
- Safe XML response from wordpress plugin
- Gutenberg: – Call a function after Server Side Component is rendered
- How are themes and plugins localized using the gettext GNU framework?
- Theme, Plugin or Both?
- Accept only PDF file for upload
- WordPress upload path decalration
- Add a custom image source
- filter on get_posts efficiently
- How to get custom user meta by id in custom Gutenberg block
- How to prepend a header section to all pages related to my WordPress Plugin
- How to access Elementor-navigation-elements via jQuery
- Hook a search form anywhere on the site, using a custom plugin
- Plugin forms overwrite each other’s options
- ACF – programmatically install and activate in pipeline to automate testing for custom plugin development?
- How can I include React useState in a custom gutenberg block plugin?
- Problem with Owl Carousel, infinite loop [closed]