|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class YIKES_Easy_Forms_Blocks_API. |
|
4
|
|
|
*/ |
|
5
|
|
|
class YIKES_Easy_Forms_Blocks_API { |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Register our hooks. |
|
9
|
|
|
*/ |
|
10
|
|
|
public function __construct() { |
|
11
|
|
|
add_action( 'wp_ajax_yikes_get_forms', array( $this, 'get_forms' ) ); |
|
12
|
|
|
add_action( 'wp_ajax_yikes_get_form', array( $this, 'get_form' ) ); |
|
13
|
|
|
add_action( 'wp_ajax_yikes_get_recaptcha', array( $this, 'get_recaptcha' ) ); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get all of our forms. |
|
18
|
|
|
*/ |
|
19
|
|
|
public function get_forms() { |
|
20
|
|
|
|
|
21
|
|
|
// Verify Nonce. |
|
22
|
|
|
if ( ! check_ajax_referer( 'fetch_forms_nonce', 'nonce', false ) ) { |
|
23
|
|
|
wp_send_json_error( '1' ); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
// Get all of our forms. |
|
27
|
|
|
$form_interface = yikes_easy_mailchimp_extender_get_form_interface(); |
|
28
|
|
|
$all_forms = $form_interface->get_all_forms(); |
|
29
|
|
|
|
|
30
|
|
|
wp_send_json_success( array_values( $all_forms ) ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get a form's data. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function get_form() { |
|
37
|
|
|
|
|
38
|
|
|
// Verify Nonce. |
|
39
|
|
|
if ( ! check_ajax_referer( 'fetch_form_nonce', 'nonce', false ) ) { |
|
40
|
|
|
wp_send_json_error( '1' ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$form_id = isset( $_POST['form_id'] ) ? filter_var( wp_unslash( $_POST['form_id'] ), FILTER_SANITIZE_NUMBER_INT ) : ''; |
|
44
|
|
|
|
|
45
|
|
|
if ( empty( $form_id ) ) { |
|
46
|
|
|
wp_send_json_error( '1' ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$form_interface = yikes_easy_mailchimp_extender_get_form_interface(); |
|
50
|
|
|
|
|
51
|
|
|
$form = $form_interface->get_form( $form_id ); |
|
52
|
|
|
|
|
53
|
|
|
wp_send_json_success( $form ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the reCAPTCHA variables. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function get_recaptcha() { |
|
60
|
|
|
|
|
61
|
|
|
// Verify Nonce. |
|
62
|
|
|
if ( ! check_ajax_referer( 'fetch_recaptcha_nonce', 'nonce', false ) ) { |
|
63
|
|
|
wp_send_json_error( '1' ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ( get_option( 'yikes-mc-recaptcha-status', '' ) === '1' ) { |
|
67
|
|
|
|
|
68
|
|
|
$site_key = get_option( 'yikes-mc-recaptcha-site-key', '' ); |
|
69
|
|
|
$secret_key = get_option( 'yikes-mc-recaptcha-secret-key', '' ); |
|
70
|
|
|
|
|
71
|
|
|
// If either of the Private the Secret key is left blank, we should display an error back to the user. |
|
72
|
|
|
if ( empty( $site_key ) || empty( $secret_key ) ) { |
|
73
|
|
|
wp_send_json_error(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$locale = get_locale(); |
|
77
|
|
|
$locale_a = explode( '_', $locale ); |
|
78
|
|
|
$locale = isset( $locale_a[0] ) ? $locale_a[0] : $locale; |
|
79
|
|
|
$return = apply_filters( 'yikes_mailchimp_recaptcha_data', array( |
|
80
|
|
|
'site_key' => $site_key, |
|
81
|
|
|
'secret_key' => $secret_key, |
|
82
|
|
|
'locale' => $locale, |
|
83
|
|
|
)); |
|
84
|
|
|
|
|
85
|
|
|
wp_send_json_success( $return ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
wp_send_json_error(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.