In wordpress I am using the following plugins Woocommerce, Woocommerce product vendors, WP Job Manager, Wp Job Manager products. I want to upgrade the user role after adding a job, so the user can access the wp-admin and edit his own product.
user can upgrade to Manage his Vendor dashboard, but the difficulty is first time he adds a Job he must login/logout in order to refresh his roles and be able to access the Dashboard.
My code is
$current_user = wp_get_current_user();
//Code 1 :
$user_id = wp_update_user(
array( 'ID' => $current_user->ID, 'role' => 'wc_product_vendors_manager_vendor' )
//Code 2 :
$user = new WP_User( $current_user->ID );
$user->remove_role( 'customer' );
$user->set_role( 'wc_product_vendors_manager_vendor' );
//Code 3 : ( this will make the user with 2 roles )
$current_user->add_role( 'wc_product_vendors_manager_vendor' );
Can I get this by deleting
wp_cache_delete . Please tell how to upgrade user roles without login/logout ?