WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/12/2018 03:02:00 AM (3 years ago)
Author:
jeremyfelt
Message:

REST API: Move object type-specific metadata integrations from the wrapper functions to the low-level Meta API functions.

Object type-specific actions that should happen before or after modification of metadata have so far been part of the respective wrapper functions. By using action and filter hooks, this changeset ensures they are always executed, even when calling the lower-level Meta API functions directly, which the REST API does as a prime example.

Merges [43729] to trunk.

Props flixos90, spacedmonkey.
Fixes #44467.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tests/phpunit/tests/term/meta.php

    r43571 r43982  
    538538        );
    539539    }
     540
     541    /**
     542     * @ticket 44467
     543     */
     544    public function test_add_metadata_sets_terms_last_changed() {
     545        $term_id = self::factory()->term->create();
     546
     547        wp_cache_delete( 'last_changed', 'terms' );
     548
     549        $this->assertInternalType( 'integer', add_metadata( 'term', $term_id, 'foo', 'bar' ) );
     550        $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
     551    }
     552
     553    /**
     554     * @ticket 44467
     555     */
     556    public function test_update_metadata_sets_terms_last_changed() {
     557        $term_id = self::factory()->term->create();
     558
     559        wp_cache_delete( 'last_changed', 'terms' );
     560
     561        $this->assertInternalType( 'integer', update_metadata( 'term', $term_id, 'foo', 'bar' ) );
     562        $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
     563    }
     564
     565    /**
     566     * @ticket 44467
     567     */
     568    public function test_delete_metadata_sets_terms_last_changed() {
     569        $term_id = self::factory()->term->create();
     570
     571        update_metadata( 'term', $term_id, 'foo', 'bar' );
     572        wp_cache_delete( 'last_changed', 'terms' );
     573
     574        $this->assertTrue( delete_metadata( 'term', $term_id, 'foo' ) );
     575        $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
     576    }
     577
     578    /**
     579     * @ticket 44467
     580     */
     581    public function test_metadata_functions_respect_term_meta_support() {
     582        $term_id = self::factory()->term->create();
     583
     584        $meta_id = add_metadata( 'term', $term_id, 'foo', 'bar' );
     585
     586        // Set database version to last version before term meta support.
     587        update_option( 'db_version', 34369 );
     588
     589        $this->assertFalse( get_metadata( 'term', $term_id, 'foo', true ) );
     590        $this->assertFalse( add_metadata( 'term', $term_id, 'foo', 'bar' ) );
     591        $this->assertFalse( update_metadata( 'term', $term_id, 'foo', 'bar' ) );
     592        $this->assertFalse( delete_metadata( 'term', $term_id, 'foo' ) );
     593        $this->assertFalse( get_metadata_by_mid( 'term', $meta_id ) );
     594        $this->assertFalse( update_metadata_by_mid( 'term', $meta_id, 'baz' ) );
     595        $this->assertFalse( delete_metadata_by_mid( 'term', $meta_id ) );
     596        $this->assertFalse( update_meta_cache( 'term', array( $term_id ) ) );
     597    }
    540598}
Note: See TracChangeset for help on using the changeset viewer.