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?
- Where the Nickname is being used in WordPress
- Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader
- How to remove duplicate sub-menu name for top level menu items in a plugin?
- Keep one user logged for a year?
- Customizing subject in comment notification e-mails
- category_name not working (not showing up in sql query debug)
- Using require_once in a Plugin?
- How can I make my custom shortcode work in a Custom HTML Widget?
- How to Loop Plugin Option Field Set?
- 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?
- Update Multiple Post Meta for the Same Post In One call?
- Allowing Custom Capability to Manage Plugin Options
- How to pass JavaScript variable to PHP in wordpress widget?
- Unable to add admin notice on plugin activation
- How To Ignore a Filter On Applying Filter the Content In a Function
- Saving Plugin settings to the database
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- WordPress widget / plugin….fields not appearing in my widget
- Add CSS animation as Preloader to WordPress
- Rename existing old uploaded images containing accented French characters (not during upload)
- How to list the Hooks and order of execution in current loading page? [duplicate]
- How can I let users to access plugin functions based on roles?
- How to Create a Directory in a Plugin Folder?
- Errors while using ajax from external wordpress page
- shortcode doesn’t work
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- Create plugin that works in background
- Deleting images through upload folder, but not deleting from media library
- Custom Shipping method not showing in checkout
- HELP: Integrating WP with raw PHP code once published button is hit
- Loading class files via autoload method
- WordPress plugin installation
- Allow Facebook to preview posts before published
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Getting media library popup in custom plugin admin page
- Create or Update thousands of woocommerce products via PHP
- send_headers don’t work on wordpress multisite
- jQuery function didn’t work in my plugin
- Current user in plugin returns NULL
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Escape when echoed
- Scope for PHP Variables Assigned in functions.php or a plugin
- Plugin exceeds memory limit
- Set user ID at time of wp_create_user
- Write to / remove from default .htaccess file from plugin?
- Update Option Error: Notice: Undefined index
- Plugin Development sqlite or WordPress’ database
- Getting user roles in plugin files
- Auto delete WordPress users according to time
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to trigger $_GET request within admin plugin page?
- How to generate video out of images via WordPress plugin
- How to write a plugin to add users to a mail list
- How can I get WordPress to save comments in markdown format?
- WooCommerce get_price returning wrong price when used via ajax
- How to ‘clone’ a wp plugin to make small changes
- 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?
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Programatically download a plugin
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- Redirecting to home page after login as custom role WordPress
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- Self deactivate plugins after an action occurs
- How to get current post user id
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- WP Post Template – Templates in own folder
- Avoid class name collision when using third party libraries in plugins?
- New User Form – Custom Menu Page
- wordpress plugin is not activating from widget
- Edit Yoast SEO breadcrumbs output [closed]
- How would I go about creating a user ranked post popularity page?
- Using a custom plugin to capture input data via Ajax and PHP
- wp_set_auth_cookie causes 403 error in the wooCommerce checkout
- code is working properly in Core PHP but writing coding in WordPress
- 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
- Image upload and download from front-end
- wp_remote_get() returns 403 while file_get_contents() does not
- How to output CMB2 select options from repeated groups select elements?
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
- WooCommerce specifc variations for specific user role [closed]
- 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 set add question capability for author role in wp pro quiz plugin
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- WP All Import – Execute Imports