Ticket #21760: 21760.10.patch
File 21760.10.patch, 3.2 KB (added by , 7 years ago) |
---|
-
src/wp-includes/taxonomy.php
849 849 'taxonomy' => $taxonomy, 850 850 'update_term_meta_cache' => false, 851 851 'orderby' => 'none', 852 'suppress_filter' => true, 852 853 ); 853 854 854 855 switch ( $field ) { … … 1012 1013 * a list of WP_Term objects. 1013 1014 * @since 4.5.0 Changed the function signature so that the `$args` array can be provided as the first parameter. 1014 1015 * Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata. 1016 * @since 4.8.0 Introduced 'suppress_filter' parameter. 1015 1017 * 1016 1018 * @internal The `$deprecated` parameter is parsed for backward compatibility only. 1017 1019 * … … 1080 1082 * conjunction with `$meta_value`. 1081 1083 * @type string $meta_value Limit terms to those matching a specific metadata value. Usually used 1082 1084 * in conjunction with `$meta_key`. 1085 * @type bool $suppress_filter Whether to suppress the {@see 'get_terms'} filter. Default false. 1083 1086 * } 1084 1087 * @param array $deprecated Argument array, when using the legacy function parameter format. If present, this 1085 1088 * parameter will be interpreted as `$args`, and the first function parameter will … … 1092 1095 1093 1096 $term_query = new WP_Term_Query(); 1094 1097 1098 $defaults = array( 1099 'suppress_filter' => false, 1100 ); 1101 1095 1102 /* 1096 1103 * Legacy argument format ($taxonomy, $args) takes precedence. 1097 1104 * … … 1105 1112 1106 1113 if ( $do_legacy_args ) { 1107 1114 $taxonomies = (array) $args; 1108 $args = wp_parse_args( $deprecated );1115 $args = wp_parse_args( $deprecated, $defaults ); 1109 1116 $args['taxonomy'] = $taxonomies; 1110 1117 } else { 1111 $args = wp_parse_args( $args );1118 $args = wp_parse_args( $args, $defaults ); 1112 1119 if ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) { 1113 1120 $args['taxonomy'] = (array) $args['taxonomy']; 1114 1121 } … … 1122 1129 } 1123 1130 } 1124 1131 1132 // Don't pass suppress_filter to WP_Term_Query. 1133 $suppress_filter = $args['suppress_filter']; 1134 unset( $args['suppress_filter'] ); 1135 1125 1136 $terms = $term_query->query( $args ); 1126 1137 1127 1138 // Count queries are not filtered, for legacy reasons. … … 1129 1140 return $terms; 1130 1141 } 1131 1142 1143 if ( $suppress_filter ) { 1144 return $terms; 1145 } 1146 1132 1147 /** 1133 1148 * Filters the found terms. 1134 1149 * -
tests/phpunit/tests/term/getTermBy.php
192 192 $this->assertSame( $term_id, $found->term_id ); 193 193 $this->assertContains( 'LIMIT 1', $wpdb->last_query ); 194 194 } 195 196 /** 197 * @ticket 21760 198 */ 199 public function test_prevent_recursion_by_get_terms_filter() { 200 $action = new MockAction(); 201 202 add_filter( 'get_terms', array( $action, 'filter' ) ); 203 get_term_by( 'name', 'burrito', 'post_tag' ); 204 remove_filter( 'get_terms', array( $action, 'filter' ) ); 205 206 $this->assertEquals( 0, $action->get_call_count() ); 207 } 195 208 }