This thread is resolved. Here is a description of the problem and solution.
Problem:
Trying to change the user role from pending to approved provoked a fatal error on the site. Solution:
I changed the code and switched how the user role is added. I initiate a variable with the user's ID, remove the old role and add the new one as follow:
add_action('cred_submit_complete', 'cred_update_user_role_pending', 10,2);
function cred_update_user_role_pending($post_id, $form_data) {
require_once(ABSPATH.'wp-admin/includes/user.php');
if ( isset($form_data) && !empty($form_data) && isset($form_data['id']) && $form_data['id'] == 4981 ) {
// update the user role
$user = new WP_User( $post_id );
$user->remove_role( 'pending_vendor' );
$user->add_role( 'vendor' );
}
}
I also put in a check to make sure by the time the form is submitted, there's a valid formdata, it was causing a fatal error for some reason.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Likewise the other ticket, just as a test, please temporarily remove the code from the plugin code-snippets and add it to your functions.php file to see if it gets the issue fixed.
If the issue remains, I would like to request temporary access (wp-admin and FTP) to your site to take better look at both issues. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.
Our Debugging Procedures
I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.
- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link
Please, let me know if you need any additional details. Have a nice day.
I changed the code slightly in order to get it worked, this is the final version:
add_action('cred_submit_complete', 'cred_update_user_role_pending', 10,2);
function cred_update_user_role_pending($post_id, $form_data) {
require_once(ABSPATH.'wp-admin/includes/user.php');
if ( isset($form_data) && !empty($form_data) && isset($form_data['id']) && $form_data['id'] == 4981 ) {
// update the user role
$user = new WP_User( $post_id );
$user->remove_role( 'pending_vendor' );
$user->add_role( 'vendor' );
}
}
I changed how the role was changed with an instantiated object approach and I added a check to see if the form_data is not null before checking the form ID just in case.
After that I tested the functionality and I was able to delete the test vendor just fine.