Make WordPress Core

Ticket #43977: 43977.2.diff

File 43977.2.diff, 7.2 KB (added by flixos90, 8 years ago)
  • src/wp-includes/bookmark.php

     
    171171                $r['exclude']       = '';  //ignore exclude, category, and category_name params if using include
    172172                $r['category']      = '';
    173173                $r['category_name'] = '';
    174                 $inclinks           = preg_split( '/[\s,]+/', $r['include'] );
     174                $inclinks           = wp_parse_id_list( $r['include'] );
    175175                if ( count( $inclinks ) ) {
    176176                        foreach ( $inclinks as $inclink ) {
    177177                                if ( empty( $inclusions ) ) {
    178                                         $inclusions = ' AND ( link_id = ' . intval( $inclink ) . ' ';
     178                                        $inclusions = ' AND ( link_id = ' . $inclink . ' ';
    179179                                } else {
    180                                         $inclusions .= ' OR link_id = ' . intval( $inclink ) . ' ';
     180                                        $inclusions .= ' OR link_id = ' . $inclink . ' ';
    181181                                }
    182182                        }
    183183                }
    … …  
    188188
    189189        $exclusions = '';
    190190        if ( ! empty( $r['exclude'] ) ) {
    191                 $exlinks = preg_split( '/[\s,]+/', $r['exclude'] );
     191                $exlinks = wp_parse_id_list( $r['exclude'] );
    192192                if ( count( $exlinks ) ) {
    193193                        foreach ( $exlinks as $exlink ) {
    194194                                if ( empty( $exclusions ) ) {
    195                                         $exclusions = ' AND ( link_id <> ' . intval( $exlink ) . ' ';
     195                                        $exclusions = ' AND ( link_id <> ' . $exlink . ' ';
    196196                                } else {
    197                                         $exclusions .= ' AND link_id <> ' . intval( $exlink ) . ' ';
     197                                        $exclusions .= ' AND link_id <> ' . $exlink . ' ';
    198198                                }
    199199                        }
    200200                }
    … …  
    223223        $category_query = '';
    224224        $join           = '';
    225225        if ( ! empty( $r['category'] ) ) {
    226                 $incategories = preg_split( '/[\s,]+/', $r['category'] );
     226                $incategories = wp_parse_id_list( $r['category'] );
    227227                if ( count( $incategories ) ) {
    228228                        foreach ( $incategories as $incat ) {
    229229                                if ( empty( $category_query ) ) {
    230                                         $category_query = ' AND ( tt.term_id = ' . intval( $incat ) . ' ';
     230                                        $category_query = ' AND ( tt.term_id = ' . $incat . ' ';
    231231                                } else {
    232                                         $category_query .= ' OR tt.term_id = ' . intval( $incat ) . ' ';
     232                                        $category_query .= ' OR tt.term_id = ' . $incat . ' ';
    233233                                }
    234234                        }
    235235                }
  • src/wp-includes/class-wp-comment-query.php

     
    482482
    483483                // 'status' accepts an array or a comma-separated string.
    484484                $status_clauses = array();
    485                 $statuses       = $this->query_vars['status'];
    486                 if ( ! is_array( $statuses ) ) {
    487                         $statuses = preg_split( '/[\s,]+/', $statuses );
    488                 }
     485                $statuses       = wp_parse_list( $this->query_vars['status'] );
    489486
    490487                // 'any' overrides other statuses.
    491488                if ( ! in_array( 'any', $statuses ) ) {
    … …  
    517514
    518515                // User IDs or emails whose unapproved comments are included, regardless of $status.
    519516                if ( ! empty( $this->query_vars['include_unapproved'] ) ) {
    520                         $include_unapproved = $this->query_vars['include_unapproved'];
    521 
    522                         // Accepts arrays or comma-separated strings.
    523                         if ( ! is_array( $include_unapproved ) ) {
    524                                 $include_unapproved = preg_split( '/[\s,]+/', $include_unapproved );
    525                         }
     517                        $include_unapproved = wp_parse_list( $this->query_vars['include_unapproved'] );
    526518
    527                         $unapproved_ids = $unapproved_emails = array();
     519                        $unapproved_ids    = array();
     520                        $unapproved_emails = array();
    528521                        foreach ( $include_unapproved as $unapproved_identifier ) {
    529522                                // Numeric values are assumed to be user ids.
    530523                                if ( is_numeric( $unapproved_identifier ) ) {
  • src/wp-includes/functions.php

     
    36923692}
    36933693
    36943694/**
     3695 * Cleans up an array, comma- or space-separated list of scalar values.
     3696 *
     3697 * @since 5.0.0
     3698 *
     3699 * @param array|string $list List of values.
     3700 * @return array Sanitized array of values.
     3701 */
     3702function wp_parse_list( $list ) {
     3703        if ( ! is_array( $list ) ) {
     3704                return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
     3705        }
     3706
     3707        return $list;
     3708}
     3709
     3710/**
    36953711 * Clean up an array, comma- or space-separated list of IDs.
    36963712 *
    36973713 * @since 3.0.0
    … …  
    37003716 * @return array Sanitized array of IDs.
    37013717 */
    37023718function wp_parse_id_list( $list ) {
    3703         if ( ! is_array( $list ) ) {
    3704                 $list = preg_split( '/[\s,]+/', $list );
    3705         }
     3719        $list = wp_parse_list( $list );
    37063720
    37073721        return array_unique( array_map( 'absint', $list ) );
    37083722}
    … …  
    37163730 * @return array Sanitized array of slugs.
    37173731 */
    37183732function wp_parse_slug_list( $list ) {
    3719         if ( ! is_array( $list ) ) {
    3720                 $list = preg_split( '/[\s,]+/', $list );
    3721         }
    3722 
    3723         foreach ( $list as $key => $value ) {
    3724                 $list[ $key ] = sanitize_title( $value );
    3725         }
     3733        $list = wp_parse_list( $list );
    37263734
    3727         return array_unique( $list );
     3735        return array_unique( array_map( 'sanitize_title', $list ) );
    37283736}
    37293737
    37303738/**
  • src/wp-includes/post.php

     
    50045004
    50055005        $author_query = '';
    50065006        if ( ! empty( $r['authors'] ) ) {
    5007                 $post_authors = preg_split( '/[\s,]+/', $r['authors'] );
     5007                $post_authors = wp_parse_list( $r['authors'] );
    50085008
    50095009                if ( ! empty( $post_authors ) ) {
    50105010                        foreach ( $post_authors as $post_author ) {
  • src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

     
    521521                if ( ! isset( $request['_fields'] ) ) {
    522522                        return $fields;
    523523                }
    524                 $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
     524                $requested_fields = wp_parse_list( $request['_fields'] );
    525525                if ( 0 === count( $requested_fields ) ) {
    526526                        return $fields;
    527527                }
  • src/wp-includes/rest-api.php

     
    651651
    652652        $data = $response->get_data();
    653653
    654         $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
     654        $fields = wp_parse_list( $request['_fields'] );
    655655
    656656        if ( 0 === count( $fields ) ) {
    657657                return $response;
    … …  
    10811081 */
    10821082function rest_validate_value_from_schema( $value, $args, $param = '' ) {
    10831083        if ( 'array' === $args['type'] ) {
    1084                 if ( ! is_array( $value ) ) {
    1085                         $value = preg_split( '/[\s,]+/', $value );
    1086                 }
     1084                $value = wp_parse_list( $value );
    10871085                if ( ! wp_is_numeric_array( $value ) ) {
    10881086                        /* translators: 1: parameter, 2: type name */
    10891087                        return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) );
    … …  
    12251223                if ( empty( $args['items'] ) ) {
    12261224                        return (array) $value;
    12271225                }
    1228                 if ( ! is_array( $value ) ) {
    1229                         $value = preg_split( '/[\s,]+/', $value );
    1230                 }
     1226                $value = wp_parse_list( $value );
    12311227                foreach ( $value as $index => $v ) {
    12321228                        $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] );
    12331229                }