REST API: JS client - Enumerate endpoints supporting trash.
Improve the logic determining which endpoints support the trash by enumerating them. Endpoints that don't support the trash require `force=true` when deleting. The previous approach relied on the `force` argument description, which is a translated string and was fragile. In the future, we can expose whether an endpoint supports the trash as part of its schema and automate this logic. Props Soean. Fixes #40672. Built from https://develop.svn.wordpress.org/trunk@42047 git-svn-id: http://core.svn.wordpress.org/trunk@41881 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b61de38e87
commit
274792f9cd
@ -803,7 +803,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var wpApiSettings = window.wpApiSettings || {};
|
||||
var wpApiSettings = window.wpApiSettings || {},
|
||||
trashableTypes = [ 'Comment', 'Media', 'Comment', 'Post', 'Page', 'Status', 'Taxonomy', 'Type' ];
|
||||
|
||||
/**
|
||||
* Backbone base model for all models.
|
||||
@ -811,32 +812,15 @@
|
||||
wp.api.WPApiBaseModel = Backbone.Model.extend(
|
||||
/** @lends WPApiBaseModel.prototype */
|
||||
{
|
||||
initialize: function( attributes, options ) {
|
||||
|
||||
// Initialize the model.
|
||||
initialize: function() {
|
||||
|
||||
/**
|
||||
* Determine if a model requires ?force=true to actually delete them.
|
||||
*/
|
||||
if (
|
||||
! _.isEmpty(
|
||||
_.filter(
|
||||
this.endpoints,
|
||||
function( endpoint ) {
|
||||
return (
|
||||
|
||||
// Does the method support DELETE?
|
||||
'DELETE' === endpoint.methods[0] &&
|
||||
|
||||
// Exclude models that support trash (Post, Page).
|
||||
(
|
||||
! _.isUndefined( endpoint.args.force ) &&
|
||||
! _.isUndefined( endpoint.args.force.description ) &&
|
||||
'Whether to bypass trash and force deletion.' !== endpoint.args.force.description
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
)
|
||||
) {
|
||||
* Types that don't support trashing require passing ?force=true to delete.
|
||||
*
|
||||
*/
|
||||
if ( -1 === _.indexOf( trashableTypes, this.name ) ) {
|
||||
this.requireForceForDelete = true;
|
||||
}
|
||||
},
|
||||
|
2
wp-includes/js/wp-api.min.js
vendored
2
wp-includes/js/wp-api.min.js
vendored
File diff suppressed because one or more lines are too long
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.9-beta4-42046';
|
||||
$wp_version = '4.9-beta4-42047';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user