Alright, finally I sorted it out – and it was a query error (embarrassing it is).
Correct code:
add_action( 'wpmu_activate_user', 'promote_to_admin', 99 );
function promote_to_admin( $user_id, $password, $meta ) {
global $wpdb;
$user = get_userdata( $user_id );
$email = $user->user_email;
// You need to prepare query first to avoid SQL errors
$query = $wpdb->prepare( "SELECT meta from `wp_signups` where `user_email` = %s", $email );
// By default, Object(stdClass) will be returned;
// tell WordPress to convert it to multidimensional array
$raw_meta = $wpdb->get_results( $query, ARRAY_A );
// After conversion, array will be represented as serialized string - unserialize it
$signup_meta = unserialize( $raw_meta[0]['meta'] );
if ( array_key_exists( 'new_role', $signup_meta ) ) {
$user->set_role( $signup_meta['new_role'] );
}
}
Related Posts:
- How do I remove/delete an old super admin user?
- Why is WordPress Multisite redirecting to wp-signup.php and how to fix it?
- Is there any central control/access panel for several WordPress sites?
- Delete sites in wordpress multisite (not suspend)
- How to synchronize user profile fields in multisite?
- How to customize the wp-signup.php for a multisite network?
- Get first_name and last_name on user_register hook
- User registration on subsite in multisite configuration
- Lock one of WP Network sites for not registered users
- Can you have multi-site WP and keep users separate?
- Multisite Independent User Base
- Why wordpress multisite redirect to wp-signup if site exists?
- Can wp-cli display all users and their roles across all sites in a multisite instance?
- How do I use different domain for subdomains in WP Multisite?
- Deleting a user in multisite
- how do I configure nginx for wordpress multisite, it occurs ERR_TOO_MANY_REDIRECTS
- Stuck with WordPress Multisite Custom signup page without .htaccess modification
- How do I list multisite users for the current site only
- Assign role to user on first login, if they are first (after admin)
- How to change user starting role in WordPress MultiSite?
- What is meant by Multisite in WordPress?
- Add menu items/actions for multisite users who are registered on the network but do not have a role or capability in any sites
- Multisite User Sync Question about blog authorship
- Preferred method of setting user role only works on Main Site in Network
- Register existing user on another site in a multisite network?
- Subsite access without being a member of the subsite in wp multisite network
- Site redirecting to http://example.com/wp-signup.php?new=example.com
- single sign on for wordpress multi site
- Multi-Site Subfolder User Permission Issue
- I want to create a 300 multi-site wordpress network using subdomains
- Network of multisites in WordPress, create new site with all the contents of the main
- how to create wordpress network with multiple wordpress installations
- WordPress multisite, allow non super admins to create sites
- User registration is currently not allowed
- Change WP-LOGIN and WP-SIGNUP for any request
- How to clone homepage for multi region site?
- Automatically add a registered user on the wordpress multisite network even to just one other site
- Easily adding multiple existing users to a multisite site
- Allowing users to manually add or remove themselves to/from WordPress multisite blogs
- WordPress API – sign-up to multiple Multisites from one single form
- Is there any hook to validate google recaptcha dislayed in wp-signup page [in WordPress Multisite]
- How to automate adduser (on linux) when add new user site in multisite
- Activation of new Registered site fails on multisite
- How to force WP to create a users table in multisite configuration?
- Right approach in doing this signup process
- How to give “author” user role appropriate capabilities to add PollDaddy polls? WordPress multisite
- Best way to convert two single WordPress sites into Multisite network with shared user base
- Advice on WP site structure using multisite
- Trying to create site-wide Active Directory sync with Multisite
- What are options are there to implement a multi language site
- WordPress Multisite Multiple child theme
- Built to scale, or worry later?
- Multisite Subdomains result in 403 Forbidden
- Set subdomains live in a next step
- W3 Total Cache Plugin with WP 3 MultiUser [closed]
- Should multi-language site using multi-site architecture have default language in base site?
- Multisite Installation: how do I setup global search?
- Register email as username
- Help with updating a wp_get_sites to get_sites and sorting by alphebetical order
- Multisite Subdomain Using More Resources Than Others?
- Can I use multisite functions in a single-site installation?
- WordPress Multisite prevent direct access to subdomain
- WordPress mutisite migration
- WordPress multisite change language
- Multisite, multiple domains per site
- delete_user_meta : how to delete all the metadata of a given user (witout SQL)
- Within the database, where is the flag which says that a user has Super Admin rights?
- problem with main site (root domain) redirects to subdomain (multisite)
- Upload file type not permitted even if explicitly registered as upload_filetypes in the db (multisite)
- Optimizing Query used for a Shortcode
- How to enable error logs and debug mode in WordPress using Azure Cloud?
- Multisite Redirection to new domains
- Mapping domains to WordPress network installed on subdomain
- How Can I Automatically Post WordPress Posts to 2 Domains
- Move Multiple WP Installs on a single domain to WP Multisite
- Activated multisite and added a site, but can’t access it
- Multisite domain mapping breaks CSS
- multisite (MU) Subdomain- only one wordpress install
- Creating a subdomain network in a subdomain
- Sub-sub folders of WordPress Multisite subdirectory
- Allow editors to switch sites (Multisite)
- moving tables between multisite installs
- Best Practise: Linking to WPMU sites from other sites
- Trouble with SQL SELECT inside switch_to_blog()
- WordPress Multisite and how to apply sef urls only to specific sites
- Custom css – WordPress Multisite
- “Multisite support is not enabled.” After Multisite Config Changes
- String translation within WordPress multisite with i18n not working on all sites
- Add new sites on the same level as the parent URL in a multisite
- Search returns “Nothing Found” on a sub directory
- Users getting linked unwanted to main mu in WordPress multisite (WPMU)
- Changed singlesite to multisite, but new site shows Maintenance
- Responsive Wordress Site – Serve different post types to each device
- Is there a way to have wordpress 301 versus 302 urls by default?
- Some Subdomains on a Multisite Install Not Found
- personal_options hook on WordPress multisite
- Multi site root site installed on subdomain, with child sites as subdirectories
- Integrating WordPress for blog and other content pages in a web app
- The wpmu_blogs_columns filter is not working
- Map WP Multisite blog.example.com to anotherdomain.com/blog?