Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r46729 r47122  
    139139     */
    140140    protected function get_parent( $parent ) {
    141         $error = new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent ID.' ), array( 'status' => 404 ) );
     141        $error = new WP_Error(
     142            'rest_post_invalid_parent',
     143            __( 'Invalid post parent ID.' ),
     144            array( 'status' => 404 )
     145        );
    142146        if ( (int) $parent <= 0 ) {
    143147            return $error;
     
    167171
    168172        $parent_post_type_obj = get_post_type_object( $parent->post_type );
     173
    169174        if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) {
    170             return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) );
     175            return new WP_Error(
     176                'rest_cannot_read',
     177                __( 'Sorry, you are not allowed to view revisions of this post.' ),
     178                array( 'status' => rest_authorization_required_code() )
     179            );
    171180        }
    172181
     
    183192     */
    184193    protected function get_revision( $id ) {
    185         $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision ID.' ), array( 'status' => 404 ) );
     194        $error = new WP_Error(
     195            'rest_post_invalid_id',
     196            __( 'Invalid revision ID.' ),
     197            array( 'status' => 404 )
     198        );
     199
    186200        if ( (int) $id <= 0 ) {
    187201            return $error;
     
    212226        // Ensure a search string is set in case the orderby is set to 'relevance'.
    213227        if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) {
    214             return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
     228            return new WP_Error(
     229                'rest_no_search_term_defined',
     230                __( 'You need to define a search term to order by relevance.' ),
     231                array( 'status' => 400 )
     232            );
    215233        }
    216234
    217235        // Ensure an include parameter is set in case the orderby is set to 'include'.
    218236        if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) {
    219             return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) );
     237            return new WP_Error(
     238                'rest_orderby_include_missing_include',
     239                __( 'You need to define an include parameter to order by include.' ),
     240                array( 'status' => 400 )
     241            );
    220242        }
    221243
     
    282304            if ( $total_revisions > 0 ) {
    283305                if ( $offset >= $total_revisions ) {
    284                     return new WP_Error( 'rest_revision_invalid_offset_number', __( 'The offset number requested is larger than or equal to the number of available revisions.' ), array( 'status' => 400 ) );
     306                    return new WP_Error(
     307                        'rest_revision_invalid_offset_number',
     308                        __( 'The offset number requested is larger than or equal to the number of available revisions.' ),
     309                        array( 'status' => 400 )
     310                    );
    285311                } elseif ( ! $offset && $page > $max_pages ) {
    286                     return new WP_Error( 'rest_revision_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
     312                    return new WP_Error(
     313                        'rest_revision_invalid_page_number',
     314                        __( 'The page number requested is larger than the number of pages available.' ),
     315                        array( 'status' => 400 )
     316                    );
    287317                }
    288318            }
     
    295325
    296326        $response = array();
     327
    297328        foreach ( $revisions as $revision ) {
    298329            $data       = $this->prepare_item_for_response( $revision, $request );
     
    355386
    356387        $parent_post_type = get_post_type_object( $parent->post_type );
     388
    357389        if ( ! current_user_can( $parent_post_type->cap->delete_post, $parent->ID ) ) {
    358             return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) );
     390            return new WP_Error(
     391                'rest_cannot_delete',
     392                __( 'Sorry, you are not allowed to delete revisions of this post.' ),
     393                array( 'status' => rest_authorization_required_code() )
     394            );
    359395        }
    360396
     
    395431
    396432        if ( ! current_user_can( $post_type->cap->delete_post, $revision->ID ) ) {
    397             return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this revision.' ), array( 'status' => rest_authorization_required_code() ) );
     433            return new WP_Error(
     434                'rest_cannot_delete',
     435                __( 'Sorry, you are not allowed to delete this revision.' ),
     436                array( 'status' => rest_authorization_required_code() )
     437            );
    398438        }
    399439
     
    419459        // We don't support trashing for revisions.
    420460        if ( ! $force ) {
    421             /* translators: %s: force=true */
    422             return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) );
     461            return new WP_Error(
     462                'rest_trash_not_supported',
     463                /* translators: %s: force=true */
     464                sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ),
     465                array( 'status' => 501 )
     466            );
    423467        }
    424468
     
    440484
    441485        if ( ! $result ) {
    442             return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) );
     486            return new WP_Error(
     487                'rest_cannot_delete',
     488                __( 'The post cannot be deleted.' ),
     489                array( 'status' => 500 )
     490            );
    443491        }
    444492
     
    702750
    703751        $this->schema = $schema;
     752
    704753        return $this->add_additional_fields_schema( $this->schema );
    705754    }
Note: See TracChangeset for help on using the changeset viewer.