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.
Problem:
Using cred form to remove user was triggering a fatal error and not deleting the user Solution:
I added a priority and fixed param numbers to the add_action call. I also test if the form_data is valid before moving forward to the deletion: