Ticket #50568: wp-includes.patch
File wp-includes.patch, 5.1 KB (added by , 5 years ago) |
---|
-
wp-includes/category.php
247 247 return term_is_ancestor_of( $cat1, $cat2, 'category' ); 248 248 } 249 249 250 // deprecate this? 250 251 /** 251 252 * Sanitizes category data based on context. 252 253 * … … 260 261 return sanitize_term( $category, 'category', $context ); 261 262 } 262 263 264 // deprecate this? 263 265 /** 264 266 * Sanitizes data in single category key field. 265 267 * -
wp-includes/class-wp-term.php
180 180 } 181 181 } 182 182 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 ); 187 184 } 188 185 189 186 /** … … 207 204 * @param string $filter Filter context. Accepts 'edit', 'db', 'display', 'attribute', 'js', 'raw'. 208 205 */ 209 206 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 ); 211 216 } 212 217 213 218 /** -
wp-includes/taxonomy.php
828 828 if ( $term instanceof WP_Term ) { 829 829 $_term = $term; 830 830 } elseif ( is_object( $term ) ) { 831 if ( empty( $term->filter ) || 'raw' === $term->filter) {831 if ( empty( $term->filter ) ) { 832 832 $_term = sanitize_term( $term, $taxonomy, 'raw' ); 833 833 $_term = new WP_Term( $_term ); 834 } elseif ( 'raw' === $term->filter ) { 835 $_term = new WP_Term( $_term ); 834 836 } else { 835 837 $_term = WP_Term::get_instance( $term->term_id ); 836 838 } … … 1481 1483 * @param array|object $term The term to check. 1482 1484 * @param string $taxonomy The taxonomy name to use. 1483 1485 * @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'. 1485 1487 * @return array|object Term with all fields sanitized. 1486 1488 */ 1487 1489 function sanitize_term( $term, $taxonomy, $context = 'display' ) { 1490 // This array doesn't match WP>4.4 WP_Term per se... scrutinize me? 1488 1491 $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' ); 1489 1492 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 ) { 1496 1502 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 ); 1498 1504 } 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 ) { 1500 1516 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 ); 1502 1518 } 1503 1519 } 1504 }1505 1506 if ( $do_object ) {1507 $term->filter = $context;1508 } else {1509 1520 $term['filter'] = $context; 1510 1521 } 1511 1512 1522 return $term; 1513 1523 } 1514 1524 … … 1532 1542 * @param int $term_id Term ID. 1533 1543 * @param string $taxonomy Taxonomy Name. 1534 1544 * @param string $context Context in which to sanitize the term field. Accepts 'edit', 'db', 'display', 1535 * 'attribute', or 'js'.1545 * 'attribute', 'raw', or 'js'. 1536 1546 * @return mixed Sanitized field. 1537 1547 */ 1538 1548 function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) { … … 1544 1554 } 1545 1555 } 1546 1556 1557 // Needless. Expect the dev to respect the API. Is this a backward compat thing? 1547 1558 $context = strtolower( $context ); 1548 1559 1549 1560 if ( 'raw' === $context ) { … … 2512 2523 if ( is_int( $term ) ) { 2513 2524 continue; 2514 2525 } 2515 2516 2526 $term_info = wp_insert_term( $term, $taxonomy ); 2517 2527 } 2518 2528 … … 3512 3522 // Object ID should not be cached. 3513 3523 unset( $_term->object_id ); 3514 3524 3525 if ( empty( $_term->filter ) ) { 3526 $_term = sanitize_term( $_term, $_term->taxonomy, 'raw' ); 3527 } 3515 3528 wp_cache_add( $term->term_id, $_term, 'terms' ); 3516 3529 } 3517 3530 }