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 / util.php

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

97 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 /**
5 * Utility functions for Qcformbuilder Forms REST API
6 *
7 * @package Caldera_Forms Modified by QuantumCloud
8 * @author Josh Pollock <Josh@CalderaWP.com>
9 * @license GPL-2.0+
10 * @link
11 * @copyright 2016 CalderaWP LLC
12 */
13 class Qcformbuilder_Forms_API_Util {
14
15 /**
16 * The namespace for Qcformbuilder Forms REST API
17 *
18 * @since 1.4.4
19 *
20 * @param string $version Optional. API version. Default is v2. Can be v3 or v2 only
21 * @return string
22 */
23 public static function api_namespace($version = 'v2'){
24 $version = in_array( $version, ['v2', 'v3' ] ) ? $version : 'v2';
25 return "wfb-api/$version";
26 }
27
28 /**
29 * The URL for Qcformbuilder Forms REST API
30 *
31 * @since 1.4.4
32 *
33 * @param string $endpoint Optional. Endpoint.
34 * @param bool $add_nonce Optional. If true, _wp_nonce is set with WP REST API nonce. Default is false
35 * @param string $version Optional. @since 1.8.0
36 * @return string
37 */
38 public static function url( $endpoint = '', $add_nonce = false, $version = 'v2' ){
39 if( ! function_exists( 'rest_url' ) ){
40 return '';
41 }
42
43 $url = rest_url( self::api_namespace($version) . '/' . $endpoint );
44 if( $add_nonce ){
45 $url = add_query_arg( '_wpnonce', self::get_core_nonce(), $url );
46 }
47
48 return $url;
49 }
50
51 public static function check_api_token( WP_REST_Request $request ){
52 $allowed = false;
53 if( false != ( $token = $request->get_header( 'x_wfb_entry_token') ) && is_string( $request[ 'form_id' ] ) ){
54 $allowed = Qcformbuilder_Forms_API_Token::check_token( $token, $request[ 'form_id' ] );
55 }
56
57 return $allowed;
58 }
59
60 /**
61 * Get the nonce for the WP REST API
62 *
63 * @since 1.5.3
64 *
65 * @return string
66 */
67 public static function get_core_nonce(){
68 return wp_create_nonce( 'wp_rest' );
69 }
70
71 /**
72 * Given an array of field IDs and form config, reduce field IDs array to fields that form has
73 *
74 * @since 1.7.0
75 *
76 * @param array $field_ids
77 * @param array $form
78 * @return array
79 */
80 public static function validate_array_of_field_ids(array $field_ids, array $form )
81 {
82 $valid_fields = [];
83 $form_fields = array_keys(Qcformbuilder_Forms_Forms::get_fields( $form, false ));
84 if (! empty( $field_ids )) {
85 foreach ($field_ids as $field_id) {
86 $field_id = trim( $field_id );
87 if( in_array( $field_id, $form_fields ) ){
88 $valid_fields[] = $field_id;
89 }
90
91 }
92 }
93
94 return $valid_fields;
95 }
96
97 }