Change "Current password" optional

Dear Support Team,

I’ve encountered an issue with the current password field in the HivePress user dashboard.

Screenshot: https://paste.pics/52d92151337754344293c06d949ec981

Despite attempting to remove or hide the current password field, it continues to be mandatory for updating fields such as email. This poses a significant inconvenience to users.

I urgently request your assistance in resolving this issue. It’s imperative that the current password field is not required for any updates made in the user profile/dashboard.

Your prompt attention to this matter would be greatly appreciated.

Thank you.

Best regards,

I have tried this, but its not working:

<?php add_filter( 'hivepress/v1/forms/user-update-profile', function( $form ) { // Make current password optional if (isset($form['fields']['current_password'])) { $form['fields']['current_password']['required'] = false; } // Make email optional if (isset($form['fields']['email'])) { $form['fields']['email']['required'] = false; } return $form; }, 1000 ); Both email and current password is still required.

I have tried this code but is again not working: still asking for current password

add_filter(
    'hivepress/v1/forms/user_update_profile',
    function( $form ) {
        // Check if the "current_password" field exists
        if (isset($form['fields']['current_password'])) {
            // Set the "required" attribute to false
            $form['fields']['current_password']['required'] = false;
        }

        return $form;
    }
);

Hello Support Team,

I’m reaching out regarding an issue I’ve encountered with the current password requirement during user profile updates on my WordPress website. Despite extensive troubleshooting efforts, I have been unable to resolve this issue. Here’s a summary of what I’ve tried and tested so far:

  1. Hook Removal: I attempted to remove the current password field from the user update profile form by utilizing various filters such as hivepress/v1/forms/user_update and hivepress/v1/forms/user-update-profile. However, even after multiple attempts, the current password field continued to be required.
  2. Code Inspections: I thoroughly examined PHP files such as class-user-update.php and class-user-update-profile.php to ensure that the current password field was being properly removed or modified. Despite making adjustments to these files, the issue persisted.
  3. Plugin Conflict: To rule out conflicts with other plugins, I deactivated all plugins except HivePress and tested for the issue. However, even with all other plugins deactivated, the current password requirement remained unchanged.
  4. Database Inspection: I reviewed the WordPress database tables wpi5_usermeta and wpi5_users, as well as any related database entries, to check for configurations or settings related to user passwords. However, no specific issues were identified in the database.
  5. JavaScript Modifications: I explored the possibility of using JavaScript to manipulate form submissions and bypass the current password requirement. However, attempts to modify form submissions through JavaScript did not resolve the issue.

Despite these efforts, the current password requirement persists during user profile updates. I’m reaching out to seek further assistance and guidance on how to resolve this issue. Any insights or suggestions you can provide would be greatly appreciated.

Hi,

We recommend leaving this as it is, as the password is required for major changes, such as email for example. If, for example, you delete the field and change the email, it will still ask for the password, as this is a condition in the code. If you decide to remove the password field for sure, we recommend using this hook hivepress/v1/forms/user_update/errors, which can catch that password error and remove it from the array of filtered errors, thus skipping it.

​I hope this is helpful to you.

Thanks for your reply but unfortunately it is not working, kindly see what I have tried after your suggestions:

add_filter(
    'hivepress/v1/forms/user_update/errors',
    function( $errors, $form ) {
        // Check if there's a password error in the array of errors
        if ( ! empty( $errors['password'] ) ) {
            // Remove the password error from the array of errors
            unset( $errors['password'] );
        }

        return $errors;
    },
    10, // Priority
    2   // Number of arguments passed to the filter
);


add_filter(
    'hivepress/v1/forms/user_update',
    function( $form ) {
        // Check if the "current_password" field exists
        if ( isset( $form['fields']['current_password'] ) ) {
            // Remove the "current_password" field from the form
            unset( $form['fields']['current_password'] );
        }

        return $form;
    },
    1000
);


add_filter(
    'hivepress/v1/forms/user_update/errors',
    function( $errors, $form ) {
        // Check if the errors array contains the current password error
        if ( isset( $errors['current_password'] ) ) {
            // Remove the current password error from the errors array
            unset( $errors['current_password'] );
        }

        return $errors;
    },
    1000,
    2
);


add_filter(
    'hivepress/v1/forms/user_update/errors',
    function( $errors, $form ) {
        // Check if the errors array contains the current password error
        if ( isset( $errors['current_password'] ) ) {
            // Remove the current password error from the errors array
            unset( $errors['current_password'] );
        }

        return $errors;
    },
    9999, // Increase the priority
    2
);


add_filter(
    'hivepress/v1/forms/user_update',
    function( $form ) {
        // Check if the "current_password" field exists
        if (isset($form['fields']['current_password'])) {
            // Remove the "current_password" field from the form
            unset($form['fields']['current_password']);
        }

        return $form;
    },
    1000
);

Dear andril, currently I have only email field is mandator in user profile rest of all is optional. When I am trying to update email it is asking for: current password is required.

I am now totally confused what to do. kindly help. Give me condition of code.

Finally I got the solutions from this page:
From: Disable Password Required User Account Page - #3 by Andrew
hivepress/includes/controllers/class-user.php at master · hivepress/hivepress · GitHub

Just go to line 642 and replace line 642-657 with given below codes, that I have generated using chatgpt

$form->set_values( $request->get_params() );

if ( ! $form->validate() ) {
    return hp\rest_error( 400, $form->get_errors() );
}

// Check if the email field is being updated
if ( $form->get_value( 'email' ) !== $user->get_email() ) {
    // Do any additional validation specific to the email field here
}

// Proceed with updating the user profile

This will disable current password required errors, especially when you are updating email field, especially for my condition in which I have no password, no current password fields.

1 Like