API endpoints for trash untrash and delete #69
This commit is contained in:
parent
abbad9bd42
commit
19899d0ed0
|
@ -56,6 +56,33 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/trash',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array($this, 'trash_items'),
|
||||||
|
'permission_callback' => array($this, 'bulk_edit_permissions_check'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/untrash',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array($this, 'untrash_items'),
|
||||||
|
'permission_callback' => array($this, 'bulk_edit_permissions_check'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/delete_items',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array($this, 'delete_items'),
|
||||||
|
'permission_callback' => array($this, 'bulk_edit_permissions_check'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/set',
|
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/set',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -196,6 +223,63 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function trash_items($request) {
|
||||||
|
$group_id = $request['group_id'];
|
||||||
|
|
||||||
|
$args = ['id' => $group_id];
|
||||||
|
|
||||||
|
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||||
|
|
||||||
|
$action = $bulk->trash_items();
|
||||||
|
|
||||||
|
if ( is_wp_error($action) ) {
|
||||||
|
return new \WP_REST_Response([
|
||||||
|
'error_message' => $action->get_error_message(),
|
||||||
|
], 400);
|
||||||
|
} else {
|
||||||
|
return new \WP_REST_Response($action, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function untrash_items($request) {
|
||||||
|
$group_id = $request['group_id'];
|
||||||
|
|
||||||
|
$args = ['id' => $group_id];
|
||||||
|
|
||||||
|
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||||
|
|
||||||
|
$action = $bulk->untrash_items();
|
||||||
|
|
||||||
|
if ( is_wp_error($action) ) {
|
||||||
|
return new \WP_REST_Response([
|
||||||
|
'error_message' => $action->get_error_message(),
|
||||||
|
], 400);
|
||||||
|
} else {
|
||||||
|
return new \WP_REST_Response($action, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete_items($request) {
|
||||||
|
$group_id = $request['group_id'];
|
||||||
|
|
||||||
|
$args = ['id' => $group_id];
|
||||||
|
|
||||||
|
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||||
|
|
||||||
|
$action = $bulk->delete_items();
|
||||||
|
|
||||||
|
if ( is_wp_error($action) ) {
|
||||||
|
return new \WP_REST_Response([
|
||||||
|
'error_message' => $action->get_error_message(),
|
||||||
|
], 400);
|
||||||
|
} else {
|
||||||
|
return new \WP_REST_Response($action, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function generic_action($method, $request, $keys = ['value']) {
|
private function generic_action($method, $request, $keys = ['value']) {
|
||||||
$body = json_decode($request->get_body(), true);
|
$body = json_decode($request->get_body(), true);
|
||||||
|
|
|
@ -299,7 +299,7 @@ class Bulk_Edit {
|
||||||
|
|
||||||
// restore status
|
// restore status
|
||||||
|
|
||||||
$query_restore = "UPDATE $wpdb->posts SET post_status = (SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_status' AND post_id = ID) WHERE ID IN ($select_q)";
|
$query_restore = "UPDATE $wpdb->posts SET post_status = (SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_status' AND post_id = ID) WHERE ID IN ($select_q) AND post_status = 'trash'";
|
||||||
$query_delete_meta1 = "DELETE FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_status' AND post_id IN ( SELECT implicitTemp.post_id FROM ($select_q) implicitTemp )";
|
$query_delete_meta1 = "DELETE FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_status' AND post_id IN ( SELECT implicitTemp.post_id FROM ($select_q) implicitTemp )";
|
||||||
$query_delete_meta2 = "DELETE FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND post_id IN ( SELECT implicitTemp.post_id FROM ($select_q) implicitTemp )";
|
$query_delete_meta2 = "DELETE FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND post_id IN ( SELECT implicitTemp.post_id FROM ($select_q) implicitTemp )";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue