Ticket #40672: 40672.b.diff
File 40672.b.diff, 2.7 KB (added by , 7 years ago) |
---|
-
src/wp-includes/js/wp-api.js
1227 1227 routeName = 'me'; 1228 1228 } 1229 1229 1230 var initializeModel = function( attributes, options ) { 1231 wp.api.WPApiBaseModel.prototype.initialize.call( this, attributes, options ); 1232 1233 /** 1234 * Determine if a model requires ?force=true to actually delete them. 1235 */ 1236 if ( 1237 ! _.isEmpty( 1238 _.filter( 1239 this.endpoints, 1240 function( endpoint ) { 1241 return ( 1242 1243 // Does the method support DELETE? 1244 'DELETE' === endpoint.methods[0] && 1245 1246 // Exclude models that support trash (Post, Page). 1247 ( 1248 ! _.isUndefined( endpoint.args.force ) && 1249 ! _.isUndefined( endpoint.args.force.description ) && 1250 'Whether to bypass trash and force deletion.' !== endpoint.args.force.description 1251 ) 1252 ); 1253 } 1254 ) 1255 ) 1256 ) { 1257 this.requireForceForDelete = true; 1258 } 1259 }; 1260 1230 1261 // If the model has a parent in its route, add that to its class name. 1231 1262 if ( '' !== parentName && parentName !== routeName ) { 1232 1263 modelClassName = wp.api.utils.capitalizeAndCamelCaseDashes( parentName ) + wp.api.utils.capitalizeAndCamelCaseDashes( routeName ); … … 1266 1297 // Include the array of route methods for easy reference. 1267 1298 methods: modelRoute.route.methods, 1268 1299 1269 initialize: function( attributes, options ) {1270 wp.api.WPApiBaseModel.prototype.initialize.call( this, attributes, options );1300 // Include the array of route endpoints for easy reference. 1301 endpoints: modelRoute.route.endpoints, 1271 1302 1272 /** 1273 * Posts and pages support trashing, other types don't support a trash 1274 * and require that you pass ?force=true to actually delete them. 1275 * 1276 * @todo we should be getting trashability from the Schema, not hard coding types here. 1277 */ 1278 if ( 1279 'Posts' !== this.name && 1280 'Pages' !== this.name && 1281 _.includes( this.methods, 'DELETE' ) 1282 ) { 1283 this.requireForceForDelete = true; 1284 } 1285 } 1303 initialize: initializeModel 1286 1304 } ); 1287 1305 } else { 1288 1306 … … 1317 1335 name: modelClassName, 1318 1336 1319 1337 // Include the array of route methods for easy reference. 1320 methods: modelRoute.route.methods 1338 methods: modelRoute.route.methods, 1339 1340 // Include the array of route endpoints for easy reference. 1341 endpoints: modelRoute.route.endpoints, 1342 1343 initialize: initializeModel 1321 1344 } ); 1322 1345 } 1323 1346