@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | <div class="addon-footer-wrap give-clearfix"> |
34 | 34 | <a href="<?php echo esc_attr( $permalink ); ?>" title="<?php echo esc_attr( $add_on_title ); ?>" class="button-secondary" target="_blank"> |
35 | - <?php esc_attr_e( 'View Add-on' , 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
35 | + <?php esc_attr_e( 'View Add-on', 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
36 | 36 | <span class="dashicons dashicons-external"></span></a> |
37 | 37 | </div> |
38 | 38 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | <div class="addon-footer-wrap give-clearfix"> |
34 | 34 | <a href="<?php echo esc_attr( $permalink ); ?>" title="<?php echo esc_attr( $add_on_title ); ?>" class="button-secondary" target="_blank"> |
35 | - <?php esc_attr_e( 'View Add-on' , 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
35 | + <?php esc_attr_e( 'View Add-on', 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
36 | 36 | <span class="dashicons dashicons-external"></span></a> |
37 | 37 | </div> |
38 | 38 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | <div class="addon-footer-wrap give-clearfix"> |
34 | 34 | <a href="<?php echo esc_attr( $permalink ); ?>" title="<?php echo esc_attr( $add_on_title ); ?>" class="button-secondary" target="_blank"> |
35 | - <?php esc_attr_e( 'View Add-on' , 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
35 | + <?php esc_attr_e( 'View Add-on', 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
36 | 36 | <span class="dashicons dashicons-external"></span></a> |
37 | 37 | </div> |
38 | 38 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | <div class="addon-footer-wrap give-clearfix"> |
34 | 34 | <a href="<?php echo esc_attr( $permalink ); ?>" title="<?php echo esc_attr( $add_on_title ); ?>" class="button-secondary" target="_blank"> |
35 | - <?php esc_attr_e( 'View Add-on' , 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
35 | + <?php esc_attr_e( 'View Add-on', 'yikes-inc-easy-mailchimp-extender' ); ?> |
|
36 | 36 | <span class="dashicons dashicons-external"></span></a> |
37 | 37 | </div> |
38 | 38 |
@@ -30,7 +30,7 @@ |
||
30 | 30 | printf( '<h2>' . esc_attr__( 'Popular Knowledge Base Articles', 'yikes-inc-easy-mailchimp-extender' ) . '</h2>' ); |
31 | 31 | printf( '<ol>' ); |
32 | 32 | foreach ( $knowledge_base_links as $kb_link ) { |
33 | - echo wp_kses_post( '<li><a href="' . esc_url( $kb_link['href'] ) . '" title="' . esc_attr( $kb_link['title'] ) . '" target="_blank">' . esc_attr( $kb_link['title'] ) . '</a></li>' ); |
|
33 | + echo wp_kses_post( '<li><a href="' . esc_url( $kb_link[ 'href' ] ) . '" title="' . esc_attr( $kb_link[ 'title' ] ) . '" target="_blank">' . esc_attr( $kb_link[ 'title' ] ) . '</a></li>' ); |
|
34 | 34 | } |
35 | 35 | printf( '</ol>' ); |
36 | 36 | } |
@@ -5,34 +5,34 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | // parse our form data |
8 | -parse_str( $_POST['form_data'], $data ); |
|
8 | +parse_str( $_POST[ 'form_data' ], $data ); |
|
9 | 9 | // store the form ID to use in our hooks and filters |
10 | -$form = $_POST['form_id']; |
|
10 | +$form = $_POST[ 'form_id' ]; |
|
11 | 11 | |
12 | 12 | // Retreive the form data from the database instead of posting it with the form-submission |
13 | 13 | global $wpdb; |
14 | 14 | // return it as an array, so we can work with it to build our form below |
15 | 15 | $form_results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'yikes_easy_mc_forms WHERE id = ' . $form . '', ARRAY_A ); |
16 | 16 | |
17 | -if( $form_results ) { |
|
18 | - $form_data = $form_results[0]; |
|
17 | +if ( $form_results ) { |
|
18 | + $form_data = $form_results[ 0 ]; |
|
19 | 19 | // List ID |
20 | - $list_id = $form_data['list_id']; |
|
20 | + $list_id = $form_data[ 'list_id' ]; |
|
21 | 21 | // decode our submission settings |
22 | - $submission_settings = json_decode( stripslashes( $form_data['submission_settings'] ), true ); |
|
22 | + $submission_settings = json_decode( stripslashes( $form_data[ 'submission_settings' ] ), true ); |
|
23 | 23 | // decode our optin settings |
24 | - $optin_settings = json_decode( stripslashes( $form_data['optin_settings'] ), true ); |
|
24 | + $optin_settings = json_decode( stripslashes( $form_data[ 'optin_settings' ] ), true ); |
|
25 | 25 | // decode our fields |
26 | - $form_fields = json_decode( stripslashes( $form_data['fields'] ), true ); |
|
26 | + $form_fields = json_decode( stripslashes( $form_data[ 'fields' ] ), true ); |
|
27 | 27 | /* Decode our error messages |
28 | 28 | * Workaround for international characters (cyrillic etc) |
29 | 29 | * See: https://wordpress.org/support/topic/custom-messages-do-not-support-cyrillic-characters?replies=11#post-7629620 |
30 | 30 | */ |
31 | - $error_messages = ( get_magic_quotes_gpc() ) ? json_decode( stripslashes( $form_data['error_messages'] ), true ) : json_decode( $form_data['error_messages'], true ); |
|
31 | + $error_messages = ( get_magic_quotes_gpc() ) ? json_decode( stripslashes( $form_data[ 'error_messages' ] ), true ) : json_decode( $form_data[ 'error_messages' ], true ); |
|
32 | 32 | /** Submit Process **/ |
33 | - $notifications = json_decode( stripslashes( $form_data['custom_notifications'] ), true ); |
|
33 | + $notifications = json_decode( stripslashes( $form_data[ 'custom_notifications' ] ), true ); |
|
34 | 34 | /* Page Data */ |
35 | - $page_data = $_POST['page_data']; |
|
35 | + $page_data = $_POST[ 'page_data' ]; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // Empty array to build up merge variables |
@@ -42,39 +42,39 @@ discard block |
||
42 | 42 | $error = 0; |
43 | 43 | |
44 | 44 | /* Check for Honeypot filled */ |
45 | -$honey_pot_filled = ( isset( $data['yikes-mailchimp-honeypot'] ) && $data['yikes-mailchimp-honeypot'] != '' ) ? true : false; |
|
45 | +$honey_pot_filled = ( isset( $data[ 'yikes-mailchimp-honeypot' ] ) && $data[ 'yikes-mailchimp-honeypot' ] != '' ) ? true : false; |
|
46 | 46 | // if it was filled out, return an error... |
47 | -if( $honey_pot_filled ) { |
|
47 | +if ( $honey_pot_filled ) { |
|
48 | 48 | wp_send_json_error( array( |
49 | 49 | 'hide' => '0', |
50 | 50 | 'error' => 1, |
51 | - 'response' => __( "Error: It looks like the honeypot was filled out and the form was not properly be submitted." , 'yikes-inc-easy-mailchimp-extender' ) |
|
51 | + 'response' => __( "Error: It looks like the honeypot was filled out and the form was not properly be submitted.", 'yikes-inc-easy-mailchimp-extender' ) |
|
52 | 52 | ) ); |
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | 56 | // Check reCAPTCHA Response was submitted with the form data |
57 | -if( isset( $data['g-recaptcha-response'] ) ) { |
|
58 | - $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key' , '' ) . '&response=' . $data['g-recaptcha-response'] . '&remoteip=' . $_SERVER["REMOTE_ADDR"] ); |
|
57 | +if ( isset( $data[ 'g-recaptcha-response' ] ) ) { |
|
58 | + $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key', '' ) . '&response=' . $data[ 'g-recaptcha-response' ] . '&remoteip=' . $_SERVER[ "REMOTE_ADDR" ] ); |
|
59 | 59 | $response = wp_remote_get( $url ); |
60 | - $response_body = json_decode( $response['body'] , true ); |
|
60 | + $response_body = json_decode( $response[ 'body' ], true ); |
|
61 | 61 | // if we've hit an error, lets return the error! |
62 | - if( $response_body['success'] != 1 ) { |
|
62 | + if ( $response_body[ 'success' ] != 1 ) { |
|
63 | 63 | $error_messages = array(); // empty array to store error messages |
64 | - if( isset( $response_body['error-codes'] ) ) { |
|
65 | - foreach( $response_body['error-codes'] as $error_code ) { |
|
66 | - if( $error_code == 'missing-input-response' ) { |
|
64 | + if ( isset( $response_body[ 'error-codes' ] ) ) { |
|
65 | + foreach ( $response_body[ 'error-codes' ] as $error_code ) { |
|
66 | + if ( $error_code == 'missing-input-response' ) { |
|
67 | 67 | $error_code = __( 'Please check the reCAPTCHA field.', 'yikes-inc-easy-mailchimp-extender' ); |
68 | 68 | } |
69 | - $error_messages[] = __( 'Error', 'yikes-inc-easy-mailchimp-extender' ) . ': ' . $error_code; |
|
69 | + $error_messages[ ] = __( 'Error', 'yikes-inc-easy-mailchimp-extender' ) . ': ' . $error_code; |
|
70 | 70 | } |
71 | 71 | } else { |
72 | - $error_messages[] = __( 'Please refresh the page and try again.', 'yikes-inc-easy-mailchimp-extender' ); |
|
72 | + $error_messages[ ] = __( 'Please refresh the page and try again.', 'yikes-inc-easy-mailchimp-extender' ); |
|
73 | 73 | } |
74 | 74 | $error = 1; |
75 | 75 | wp_send_json_error( array( |
76 | 76 | 'hide' => '0', |
77 | - 'error' => $error , |
|
77 | + 'error' => $error, |
|
78 | 78 | 'response' => apply_filters( 'yikes-mailchimp-recaptcha-required-error', implode( ' ', $error_messages ) ), |
79 | 79 | ) ); |
80 | 80 | exit(); |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | |
84 | 84 | // loop to push variables to our array |
85 | 85 | foreach ( $data as $merge_tag => $value ) { |
86 | - if( $merge_tag != 'yikes_easy_mc_new_subscriber' && $merge_tag != '_wp_http_referer' ) { |
|
86 | + if ( $merge_tag != 'yikes_easy_mc_new_subscriber' && $merge_tag != '_wp_http_referer' ) { |
|
87 | 87 | // check if the current iteration has a 'date_format' key set |
88 | 88 | // (aka - date/birthday fields) |
89 | - if( isset( $form_fields[$merge_tag]['date_format'] ) ) { |
|
89 | + if ( isset( $form_fields[ $merge_tag ][ 'date_format' ] ) ) { |
|
90 | 90 | // check if EU date format |
91 | - if( $form_fields[$merge_tag]['date_format'] == 'DD/MM/YYYY' ) { |
|
91 | + if ( $form_fields[ $merge_tag ][ 'date_format' ] == 'DD/MM/YYYY' ) { |
|
92 | 92 | // convert '/' to '.' and to UNIX timestamp |
93 | 93 | $value = date( 'Y-m-d', strtotime( str_replace( '/', '.', $value ) ) ); |
94 | 94 | } else { |
@@ -96,22 +96,22 @@ discard block |
||
96 | 96 | $value = date( 'Y-m-d', strtotime( $value ) ); |
97 | 97 | } |
98 | 98 | } |
99 | - if( is_numeric( $merge_tag ) ) { // this is is an interest group! |
|
100 | - $merge_variables['groupings'][] = array( 'id' => $merge_tag , 'groups' => ( is_array( $value ) ) ? $value : array( $value ) ); |
|
99 | + if ( is_numeric( $merge_tag ) ) { // this is is an interest group! |
|
100 | + $merge_variables[ 'groupings' ][ ] = array( 'id' => $merge_tag, 'groups' => ( is_array( $value ) ) ? $value : array( $value ) ); |
|
101 | 101 | } else { // or else it's just a standard merge variable |
102 | - $merge_variables[$merge_tag] = $value; |
|
102 | + $merge_variables[ $merge_tag ] = $value; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } |
106 | 106 | // store the opt-in time |
107 | -$merge_variables['optin_time'] = current_time( 'Y-m-d H:i:s', 1 ); |
|
107 | +$merge_variables[ 'optin_time' ] = current_time( 'Y-m-d H:i:s', 1 ); |
|
108 | 108 | |
109 | 109 | // Submit our form data |
110 | 110 | $api_key = yikes_get_mc_api_key(); |
111 | 111 | $dash_position = strpos( $api_key, '-' ); |
112 | 112 | |
113 | 113 | // setup the end point |
114 | -if( $dash_position !== false ) { |
|
114 | +if ( $dash_position !== false ) { |
|
115 | 115 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/subscribe.json'; |
116 | 116 | } |
117 | 117 | |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | * Allow users to check for submit value |
138 | 138 | * and pass back an error to the user |
139 | 139 | */ |
140 | -if( isset( $merge_variables['error'] ) ) { |
|
140 | +if ( isset( $merge_variables[ 'error' ] ) ) { |
|
141 | 141 | // send our error response back |
142 | - wp_send_json_error( array( 'hide' => '0', 'error' => $merge_variables['error'] , 'response' => $merge_variables['message'] ) ); |
|
142 | + wp_send_json_error( array( 'hide' => '0', 'error' => $merge_variables[ 'error' ], 'response' => $merge_variables[ 'message' ] ) ); |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | * Setup whether or not we should update the user, or display the error with email generation |
148 | 148 | * @since 6.1 |
149 | 149 | */ |
150 | -if ( isset( $optin_settings['update_existing_user'] ) && 1 === absint( $optin_settings['update_existing_user'] ) ) { |
|
150 | +if ( isset( $optin_settings[ 'update_existing_user' ] ) && 1 === absint( $optin_settings[ 'update_existing_user' ] ) ) { |
|
151 | 151 | // Should we send the update email |
152 | - if ( isset( $optin_settings['send_update_email'] ) && 1 === absint( $optin_settings['send_update_email'] ) ) { |
|
152 | + if ( isset( $optin_settings[ 'send_update_email' ] ) && 1 === absint( $optin_settings[ 'send_update_email' ] ) ) { |
|
153 | 153 | $update_existing_user = 0; |
154 | 154 | } else { |
155 | 155 | $update_existing_user = 1; |
@@ -164,38 +164,38 @@ discard block |
||
164 | 164 | 'body' => apply_filters( 'yikes-mailchimp-user-subscribe-api-request', array( |
165 | 165 | 'apikey' => $api_key, |
166 | 166 | 'id' => $list_id, |
167 | - 'email' => array( 'email' => sanitize_email( $data['EMAIL'] ) ), |
|
167 | + 'email' => array( 'email' => sanitize_email( $data[ 'EMAIL' ] ) ), |
|
168 | 168 | 'merge_vars' => $merge_variables, |
169 | - 'double_optin' => $optin_settings['optin'], |
|
169 | + 'double_optin' => $optin_settings[ 'optin' ], |
|
170 | 170 | 'update_existing' => $update_existing_user, // Decide if we should update the user or not |
171 | - 'send_welcome' => $optin_settings['send_welcome_email'], |
|
172 | - 'replace_interests' => ( isset( $submission_settings['replace_interests'] ) ) ? $submission_settings['replace_interests'] : 1, // defaults to replace |
|
173 | - ), $form, $list_id, $data['EMAIL'] ), |
|
171 | + 'send_welcome' => $optin_settings[ 'send_welcome_email' ], |
|
172 | + 'replace_interests' => ( isset( $submission_settings[ 'replace_interests' ] ) ) ? $submission_settings[ 'replace_interests' ] : 1, // defaults to replace |
|
173 | + ), $form, $list_id, $data[ 'EMAIL' ] ), |
|
174 | 174 | 'timeout' => 10, |
175 | 175 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
176 | 176 | ) ); |
177 | 177 | |
178 | 178 | $subscribe_response = json_decode( wp_remote_retrieve_body( $subscribe_response ), true ); |
179 | 179 | |
180 | - if( isset( $subscribe_response['error'] ) ) { |
|
180 | + if ( isset( $subscribe_response[ 'error' ] ) ) { |
|
181 | 181 | |
182 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
182 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
183 | 183 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
184 | 184 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
185 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscribe_response['error'], __( "Subscribe New User" , 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission_ajax.php" ); |
|
185 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscribe_response[ 'error' ], __( "Subscribe New User", 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission_ajax.php" ); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | $update_account_details_link = ''; |
189 | 189 | $error = 1; |
190 | - switch( $subscribe_response['code'] ) { |
|
190 | + switch ( $subscribe_response[ 'code' ] ) { |
|
191 | 191 | // user already subscribed |
192 | 192 | case '214': |
193 | - $custom_already_subscribed_text = apply_filters( 'yikes-easy-mailchimp-update-existing-subscriber-text', sprintf( __( ' To update your MailChimp profile, please %s.', 'yikes-inc-easy-mailchimp-extender' ), '<a class="send-update-email" data-list-id="' . $list_id . '" data-user-email="' . sanitize_email( $data['EMAIL'] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ), $form, '<a class="send-update-email" data-list-id="' . $_POST['yikes-mailchimp-associated-list-id'] . '" data-user-email="' . sanitize_email( $data['EMAIL'] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ); |
|
194 | - $update_account_details_link = ( 1 === absint( $optin_settings['update_existing_user'] ) && 1 === absint( $optin_settings['send_update_email'] ) ) ? $custom_already_subscribed_text : false; |
|
195 | - if( ! empty( $error_messages['already-subscribed'] ) ) { |
|
196 | - $error_response = apply_filters( 'yikes-easy-mailchimp-user-already-subscribed-text', $error_messages['already-subscribed'] , $form, $data['EMAIL'] ) . ' ' . $update_account_details_link; |
|
193 | + $custom_already_subscribed_text = apply_filters( 'yikes-easy-mailchimp-update-existing-subscriber-text', sprintf( __( ' To update your MailChimp profile, please %s.', 'yikes-inc-easy-mailchimp-extender' ), '<a class="send-update-email" data-list-id="' . $list_id . '" data-user-email="' . sanitize_email( $data[ 'EMAIL' ] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ), $form, '<a class="send-update-email" data-list-id="' . $_POST[ 'yikes-mailchimp-associated-list-id' ] . '" data-user-email="' . sanitize_email( $data[ 'EMAIL' ] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ); |
|
194 | + $update_account_details_link = ( 1 === absint( $optin_settings[ 'update_existing_user' ] ) && 1 === absint( $optin_settings[ 'send_update_email' ] ) ) ? $custom_already_subscribed_text : false; |
|
195 | + if ( ! empty( $error_messages[ 'already-subscribed' ] ) ) { |
|
196 | + $error_response = apply_filters( 'yikes-easy-mailchimp-user-already-subscribed-text', $error_messages[ 'already-subscribed' ], $form, $data[ 'EMAIL' ] ) . ' ' . $update_account_details_link; |
|
197 | 197 | } else { |
198 | - $error_response = $subscribe_response['error'] . ' ' . $update_account_details_link; |
|
198 | + $error_response = $subscribe_response[ 'error' ] . ' ' . $update_account_details_link; |
|
199 | 199 | } |
200 | 200 | break; |
201 | 201 | // missing a required field |
@@ -203,34 +203,34 @@ discard block |
||
203 | 203 | // get all merge variables in array, loop and str_replace error code with field name |
204 | 204 | $api_key = yikes_get_mc_api_key(); |
205 | 205 | $dash_position = strpos( $api_key, '-' ); |
206 | - if( $dash_position !== false ) { |
|
206 | + if ( $dash_position !== false ) { |
|
207 | 207 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/merge-vars.json'; |
208 | 208 | } |
209 | 209 | $merge_variables = wp_remote_post( $api_endpoint, array( |
210 | 210 | 'body' => array( |
211 | 211 | 'apikey' => $api_key, |
212 | - 'id' => array( $list_id ) , |
|
212 | + 'id' => array( $list_id ), |
|
213 | 213 | ), |
214 | 214 | 'timeout' => 10, |
215 | 215 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ), |
216 | 216 | ) ); |
217 | 217 | $merge_variables = json_decode( wp_remote_retrieve_body( $merge_variables ), true ); |
218 | - if( is_wp_error( $merge_variables ) || isset( $merge_variables['error'] ) ) { |
|
219 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
218 | + if ( is_wp_error( $merge_variables ) || isset( $merge_variables[ 'error' ] ) ) { |
|
219 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
220 | 220 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
221 | 221 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
222 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $merge_variables['error'], __( "Get Merge Variables" , 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission_ajax.php" ); |
|
222 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $merge_variables[ 'error' ], __( "Get Merge Variables", 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission_ajax.php" ); |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | // re-store our data |
226 | - $merge_variables = $merge_variables['data'][0]['merge_vars']; |
|
226 | + $merge_variables = $merge_variables[ 'data' ][ 0 ][ 'merge_vars' ]; |
|
227 | 227 | $merge_variable_name_array = array(); |
228 | - foreach( $merge_variables as $merge_var ) { |
|
229 | - $merge_variables_name_array[$merge_var['tag']] = $merge_var['name']; |
|
228 | + foreach ( $merge_variables as $merge_var ) { |
|
229 | + $merge_variables_name_array[ $merge_var[ 'tag' ] ] = $merge_var[ 'name' ]; |
|
230 | 230 | } |
231 | - $error_message = $subscribe_response['error']; |
|
231 | + $error_message = $subscribe_response[ 'error' ]; |
|
232 | 232 | // replace tag with name in the error message. |
233 | - foreach( $merge_variables_name_array as $tag => $name ) { |
|
233 | + foreach ( $merge_variables_name_array as $tag => $name ) { |
|
234 | 234 | $error_message = str_replace( $tag, $name, $error_message ); |
235 | 235 | } |
236 | 236 | $error_response = $error_message; |
@@ -238,14 +238,14 @@ discard block |
||
238 | 238 | // [email protected] is not allowed |
239 | 239 | case '-99': |
240 | 240 | // generic error |
241 | - $error_response = str_replace( ' and cannot be imported', '', str_replace( 'List_RoleEmailMember:', '', $subscribe_response['error'] ) ); |
|
241 | + $error_response = str_replace( ' and cannot be imported', '', str_replace( 'List_RoleEmailMember:', '', $subscribe_response[ 'error' ] ) ); |
|
242 | 242 | break; |
243 | 243 | // invalid email (or no email at all) |
244 | 244 | case '-100': |
245 | - $error_response = ( ! empty( $error_messages['invalid-email'] ) ) ? $error_messages['invalid-email'] : __( 'Please provide a valid email address.', 'yikes-inc-easy-mailchimp-extender' ); |
|
245 | + $error_response = ( ! empty( $error_messages[ 'invalid-email' ] ) ) ? $error_messages[ 'invalid-email' ] : __( 'Please provide a valid email address.', 'yikes-inc-easy-mailchimp-extender' ); |
|
246 | 246 | break; |
247 | 247 | default: |
248 | - $error_response = ( ! empty( $error_messages['general-error'] ) ) ? $error_messages['general-error'] : $subscribe_response['error']; |
|
248 | + $error_response = ( ! empty( $error_messages[ 'general-error' ] ) ) ? $error_messages[ 'general-error' ] : $subscribe_response[ 'error' ]; |
|
249 | 249 | break; |
250 | 250 | } |
251 | 251 | // send the response |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | /* |
264 | 264 | * Successful form submission redirect |
265 | 265 | */ |
266 | - if( $submission_settings['redirect_on_submission'] == '1' ) { |
|
266 | + if ( $submission_settings[ 'redirect_on_submission' ] == '1' ) { |
|
267 | 267 | $redirection = '1'; |
268 | - $redirect_url = ( 'custom_url' != $submission_settings['redirect_page'] ) ? get_permalink( $submission_settings['redirect_page'] ) : $submission_settings['custom_redirect_url']; |
|
268 | + $redirect_url = ( 'custom_url' != $submission_settings[ 'redirect_page' ] ) ? get_permalink( $submission_settings[ 'redirect_page' ] ) : $submission_settings[ 'custom_redirect_url' ]; |
|
269 | 269 | $redirect = '<script type="text/javascript">setTimeout(function() { window.location="' . apply_filters( 'yikes-mailchimp-redirect-url', esc_url( $redirect_url ), $form, $page_data ) . '"; }, ' . apply_filters( 'yikes-mailchimp-redirect-timer', 1500 ) . ');</script>'; |
270 | 270 | } |
271 | 271 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | do_action( 'yikes-mailchimp-after-submission-' . $form, $merge_variables ); |
282 | 282 | |
283 | 283 | // send our notifications if setup (must go before wp_send_json()) |
284 | - do_action( 'yikes-mailchimp-form-submission' , sanitize_email( $data['EMAIL'] ), $merge_variables , $form , $notifications ); |
|
285 | - do_action( 'yikes-mailchimp-form-submission-' . $form, sanitize_email( $data['EMAIL'] ), $merge_variables , $form , $notifications ); |
|
284 | + do_action( 'yikes-mailchimp-form-submission', sanitize_email( $data[ 'EMAIL' ] ), $merge_variables, $form, $notifications ); |
|
285 | + do_action( 'yikes-mailchimp-form-submission-' . $form, sanitize_email( $data[ 'EMAIL' ] ), $merge_variables, $form, $notifications ); |
|
286 | 286 | |
287 | - $default_success_response = ( 1 === $optin_settings['optin'] ) ? __( "Thank you for subscribing! Check your email for the confirmation message." , 'yikes-inc-easy-mailchimp-extender' ) : __( "Thank you for subscribing!" , 'yikes-inc-easy-mailchimp-extender' ); |
|
287 | + $default_success_response = ( 1 === $optin_settings[ 'optin' ] ) ? __( "Thank you for subscribing! Check your email for the confirmation message.", 'yikes-inc-easy-mailchimp-extender' ) : __( "Thank you for subscribing!", 'yikes-inc-easy-mailchimp-extender' ); |
|
288 | 288 | |
289 | 289 | wp_send_json_success( |
290 | 290 | array( |
291 | - 'hide' => $submission_settings['hide_form_post_signup'], |
|
291 | + 'hide' => $submission_settings[ 'hide_form_post_signup' ], |
|
292 | 292 | 'error' => $error, |
293 | - 'response' => apply_filters( 'yikes-mailchimp-success-response', ( ! empty( $error_messages['success'] ) ? $error_messages['success'] : $default_success_response ), $form, $merge_variables ), |
|
293 | + 'response' => apply_filters( 'yikes-mailchimp-success-response', ( ! empty( $error_messages[ 'success' ] ) ? $error_messages[ 'success' ] : $default_success_response ), $form, $merge_variables ), |
|
294 | 294 | 'redirection' => isset( $redirection ) ? '1' : '0', |
295 | 295 | 'redirect' => isset( $redirect ) ? $redirect : '', |
296 | 296 | ) |
@@ -8,45 +8,45 @@ discard block |
||
8 | 8 | global $form_submitted, $process_submission_response; |
9 | 9 | |
10 | 10 | // confirm we have a form id to work with |
11 | -$form_id = ( ! empty( $_POST['yikes-mailchimp-submitted-form'] ) ) ? $_POST['yikes-mailchimp-submitted-form'] : false; |
|
12 | -if( ! $form_id ) { |
|
11 | +$form_id = ( ! empty( $_POST[ 'yikes-mailchimp-submitted-form' ] ) ) ? $_POST[ 'yikes-mailchimp-submitted-form' ] : false; |
|
12 | +if ( ! $form_id ) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | -$form_settings = Yikes_Inc_Easy_Mailchimp_Extender_Public::yikes_retrieve_form_settings( $_POST['yikes-mailchimp-submitted-form'] ); |
|
16 | +$form_settings = Yikes_Inc_Easy_Mailchimp_Extender_Public::yikes_retrieve_form_settings( $_POST[ 'yikes-mailchimp-submitted-form' ] ); |
|
17 | 17 | |
18 | 18 | // Process our form submissions (non ajax forms) |
19 | -if ( ! isset( $_POST['yikes_easy_mc_new_subscriber'] ) || ! wp_verify_nonce( $_POST['yikes_easy_mc_new_subscriber'], 'yikes_easy_mc_form_submit' ) ) { |
|
19 | +if ( ! isset( $_POST[ 'yikes_easy_mc_new_subscriber' ] ) || ! wp_verify_nonce( $_POST[ 'yikes_easy_mc_new_subscriber' ], 'yikes_easy_mc_form_submit' ) ) { |
|
20 | 20 | |
21 | - $process_submission_response = '<p><small class="form_submission_error">' . __( "Error : Sorry, the nonce security check didn't pass. Please reload the page and try again. You may want to try clearing your browser cache as a last attempt." , 'yikes-inc-easy-mailchimp-extender' ) . '</small></p>'; |
|
21 | + $process_submission_response = '<p><small class="form_submission_error">' . __( "Error : Sorry, the nonce security check didn't pass. Please reload the page and try again. You may want to try clearing your browser cache as a last attempt.", 'yikes-inc-easy-mailchimp-extender' ) . '</small></p>'; |
|
22 | 22 | return; |
23 | 23 | |
24 | 24 | } else { |
25 | 25 | |
26 | 26 | /* Check for Honeypot filled */ |
27 | - $honey_pot_filled = ( isset( $_POST['yikes-mailchimp-honeypot'] ) && $_POST['yikes-mailchimp-honeypot'] != '' ) ? true : false; |
|
27 | + $honey_pot_filled = ( isset( $_POST[ 'yikes-mailchimp-honeypot' ] ) && $_POST[ 'yikes-mailchimp-honeypot' ] != '' ) ? true : false; |
|
28 | 28 | // if it was filled out, return an error... |
29 | 29 | if ( $honey_pot_filled ) { |
30 | - $process_submission_response = '<p><small class="form_submission_error">' . __( "Error: It looks like the honeypot was filled out and the form was not properly be submitted." , 'yikes-inc-easy-mailchimp-extender' ) . '</small></p>'; |
|
30 | + $process_submission_response = '<p><small class="form_submission_error">' . __( "Error: It looks like the honeypot was filled out and the form was not properly be submitted.", 'yikes-inc-easy-mailchimp-extender' ) . '</small></p>'; |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | 34 | // Check reCAPTCHA Response |
35 | - if( isset( $_POST['g-recaptcha-response'] ) ) { |
|
36 | - $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key' , '' ) . '&response=' . $_POST['g-recaptcha-response'] . '&remoteip=' . $_SERVER["REMOTE_ADDR"] ); |
|
35 | + if ( isset( $_POST[ 'g-recaptcha-response' ] ) ) { |
|
36 | + $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key', '' ) . '&response=' . $_POST[ 'g-recaptcha-response' ] . '&remoteip=' . $_SERVER[ "REMOTE_ADDR" ] ); |
|
37 | 37 | $response = wp_remote_get( $url ); |
38 | - $response_body = json_decode( $response['body'] , true ); |
|
38 | + $response_body = json_decode( $response[ 'body' ], true ); |
|
39 | 39 | |
40 | 40 | // if we've hit an error, lets return the error! |
41 | - if( $response_body['success'] != 1 ) { |
|
41 | + if ( $response_body[ 'success' ] != 1 ) { |
|
42 | 42 | $recaptcha_error = array(); // empty array to store error messages |
43 | - foreach( $response_body['error-codes'] as $error_code ) { |
|
44 | - if( $error_code == 'missing-input-response' ) { |
|
43 | + foreach ( $response_body[ 'error-codes' ] as $error_code ) { |
|
44 | + if ( $error_code == 'missing-input-response' ) { |
|
45 | 45 | $error_code = __( 'Please check the reCAPTCHA field.', 'yikes-inc-easy-mailchimp-extender' ); |
46 | 46 | } |
47 | - $recaptcha_error[] = $error_code; |
|
47 | + $recaptcha_error[ ] = $error_code; |
|
48 | 48 | } |
49 | - $process_submission_response .= "<p class='yikes-easy-mc-error-message'>" . apply_filters( 'yikes-mailchimp-recaptcha-required-error', __( 'Error' , 'yikes-inc-easy-mailchimp-extender' ) . ': ' . implode( ' ' , $recaptcha_error ) ) . "</p>"; |
|
49 | + $process_submission_response .= "<p class='yikes-easy-mc-error-message'>" . apply_filters( 'yikes-mailchimp-recaptcha-required-error', __( 'Error', 'yikes-inc-easy-mailchimp-extender' ) . ': ' . implode( ' ', $recaptcha_error ) ) . "</p>"; |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | } |
@@ -56,20 +56,20 @@ discard block |
||
56 | 56 | * No HTML5 validation, and don't want to use jQuery for non-ajax forms |
57 | 57 | */ |
58 | 58 | $missing_required_checkbox_interest_groups = array(); |
59 | - foreach( $form_settings['fields'] as $merge_tag => $field_data ) { |
|
60 | - if( is_numeric( $merge_tag ) ) { |
|
59 | + foreach ( $form_settings[ 'fields' ] as $merge_tag => $field_data ) { |
|
60 | + if ( is_numeric( $merge_tag ) ) { |
|
61 | 61 | // check if the checkbox group was set to required, if so return an error |
62 | - if( isset( $field_data['require'] ) && $field_data['require'] == 1 ) { |
|
63 | - if( $field_data['type'] == 'checkboxes' ) { |
|
64 | - if( ! isset( $_POST[$merge_tag] ) ) { |
|
65 | - $missing_required_checkbox_interest_groups[] = $merge_tag; |
|
62 | + if ( isset( $field_data[ 'require' ] ) && $field_data[ 'require' ] == 1 ) { |
|
63 | + if ( $field_data[ 'type' ] == 'checkboxes' ) { |
|
64 | + if ( ! isset( $_POST[ $merge_tag ] ) ) { |
|
65 | + $missing_required_checkbox_interest_groups[ ] = $merge_tag; |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - if( ! empty( $missing_required_checkbox_interest_groups ) ) { |
|
72 | + if ( ! empty( $missing_required_checkbox_interest_groups ) ) { |
|
73 | 73 | $process_submission_response = '<p class="yikes-easy-mc-error-message">' . apply_filters( 'yikes-mailchimp-interest-group-required-top-error', sprintf( _n( 'It looks like you forgot to fill in a required field.', 'It looks like you forgot to fill in %s required fields.', count( $missing_required_checkbox_interest_groups ), 'yikes-inc-easy-mailchimp-extender' ), count( $missing_required_checkbox_interest_groups ) ), count( $missing_required_checkbox_interest_groups ), $form_id ) . '</p>'; |
74 | 74 | return; |
75 | 75 | } |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | |
80 | 80 | // loop to push variables to our array |
81 | 81 | foreach ( $_POST as $merge_tag => $value ) { |
82 | - if( $merge_tag != 'yikes_easy_mc_new_subscriber' && $merge_tag != '_wp_http_referer' ) { |
|
82 | + if ( $merge_tag != 'yikes_easy_mc_new_subscriber' && $merge_tag != '_wp_http_referer' ) { |
|
83 | 83 | // check if the current iteration has a 'date_format' key set |
84 | 84 | // (aka - date/birthday fields) |
85 | - if( isset( $form_settings['fields'][$merge_tag]['date_format'] ) ) { |
|
85 | + if ( isset( $form_settings[ 'fields' ][ $merge_tag ][ 'date_format' ] ) ) { |
|
86 | 86 | // check if EU date format |
87 | - if( $form_settings['fields'][$merge_tag]['date_format'] == 'DD/MM/YYYY' ) { |
|
87 | + if ( $form_settings[ 'fields' ][ $merge_tag ][ 'date_format' ] == 'DD/MM/YYYY' ) { |
|
88 | 88 | // convert '/' to '.' and to UNIX timestamp |
89 | 89 | $value = ( '' != $value ) ? date( 'Y-m-d', strtotime( str_replace( '/', '.', $value ) ) ) : ''; |
90 | 90 | } else { |
@@ -92,23 +92,23 @@ discard block |
||
92 | 92 | $value = ( '' != $value ) ? date( 'Y-m-d', strtotime( $value ) ) : ''; |
93 | 93 | } |
94 | 94 | } |
95 | - if( is_numeric( $merge_tag ) ) { // this is is an interest group! |
|
96 | - $merge_variables['groupings'][] = array( 'id' => $merge_tag , 'groups' => ( is_array( $value ) ) ? $value : array( $value ) ); |
|
95 | + if ( is_numeric( $merge_tag ) ) { // this is is an interest group! |
|
96 | + $merge_variables[ 'groupings' ][ ] = array( 'id' => $merge_tag, 'groups' => ( is_array( $value ) ) ? $value : array( $value ) ); |
|
97 | 97 | } else { // or else it's just a standard merge variable |
98 | - $merge_variables[$merge_tag] = $value; |
|
98 | + $merge_variables[ $merge_tag ] = $value; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | 103 | // store the opt-in time |
104 | - $merge_variables['optin_time'] = current_time( 'Y-m-d H:i:s', 1 ); |
|
104 | + $merge_variables[ 'optin_time' ] = current_time( 'Y-m-d H:i:s', 1 ); |
|
105 | 105 | |
106 | 106 | // Submit our form data |
107 | 107 | $api_key = yikes_get_mc_api_key(); |
108 | 108 | $dash_position = strpos( $api_key, '-' ); |
109 | 109 | |
110 | 110 | // setup the end point |
111 | - if( $dash_position !== false ) { |
|
111 | + if ( $dash_position !== false ) { |
|
112 | 112 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/subscribe.json'; |
113 | 113 | } |
114 | 114 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * Allow users to check for submit value |
137 | 137 | * and pass back an error to the user |
138 | 138 | */ |
139 | - if( isset( $merge_variables['error'] ) ) { |
|
140 | - $process_submission_response = apply_filters( 'yikes-mailchimp-frontend-content' , $merge_variables['message'] ); |
|
139 | + if ( isset( $merge_variables[ 'error' ] ) ) { |
|
140 | + $process_submission_response = apply_filters( 'yikes-mailchimp-frontend-content', $merge_variables[ 'message' ] ); |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | * Setup whether or not we should update the user, or display the error with email generation |
146 | 146 | * @since 6.1 |
147 | 147 | */ |
148 | - if ( isset( $form_settings['optin_settings']['update_existing_user'] ) && 1 === absint( $form_settings['optin_settings']['update_existing_user'] ) ) { |
|
148 | + if ( isset( $form_settings[ 'optin_settings' ][ 'update_existing_user' ] ) && 1 === absint( $form_settings[ 'optin_settings' ][ 'update_existing_user' ] ) ) { |
|
149 | 149 | $update_existing_user = 1; |
150 | 150 | // Should we send the update email |
151 | - if ( isset( $form_settings['optin_settings']['send_update_email'] ) && 1 === absint( $form_settings['optin_settings']['send_update_email'] ) ) { |
|
151 | + if ( isset( $form_settings[ 'optin_settings' ][ 'send_update_email' ] ) && 1 === absint( $form_settings[ 'optin_settings' ][ 'send_update_email' ] ) ) { |
|
152 | 152 | $update_existing_user = 0; |
153 | 153 | } |
154 | 154 | } else { |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | $subscribe_response = wp_remote_post( $api_endpoint, array( |
161 | 161 | 'body' => apply_filters( 'yikes-mailchimp-user-subscribe-api-request', array( |
162 | 162 | 'apikey' => $api_key, |
163 | - 'id' => $_POST['yikes-mailchimp-associated-list-id'], |
|
164 | - 'email' => array( 'email' => sanitize_email( $_POST['EMAIL'] ) ), |
|
163 | + 'id' => $_POST[ 'yikes-mailchimp-associated-list-id' ], |
|
164 | + 'email' => array( 'email' => sanitize_email( $_POST[ 'EMAIL' ] ) ), |
|
165 | 165 | 'merge_vars' => $merge_variables, |
166 | - 'double_optin' => $form_settings['optin_settings']['optin'], |
|
166 | + 'double_optin' => $form_settings[ 'optin_settings' ][ 'optin' ], |
|
167 | 167 | 'update_existing' => $update_existing_user, // Decide if we should update the user or not |
168 | - 'send_welcome' => $form_settings['optin_settings']['send_welcome_email'], |
|
169 | - 'replace_interests' => ( isset( $form_settings['submission_settings']['replace_interests'] ) ) ? $form_settings['submission_settings']['replace_interests'] : 1, // defaults to replace |
|
170 | - ), $form_id, $_POST['yikes-mailchimp-associated-list-id'], $_POST['EMAIL'] ), |
|
168 | + 'send_welcome' => $form_settings[ 'optin_settings' ][ 'send_welcome_email' ], |
|
169 | + 'replace_interests' => ( isset( $form_settings[ 'submission_settings' ][ 'replace_interests' ] ) ) ? $form_settings[ 'submission_settings' ][ 'replace_interests' ] : 1, // defaults to replace |
|
170 | + ), $form_id, $_POST[ 'yikes-mailchimp-associated-list-id' ], $_POST[ 'EMAIL' ] ), |
|
171 | 171 | 'timeout' => 10, |
172 | 172 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
173 | 173 | ) ); |
@@ -175,32 +175,32 @@ discard block |
||
175 | 175 | $subscribe_response = json_decode( wp_remote_retrieve_body( $subscribe_response ), true ); |
176 | 176 | |
177 | 177 | // check for any errors |
178 | - if( isset( $subscribe_response['error'] ) ) { |
|
178 | + if ( isset( $subscribe_response[ 'error' ] ) ) { |
|
179 | 179 | |
180 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
180 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
181 | 181 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
182 | 182 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
183 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscribe_response['error'], __( "Subscribe New User" , 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission.php" ); |
|
183 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscribe_response[ 'error' ], __( "Subscribe New User", 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission.php" ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $update_account_details_link = ''; |
187 | - switch( $subscribe_response['code'] ) { |
|
187 | + switch ( $subscribe_response[ 'code' ] ) { |
|
188 | 188 | // user already subscribed |
189 | 189 | case '214': |
190 | - $custom_already_subscribed_text = apply_filters( 'yikes-easy-mailchimp-update-existing-subscriber-text', sprintf( __( ' To update your MailChimp profile, please %s.', 'yikes-inc-easy-mailchimp-extender' ), '<a class="send-update-email" data-list-id="' . $_POST['yikes-mailchimp-associated-list-id'] . '" data-user-email="' . sanitize_email( $_POST['EMAIL'] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ), $form_id, '<a class="send-update-email" data-list-id="' . $_POST['yikes-mailchimp-associated-list-id'] . '" data-user-email="' . sanitize_email( $_POST['EMAIL'] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ); |
|
191 | - $update_account_details_link = ( 1 === absint( $form_settings['optin_settings']['update_existing_user'] ) && 1 === absint( $form_settings['optin_settings']['send_update_email'] ) ) ? $custom_already_subscribed_text : false; |
|
192 | - if( $update_account_details_link ) { |
|
190 | + $custom_already_subscribed_text = apply_filters( 'yikes-easy-mailchimp-update-existing-subscriber-text', sprintf( __( ' To update your MailChimp profile, please %s.', 'yikes-inc-easy-mailchimp-extender' ), '<a class="send-update-email" data-list-id="' . $_POST[ 'yikes-mailchimp-associated-list-id' ] . '" data-user-email="' . sanitize_email( $_POST[ 'EMAIL' ] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ), $form_id, '<a class="send-update-email" data-list-id="' . $_POST[ 'yikes-mailchimp-associated-list-id' ] . '" data-user-email="' . sanitize_email( $_POST[ 'EMAIL' ] ) . '" href="#">' . __( 'click to send yourself an update link', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' ); |
|
191 | + $update_account_details_link = ( 1 === absint( $form_settings[ 'optin_settings' ][ 'update_existing_user' ] ) && 1 === absint( $form_settings[ 'optin_settings' ][ 'send_update_email' ] ) ) ? $custom_already_subscribed_text : false; |
|
192 | + if ( $update_account_details_link ) { |
|
193 | 193 | // if update account details is set, we need to include our script to send out the update email |
194 | - wp_enqueue_script( 'update-existing-subscriber.js', YIKES_MC_URL . 'public/js/yikes-update-existing-subscriber.js' , array( 'jquery' ), 'all' ); |
|
194 | + wp_enqueue_script( 'update-existing-subscriber.js', YIKES_MC_URL . 'public/js/yikes-update-existing-subscriber.js', array( 'jquery' ), 'all' ); |
|
195 | 195 | wp_localize_script( 'update-existing-subscriber.js', 'update_subscriber_details_data', array( |
196 | 196 | 'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ), |
197 | 197 | 'preloader_url' => apply_filters( 'yikes-mailchimp-preloader', esc_url_raw( admin_url( 'images/wpspin_light.gif' ) ) ), |
198 | 198 | ) ); |
199 | 199 | } |
200 | - if( ! empty( $form_settings['error_messages']['already-subscribed'] ) ) { |
|
201 | - $process_submission_response = '<p class="yikes-easy-mc-error-message">' . apply_filters( 'yikes-easy-mailchimp-user-already-subscribed-text', $form_settings['error_messages']['already-subscribed'], $form_id, $_POST['EMAIL'] ) . ' ' . $update_account_details_link . '</p>'; |
|
200 | + if ( ! empty( $form_settings[ 'error_messages' ][ 'already-subscribed' ] ) ) { |
|
201 | + $process_submission_response = '<p class="yikes-easy-mc-error-message">' . apply_filters( 'yikes-easy-mailchimp-user-already-subscribed-text', $form_settings[ 'error_messages' ][ 'already-subscribed' ], $form_id, $_POST[ 'EMAIL' ] ) . ' ' . $update_account_details_link . '</p>'; |
|
202 | 202 | } else { |
203 | - $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $subscribe_response['error'] . ' ' . $update_account_details_link . '</p>'; |
|
203 | + $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $subscribe_response[ 'error' ] . ' ' . $update_account_details_link . '</p>'; |
|
204 | 204 | } |
205 | 205 | break; |
206 | 206 | // missing a required field |
@@ -208,34 +208,34 @@ discard block |
||
208 | 208 | // get all merge variables in array, loop and str_replace error code with field name |
209 | 209 | $api_key = yikes_get_mc_api_key(); |
210 | 210 | $dash_position = strpos( $api_key, '-' ); |
211 | - if( $dash_position !== false ) { |
|
211 | + if ( $dash_position !== false ) { |
|
212 | 212 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/merge-vars.json'; |
213 | 213 | } |
214 | 214 | $merge_variables = wp_remote_post( $api_endpoint, array( |
215 | 215 | 'body' => array( |
216 | 216 | 'apikey' => $api_key, |
217 | - 'id' => array( $_POST['yikes-mailchimp-associated-list-id'] ) , |
|
217 | + 'id' => array( $_POST[ 'yikes-mailchimp-associated-list-id' ] ), |
|
218 | 218 | ), |
219 | 219 | 'timeout' => 10, |
220 | 220 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ), |
221 | 221 | ) ); |
222 | 222 | $merge_variables = json_decode( wp_remote_retrieve_body( $merge_variables ), true ); |
223 | - if( isset( $merge_variables['error'] ) ) { |
|
224 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
223 | + if ( isset( $merge_variables[ 'error' ] ) ) { |
|
224 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
225 | 225 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
226 | 226 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
227 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $merge_variables['error'], __( "Get Merge Variables" , 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission.php" ); |
|
227 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $merge_variables[ 'error' ], __( "Get Merge Variables", 'yikes-inc-easy-mailchimp-extender' ), "process_form_submission.php" ); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | // re-store our data |
231 | - $merge_variables = $merge_variables['data'][0]['merge_vars']; |
|
231 | + $merge_variables = $merge_variables[ 'data' ][ 0 ][ 'merge_vars' ]; |
|
232 | 232 | $merge_variable_name_array = array(); |
233 | - foreach( $merge_variables as $merge_var ) { |
|
234 | - $merge_variables_name_array[$merge_var['tag']] = $merge_var['name']; |
|
233 | + foreach ( $merge_variables as $merge_var ) { |
|
234 | + $merge_variables_name_array[ $merge_var[ 'tag' ] ] = $merge_var[ 'name' ]; |
|
235 | 235 | } |
236 | - $error_message = $subscribe_response['error']; |
|
236 | + $error_message = $subscribe_response[ 'error' ]; |
|
237 | 237 | // replace tag with name in the error message. |
238 | - foreach( $merge_variables_name_array as $tag => $name ) { |
|
238 | + foreach ( $merge_variables_name_array as $tag => $name ) { |
|
239 | 239 | $error_message = str_replace( $tag, $name, $error_message ); |
240 | 240 | } |
241 | 241 | $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $error_message . '.</p>'; |
@@ -243,18 +243,18 @@ discard block |
||
243 | 243 | // [email protected] is not allowed |
244 | 244 | case '-99': |
245 | 245 | // generic error |
246 | - $process_submission_response = '<p class="yikes-easy-mc-error-message">' . str_replace( ' and cannot be imported', '', str_replace( 'List_RoleEmailMember:', '', $subscribe_response['error'] ) ) . '</p>'; |
|
246 | + $process_submission_response = '<p class="yikes-easy-mc-error-message">' . str_replace( ' and cannot be imported', '', str_replace( 'List_RoleEmailMember:', '', $subscribe_response[ 'error' ] ) ) . '</p>'; |
|
247 | 247 | break; |
248 | 248 | // invalid email (or no email at all) |
249 | 249 | case '-100': |
250 | - $process_submission_response = ( ! empty( $form_settings['error_messages']['invalid-email'] ) ) ? '<p class="yikes-easy-mc-error-message">' . $form_settings['error_messages']['invalid-email'] . '</p>' : '<p class="yikes-easy-mc-error-message">' . __( 'Please provide a valid email address.', 'yikes-inc-easy-mailchimp-extender' ) . '</p>'; |
|
250 | + $process_submission_response = ( ! empty( $form_settings[ 'error_messages' ][ 'invalid-email' ] ) ) ? '<p class="yikes-easy-mc-error-message">' . $form_settings[ 'error_messages' ][ 'invalid-email' ] . '</p>' : '<p class="yikes-easy-mc-error-message">' . __( 'Please provide a valid email address.', 'yikes-inc-easy-mailchimp-extender' ) . '</p>'; |
|
251 | 251 | break; |
252 | 252 | default: |
253 | 253 | // generic error |
254 | - if( ! empty( $form_settings['error_messages']['general-error'] ) ) { |
|
255 | - $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $form_settings['error_messages']['general-error'] . '</p>'; |
|
254 | + if ( ! empty( $form_settings[ 'error_messages' ][ 'general-error' ] ) ) { |
|
255 | + $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $form_settings[ 'error_messages' ][ 'general-error' ] . '</p>'; |
|
256 | 256 | } else { |
257 | - $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $subscribe_response['error'] . '</p>'; |
|
257 | + $process_submission_response = '<p class="yikes-easy-mc-error-message">' . $subscribe_response[ 'error' ] . '</p>'; |
|
258 | 258 | } |
259 | 259 | break; |
260 | 260 | } |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | $form_submitted = 1; |
266 | 266 | |
267 | 267 | // Display the success message |
268 | - if( ! empty( $form_settings['error_messages']['success'] ) ) { |
|
269 | - $process_submission_response = '<p class="yikes-easy-mc-success-message">' . apply_filters( 'yikes-mailchimp-success-response', stripslashes( esc_html( $form_settings['error_messages']['success'] ) ), $form_id, $merge_variables ) . '</p>'; |
|
268 | + if ( ! empty( $form_settings[ 'error_messages' ][ 'success' ] ) ) { |
|
269 | + $process_submission_response = '<p class="yikes-easy-mc-success-message">' . apply_filters( 'yikes-mailchimp-success-response', stripslashes( esc_html( $form_settings[ 'error_messages' ][ 'success' ] ) ), $form_id, $merge_variables ) . '</p>'; |
|
270 | 270 | // echo stripslashes( esc_html( $error_messages['success'] ) ); |
271 | 271 | } else { |
272 | - $default_success_response = ( 1 === $form_settings['optin_settings']['optin'] ) ? __( 'Thank you for subscribing! Check your email for the confirmation message.' , 'yikes-inc-easy-mailchimp-extender' ) : __( 'Thank you for subscribing!' , 'yikes-inc-easy-mailchimp-extender' ); |
|
272 | + $default_success_response = ( 1 === $form_settings[ 'optin_settings' ][ 'optin' ] ) ? __( 'Thank you for subscribing! Check your email for the confirmation message.', 'yikes-inc-easy-mailchimp-extender' ) : __( 'Thank you for subscribing!', 'yikes-inc-easy-mailchimp-extender' ); |
|
273 | 273 | $process_submission_response = '<p class="yikes-easy-mc-success-message">' . apply_filters( 'yikes-mailchimp-success-response', $default_success_response, $form_id, $merge_variables ) . '</p>'; |
274 | 274 | // echo $default_success_response; |
275 | 275 | } |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * optional @form - the ID of the form to filter |
283 | 283 | * @since 6.0.0 |
284 | 284 | */ |
285 | - do_action( 'yikes-mailchimp-after-submission' , $merge_variables ); |
|
286 | - do_action( 'yikes-mailchimp-after-submission-' . $form_id , $merge_variables ); |
|
285 | + do_action( 'yikes-mailchimp-after-submission', $merge_variables ); |
|
286 | + do_action( 'yikes-mailchimp-after-submission-' . $form_id, $merge_variables ); |
|
287 | 287 | |
288 | 288 | /* |
289 | 289 | * Non-AJAX redirects now handled in class-yikes-inc-easy-mailchimp-extender-public.php |
@@ -301,23 +301,23 @@ discard block |
||
301 | 301 | * @$notifications - the notification array |
302 | 302 | * @since 6.0.0 |
303 | 303 | */ |
304 | - do_action( 'yikes-mailchimp-form-submission' , $_POST['EMAIL'] , $merge_variables , $form_id , $form_settings['notifications'] ); |
|
305 | - do_action( 'yikes-mailchimp-form-submission-' . $form_id , $_POST['EMAIL'] , $merge_variables , $form_id , $form_settings['notifications'] ); |
|
304 | + do_action( 'yikes-mailchimp-form-submission', $_POST[ 'EMAIL' ], $merge_variables, $form_id, $form_settings[ 'notifications' ] ); |
|
305 | + do_action( 'yikes-mailchimp-form-submission-' . $form_id, $_POST[ 'EMAIL' ], $merge_variables, $form_id, $form_settings[ 'notifications' ] ); |
|
306 | 306 | |
307 | 307 | /* |
308 | 308 | * Increase the submission count for this form |
309 | 309 | * on a successful submission |
310 | 310 | * @since 6.0.0 |
311 | 311 | */ |
312 | - $form_settings['submissions']++; |
|
312 | + $form_settings[ 'submissions' ]++; |
|
313 | 313 | $wpdb->update( |
314 | 314 | $wpdb->prefix . 'yikes_easy_mc_forms', |
315 | 315 | array( |
316 | - 'submissions' => $form_settings['submissions'], |
|
316 | + 'submissions' => $form_settings[ 'submissions' ], |
|
317 | 317 | ), |
318 | 318 | array( 'ID' => $form_id ), |
319 | 319 | array( |
320 | - '%d', // send welcome email |
|
320 | + '%d', // send welcome email |
|
321 | 321 | ), |
322 | 322 | array( '%d' ) |
323 | 323 | ); |
@@ -12,42 +12,42 @@ discard block |
||
12 | 12 | array( |
13 | 13 | 'form' => '', // pass in a form, which will retreive the associated list ID -- takes precendence |
14 | 14 | 'list' => '', // pass in a specific list ID |
15 | - ), $attributes , 'yikes-mailchimp-subscriber-count' ) |
|
15 | + ), $attributes, 'yikes-mailchimp-subscriber-count' ) |
|
16 | 16 | ); |
17 | 17 | |
18 | 18 | /* If the user hasn't authenticated yet - bail */ |
19 | - if( get_option( 'yikes-mc-api-validation' , 'invalid_api_key' ) != 'valid_api_key' ) { |
|
20 | - if( WP_DEBUG ) { |
|
19 | + if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) != 'valid_api_key' ) { |
|
20 | + if ( WP_DEBUG ) { |
|
21 | 21 | return '<strong>' . __( "You don't appear to be connected to MailChimp.", "yikes-inc-easy-mailchimp-extender" ) . '</strong>'; |
22 | 22 | } |
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | - $form = ( ! empty( $attributes['form'] ) ) ? str_replace( '"', '', $attributes['form'] ) : false; // replace the sanitize quotes to perform a proper query |
|
27 | - $list_id = ( ! empty( $attributes['list'] ) ) ? $attributes['list'] : false; |
|
26 | + $form = ( ! empty( $attributes[ 'form' ] ) ) ? str_replace( '"', '', $attributes[ 'form' ] ) : false; // replace the sanitize quotes to perform a proper query |
|
27 | + $list_id = ( ! empty( $attributes[ 'list' ] ) ) ? $attributes[ 'list' ] : false; |
|
28 | 28 | |
29 | 29 | /* If no list ID was passed into the shortcode - bail */ |
30 | - if( ! $list_id && ! $form) { |
|
31 | - if( WP_DEBUG ) { |
|
30 | + if ( ! $list_id && ! $form ) { |
|
31 | + if ( WP_DEBUG ) { |
|
32 | 32 | return '<strong>' . __( 'You forgot to include the list or form ID.', 'yikes-inc-easy-mailchimp-extender' ) . '</strong>'; |
33 | 33 | } |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | 37 | /* if a form ID and a list ID were passed in, use the form ID */ |
38 | - if( ( $form ) || ( $form && $list_id ) ) { |
|
38 | + if ( ( $form ) || ( $form && $list_id ) ) { |
|
39 | 39 | global $wpdb; |
40 | 40 | // return it as an array, so we can work with it to build our form below |
41 | 41 | $form_results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'yikes_easy_mc_forms WHERE id = ' . $form . '', ARRAY_A ); |
42 | 42 | // confirm we have some results, or return an error |
43 | - if( ! $form_results ) { |
|
44 | - if( WP_DEBUG ) { |
|
45 | - return __( "Oh no...This form doesn't exist. Head back to the manage forms page and select a different form." , 'yikes-inc-easy-mailchimp-extender' ); |
|
43 | + if ( ! $form_results ) { |
|
44 | + if ( WP_DEBUG ) { |
|
45 | + return __( "Oh no...This form doesn't exist. Head back to the manage forms page and select a different form.", 'yikes-inc-easy-mailchimp-extender' ); |
|
46 | 46 | } |
47 | 47 | return; |
48 | 48 | } |
49 | - $form_data = $form_results[0]; |
|
50 | - $list_id = sanitize_key( $form_data['list_id'] ); // associated list id (users who fill out the form will be subscribed to this list) |
|
49 | + $form_data = $form_results[ 0 ]; |
|
50 | + $list_id = sanitize_key( $form_data[ 'list_id' ] ); // associated list id (users who fill out the form will be subscribed to this list) |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // object buffer |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | // get the api key |
60 | 60 | $api_key = yikes_get_mc_api_key(); |
61 | 61 | $dash_position = strpos( $api_key, '-' ); |
62 | - if( $dash_position !== false ) { |
|
62 | + if ( $dash_position !== false ) { |
|
63 | 63 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/list.json'; |
64 | 64 | } |
65 | 65 | |
@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | ) ); |
77 | 77 | |
78 | 78 | $subscriber_count_response = json_decode( wp_remote_retrieve_body( $subscriber_count_response ), true ); |
79 | - if( isset( $subscriber_count_response['error'] ) ) { |
|
80 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
79 | + if ( isset( $subscriber_count_response[ 'error' ] ) ) { |
|
80 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
81 | 81 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
82 | 82 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
83 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscriber_count_response['error'], __( "Get Account Lists" , 'yikes-inc-easy-mailchimp-extender' ), "yikes-mailchimp-subscriber-count.php" ); |
|
83 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscriber_count_response[ 'error' ], __( "Get Account Lists", 'yikes-inc-easy-mailchimp-extender' ), "yikes-mailchimp-subscriber-count.php" ); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | // if more than one list is returned, something went wrong - bail |
87 | - if( $subscriber_count_response['total'] != 1 ) { |
|
88 | - if( WP_DEBUG ) { |
|
87 | + if ( $subscriber_count_response[ 'total' ] != 1 ) { |
|
88 | + if ( WP_DEBUG ) { |
|
89 | 89 | return '<strong>' . sprintf( __( "It looks like this list wasn't found. Double check the list with with ID '%s' exists.", "yikes-inc-easy-mailchimp-extender" ), $list_id ) . '</strong>'; |
90 | 90 | } |
91 | 91 | return; |
92 | 92 | } |
93 | 93 | |
94 | 94 | /* type cast the returned value as an integer */ |
95 | - echo (int) apply_filters( 'yikes-mailchimp-subscriber-count-value', $subscriber_count_response['data'][0]['stats']['member_count'] ); |
|
95 | + echo (int) apply_filters( 'yikes-mailchimp-subscriber-count-value', $subscriber_count_response[ 'data' ][ 0 ][ 'stats' ][ 'member_count' ] ); |
|
96 | 96 | |
97 | 97 | } catch ( Exception $error ) { |
98 | 98 | echo $error->getMessage(); |
@@ -11,16 +11,16 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function __construct() { |
13 | 13 | // ajax process form submission |
14 | - add_action( 'wp_ajax_nopriv_process_form_submission', array( $this , 'process_form_submission' ), 10 ); |
|
15 | - add_action( 'wp_ajax_process_form_submission', array( $this , 'process_form_submission' ), 10 ); |
|
14 | + add_action( 'wp_ajax_nopriv_process_form_submission', array( $this, 'process_form_submission' ), 10 ); |
|
15 | + add_action( 'wp_ajax_process_form_submission', array( $this, 'process_form_submission' ), 10 ); |
|
16 | 16 | |
17 | 17 | // ajax send update emails |
18 | - add_action( 'wp_ajax_nopriv_easy_forms_send_email', array( $this , 'sendUpdateProfileEmail' ), 10 ); |
|
19 | - add_action( 'wp_ajax_easy_forms_send_email', array( $this , 'sendUpdateProfileEmail' ), 10 ); |
|
18 | + add_action( 'wp_ajax_nopriv_easy_forms_send_email', array( $this, 'sendUpdateProfileEmail' ), 10 ); |
|
19 | + add_action( 'wp_ajax_easy_forms_send_email', array( $this, 'sendUpdateProfileEmail' ), 10 ); |
|
20 | 20 | |
21 | 21 | // increase submission count for a given form on successful submit |
22 | - add_action( 'wp_ajax_nopriv_increase_submission_count' , array( $this , 'increase_submission_count' ), 10 ); |
|
23 | - add_action( 'wp_ajax_increase_submission_count' , array( $this , 'increase_submission_count' ), 10 ); |
|
22 | + add_action( 'wp_ajax_nopriv_increase_submission_count', array( $this, 'increase_submission_count' ), 10 ); |
|
23 | + add_action( 'wp_ajax_increase_submission_count', array( $this, 'increase_submission_count' ), 10 ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /* |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function increase_submission_count() { |
42 | 42 | // store our posted form ID |
43 | - $form_id = $_POST['form_id']; |
|
43 | + $form_id = $_POST[ 'form_id' ]; |
|
44 | 44 | global $wpdb; |
45 | 45 | // query the form |
46 | 46 | $form_results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'yikes_easy_mc_forms WHERE id = ' . $form_id . '', ARRAY_A ); |
47 | - $form_data = $form_results[0]; |
|
47 | + $form_data = $form_results[ 0 ]; |
|
48 | 48 | // increase the submission |
49 | - $form_data['submissions']++; |
|
49 | + $form_data[ 'submissions' ]++; |
|
50 | 50 | // update the value in the database |
51 | 51 | $wpdb->update( |
52 | 52 | $wpdb->prefix . 'yikes_easy_mc_forms', |
53 | 53 | array( |
54 | - 'submissions' => $form_data['submissions'], |
|
54 | + 'submissions' => $form_data[ 'submissions' ], |
|
55 | 55 | ), |
56 | 56 | array( 'ID' => $form_id ), |
57 | 57 | array( |
@@ -68,17 +68,17 @@ discard block |
||
68 | 68 | @since v6.0.4.1 |
69 | 69 | */ |
70 | 70 | public function sendUpdateProfileEmail() { |
71 | - $user_email = $_POST['user_email']; |
|
72 | - $list_id = $_POST['list_id']; |
|
71 | + $user_email = $_POST[ 'user_email' ]; |
|
72 | + $list_id = $_POST[ 'list_id' ]; |
|
73 | 73 | |
74 | 74 | $api_key = yikes_get_mc_api_key(); |
75 | 75 | $dash_position = strpos( $api_key, '-' ); |
76 | - $explode_key = explode( '-' , $api_key ); |
|
77 | - $data_center = $explode_key[1]; |
|
78 | - $full_site_url = get_bloginfo('url'); |
|
76 | + $explode_key = explode( '-', $api_key ); |
|
77 | + $data_center = $explode_key[ 1 ]; |
|
78 | + $full_site_url = get_bloginfo( 'url' ); |
|
79 | 79 | |
80 | 80 | // list details api call |
81 | - if( $dash_position !== false ) { |
|
81 | + if ( $dash_position !== false ) { |
|
82 | 82 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/list.json'; |
83 | 83 | } |
84 | 84 | $list_details = wp_remote_post( $api_endpoint, array( |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
93 | 93 | ) ); |
94 | 94 | $list_details = json_decode( wp_remote_retrieve_body( $list_details ), true ); |
95 | - if( isset( $list_details['error'] ) ) { |
|
96 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
95 | + if ( isset( $list_details[ 'error' ] ) ) { |
|
96 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
97 | 97 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
98 | 98 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
99 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $list_details['error'], __( "Send Update Profile Email - Get Account Lists" , 'yikes-inc-easy-mailchimp-extender' ), "class.public_ajax.php" ); |
|
99 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $list_details[ 'error' ], __( "Send Update Profile Email - Get Account Lists", 'yikes-inc-easy-mailchimp-extender' ), "class.public_ajax.php" ); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | 103 | // account details api call |
104 | - if( $dash_position !== false ) { |
|
104 | + if ( $dash_position !== false ) { |
|
105 | 105 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/helper/account-details.json'; |
106 | 106 | } |
107 | 107 | $account_details = wp_remote_post( $api_endpoint, array( |
@@ -112,16 +112,16 @@ discard block |
||
112 | 112 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
113 | 113 | ) ); |
114 | 114 | $account_details = json_decode( wp_remote_retrieve_body( $account_details ), true ); |
115 | - if( isset( $account_details['error'] ) ) { |
|
116 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
115 | + if ( isset( $account_details[ 'error' ] ) ) { |
|
116 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
117 | 117 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
118 | 118 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
119 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $account_details['error'], __( "Send Update Profile Email - Get Account Details" , 'yikes-inc-easy-mailchimp-extender' ), "class.public_ajax.php" ); |
|
119 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $account_details[ 'error' ], __( "Send Update Profile Email - Get Account Details", 'yikes-inc-easy-mailchimp-extender' ), "class.public_ajax.php" ); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | 123 | // subscriber details api call |
124 | - if( $dash_position !== false ) { |
|
124 | + if ( $dash_position !== false ) { |
|
125 | 125 | $api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/member-info.json'; |
126 | 126 | } |
127 | 127 | $subscriber_account_details = wp_remote_post( $api_endpoint, array( |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | 'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
137 | 137 | ) ); |
138 | 138 | $subscriber_account_details = json_decode( wp_remote_retrieve_body( $subscriber_account_details ), true ); |
139 | - if( isset( $subscriber_account_details['error'] ) ) { |
|
140 | - if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
|
139 | + if ( isset( $subscriber_account_details[ 'error' ] ) ) { |
|
140 | + if ( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) { |
|
141 | 141 | require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
142 | 142 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
143 | - $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscriber_account_details['error'], __( "Send Update Profile Email - Get Member Info." , 'yikes-inc-easy-mailchimp-extender' ), "class.public_ajax.php" ); |
|
143 | + $error_logging->yikes_easy_mailchimp_write_to_error_log( $subscriber_account_details[ 'error' ], __( "Send Update Profile Email - Get Member Info.", 'yikes-inc-easy-mailchimp-extender' ), "class.public_ajax.php" ); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | // check for errors in any of the calls |
148 | - if( isset( $list_details['error'] ) || isset( $account_details['error'] ) || isset( $subscriber_account_details['error'] ) ) { |
|
149 | - $error_message = ( isset( $list_details['error'] ) ) ? $list_details['error'] : false; |
|
150 | - if( ! $error_message ) { |
|
151 | - $error_message = ( isset( $account_details['error'] ) ) ? $account_details['error'] : false; |
|
152 | - if( ! $error_message ) { |
|
153 | - $error_message = ( isset( $subscriber_account_details['error'] ) ) ? $subscriber_account_details['error'] : false; |
|
154 | - if( ! $error_message ) { |
|
148 | + if ( isset( $list_details[ 'error' ] ) || isset( $account_details[ 'error' ] ) || isset( $subscriber_account_details[ 'error' ] ) ) { |
|
149 | + $error_message = ( isset( $list_details[ 'error' ] ) ) ? $list_details[ 'error' ] : false; |
|
150 | + if ( ! $error_message ) { |
|
151 | + $error_message = ( isset( $account_details[ 'error' ] ) ) ? $account_details[ 'error' ] : false; |
|
152 | + if ( ! $error_message ) { |
|
153 | + $error_message = ( isset( $subscriber_account_details[ 'error' ] ) ) ? $subscriber_account_details[ 'error' ] : false; |
|
154 | + if ( ! $error_message ) { |
|
155 | 155 | $error_message = ''; |
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
159 | - $errorMessage = sprintf( __( 'Error sending update profile email. <strong>Error: %s</strong>. Please contact the site administrator.' , 'yikes-inc-easy-mailchimp-extender' ), $error_message ); |
|
159 | + $errorMessage = sprintf( __( 'Error sending update profile email. <strong>Error: %s</strong>. Please contact the site administrator.', 'yikes-inc-easy-mailchimp-extender' ), $error_message ); |
|
160 | 160 | wp_send_json_error( |
161 | 161 | array( |
162 | 162 | 'response_text' => '<div class="yikes-easy-mc-error-message">✕ ' . $errorMessage . '</div>', |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | } |
167 | 167 | |
168 | 168 | // send the email! |
169 | - $subscriber_id = $subscriber_account_details['data'][0]['id']; |
|
170 | - $explode_url = explode( '.' , $account_details['contact']['url'] ); |
|
171 | - $update_link_href = 'http://' . $explode_url[1] . '.' . $data_center . '.list-manage1.com/profile?u=' . $account_details['user_id'] . '&id=' . $list_id .'&e=' . $subscriber_id; |
|
169 | + $subscriber_id = $subscriber_account_details[ 'data' ][ 0 ][ 'id' ]; |
|
170 | + $explode_url = explode( '.', $account_details[ 'contact' ][ 'url' ] ); |
|
171 | + $update_link_href = 'http://' . $explode_url[ 1 ] . '.' . $data_center . '.list-manage1.com/profile?u=' . $account_details[ 'user_id' ] . '&id=' . $list_id . '&e=' . $subscriber_id; |
|
172 | 172 | $subject = 'MailChimp Profile Update'; |
173 | - $headers = 'From: ' . $list_details['data'][0]['default_from_name'] . ' <' . $list_details['data'][0]['default_from_email'] . '>' . "\r\n"; |
|
173 | + $headers = 'From: ' . $list_details[ 'data' ][ 0 ][ 'default_from_name' ] . ' <' . $list_details[ 'data' ][ 0 ][ 'default_from_email' ] . '>' . "\r\n"; |
|
174 | 174 | $headers .= 'Content-type: text/html'; |
175 | 175 | $email_content = '<p>Greetings,</p> <p>A request has been made to update your MailChimp account profile information. To do so please use the following link: <a href="' . $update_link_href . '" title="Update MailChimp Profile">Update MailChimp Profile Info.</a>'; |
176 | 176 | $email_content .= "<p>If you did not request this update, please disregard this email.</p>"; |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | if ( wp_mail( $user_email, apply_filters( 'yikes-mailchimp-update-email-subject', $subject ), apply_filters( 'yikes-mailchimp-update-email-content', $email_content, $update_link_href ), $headers ) ) { |
184 | 184 | wp_send_json_success( |
185 | 185 | array( |
186 | - 'response_text' => '<div class="yikes-easy-mc-success-message">' . sprintf( __( '%s Update email successfully sent. Please check your inbox for the message.' , 'yikes-inc-easy-mailchimp-extender' ), '✔' ) . '</div>', |
|
186 | + 'response_text' => '<div class="yikes-easy-mc-success-message">' . sprintf( __( '%s Update email successfully sent. Please check your inbox for the message.', 'yikes-inc-easy-mailchimp-extender' ), '✔' ) . '</div>', |
|
187 | 187 | ) |
188 | 188 | ); |
189 | 189 | exit; |
190 | 190 | } else { |
191 | 191 | wp_send_json_error( |
192 | 192 | array( |
193 | - 'response_text' => '<div class="yikes-easy-mc-error-message">' . sprintf( __( '%s Email failed to send. Please contact the site administrator.' , 'yikes-inc-easy-mailchimp-extender' ), '✕' ) . '</div>', |
|
193 | + 'response_text' => '<div class="yikes-easy-mc-error-message">' . sprintf( __( '%s Email failed to send. Please contact the site administrator.', 'yikes-inc-easy-mailchimp-extender' ), '✕' ) . '</div>', |
|
194 | 194 | ) |
195 | 195 | ); |
196 | 196 | exit; |