Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (5 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-terms-controller.php

    r46823 r47122  
    145145    public function get_items_permissions_check( $request ) {
    146146        $tax_obj = get_taxonomy( $this->taxonomy );
     147
    147148        if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
    148149            return false;
    149150        }
     151
    150152        if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) {
    151             return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
    152         }
     153            return new WP_Error(
     154                'rest_forbidden_context',
     155                __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ),
     156                array( 'status' => rest_authorization_required_code() )
     157            );
     158        }
     159
    153160        return true;
    154161    }
     
    259266        $total_terms = wp_count_terms( $this->taxonomy, $count_args );
    260267
    261         // wp_count_terms can return a falsy value when the term has no children.
     268        // wp_count_terms() can return a falsy value when the term has no children.
    262269        if ( ! $total_terms ) {
    263270            $total_terms = 0;
     
    313320     */
    314321    protected function get_term( $id ) {
    315         $error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) );
     322        $error = new WP_Error(
     323            'rest_term_invalid',
     324            __( 'Term does not exist.' ),
     325            array( 'status' => 404 )
     326        );
    316327
    317328        if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
     
    341352    public function get_item_permissions_check( $request ) {
    342353        $term = $this->get_term( $request['id'] );
     354
    343355        if ( is_wp_error( $term ) ) {
    344356            return $term;
     
    346358
    347359        if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) {
    348             return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) );
    349         }
     360            return new WP_Error(
     361                'rest_forbidden_context',
     362                __( 'Sorry, you are not allowed to edit this term.' ),
     363                array( 'status' => rest_authorization_required_code() )
     364            );
     365        }
     366
    350367        return true;
    351368    }
     
    385402
    386403        $taxonomy_obj = get_taxonomy( $this->taxonomy );
     404
    387405        if ( ( is_taxonomy_hierarchical( $this->taxonomy )
    388406                && ! current_user_can( $taxonomy_obj->cap->edit_terms ) )
    389407            || ( ! is_taxonomy_hierarchical( $this->taxonomy )
    390408                && ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) {
    391             return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) );
     409            return new WP_Error(
     410                'rest_cannot_create',
     411                __( 'Sorry, you are not allowed to create new terms.' ),
     412                array( 'status' => rest_authorization_required_code() )
     413            );
    392414        }
    393415
     
    406428        if ( isset( $request['parent'] ) ) {
    407429            if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
    408                 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
     430                return new WP_Error(
     431                    'rest_taxonomy_not_hierarchical',
     432                    __( 'Cannot set parent term, taxonomy is not hierarchical.' ),
     433                    array( 'status' => 400 )
     434                );
    409435            }
    410436
     
    412438
    413439            if ( ! $parent ) {
    414                 return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) );
     440                return new WP_Error(
     441                    'rest_term_invalid',
     442                    __( 'Parent term does not exist.' ),
     443                    array( 'status' => 400 )
     444                );
    415445            }
    416446        }
     
    503533    public function update_item_permissions_check( $request ) {
    504534        $term = $this->get_term( $request['id'] );
     535
    505536        if ( is_wp_error( $term ) ) {
    506537            return $term;
     
    508539
    509540        if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
    510             return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) );
     541            return new WP_Error(
     542                'rest_cannot_update',
     543                __( 'Sorry, you are not allowed to edit this term.' ),
     544                array( 'status' => rest_authorization_required_code() )
     545            );
    511546        }
    512547
     
    530565        if ( isset( $request['parent'] ) ) {
    531566            if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
    532                 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
     567                return new WP_Error(
     568                    'rest_taxonomy_not_hierarchical',
     569                    __( 'Cannot set parent term, taxonomy is not hierarchical.' ),
     570                    array( 'status' => 400 )
     571                );
    533572            }
    534573
     
    536575
    537576            if ( ! $parent ) {
    538                 return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) );
     577                return new WP_Error(
     578                    'rest_term_invalid',
     579                    __( 'Parent term does not exist.' ),
     580                    array( 'status' => 400 )
     581                );
    539582            }
    540583        }
     
    591634    public function delete_item_permissions_check( $request ) {
    592635        $term = $this->get_term( $request['id'] );
     636
    593637        if ( is_wp_error( $term ) ) {
    594638            return $term;
     
    596640
    597641        if ( ! current_user_can( 'delete_term', $term->term_id ) ) {
    598             return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) );
     642            return new WP_Error(
     643                'rest_cannot_delete',
     644                __( 'Sorry, you are not allowed to delete this term.' ),
     645                array( 'status' => rest_authorization_required_code() )
     646            );
    599647        }
    600648
     
    620668        // We don't support trashing for terms.
    621669        if ( ! $force ) {
    622             /* translators: %s: force=true */
    623             return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) );
     670            return new WP_Error(
     671                'rest_trash_not_supported',
     672                /* translators: %s: force=true */
     673                sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ),
     674                array( 'status' => 501 )
     675            );
    624676        }
    625677
     
    631683
    632684        if ( ! $retval ) {
    633             return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) );
     685            return new WP_Error(
     686                'rest_cannot_delete',
     687                __( 'The term cannot be deleted.' ),
     688                array( 'status' => 500 )
     689            );
    634690        }
    635691
     
    930986
    931987        $this->schema = $schema;
     988
    932989        return $this->add_additional_fields_schema( $this->schema );
    933990    }
Note: See TracChangeset for help on using the changeset viewer.