That’s because you’re not passing an actual ID to get_user_meta
, but merely a string of id
:
$get_portal_number = get_user_meta('id', 'portal_number', false);
In addition, the third parameter is set to false
, which will return an array. You’re passing that value straight to $user->add_role
, but that expects a string.
You either have to loop over your post meta results, or return the role as a single value by passing true
as the third parameter.
Try this:
add_action('um_after_save_registration_details', 'custom_after_new_user_register', 10, 2);
function custom_after_new_user_register($user_id) {
$user = get_user_by('id', $user_id);
$get_portal_number = get_user_meta($user_id, 'portal_number', true);
if (!in_array('subscriber', $user->roles)) {
$user->add_role($get_portal_number);
}}
Related Posts:
- Checking for user role in a custom plugin
- Redirection of users away from wp-admin (but not administrators)
- Allow a particular user to access a particular plugin?
- What are the differences between WPINC and ABSPATH?
- Using require_once in a Plugin?
- WordPress Capabilities: edit_user vs edit_users
- How to find out if option exists but is empty?
- Errors while using ajax from external wordpress page
- shortcode doesn’t work
- Current user in plugin returns NULL
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Scope for PHP Variables Assigned in functions.php or a plugin
- Plugin Development sqlite or WordPress’ database
- How to write a plugin to add users to a mail list
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- How to keep users unique id stored in session in addition to IP in WordPress plugin?
- Where should I save an API key of my user when installing my plugin?
- How to make a customize role and view a specific plugins base on that role?
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- WP Post Template – Templates in own folder
- New User Form – Custom Menu Page
- wordpress plugin is not activating from widget
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- What are the specifics of WordPress development I need to know? [closed]
- Ajax call returning 0
- How to create restrict content to users (by user, not by role)
- How to replace WordPress Media Upload Window with user’s device window?
- Conditional attributes and logic per product category
- How to create a custom post type that contains another custom post type?
- Can a Plugin Override New User Default Role Type
- Setup wp_schedule_event within a custom plugin
- Multisite – maximum number of users with specific role
- Issue running db create table query from static method
- execute function after one completed
- How to make multiple admin pages for one plugin?
- Include a php file from another plugin
- Integrating boxtal PHP library into a custom WordPress Plugin
- How to create plugin/ page that reads from database
- Save user total active time after login in wordpress [closed]
- How WordPress core manage the plugin installation
- Switch from wp-cron to a server cron job
- Why is it important to check for isset and is_array before checking in_array in this example?
- Calling a save function from a “submit” button
- Wp Debug Enabled True Notices and Warning
- How to call external functions from a PHP script in a WordPress plugin?
- How To Create A File Archive in WordPress?
- How to add custom function to pluggable.php
- Plugin privelages for “editors”
- How to displaying Custom image, text and default image logo from Redux Framework option panel
- Disable Author Archive just for certain roles in bulk
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- save_post_product action not firing
- How to get the custom field value using SQL query
- Unexpected add action function in WP plugin
- Prevent WordPress from sending set-cookie http header
- Cookie value changes back to previous value after changing
- How use wp_insert_post and add og:custom tags?
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Problem with checked box on wp car manager plugin
- WordPress rewrite rule depend on meta values not ids
- how to create user profile pages and display them based on users roles
- How to change “Read More” text?
- Problem with wordpress has_action() function
- Offering a freemium plugin (a free version + paid version)
- Using id to show item
- Generate and send ICS file through WordPress
- Is admin section completely customizable in terms of styling?
- Woocommerce list variations that are added already to cart in Single Product
- WordPress Admin sub-level menu issue
- Change pricing in Woocommerce based on Category and Product [closed]
- User / membership Plugin [closed]
- Passing ajax variable to more than one wordpress plugin function
- WordPress environment not loading properly
- WordPress not displaying information on post sent from custom admin form
- How to order users alphabetically by name? in plugin UPME
- Defined user role to access plugin’s pages
- Creating a user ‘add custom field’ section
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Saving an array to get_options
- Doing action based on input from options menu
- Help me with my first very basic plugin
- Want to add post to user dashboard
- How use Dynamic hyperlink on each wordpress post?
- My wordpress website admin panel loads very slow, what can i do about that? [closed]
- How to create post comparison in wordpress
- What can I do to customize a widget provided with this plugin? from where have I to start?
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- How to add custom html to the Media > Attachment Details modal?
- Function not being called on form submit, only blank admin-post.php page
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How to override plugin function in code snippets WordPress
- How to create a “Most Popular” & “Latest” TAB in WordPress
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- plugin doesn’t retrieve data from database