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 / get-shortcode.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
get-shortcode.php
107 lines
1 <?php
2 /**
3 * Get Shortcode 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 * Get_Shortcode ability class.
20 *
21 * Returns the shortcode and block markup for embedding a SureForms form.
22 *
23 * @since 2.5.2
24 */
25 class Get_Shortcode extends Abstract_Ability {
26 /**
27 * Constructor.
28 *
29 * @since 2.5.2
30 */
31 public function __construct() {
32 $this->id = 'sureforms/get-shortcode';
33 $this->label = __( 'Get Form Shortcode', 'sureforms' );
34 $this->description = __( 'Get the shortcode and block markup needed to embed a SureForms form on any page or post.', 'sureforms' );
35 $this->capability = 'manage_options';
36 }
37
38 /**
39 * {@inheritDoc}
40 */
41 public function get_annotations() {
42 return [
43 'readonly' => true,
44 'destructive' => false,
45 'idempotent' => true,
46 'priority' => 1.0,
47 'openWorldHint' => false,
48 ];
49 }
50
51 /**
52 * {@inheritDoc}
53 */
54 public function get_input_schema() {
55 return [
56 'type' => 'object',
57 'additionalProperties' => false,
58 'properties' => [
59 'form_id' => [
60 'type' => 'integer',
61 'description' => __( 'The ID of the form to get the shortcode for.', 'sureforms' ),
62 ],
63 ],
64 'required' => [ 'form_id' ],
65 ];
66 }
67
68 /**
69 * {@inheritDoc}
70 */
71 public function get_output_schema() {
72 return [
73 'type' => 'object',
74 'properties' => [
75 'form_id' => [ 'type' => 'integer' ],
76 'shortcode' => [ 'type' => 'string' ],
77 'block_markup' => [ 'type' => 'string' ],
78 ],
79 ];
80 }
81
82 /**
83 * Execute the get-shortcode ability.
84 *
85 * @param array<string,mixed> $input Validated input data.
86 * @return array<string,mixed>|\WP_Error
87 */
88 public function execute( $input ) {
89 $form_id = Helper::get_integer_value( $input['form_id'] ?? 0 );
90 $post = get_post( $form_id );
91
92 if ( ! $post || SRFM_FORMS_POST_TYPE !== $post->post_type ) {
93 return new \WP_Error(
94 'srfm_form_not_found',
95 __( 'Form not found.', 'sureforms' ),
96 [ 'status' => 404 ]
97 );
98 }
99
100 return [
101 'form_id' => $form_id,
102 'shortcode' => sprintf( '[sureforms id="%d"]', $form_id ),
103 'block_markup' => sprintf( '<!-- wp:srfm/form {"id":%d} /-->', $form_id ),
104 ];
105 }
106 }
107