Changeset 34538
- Timestamp:
- 09/25/2015 01:46:36 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy-functions.php
r34534 r34538 1489 1489 */ 1490 1490 function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { 1491 return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1491 $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); 1492 1493 // Bust term query cache. 1494 if ( $added ) { 1495 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1496 } 1497 1498 return $added; 1492 1499 } 1493 1500 … … 1503 1510 */ 1504 1511 function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) { 1505 return delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1512 $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value ); 1513 1514 // Bust term query cache. 1515 if ( $deleted ) { 1516 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1517 } 1518 1519 return $deleted; 1506 1520 } 1507 1521 … … 1537 1551 */ 1538 1552 function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { 1539 return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1553 $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 1554 1555 // Bust term query cache. 1556 if ( $updated ) { 1557 wp_cache_set( 'last_changed', microtime(), 'terms' ); 1558 } 1559 1560 return $updated; 1540 1561 } 1541 1562 -
trunk/tests/phpunit/tests/term/meta.php
r34529 r34538 145 145 } 146 146 } 147 148 public function test_adding_term_meta_should_bust_get_terms_cache() { 149 $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 150 151 add_term_meta( $terms[0], 'foo', 'bar' ); 152 153 // Prime cache. 154 $found = get_terms( 'wptests_tax', array( 155 'hide_empty' => false, 156 'fields' => 'ids', 157 'meta_query' => array( 158 array( 159 'key' => 'foo', 160 'value' => 'bar', 161 ), 162 ), 163 ) ); 164 165 $this->assertEqualSets( array( $terms[0] ), $found ); 166 167 add_term_meta( $terms[1], 'foo', 'bar' ); 168 169 $found = get_terms( 'wptests_tax', array( 170 'hide_empty' => false, 171 'fields' => 'ids', 172 'meta_query' => array( 173 array( 174 'key' => 'foo', 175 'value' => 'bar', 176 ), 177 ), 178 ) ); 179 180 $this->assertEqualSets( array( $terms[0], $terms[1] ), $found ); 181 } 182 183 public function test_updating_term_meta_should_bust_get_terms_cache() { 184 $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 185 186 add_term_meta( $terms[0], 'foo', 'bar' ); 187 add_term_meta( $terms[1], 'foo', 'baz' ); 188 189 // Prime cache. 190 $found = get_terms( 'wptests_tax', array( 191 'hide_empty' => false, 192 'fields' => 'ids', 193 'meta_query' => array( 194 array( 195 'key' => 'foo', 196 'value' => 'bar', 197 ), 198 ), 199 ) ); 200 201 $this->assertEqualSets( array( $terms[0] ), $found ); 202 203 update_term_meta( $terms[1], 'foo', 'bar' ); 204 205 $found = get_terms( 'wptests_tax', array( 206 'hide_empty' => false, 207 'fields' => 'ids', 208 'meta_query' => array( 209 array( 210 'key' => 'foo', 211 'value' => 'bar', 212 ), 213 ), 214 ) ); 215 216 $this->assertEqualSets( array( $terms[0], $terms[1] ), $found ); 217 } 218 219 public function test_deleting_term_meta_should_bust_get_terms_cache() { 220 $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 221 222 add_term_meta( $terms[0], 'foo', 'bar' ); 223 add_term_meta( $terms[1], 'foo', 'bar' ); 224 225 // Prime cache. 226 $found = get_terms( 'wptests_tax', array( 227 'hide_empty' => false, 228 'fields' => 'ids', 229 'meta_query' => array( 230 array( 231 'key' => 'foo', 232 'value' => 'bar', 233 ), 234 ), 235 ) ); 236 237 $this->assertEqualSets( array( $terms[0], $terms[1] ), $found ); 238 239 delete_term_meta( $terms[1], 'foo', 'bar' ); 240 241 $found = get_terms( 'wptests_tax', array( 242 'hide_empty' => false, 243 'fields' => 'ids', 244 'meta_query' => array( 245 array( 246 'key' => 'foo', 247 'value' => 'bar', 248 ), 249 ), 250 ) ); 251 252 $this->assertEqualSets( array( $terms[0] ), $found ); 253 } 147 254 }
Note: See TracChangeset
for help on using the changeset viewer.