PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.11.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.11.1
2.12.6 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 All 96 releases
sureforms / inc / abilities / forms / get-shortcode.php
get-shortcode.php
107 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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