PluginProbe
WPBot – ChatBot Conversational Forms / 1.2.0
WPBot – ChatBot Conversational Forms v1.2.0
1.5.0 1.4.8 1.4.7 trunk 0.9.2 0.9.3 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.6 1.1.7 1.1.8 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 All 36 releases
conversational-forms / classes / api / jsconfig.php

jsconfig.php in WPBot – ChatBot Conversational Forms 1.2.0, at classes/api/jsconfig.php

96 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstraction for creating data to pass to wp_localize_script when working with Qcformbuilder Forms REST API
4 *
5 * @package Caldera_Forms Modified by QuantumCloud
6 * @author Josh Pollock <Josh@CalderaWP.com>
7 * @license GPL-2.0+
8 * @link
9 * @copyright 2017 CalderaWP LLC
10 */
11 class Qcformbuilder_Forms_API_JsConfig implements JsonSerializable{
12
13 /**
14 * Form config
15 *
16 * @since 1.5.0
17 *
18 * @var array
19 */
20 protected $form;
21
22 /**
23 * Data to return
24 *
25 * @since 1.5.0
26 *
27 * @var array
28 */
29 protected $data;
30
31 /**
32 * Qcformbuilder_Forms_API_JsConfig constructor.
33 *
34 * @param array $form Optional, form config with tying to a specific form
35 */
36 public function __construct( array $form = array() ) {
37 $this->form = $form;
38 }
39
40 /**
41 * @inheritdoc
42 * @since 1.5.0
43 */
44 public function jsonSerialize():mixed {
45 return $this->toArray();
46 }
47
48 /**
49 * Get data as array
50 *
51 * @since 1.5.0
52 *
53 * @return array
54 */
55 public function toArray(){
56 if ( empty( $this->data ) ) {
57 $this->set_data();
58 }
59
60 return $this->data;
61 }
62
63 /**
64 * Setup data to localize
65 *
66 * @since 1.5.0
67 */
68 protected function set_data(){
69 $this->data = array(
70 'dateFormat' => Qcformbuilder_Forms::time_format(),
71 'api' => array(
72 'root' => esc_url( trailingslashit( Qcformbuilder_Forms_API_Util::url() ) ),
73 'form' => esc_url( trailingslashit( Qcformbuilder_Forms_API_Util::url( 'forms' ) ) ),
74 'entries' => esc_url( trailingslashit( Qcformbuilder_Forms_API_Util::url( 'entries' ) ) ),
75 'entrySettings' => esc_url( trailingslashit( Qcformbuilder_Forms_API_Util::url( 'settings/entries' ) ) ),
76 'nonce' => wp_create_nonce( 'wp_rest' ),
77 'token' => 'false',
78 ),
79 );
80
81 if( ! empty( $this->form ) ){
82 $this->data[ 'formId' ] = $this->form[ 'ID' ];
83 }
84
85 /**
86 * Modify data to localize for API
87 *
88 * @since 1.5.0
89 *
90 * @param array $data The data
91 * @param array|null $form Form config if used, might be empty
92 */
93 $this->data = apply_filters( 'qcformbuilder_forms_api_js_config', $this->data, $this->form );
94
95 }
96 }