PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.3
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.3
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / abilities / entries / delete-entry.php
sureforms / inc / abilities / entries Last commit date
bulk-get-entries.php 3 weeks ago delete-entry.php 5 months ago entry-parser.php 3 weeks ago get-entry.php 3 weeks ago list-entries.php 3 weeks ago update-entry-status.php 5 months ago
delete-entry.php
133 lines
1 <?php
2 /**
3 * Delete Entry Ability.
4 *
5 * @package sureforms
6 * @since 2.5.2
7 */
8
9 namespace SRFM\Inc\Abilities\Entries;
10
11 use SRFM\Inc\Abilities\Abstract_Ability;
12 use SRFM\Inc\Entries;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Delete_Entry ability class.
20 *
21 * Permanently deletes one or more form submission entries.
22 *
23 * @since 2.5.2
24 */
25 class Delete_Entry extends Abstract_Ability {
26 /**
27 * Maximum number of entries that can be deleted in a single call.
28 *
29 * @since 2.5.2
30 */
31 public const MAX_ENTRIES = 50;
32
33 /**
34 * Constructor.
35 *
36 * @since 2.5.2
37 */
38 public function __construct() {
39 $this->id = 'sureforms/delete-entry';
40 $this->label = __( 'Delete Entry', 'sureforms' );
41 $this->description = __( 'Permanently delete one or more SureForms form submission entries. This action cannot be undone.', 'sureforms' );
42 $this->capability = 'manage_options';
43 $this->gated = 'srfm_abilities_api_delete';
44 }
45
46 /**
47 * {@inheritDoc}
48 *
49 * @since 2.5.2
50 */
51 public function get_annotations() {
52 return [
53 'readonly' => false,
54 'destructive' => true,
55 'idempotent' => false,
56 'priority' => 3.0,
57 'openWorldHint' => false,
58 'instructions' => 'Always confirm with the user before deleting. This permanently removes the entry and cannot be undone.',
59 ];
60 }
61
62 /**
63 * {@inheritDoc}
64 *
65 * @since 2.5.2
66 */
67 public function get_input_schema() {
68 return [
69 'type' => 'object',
70 'additionalProperties' => false,
71 'properties' => [
72 'entry_ids' => [
73 'type' => 'array',
74 'description' => __( 'Array of entry IDs to permanently delete.', 'sureforms' ),
75 'items' => [ 'type' => 'integer' ],
76 ],
77 ],
78 'required' => [ 'entry_ids' ],
79 ];
80 }
81
82 /**
83 * {@inheritDoc}
84 *
85 * @since 2.5.2
86 */
87 public function get_output_schema() {
88 return [
89 'type' => 'object',
90 'properties' => [
91 'success' => [ 'type' => 'boolean' ],
92 'deleted' => [ 'type' => 'integer' ],
93 'errors' => [
94 'type' => 'array',
95 'items' => [ 'type' => 'string' ],
96 ],
97 ],
98 ];
99 }
100
101 /**
102 * Execute the delete-entry ability.
103 *
104 * @param array<string,mixed> $input Validated input data.
105 * @since 2.5.2
106 * @return array<string,mixed>|\WP_Error
107 */
108 public function execute( $input ) {
109 $entry_ids = $input['entry_ids'] ?? [];
110
111 if ( empty( $entry_ids ) || ! is_array( $entry_ids ) ) {
112 return new \WP_Error(
113 'srfm_missing_entry_ids',
114 __( 'At least one entry ID is required.', 'sureforms' ),
115 [ 'status' => 400 ]
116 );
117 }
118
119 if ( count( $entry_ids ) > self::MAX_ENTRIES ) {
120 return new \WP_Error(
121 'srfm_too_many_entry_ids',
122 /* translators: %d is the maximum number of entries allowed. */
123 sprintf( __( 'Maximum %d entry IDs allowed per request.', 'sureforms' ), self::MAX_ENTRIES ),
124 [ 'status' => 400 ]
125 );
126 }
127
128 $entry_ids = array_map( 'absint', $entry_ids );
129
130 return Entries::delete_entries( $entry_ids );
131 }
132 }
133