diff --git src/wp-includes/js/wp-api.js src/wp-includes/js/wp-api.js
index 3f950a47f5..634db4357e 100644
|
|
|
1112 | 1112 | 'PostsRevisions': 'PostRevisions', |
1113 | 1113 | 'PostsTags': 'PostTags' |
1114 | 1114 | } |
1115 | | }; |
| 1115 | }, |
| 1116 | |
| 1117 | modelEndpoints = routeModel.get( 'modelEndpoints' ), |
| 1118 | modelRegex = new RegExp( '(?:.*[+)]|\/(' + modelEndpoints.join( '|' ) + '))$' ); |
1116 | 1119 | |
1117 | 1120 | /** |
1118 | 1121 | * Iterate thru the routes, picking up models and collections to build. Builds two arrays, |
… |
… |
|
1137 | 1140 | index !== ( '/' + routeModel.get( 'versionString' ).slice( 0, -1 ) ) |
1138 | 1141 | ) { |
1139 | 1142 | |
1140 | | // Single items end with a regex (or the special case 'me'). |
1141 | | if ( /(?:.*[+)]|\/me)$/.test( index ) ) { |
| 1143 | // Single items end with a regex, or a special case word. |
| 1144 | if ( modelRegex.test( index ) ) { |
1142 | 1145 | modelRoutes.push( { index: index, route: route } ); |
1143 | 1146 | } else { |
1144 | 1147 | |
… |
… |
|
1360 | 1363 | wp.api.init = function( args ) { |
1361 | 1364 | var endpoint, attributes = {}, deferred, promise; |
1362 | 1365 | |
1363 | | args = args || {}; |
1364 | | attributes.apiRoot = args.apiRoot || wpApiSettings.root || '/wp-json'; |
1365 | | attributes.versionString = args.versionString || wpApiSettings.versionString || 'wp/v2/'; |
1366 | | attributes.schema = args.schema || null; |
| 1366 | args = args || {}; |
| 1367 | attributes.apiRoot = args.apiRoot || wpApiSettings.root || '/wp-json'; |
| 1368 | attributes.versionString = args.versionString || wpApiSettings.versionString || 'wp/v2/'; |
| 1369 | attributes.schema = args.schema || null; |
| 1370 | attributes.modelEndpoints = args.modelEndpoints || [ 'me', 'settings' ]; |
1367 | 1371 | if ( ! attributes.schema && attributes.apiRoot === wpApiSettings.root && attributes.versionString === wpApiSettings.versionString ) { |
1368 | 1372 | attributes.schema = wpApiSettings.schema; |
1369 | 1373 | } |
diff --git tests/qunit/fixtures/wp-api.js tests/qunit/fixtures/wp-api.js
index c28486d421..04c9dd1823 100644
|
|
var pathToData = { |
24 | 24 | 'wp-json/wp/v2/taxonomy': mockedApiResponse.TaxonomyModel, |
25 | 25 | 'wp-json/wp/v2/status': mockedApiResponse.StatusModel, |
26 | 26 | 'wp-json/wp/v2/type': mockedApiResponse.TypeModel, |
27 | | 'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema |
| 27 | 'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema, |
| 28 | 'wp-json/wp/v2/users/me': mockedApiResponse.me, |
| 29 | 'wp-json/wp/v2/settings': mockedApiResponse.settings |
28 | 30 | }; |
29 | 31 | |
30 | 32 | /** |
diff --git tests/qunit/wp-includes/js/wp-api.js tests/qunit/wp-includes/js/wp-api.js
index 180942fbce..a64e406a49 100644
|
|
|
115 | 115 | 'Page', |
116 | 116 | 'Post', |
117 | 117 | 'Tag', |
118 | | 'User' |
| 118 | 'User', |
| 119 | 'UsersMe', |
| 120 | 'Settings' |
119 | 121 | ]; |
120 | 122 | |
121 | 123 | _.each( modelsWithIdsClassNames, function( className ) { |
… |
… |
|
130 | 132 | assert.ok( theModel, 'We can instantiate wp.api.models.' + className ); |
131 | 133 | theModel.fetch().done( function( ) { |
132 | 134 | var theModel2 = new wp.api.models[ className ](); |
133 | | theModel2.set( 'id', theModel.attributes[0].id ); |
| 135 | theModel2.set( 'id', theModel.attributes.id ); |
134 | 136 | theModel2.fetch().done( function() { |
135 | 137 | |
136 | 138 | // We were able to retrieve the model. |
137 | 139 | assert.equal( |
138 | | theModel.attributes[0].id, |
| 140 | theModel.attributes.id, |
139 | 141 | theModel2.get( 'id' ) , |
140 | 142 | 'We should be able to get a ' + className |
141 | 143 | ); |