Make WordPress Core


Ignore:
Timestamp:
06/18/2017 10:39:12 AM (9 years ago)
Author:
boonebgorges
Message:

Add term meta support to XML-RPC addTerm and editTerm endpoints.

This changeset also includes the new function has_term_meta(), a
counterpart to has_meta() (for posts).

Props enrico.sorcinelli.
Fixes #35991.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/xmlrpc/wp/editTerm.php

    r40417 r40916  
    146146                $this->assertInternalType( 'boolean', $result );
    147147        }
     148
     149        /**
     150         * @ticket 35991
     151         */
     152        public function test_update_term_meta() {
     153                register_taxonomy( 'wptests_tax', 'post' );
     154
     155                $t = self::factory()->term->create( array(
     156                        'taxonomy' => 'wptests_tax',
     157                ) );
     158                $meta_id = add_term_meta( $t, 'foo', 'bar' );
     159
     160                $this->make_user_by_role( 'editor' );
     161
     162                $result = $this->myxmlrpcserver->wp_editTerm( array(
     163                        1,
     164                        'editor',
     165                        'editor',
     166                        $t,
     167                        array(
     168                                'taxonomy' => 'wptests_tax',
     169                                'custom_fields' => array(
     170                                        array(
     171                                                'id' => $meta_id,
     172                                                'key' => 'foo',
     173                                                'value' => 'baz',
     174                                        ),
     175                                ),
     176                        ),
     177                ) );
     178
     179                $this->assertNotIXRError( $result );
     180
     181                $found = get_term_meta( $t, 'foo', true );
     182                $this->assertSame( 'baz', $found );
     183        }
     184
     185        /**
     186         * @ticket 35991
     187         */
     188        public function test_delete_term_meta() {
     189                register_taxonomy( 'wptests_tax', 'post' );
     190
     191                $t = self::factory()->term->create( array(
     192                        'taxonomy' => 'wptests_tax',
     193                ) );
     194                $meta_id = add_term_meta( $t, 'foo', 'bar' );
     195
     196                $this->make_user_by_role( 'editor' );
     197
     198                $result = $this->myxmlrpcserver->wp_editTerm( array(
     199                        1,
     200                        'editor',
     201                        'editor',
     202                        $t,
     203                        array(
     204                                'taxonomy' => 'wptests_tax',
     205                                'custom_fields' => array(
     206                                        array(
     207                                                'id' => $meta_id,
     208                                        ),
     209                                ),
     210                        ),
     211                ) );
     212
     213                $this->assertNotIXRError( $result );
     214
     215                $found = get_term_meta( $t, 'foo' );
     216                $this->assertSame( array(), $found );
     217        }
    148218}
Note: See TracChangeset for help on using the changeset viewer.