I am working on a wordpress project with the following plugins :
- Woocommerce product vendors
- WP Job Manager
- Wp Job Manager products
I am trying to upgrade the user role after adding a job, so the user can access the wp-admin and edit his own product.
Now the user can be upgraded to Manage his Vendor dashboard but the problem that the first time he adds a Job he must login/logout in order to refresh his roles and be able to access the Dashboard.
Here what I tried :
$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' );
Is it possible to achieve this by deleting the wp_cache_delete ... does anyone knows a good solution to upgrade user roles without login/logout ?
Thank you for you help!