Support » Plugin: Password Protected » REST API blocked

  • Hi there

    I have version 2.2.2 installed and even if the Password Protected Status is not enabled it blocks the access to the Rest API for not logged in users.

    Is that an intended behaviour?

    Kind regards,
    Nico

Viewing 5 replies - 1 through 5 (of 5 total)
  • Nico

    (@kodak2305)

    I have the same problem and it also breaks Contact Form 7 and possible other plugins!

    >I have version 2.2.2 installed and even if the Password Protected Status is not enabled it blocks the access to the Rest API for not logged in users.

    I have the same problem.

    Me too. I have disabled the plugin because it blocks the Rest API.

    401 Error Code returned. Unauthorized.

    Any ideas on a fix?

    Ta

    Hotfix:

    1. Open password-protected.php in your plugins/password-protected/ folder.
    2. Look at the end of the file around line 800
    3. There is a function called “only_allow_logged_in_rest_access”, this function needs a modification
    4. Look at the if-condition:

    if ( ! $this->is_user_logged_in() && ! is_user_logged_in() && ! (bool) get_option( 'password_protected_rest' ) ) {
    			return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'password-protected' ), array( 'status' => rest_authorization_required_code() ) );
    		}

    Replace it with:

    if ( (bool) get_option('password_protected_status') && ! $this->is_user_logged_in() && ! is_user_logged_in() && ! (bool) get_option( 'password_protected_rest' ) ) {
    			return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'password-protected' ), array( 'status' => rest_authorization_required_code() ) );
    		}

    Done!

    Explaination:
    The rest api will be blocked always if the user isn’t logged in and the option to allow rest is not checked. Now, with the hotfix, the status checkbox to activate the plugin on the password protected option page needs also to be checked to block the api.

    This has been fixed in version 2.2.3

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘REST API blocked’ is closed to new replies.