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 / duplicate-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
duplicate-form.php
120 lines
1 <?php
2 /**
3 * Duplicate 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\Duplicate_Form as Duplicate_Form_Handler;
13 use SRFM\Inc\Helper;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Duplicate_Form ability class.
21 *
22 * Duplicates an existing SureForms form with all its fields and metadata.
23 *
24 * @since 2.5.2
25 */
26 class Duplicate_Form extends Abstract_Ability {
27 /**
28 * Constructor.
29 *
30 * @since 2.5.2
31 */
32 public function __construct() {
33 $this->id = 'sureforms/duplicate-form';
34 $this->label = __( 'Duplicate SureForms Form', 'sureforms' );
35 $this->description = __( 'Duplicate an existing SureForms form with all its fields, metadata, and settings. The new form is created as a draft.', 'sureforms' );
36 $this->capability = 'manage_options';
37 $this->gated = 'srfm_abilities_api_edit';
38 }
39
40 /**
41 * {@inheritDoc}
42 *
43 * @since 2.5.2
44 */
45 public function get_annotations() {
46 return [
47 'readonly' => false,
48 'destructive' => false,
49 'idempotent' => false,
50 'priority' => 2.0,
51 'openWorldHint' => false,
52 'instructions' => 'Confirm which form is being duplicated and the intended title suffix with the user.',
53 ];
54 }
55
56 /**
57 * {@inheritDoc}
58 *
59 * @since 2.5.2
60 */
61 public function get_input_schema() {
62 return [
63 'type' => 'object',
64 'additionalProperties' => false,
65 'properties' => [
66 'form_id' => [
67 'type' => 'integer',
68 'description' => __( 'The ID of the form to duplicate.', 'sureforms' ),
69 ],
70 'title_suffix' => [
71 'type' => 'string',
72 'description' => __( 'Suffix to append to the duplicated form title.', 'sureforms' ),
73 'default' => ' (Copy)',
74 ],
75 ],
76 'required' => [ 'form_id' ],
77 ];
78 }
79
80 /**
81 * {@inheritDoc}
82 *
83 * @since 2.5.2
84 */
85 public function get_output_schema() {
86 return [
87 'type' => 'object',
88 'properties' => [
89 'original_form_id' => [ 'type' => 'integer' ],
90 'new_form_id' => [ 'type' => 'integer' ],
91 'new_form_title' => [ 'type' => 'string' ],
92 'edit_url' => [ 'type' => 'string' ],
93 'shortcode' => [ 'type' => 'string' ],
94 ],
95 ];
96 }
97
98 /**
99 * Execute the duplicate-form ability.
100 *
101 * @param array<string,mixed> $input Validated input data.
102 * @since 2.5.2
103 * @return array<string,mixed>|\WP_Error
104 */
105 public function execute( $input ) {
106 $form_id = Helper::get_integer_value( $input['form_id'] ?? 0 );
107 $title_suffix = ! empty( $input['title_suffix'] ) ? sanitize_text_field( Helper::get_string_value( $input['title_suffix'] ) ) : ' (Copy)';
108
109 $result = Duplicate_Form_Handler::get_instance()->duplicate_form( $form_id, $title_suffix );
110
111 if ( is_wp_error( $result ) ) {
112 return $result;
113 }
114
115 $result['shortcode'] = sprintf( '[sureforms id="%d"]', Helper::get_integer_value( $result['new_form_id'] ?? 0 ) );
116
117 return $result;
118 }
119 }
120