You can use the user_registration
action to set a custom role directly after wp_insert_user() has been called.
add_action('user_register', 'foo_set_new_user_role', 9999, 1);
function foo_set_new_user_role($user_id){
$user = new WP_User( $user_id );
$user->set_role('your_new_role');
}
You can also use the action profile_update
for just that, profile updates. It takes two parameters $user_id
and $old_user_data
.
Hope this helps you out.
Related Posts:
- WordPress Capabilities: edit_user vs edit_users
- Allowing Custom Capability to Manage Plugin Options
- Checking for user role in a custom plugin
- Allow Facebook to preview posts before published
- Set user ID at time of wp_create_user
- How to write a plugin to add users to a mail list
- How to make a customize role and view a specific plugins base on that role?
- Redirection of users away from wp-admin (but not administrators)
- How to set add question capability for author role in wp pro quiz plugin
- Add User Role: Pre-saved in User-Meta [SOLVED]
- How To Create A File Archive in WordPress?
- Allow a particular user to access a particular plugin?
- Pass PHP variable to javascript
- wordpress get meta value by meta key
- What areas to Unit test while building a plugin?
- How to find out if option exists but is empty?
- How to assign user a role if none is present when logging in
- update_meta_user difference in i:1 and b:1, how to write b:1
- Registration Form Validation in wordpress
- Errors while using ajax from external wordpress page
- Add_rewrite_rule doesn’t add custom url in plugin
- Dequeue / Deregister script and replace it with a new plugin
- How to add inline css/js inside a shortcode
- Is this plugin being loaded before file.php, subsequently not allowing me to use certain functions?
- Hide Theme options and Customize Admin menu
- Current user in plugin returns NULL
- How can I implement a notification system in wordpress?
- Building an email signup form. Where should the information be saved in the DB?
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- Where should I save an API key of my user when installing my plugin?
- Custom form action to handle data inside a plugin
- WP Post Template – Templates in own folder
- Map Custom Registration Fields to WordPress User Roles
- custom payment gateway in woocommerce failed to connect to remote api server
- Plugin options page with live preview?
- Ajax call returning 0
- How to create restrict content to users (by user, not by role)
- How to update post’s content on post publish?
- How to create user that has permission to create new sites on WordPress with multisite option enabled?
- WordPress plugin admin html being shown in Customizer iframe
- WordPress Widget – Saving multidimensional arrays into $instance
- Ordering taxonomies by rank
- populating a form field with output from a custom plugin function
- Understanding State in WordPress Multisites
- Can I use Symfony components in a plugin that I want to submit to the WordPress plugin repository?
- Custom license for WordPress plugin
- Custom Login Page — wp_signon Headers Already Sent?
- Is there a way to add custom endpoint to specific page only
- IF condition based on wp_remote_get output
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- How WordPress core manage the plugin installation
- Why is my WordPress Plugin page requesting my FTP Login Credentials?
- Cross Sells are not being shown in Cart Page. Please Help!
- Plugin not properly prepared for localization
- adding custom code as a wordpress plugin
- Show media-uploads to all users
- count the number of views of a post excluding own views
- Custom Post Type, Custom Columns List
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- How to upload large media file in chunks, without any plugin?
- How to set Google Analytics tracking code on WordPress plugin directory page?
- How to add styles to a submenu page?
- How to store a secret for a plugin inside public_html
- Problem with checked box on wp car manager plugin
- How to use functions found inside pluggable.php with my plugin files
- Create a link that calls our custom function in WordPress
- Update a previous version of plugin when the new plugin is built from the scratch
- wc_get_product_terms() throws “Notice: Undefined offset: 0”
- Woocommerce list variations that are added already to cart in Single Product
- Plugin json page
- How do I add a textarea (multirow) option to my WordPress plugin?
- Passing ajax variable to more than one wordpress plugin function
- search into subcategories plugin subcategory value not come
- Why isn’t my plugin seeing other classes?
- How Can the_post Be Hooked Like the_content and the_excerpt?
- Update post meta not working on wp_postmeta
- How to tell which Plugin is displaying?
- Get Core Functionality from Within a (Secondary) Plugin File
- wp_insert_post_data filter to set category
- is there a way I can add or remove some plugin options?
- How to provide access to specific plugin to all the user roles except subscriber in wordpress
- Output pure JSON wordpress
- What can I do to customize a widget provided with this plugin? from where have I to start?
- how to remove a rel=”nofollow” using call to action plugin
- Activate plugin button do nothing [closed]
- Custom wordpress plugin does not save select element
- How to set meta-data for my plugin
- WordPress isn’t sending welcome email with the password reset
- A splash page on landing page
- Inline AJAX script passing variables to PHP
- I’m getting the following error: Fatal error: Uncaught Error: Call to undefined function oil_paint_regeneration() [closed]
- how to code activate/deactive button of custom plugin within backend?
- move setting data from wordpress api to codestar freamwork
- How to access the page without registering in wordpress
- CPT template is not being automatically used single post pages
- How to trigger plugin migration code when plugin updates?
- How to Save Category and Delete Category in same Function
- claim a permalink and all sublinks in plugin
- Vanilla javascript in custom gutenberg block not working
- How to use `$order->get_discount_total()`, avoiding defoult WC decimal rounding?