WP-API JS Client: Improve support for meta.
* Add/fix `getMeta`, `getMetas`, `setMeta` and `setMetas` helpers for models that support meta. * Add tests for new helpers, verify meta support for `Posts`, `Comments`, `Tags` and `Users`. * Include meta data in fixture generation and fixture file driving tests. Fixes #41055. Built from https://develop.svn.wordpress.org/trunk@41678 git-svn-id: http://core.svn.wordpress.org/trunk@41512 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
df7af1ee21
commit
5087d26d2d
|
@ -501,8 +501,49 @@
|
|||
* Add a helper function to handle post Meta.
|
||||
*/
|
||||
MetaMixin = {
|
||||
getMeta: function() {
|
||||
return buildCollectionGetter( this, 'PostMeta', 'https://api.w.org/meta' );
|
||||
|
||||
/**
|
||||
* Get meta by key for a post.
|
||||
*
|
||||
* @param {string} key The meta key.
|
||||
*
|
||||
* @return {object} The post meta value.
|
||||
*/
|
||||
getMeta: function( key ) {
|
||||
var metas = this.get( 'meta' );
|
||||
return metas[ key ];
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all meta key/values for a post.
|
||||
*
|
||||
* @return {object} The post metas, as a key value pair object.
|
||||
*/
|
||||
getMetas: function() {
|
||||
return this.get( 'meta' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Set a group of meta key/values for a post.
|
||||
*
|
||||
* @param {object} meta The post meta to set, as key/value pairs.
|
||||
*/
|
||||
setMetas: function( meta ) {
|
||||
var metas = this.get( 'meta' );
|
||||
_.extend( metas, meta );
|
||||
this.set( 'meta', metas );
|
||||
},
|
||||
|
||||
/**
|
||||
* Set a single meta value for a post, by key.
|
||||
*
|
||||
* @param {string} key The meta key.
|
||||
* @param {object} value The meta value.
|
||||
*/
|
||||
setMeta: function( key, value ) {
|
||||
var metas = this.get( 'meta' );
|
||||
metas[ key ] = value;
|
||||
this.set( 'meta', metas );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -734,8 +775,8 @@
|
|||
model = model.extend( CategoriesMixin );
|
||||
}
|
||||
|
||||
// Add the MetaMixin for models that support meta collections.
|
||||
if ( ! _.isUndefined( loadingObjects.collections[ modelClassName + 'Meta' ] ) ) {
|
||||
// Add the MetaMixin for models that support meta.
|
||||
if ( ! _.isUndefined( model.prototype.args.meta ) ) {
|
||||
model = model.extend( MetaMixin );
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.9-alpha-41677';
|
||||
$wp_version = '4.9-alpha-41678';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue