Make WordPress Core

Ticket #50568: wp-includes.patch

File wp-includes.patch, 5.1 KB (added by Cybr, 5 years ago)
  • wp-includes/category.php

     
    247247        return term_is_ancestor_of( $cat1, $cat2, 'category' );
    248248}
    249249
     250// deprecate this?
    250251/**
    251252 * Sanitizes category data based on context.
    252253 *
     
    260261        return sanitize_term( $category, 'category', $context );
    261262}
    262263
     264// deprecate this?
    263265/**
    264266 * Sanitizes data in single category key field.
    265267 *
  • wp-includes/class-wp-term.php

     
    180180                        }
    181181                }
    182182
    183                 $term_obj = new WP_Term( $_term );
    184                 $term_obj->filter( $term_obj->filter );
    185 
    186                 return $term_obj;
     183                return new WP_Term( $_term );
    187184        }
    188185
    189186        /**
     
    207204         * @param string $filter Filter context. Accepts 'edit', 'db', 'display', 'attribute', 'js', 'raw'.
    208205         */
    209206        public function filter( $filter ) {
    210                 sanitize_term( $this, $this->taxonomy, $filter );
     207                if ( $this->filter === $filter ) {
     208                        return $this;
     209                }
     210
     211                if ( 'raw' === $filter ) {
     212                        return self::get_instance( $this->term_id );
     213                }
     214
     215                return sanitize_term( $this, $this->taxonomy, $filter );
    211216        }
    212217
    213218        /**
  • wp-includes/taxonomy.php

     
    828828        if ( $term instanceof WP_Term ) {
    829829                $_term = $term;
    830830        } elseif ( is_object( $term ) ) {
    831                 if ( empty( $term->filter ) || 'raw' === $term->filter ) {
     831                if ( empty( $term->filter ) ) {
    832832                        $_term = sanitize_term( $term, $taxonomy, 'raw' );
    833833                        $_term = new WP_Term( $_term );
     834                } elseif ( 'raw' === $term->filter ) {
     835                        $_term = new WP_Term( $_term );
    834836                } else {
    835837                        $_term = WP_Term::get_instance( $term->term_id );
    836838                }
     
    14811483 * @param array|object $term     The term to check.
    14821484 * @param string       $taxonomy The taxonomy name to use.
    14831485 * @param string       $context  Optional. Context in which to sanitize the term. Accepts 'edit', 'db',
    1484  *                               'display', 'attribute', or 'js'. Default 'display'.
     1486 *                               'display', 'attribute', 'raw', or 'js'. Default 'display'.
    14851487 * @return array|object Term with all fields sanitized.
    14861488 */
    14871489function sanitize_term( $term, $taxonomy, $context = 'display' ) {
     1490        // This array doesn't match WP>4.4 WP_Term per se... scrutinize me?
    14881491        $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' );
    14891492
    1490         $do_object = is_object( $term );
    1491 
    1492         $term_id = $do_object ? $term->term_id : ( isset( $term['term_id'] ) ? $term['term_id'] : 0 );
    1493 
    1494         foreach ( (array) $fields as $field ) {
    1495                 if ( $do_object ) {
     1493        if ( is_object( $term ) ) {
     1494                // Check if term already filtered for this context.
     1495                if ( isset( $term->filter ) && $context === $term->filter ) {
     1496                        return $term;
     1497                }
     1498                if ( ! isset( $term->term_id ) ) {
     1499                        $term->term_id = 0;
     1500                }
     1501                foreach ( (array) $fields as $field ) {
    14961502                        if ( isset( $term->$field ) ) {
    1497                                 $term->$field = sanitize_term_field( $field, $term->$field, $term_id, $taxonomy, $context );
     1503                                $term->$field = sanitize_term_field( $field, $term->$field, $term->term_id, $taxonomy, $context );
    14981504                        }
    1499                 } else {
     1505                }
     1506                $term->filter = $context;
     1507        } elseif ( is_array( $term ) ) {
     1508                // Check if term already filtered for this context.
     1509                if ( isset( $term['filter'] ) && $context === $term['filter'] ) {
     1510                        return $term;
     1511                }
     1512                if ( ! isset( $term['term_id'] ) ) {
     1513                        $term['term_id'] = 0;
     1514                }
     1515                foreach ( (array) $fields as $field ) {
    15001516                        if ( isset( $term[ $field ] ) ) {
    1501                                 $term[ $field ] = sanitize_term_field( $field, $term[ $field ], $term_id, $taxonomy, $context );
     1517                                $term->$field = sanitize_term_field( $field, $term[ $field ], $term['term_id'], $taxonomy, $context );
    15021518                        }
    15031519                }
    1504         }
    1505 
    1506         if ( $do_object ) {
    1507                 $term->filter = $context;
    1508         } else {
    15091520                $term['filter'] = $context;
    15101521        }
    1511 
    15121522        return $term;
    15131523}
    15141524
     
    15321542 * @param int    $term_id  Term ID.
    15331543 * @param string $taxonomy Taxonomy Name.
    15341544 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
    1535  *                         'attribute', or 'js'.
     1545 *                         'attribute', 'raw', or 'js'.
    15361546 * @return mixed Sanitized field.
    15371547 */
    15381548function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) {
     
    15441554                }
    15451555        }
    15461556
     1557        // Needless. Expect the dev to respect the API. Is this a backward compat thing?
    15471558        $context = strtolower( $context );
    15481559
    15491560        if ( 'raw' === $context ) {
     
    25122523                        if ( is_int( $term ) ) {
    25132524                                continue;
    25142525                        }
    2515 
    25162526                        $term_info = wp_insert_term( $term, $taxonomy );
    25172527                }
    25182528
     
    35123522                // Object ID should not be cached.
    35133523                unset( $_term->object_id );
    35143524
     3525                if ( empty( $_term->filter ) ) {
     3526                        $_term = sanitize_term( $_term, $_term->taxonomy, 'raw' );
     3527                }
    35153528                wp_cache_add( $term->term_id, $_term, 'terms' );
    35163529        }
    35173530}