PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.4.0
EmailKit – Email Customizer for WooCommerce & WP v1.4.0
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / Api / DeleteData.php

DeleteData.php in EmailKit – Email Customizer for WooCommerce & WP 1.4.0, at includes/Admin/Api/DeleteData.php

61 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\Api;
4
5 defined('ABSPATH') || exit;
6
7 class DeleteData
8 {
9 public $prefix = '';
10 public $param = '';
11 public $request = null;
12
13 public function __construct()
14 {
15 add_action('rest_api_init', function () {
16 register_rest_route('emailkit/v1/delete-data', '(?P<post_id>\d+)', array(
17 'methods' => \WP_REST_Server::ALLMETHODS,
18 'callback' => [$this, 'delete_action'],
19 'permission_callback' => '__return_true',
20 ));
21 });
22 }
23
24 public function delete_action($request)
25 {
26 if (!wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest')) {
27 return [
28 'status' => 'fail',
29 'message' => ['Nonce mismatch.']
30 ];
31 }
32
33 if (!is_user_logged_in() || !current_user_can('publish_posts')) {
34 return [
35 'status' => 'fail',
36 'message' => ['Access denied.']
37 ];
38 }
39
40 $post_id = $request->get_param('post_id');
41
42 $deleted = wp_delete_post($post_id, true);
43
44 if ($deleted === false) {
45 return [
46 "status" => "failed",
47 "message" => [
48 "post Data not deleted ",
49 ],
50 ];
51 } else {
52 return [
53 "status" => "success",
54 "result" => $post_id,
55 "message" => [
56 "post data deleted successfully.",
57 ],
58 ];
59 }
60 }
61 }