Make WordPress Core


Ignore:
Timestamp:
11/23/2016 11:12:05 PM (9 years ago)
Author:
joehoyle
Message:

REST API: Allow unsetting a post’s password.

Props danielbachhuber, iseulde.
Fixes #38919.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r39349 r39352  
    974974
    975975        // Post password.
    976         if ( ! empty( $schema['properties']['password'] ) && isset( $request['password'] ) && '' !== $request['password'] ) {
     976        if ( ! empty( $schema['properties']['password'] ) && isset( $request['password'] ) ) {
    977977            $prepared_post->post_password = $request['password'];
    978978
    979             if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) {
    980                 return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) );
    981             }
    982 
    983             if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) {
    984                 return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) );
     979            if ( '' !== $request['password'] ) {
     980                if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) {
     981                    return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) );
     982                }
     983
     984                if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) {
     985                    return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) );
     986                }
    985987            }
    986988        }
Note: See TracChangeset for help on using the changeset viewer.