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 / forms / delete-form.php
sureforms / inc / abilities / forms Last commit date
create-form.php 1 month ago delete-form.php 5 months ago duplicate-form.php 5 months ago form-field-schema.php 2 months ago form-metadata.php 1 month ago get-form-stats.php 5 months ago get-form.php 5 months ago get-shortcode.php 5 months ago list-forms.php 2 months ago update-form.php 1 month ago
delete-form.php
131 lines
1 <?php
2 /**
3 * Delete Form Ability.
4 *
5 * @package sureforms
6 * @since 2.5.2
7 */
8
9 namespace SRFM\Inc\Abilities\Forms;
10
11 use SRFM\Inc\Abilities\Abstract_Ability;
12 use SRFM\Inc\Helper;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Delete_Form ability class.
20 *
21 * Trashes or permanently deletes a SureForms form.
22 *
23 * @since 2.5.2
24 */
25 class Delete_Form extends Abstract_Ability {
26 /**
27 * Constructor.
28 *
29 * @since 2.5.2
30 */
31 public function __construct() {
32 $this->id = 'sureforms/delete-form';
33 $this->label = __( 'Delete SureForms Form', 'sureforms' );
34 $this->description = __( 'Move a SureForms form to trash. When force is true, the form and all its metadata are permanently deleted — this cannot be undone.', 'sureforms' );
35 $this->capability = 'manage_options';
36 $this->gated = 'srfm_abilities_api_delete';
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public function get_annotations() {
43 return [
44 'readonly' => false,
45 'destructive' => true,
46 'idempotent' => false,
47 'priority' => 3.0,
48 'openWorldHint' => false,
49 'instructions' => 'Always confirm with the user before deleting. When force is true, the form and all its data are permanently destroyed and cannot be recovered.',
50 ];
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 public function get_input_schema() {
57 return [
58 'type' => 'object',
59 'additionalProperties' => false,
60 'properties' => [
61 'form_id' => [
62 'type' => 'integer',
63 'description' => __( 'The ID of the form to delete.', 'sureforms' ),
64 ],
65 'force' => [
66 'type' => 'boolean',
67 'description' => __( 'If true, permanently deletes the form. Otherwise moves to trash.', 'sureforms' ),
68 'default' => false,
69 ],
70 ],
71 'required' => [ 'form_id' ],
72 ];
73 }
74
75 /**
76 * {@inheritDoc}
77 */
78 public function get_output_schema() {
79 return [
80 'type' => 'object',
81 'properties' => [
82 'form_id' => [ 'type' => 'integer' ],
83 'deleted' => [ 'type' => 'boolean' ],
84 'previous_status' => [ 'type' => 'string' ],
85 ],
86 ];
87 }
88
89 /**
90 * Execute the delete-form ability.
91 *
92 * @param array<string,mixed> $input Validated input data.
93 * @return array<string,mixed>|\WP_Error
94 */
95 public function execute( $input ) {
96 $form_id = Helper::get_integer_value( $input['form_id'] ?? 0 );
97 $force = ! empty( $input['force'] );
98 $post = get_post( $form_id );
99
100 if ( ! $post || SRFM_FORMS_POST_TYPE !== $post->post_type ) {
101 return new \WP_Error(
102 'srfm_form_not_found',
103 __( 'Form not found.', 'sureforms' ),
104 [ 'status' => 404 ]
105 );
106 }
107
108 $previous_status = $post->post_status;
109
110 if ( $force ) {
111 $result = wp_delete_post( $form_id, true );
112 } else {
113 $result = wp_trash_post( $form_id );
114 }
115
116 if ( ! $result ) {
117 return new \WP_Error(
118 'srfm_delete_failed',
119 __( 'Failed to delete the form.', 'sureforms' ),
120 [ 'status' => 500 ]
121 );
122 }
123
124 return [
125 'form_id' => $form_id,
126 'deleted' => true,
127 'previous_status' => $previous_status,
128 ];
129 }
130 }
131