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 / update-entry-status.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
update-entry-status.php
148 lines
1 <?php
2 /**
3 * Update Entry Status 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 use SRFM\Inc\Helper;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Update_Entry_Status ability class.
21 *
22 * Updates the status of one or more form submission entries.
23 *
24 * @since 2.5.2
25 */
26 class Update_Entry_Status extends Abstract_Ability {
27 /**
28 * Maximum number of entries that can be updated in a single call.
29 *
30 * @since 2.5.2
31 */
32 public const MAX_ENTRIES = 50;
33
34 /**
35 * Constructor.
36 *
37 * @since 2.5.2
38 */
39 public function __construct() {
40 $this->id = 'sureforms/update-entry-status';
41 $this->label = __( 'Update Entry Status', 'sureforms' );
42 $this->description = __( 'Update the status of one or more SureForms form submission entries. Supports read, unread, trash, and restore operations.', 'sureforms' );
43 $this->capability = 'manage_options';
44 $this->gated = 'srfm_abilities_api_edit';
45 }
46
47 /**
48 * {@inheritDoc}
49 *
50 * @since 2.5.2
51 */
52 public function get_annotations() {
53 return [
54 'readonly' => false,
55 'destructive' => true,
56 'idempotent' => true,
57 'priority' => 2.0,
58 'openWorldHint' => false,
59 'instructions' => 'Confirm the target status with the user before executing. Trashing entries moves them toward permanent deletion.',
60 ];
61 }
62
63 /**
64 * {@inheritDoc}
65 *
66 * @since 2.5.2
67 */
68 public function get_input_schema() {
69 return [
70 'type' => 'object',
71 'additionalProperties' => false,
72 'properties' => [
73 'entry_ids' => [
74 'type' => 'array',
75 'description' => __( 'Array of entry IDs to update.', 'sureforms' ),
76 'items' => [ 'type' => 'integer' ],
77 ],
78 'status' => [
79 'type' => 'string',
80 'description' => __( 'New status for the entries.', 'sureforms' ),
81 'enum' => [ 'read', 'unread', 'trash', 'restore' ],
82 ],
83 ],
84 'required' => [ 'entry_ids', 'status' ],
85 ];
86 }
87
88 /**
89 * {@inheritDoc}
90 *
91 * @since 2.5.2
92 */
93 public function get_output_schema() {
94 return [
95 'type' => 'object',
96 'properties' => [
97 'success' => [ 'type' => 'boolean' ],
98 'updated' => [ 'type' => 'integer' ],
99 'errors' => [
100 'type' => 'array',
101 'items' => [ 'type' => 'string' ],
102 ],
103 ],
104 ];
105 }
106
107 /**
108 * Execute the update-entry-status ability.
109 *
110 * @param array<string,mixed> $input Validated input data.
111 * @since 2.5.2
112 * @return array<string,mixed>|\WP_Error
113 */
114 public function execute( $input ) {
115 $entry_ids = $input['entry_ids'] ?? [];
116 $status = sanitize_text_field( Helper::get_string_value( $input['status'] ?? '' ) );
117
118 if ( empty( $entry_ids ) || ! is_array( $entry_ids ) ) {
119 return new \WP_Error(
120 'srfm_missing_entry_ids',
121 __( 'At least one entry ID is required.', 'sureforms' ),
122 [ 'status' => 400 ]
123 );
124 }
125
126 if ( count( $entry_ids ) > self::MAX_ENTRIES ) {
127 return new \WP_Error(
128 'srfm_too_many_entry_ids',
129 /* translators: %d is the maximum number of entries allowed. */
130 sprintf( __( 'Maximum %d entry IDs allowed per request.', 'sureforms' ), self::MAX_ENTRIES ),
131 [ 'status' => 400 ]
132 );
133 }
134
135 $entry_ids = array_map( 'absint', $entry_ids );
136
137 if ( empty( $status ) ) {
138 return new \WP_Error(
139 'srfm_missing_status',
140 __( 'Status is required.', 'sureforms' ),
141 [ 'status' => 400 ]
142 );
143 }
144
145 return Entries::update_status( $entry_ids, $status );
146 }
147 }
148