PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Abilities / Manage / DeleteNotification.php

DeleteNotification.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar trunk, at includes/Abilities/Manage/DeleteNotification.php

87 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ability: delete a notification.
4 *
5 * @package NotificationX\Abilities\Manage
6 */
7
8 namespace NotificationX\Abilities\Manage;
9
10 use NotificationX\Abilities\AbilityBase;
11 use NotificationX\Core\PostType;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Permanently deletes a notification (and its entries/stats). Requires an
19 * explicit confirm flag so an assistant cannot delete on a loose instruction.
20 */
21 class DeleteNotification extends AbilityBase {
22
23 protected $id = 'notificationx/delete-notification';
24 protected $label = 'Delete a notification';
25 protected $description = 'Permanently delete a notification and its analytics. This cannot be undone. Requires confirm:true to proceed.';
26 protected $is_write = true;
27 protected $is_idempotent = false;
28
29 public function input_schema() {
30 return array(
31 'type' => 'object',
32 'required' => array( 'nx_id', 'confirm' ),
33 'properties' => array(
34 'nx_id' => array(
35 'type' => 'integer',
36 'description' => 'The notification id to delete.',
37 ),
38 'confirm' => array(
39 'type' => 'boolean',
40 'description' => 'Must be true to confirm permanent deletion.',
41 ),
42 ),
43 );
44 }
45
46 public function output_schema() {
47 return array(
48 'type' => 'object',
49 'properties' => array(
50 'nx_id' => array( 'type' => 'integer' ),
51 'deleted' => array( 'type' => 'boolean' ),
52 ),
53 );
54 }
55
56 public function execute( $input ) {
57 $nx_id = (int) $input['nx_id'];
58
59 if ( empty( $input['confirm'] ) ) {
60 return new \WP_Error(
61 'nx_mcp_confirm_required',
62 __( 'Deletion not confirmed. Pass confirm:true to permanently delete this notification.', 'notificationx' ),
63 array( 'status' => 400 )
64 );
65 }
66
67 $post_type = PostType::get_instance();
68 $existing = $post_type->get_post( $nx_id );
69
70 if ( empty( $existing ) ) {
71 return new \WP_Error(
72 'nx_mcp_not_found',
73 /* translators: %d: notification id. */
74 sprintf( __( 'No notification found with id %d.', 'notificationx' ), $nx_id ),
75 array( 'status' => 404 )
76 );
77 }
78
79 $post_type->delete_post( $nx_id );
80
81 return array(
82 'nx_id' => $nx_id,
83 'deleted' => true,
84 );
85 }
86 }
87