PluginProbe
Mailchimp List Subscribe Form / trunk
Mailchimp List Subscribe Form vtrunk
1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 All 55 releases
mailchimp / includes / class-mailchimp-admin.php

class-mailchimp-admin.php in Mailchimp List Subscribe Form trunk, at includes/class-mailchimp-admin.php

943 lines 39.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class responsible for admin side functionalities.
4 *
5 * The long term plan is to break up admin functionality into smaller, more focused
6 * files to improve maintainability. This could also include:
7 * - Moving OAuth related code to oauth.php
8 * - Moving account creation code to account.php
9 * - Moving settings page code to settings.php
10 * - Moving notices code to notices.php (already done)
11 * This will help avoid having too much code in a single file and make the codebase more modular.
12 *
13 * @package Mailchimp
14 */
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Class Mailchimp_Admin
23 *
24 * @since 1.6.0
25 */
26 class Mailchimp_Admin {
27
28 /**
29 * The OAuth base endpoint
30 *
31 * @since 1.6.0
32 * @var string
33 */
34 private $oauth_url = 'https://wordpress.mailchimpapp.com';
35
36 /**
37 * Initialize the class
38 */
39 public function init() {
40 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
41 add_action( 'wp_ajax_mailchimp_sf_oauth_start', array( $this, 'start_oauth_process' ) );
42 add_action( 'wp_ajax_mailchimp_sf_oauth_finish', array( $this, 'finish_oauth_process' ) );
43 add_action( 'wp_ajax_mailchimp_sf_create_account', array( $this, 'mailchimp_create_account' ) );
44 add_action( 'wp_ajax_mailchimp_sf_check_login_session', array( $this, 'check_login_session' ) );
45 add_action( 'wp_ajax_mailchimp_sf_preview_form', array( $this, 'preview_subscribe_form' ) );
46
47 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_page_scripts' ) );
48 add_action( 'admin_menu', array( $this, 'add_admin_menu_pages' ) );
49 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
50
51 Mailchimp_Admin_Notices::instance()->init();
52
53 $user_sync = new Mailchimp_User_Sync();
54 $user_sync->init();
55 }
56
57 /**
58 * Start the OAuth process.
59 *
60 * This function is called via AJAX.
61 *
62 * It starts the OAuth process by the calling the OAuth middleware
63 * server and sending the response to the front-end.
64 */
65 public function start_oauth_process() {
66 // Validate the nonce and permissions.
67 if (
68 ! current_user_can( 'manage_options' ) ||
69 ! isset( $_POST['nonce'] ) ||
70 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'mailchimp_sf_oauth_start_nonce' )
71 ) {
72 wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to perform this action.', 'mailchimp' ) ) );
73 }
74
75 // Generate a secret and send it to the OAuth server.
76 $secret = uniqid( 'mailchimp_sf_' );
77 $args = array(
78 'domain' => site_url(),
79 'secret' => $secret,
80 );
81
82 $options = array(
83 'headers' => array(
84 'Content-type' => 'application/json',
85 ),
86 'body' => wp_json_encode( $args ),
87 );
88
89 $response = wp_remote_post( $this->oauth_url . '/api/start', $options );
90
91 // Check for errors.
92 if ( $response instanceof WP_Error ) {
93 wp_send_json_error( array( 'message' => $response->get_error_message() ) );
94 }
95
96 // Send the response to the front-end.
97 if ( 201 === $response['response']['code'] && ! empty( $response['body'] ) ) {
98 set_site_transient( 'mailchimp_sf_oauth_secret', $secret, 60 * 60 );
99 $result = json_decode( $response['body'], true );
100 wp_send_json_success( $result );
101 } else {
102 if ( ! empty( $response['response'] ) ) {
103 $response = $response['response'];
104 }
105 wp_send_json_error( $response );
106 }
107 }
108
109 /**
110 * Finish the OAuth process.
111 *
112 * This function is called via AJAX.
113 *
114 * This function finishes the OAuth process by the sending
115 * a temporary token back to the OAuth server.
116 */
117 public function finish_oauth_process() {
118 // Validate the nonce and permissions.
119 if (
120 ! current_user_can( 'manage_options' ) ||
121 ! isset( $_POST['nonce'] ) ||
122 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'mailchimp_sf_oauth_finish_nonce' )
123 ) {
124 wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to perform this action.', 'mailchimp' ) ) );
125 }
126
127 $token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
128 $args = array(
129 'domain' => site_url(),
130 'secret' => get_site_transient( 'mailchimp_sf_oauth_secret' ),
131 'token' => $token,
132 );
133
134 $options = array(
135 'headers' => array(
136 'Content-type' => 'application/json',
137 ),
138 'body' => wp_json_encode( $args ),
139 );
140 $response = wp_remote_post( $this->oauth_url . '/api/finish', $options );
141
142 // Check for errors.
143 if ( $response instanceof WP_Error ) {
144 wp_send_json_error( array( 'message' => $response->get_error_message() ) );
145 }
146
147 if ( 200 === $response['response']['code'] ) {
148 // Save the access token and data center.
149 $result = json_decode( $response['body'], true );
150 if ( $result && ! empty( $result['access_token'] ) && ! empty( $result['data_center'] ) ) {
151 delete_site_transient( 'mailchimp_sf_oauth_secret' );
152
153 // Verify the token.
154 $verify = $this->verify_and_save_oauth_token( $result['access_token'], $result['data_center'] );
155
156 if ( is_wp_error( $verify ) ) {
157 // If there is an error, send it back to the front-end.
158 wp_send_json_error( array( 'message' => $verify->get_error_message() ) );
159 }
160
161 wp_send_json_success( true );
162 } else {
163 wp_send_json_error( array( 'message' => esc_html__( 'Invalid response from the server.', 'mailchimp' ) ) );
164 }
165 } else {
166 wp_send_json_error( $response );
167 }
168 }
169
170 /**
171 * Create a new Mailchimp account.
172 *
173 * This function is called via AJAX.
174 *
175 * This function creates a new Mailchimp account by sending the user data to the middleware server.
176 */
177 public function mailchimp_create_account() {
178 // Validate the nonce and permissions.
179 if (
180 ! current_user_can( 'manage_options' ) ||
181 ! isset( $_POST['nonce'] ) ||
182 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'mailchimp_sf_create_account_nonce' )
183 ) {
184 wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to perform this action.', 'mailchimp' ) ) );
185 }
186
187 $data = isset( $_POST['data'] ) ? $this->sanitize_data( wp_unslash( $_POST['data'] ) ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Data is sanitized in the sanitize_data method.
188 if ( empty( $data ) ) {
189 wp_send_json_error( array( 'message' => esc_html__( 'No data provided.', 'mailchimp' ) ) );
190 }
191
192 // Get the IP address.
193 if ( isset( $_SERVER['REMOTE_ADDR'] ) && ( '::1' === $_SERVER['REMOTE_ADDR'] || '127.0.0.1' === $_SERVER['REMOTE_ADDR'] ) ) {
194 $data['ip_address'] = '127.0.0.1';
195 } elseif ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
196 $data['ip_address'] = sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) );
197 } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
198 $data['ip_address'] = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
199 } else {
200 $data['ip_address'] = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
201 }
202
203 $request_data = array(
204 'headers' => array(
205 'Content-type' => 'application/json',
206 'Accept' => 'application/json',
207 ),
208 'body' => wp_json_encode( $data ),
209 'timeout' => 30,
210 );
211
212 $response = wp_remote_post( $this->oauth_url . '/api/signup/', $request_data );
213 // Return the error if there is one.
214 if ( $response instanceof WP_Error ) {
215 wp_send_json_error( array( 'message' => $response->get_error_message() ) );
216 }
217
218 $response_body = json_decode( $response['body'] );
219 if ( 200 === $response['response']['code'] && true === $response_body->success ) {
220 $result = json_decode( $response['body'], true );
221
222 // Verify and save the token.
223 $verify = $this->verify_and_save_oauth_token( $result['data']['oauth_token'], $result['data']['dc'] );
224
225 if ( is_wp_error( $verify ) ) {
226 // If there is an error, send it back to the front-end.
227 wp_send_json_error( array( 'message' => $verify->get_error_message() ) );
228 }
229 update_option( 'mailchimp_sf_waiting_for_login', 'waiting' );
230 wp_send_json_success( true );
231
232 } elseif ( 404 === $response['response']['code'] ) {
233 wp_send_json_error( array( 'success' => false ) );
234
235 } else {
236 $username = isset( $_POST['data']['username'] ) ? sanitize_email( wp_unslash( $_POST['data']['username'] ) ) : '';
237 $username = preg_replace( '/[^A-Za-z0-9\-\@\.]/', '', $username );
238 $suggestion = wp_remote_get( $this->oauth_url . '/api/usernames/suggestions/' . $username );
239 $suggested_username = json_decode( $suggestion['body'] )->data;
240 wp_send_json_error(
241 array(
242 'success' => false,
243 'suggest_login' => true,
244 'suggested_username' => $suggested_username,
245 )
246 );
247 }
248 }
249
250 /**
251 * Check the login session.
252 *
253 * This function is called via AJAX.
254 *
255 * This function checks if the user is logged in to Mailchimp which confirms the account activation.
256 */
257 public function check_login_session() {
258 // Validate the nonce and permissions.
259 if (
260 ! current_user_can( 'manage_options' ) ||
261 ! isset( $_POST['nonce'] ) ||
262 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'mailchimp_sf_check_login_session_nonce' )
263 ) {
264 wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to perform this action.', 'mailchimp' ) ) );
265 }
266
267 $api = mailchimp_sf_get_api();
268 if ( $api ) {
269 $profile = $api->get( '' );
270 if ( is_wp_error( $profile ) ) {
271 wp_send_json_error( array( 'message' => $profile->get_error_message() ) );
272 }
273
274 $logged_in = ( ! empty( $profile['last_login'] ) );
275 if ( $logged_in ) {
276 delete_option( 'mailchimp_sf_waiting_for_login' );
277 }
278 wp_send_json_success(
279 array(
280 'success' => true,
281 'logged_in' => $logged_in,
282 'redirect' => admin_url( 'admin.php?page=mailchimp_sf_options' ),
283 )
284 );
285 } else {
286 wp_send_json_error( array( 'success' => false ) );
287 }
288 }
289
290 /**
291 * Preview the subscribe form.
292 *
293 * This function is called via AJAX.
294 *
295 * This function previews the subscribe form on the settings page based on the form settings.
296 */
297 public function preview_subscribe_form() {
298 // Check the nonce for security
299 check_ajax_referer( 'mailchimp_sf_preview_form_nonce', 'nonce' );
300
301 // Validate the permissions.
302 if ( ! current_user_can( 'manage_options' ) ) {
303 wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to perform this action.', 'mailchimp' ) ) );
304 }
305
306 $fields = isset( $_POST['preview_data']['fields'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['preview_data']['fields'] ) ) : array();
307 $fields = array_map(
308 function ( $ele ) {
309 return 'true' === $ele;
310 },
311 $fields
312 );
313 $groups = isset( $_POST['preview_data']['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['preview_data']['groups'] ) ) : array();
314 $groups = array_map(
315 function ( $ele ) {
316 return 'true' === $ele;
317 },
318 $groups
319 );
320
321 $preview_data = array(
322 'header' => isset( $_POST['preview_data']['header'] ) ? sanitize_text_field( wp_unslash( $_POST['preview_data']['header'] ) ) : get_option( 'mc_header_content' ),
323 'sub_heading' => isset( $_POST['preview_data']['sub_heading'] ) ? sanitize_text_field( wp_unslash( $_POST['preview_data']['sub_heading'] ) ) : get_option( 'mc_subheader_content' ),
324 'submit_text' => isset( $_POST['preview_data']['submit_text'] ) ? sanitize_text_field( wp_unslash( $_POST['preview_data']['submit_text'] ) ) : get_option( 'mc_submit_text' ),
325 'fields' => $fields,
326 'groups' => $groups,
327 'display_unsub_link' => isset( $_POST['preview_data']['display_unsub_link'] ) ? 'true' === sanitize_text_field( wp_unslash( $_POST['preview_data']['display_unsub_link'] ) ) : get_option( 'mc_use_unsub_link' ),
328 );
329
330 ob_start();
331 mailchimp_sf_signup_form(
332 array(
333 'is_preview' => true,
334 'preview_data' => $preview_data,
335 )
336 );
337 $form = ob_get_clean();
338 wp_send_json_success( $form );
339 }
340
341 /**
342 * Verify and save the OAuth token.
343 *
344 * @param string $access_token The token to verify.
345 * @param string $data_center The data center to verify.
346 * @return mixed
347 */
348 public function verify_and_save_oauth_token( $access_token, $data_center ) {
349 try {
350 $api = new MailChimp_API( $access_token, $data_center );
351 } catch ( Exception $e ) {
352 $msg = $e->getMessage();
353 return new WP_Error( 'mailchimp-sf-invalid-token', $msg );
354 }
355
356 $user = $api->get( '' );
357 if ( is_wp_error( $user ) ) {
358 return $user;
359 }
360
361 // Might as well set this data if we have it already.
362 $valid_roles = array( 'owner', 'admin', 'manager' );
363 if ( isset( $user['role'] ) && in_array( $user['role'], $valid_roles, true ) ) {
364 $data_encryption = new Mailchimp_Data_Encryption();
365
366 // Clean up the old data.
367 delete_option( 'mc_api_key' ); // Deprecated API key, need to remove as part of the migration.
368 delete_option( 'mailchimp_sf_access_token' );
369 delete_option( 'mailchimp_sf_auth_error' );
370 delete_option( 'mc_datacenter' );
371
372 update_option( 'mailchimp_sf_access_token', $data_encryption->encrypt( $access_token ) );
373 update_option( 'mc_datacenter', sanitize_text_field( $data_center ) );
374 update_option( 'mc_user', $this->sanitize_data( $user ) );
375
376 // Clear Mailchimp List ID if saved list is not available.
377 $lists = mailchimp_sf_get_lists();
378 if ( ! is_wp_error( $lists ) ) {
379 $lists = $lists['lists'] ?? array();
380 $saved_list_id = get_option( 'mc_list_id' );
381 $list_ids = array_map(
382 function ( $ele ) {
383 return $ele['id'];
384 },
385 $lists
386 );
387 if ( ! in_array( $saved_list_id, $list_ids, true ) ) {
388 delete_option( 'mc_list_id' );
389 }
390
391 // Update lists option.
392 if ( ! empty( $lists ) ) {
393 update_option( 'mailchimp_sf_lists', $lists );
394 }
395 }
396 return true;
397 } else {
398 $msg = esc_html__( 'API Key must belong to "Owner", "Admin", or "Manager."', 'mailchimp' );
399 return new WP_Error( 'mailchimp-sf-invalid-role', $msg );
400 }
401 }
402
403 /**
404 * Display admin notices.
405 *
406 * @since 1.6.0
407 */
408 public function admin_notices() {
409 if ( ! current_user_can( 'manage_options' ) ) {
410 return;
411 }
412 $current_screen = get_current_screen();
413
414 // Display a deprecation notice if the user is using an API key to connect with Mailchimp.
415 if ( get_option( 'mc_api_key', '' ) && ! get_option( 'mailchimp_sf_access_token', '' ) && mailchimp_sf_should_display_form() ) {
416
417 if ( $current_screen && 'toplevel_page_mailchimp_sf_options' === $current_screen->id ) {
418 ?>
419 <div class="notice notice-warning">
420 <p>
421 <?php
422 esc_html_e( 'You are using an outdated API Key connection to Mailchimp, please migrate to the new OAuth authentication method to continue accessing your Mailchimp account.', 'mailchimp' );
423 ?>
424 </p>
425 <div class="migrate-to-oauth-wrapper">
426 <?php
427 // Migrate button.
428 $login_button_text = __( 'Migrate to OAuth authentication', 'mailchimp' );
429 include_once MCSF_DIR . 'includes/admin/templates/login-button.php'; // phpcs:ignore PEAR.Files.IncludingFile.UseRequireOnce
430 ?>
431 </div>
432 </div>
433 <?php
434 } else {
435 ?>
436 <div class="notice notice-warning is-dismissible">
437 <p>
438 <?php
439 $message = sprintf(
440 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
441 __( 'You are using an outdated API Key connection to Mailchimp, please migrate to the new OAuth authentication method to continue accessing your Mailchimp account by clicking the "Migrate to OAuth authentication" button on the %1$sMailchimp settings%2$s page.', 'mailchimp' ),
442 '<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
443 '</a>'
444 );
445
446 echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
447 ?>
448 </p>
449 </div>
450 <?php
451 }
452 }
453
454 // Display a notice if the user is waiting for the login to complete.
455 if ( $current_screen && 'toplevel_page_mailchimp_sf_options' === $current_screen->id ) {
456 $api = mailchimp_sf_get_api();
457 if ( $api && 'waiting' === get_option( 'mailchimp_sf_waiting_for_login' ) ) {
458 $profile = $api->get( '' );
459 if ( ! is_wp_error( $profile ) ) {
460 if ( ! empty( $profile['last_login'] ) ) {
461 // Clear the waiting flag if the user is logged in.
462 delete_option( 'mailchimp_sf_waiting_for_login' );
463 } else {
464 ?>
465 <div class="notice notice-warning is-dismissible">
466 <p>
467 <?php
468 esc_html_e( 'Please activate your Mailchimp account to complete the setup. Without activation, the connection to WordPress may be interrupted.', 'mailchimp' );
469 ?>
470 </p>
471 </div>
472 <?php
473 }
474 }
475 }
476 }
477
478 if (
479 ! get_option( 'mailchimp_sf_auth_error', false ) ||
480 ! get_option( 'mailchimp_sf_access_token', '' )
481 ) {
482 return;
483 }
484
485 // Display a notice if the access token is invalid/revoked.
486 ?>
487 <div class="notice notice-error is-dismissible">
488 <p>
489 <?php
490 $message = sprintf(
491 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
492 __( 'Heads up! There may be a problem with your connection to Mailchimp. Please %1$sre-connect%2$s your Mailchimp account to fix the issue.', 'mailchimp' ),
493 '<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
494 '</a>'
495 );
496
497 echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
498 ?>
499 </p>
500 </div>
501 <?php
502 }
503
504 /**
505 * Sanitize variables using sanitize_text_field.
506 *
507 * Arrays are sanitized recursively, non-scalar values are ignored.
508 *
509 * @param string|array $data Data to sanitize.
510 * @return string|array
511 */
512 public function sanitize_data( $data ) {
513 if ( is_array( $data ) ) {
514 return array_map( array( $this, 'sanitize_data' ), $data );
515 } else {
516 return is_scalar( $data ) ? sanitize_text_field( $data ) : $data;
517 }
518 }
519
520 /**
521 * Enqueue scripts/styles for the Mailchimp admin page
522 *
523 * @param string $hook_suffix The current admin page.
524 * @return void
525 */
526 public function enqueue_admin_page_scripts( $hook_suffix ) {
527 if ( 'toplevel_page_mailchimp_sf_options' !== $hook_suffix && 'admin_page_mailchimp_sf_create_account' !== $hook_suffix ) {
528 return;
529 }
530
531 wp_enqueue_style( 'mailchimp_sf_admin_css', MCSF_URL . 'assets/css/admin.css', array( 'wp-jquery-ui-dialog' ), true );
532 wp_enqueue_script( 'showMe', MCSF_URL . 'assets/js/hidecss.js', array( 'jquery' ), MCSF_VER, true );
533 wp_enqueue_script( 'mailchimp_sf_admin', MCSF_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-ui-dialog' ), MCSF_VER, true );
534
535 $data = array(
536 'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
537 'oauth_url' => esc_url( $this->oauth_url ),
538 'oauth_start_nonce' => wp_create_nonce( 'mailchimp_sf_oauth_start_nonce' ),
539 'oauth_finish_nonce' => wp_create_nonce( 'mailchimp_sf_oauth_finish_nonce' ),
540 'oauth_window_name' => esc_html__( 'Mailchimp For WordPress OAuth', 'mailchimp' ),
541 'generic_error' => esc_html__( 'An error occurred. Please try again.', 'mailchimp' ),
542 'modal_title' => esc_html__( 'Login Popup is blocked!', 'mailchimp' ),
543 'modal_button_try_again' => esc_html__( 'Try again', 'mailchimp' ),
544 'modal_button_cancel' => esc_html__( 'No, cancel!', 'mailchimp' ),
545 'admin_settings_url' => esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ),
546 'user_sync_status_nonce' => wp_create_nonce( 'mailchimp_sf_user_sync_status' ),
547 'delete_user_sync_error_nonce' => wp_create_nonce( 'mailchimp_sf_delete_user_sync_error' ),
548 'no_errors_found' => esc_html__( 'No errors found', 'mailchimp' ),
549 'preview_form_nonce' => wp_create_nonce( 'mailchimp_sf_preview_form_nonce' ),
550 );
551
552 // Create account page specific data.
553 if ( 'admin_page_mailchimp_sf_create_account' === $hook_suffix ) {
554 $data['create_account_nonce'] = wp_create_nonce( 'mailchimp_sf_create_account_nonce' );
555 $data['check_login_session_nonce'] = wp_create_nonce( 'mailchimp_sf_check_login_session_nonce' );
556 /* translators: %s is field name. */
557 $data['required_error'] = esc_html__( '%s can\'t be blank.', 'mailchimp' );
558 $data['invalid_email_error'] = esc_html__( 'Insert correct email.', 'mailchimp' );
559 $data['confirm_email_match'] = esc_html__( 'Email confirmation must match confirmation email.', 'mailchimp' );
560 $data['confirm_email_match2'] = esc_html__( 'Email confirmation must match the field above.', 'mailchimp' );
561 }
562
563 wp_localize_script(
564 'mailchimp_sf_admin',
565 'mailchimp_sf_admin_params',
566 $data
567 );
568 }
569
570 /**
571 * Add the create account page and the settings page to the admin menu.
572 *
573 * @since 1.6.0
574 */
575 public function add_admin_menu_pages() {
576 // Add settings page.
577 add_menu_page(
578 esc_html__( 'Mailchimp Setup', 'mailchimp' ),
579 esc_html__( 'Mailchimp', 'mailchimp' ),
580 MCSF_CAP_THRESHOLD,
581 'mailchimp_sf_options',
582 array( $this, 'settings_page' ),
583 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1Mi4wMyA1NSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiNmZmY7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5Bc3NldCAxPC90aXRsZT48ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIj48ZyBpZD0iTGF5ZXJfMS0yIiBkYXRhLW5hbWU9IkxheWVyIDEiPjxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTExLjY0LDI4LjU0YTQuNzUsNC43NSwwLDAsMC0xLjE3LjA4Yy0yLjc5LjU2LTQuMzYsMi45NC00LjA1LDZhNi4yNCw2LjI0LDAsMCwwLDUuNzIsNS4yMSw0LjE3LDQuMTcsMCwwLDAsLjgtLjA2YzIuODMtLjQ4LDMuNTctMy41NSwzLjEtNi41N0MxNS41MSwyOS44MywxMy4yMSwyOC42MywxMS42NCwyOC41NFptMi43Nyw4LjA3YTEuMTcsMS4xNywwLDAsMS0xLjEuNTUsMS41MywxLjUzLDAsMCwxLTEuMzctMS41OEE0LDQsMCwwLDEsMTIuMjMsMzRhMS40NCwxLjQ0LDAsMCwwLS41NS0xLjc0LDEuNDgsMS40OCwwLDAsMC0xLjEyLS4yMSwxLjQ0LDEuNDQsMCwwLDAtLjkyLjY0LDMuMzksMy4zOSwwLDAsMC0uMzQuNzlsMCwuMTFjLS4xMy4zNC0uMzMuNDUtLjQ3LjQzcy0uMTYtLjA1LS4yMS0uMjFhMywzL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MSwwLC4xNi0uMTUuMDctLjJhMTEsMTEsMCwwLDAtNC42OS0xLjIzLjA5LjA5LDAsMCwxLS4wNy0uMTQsNC43OCw0Ljc4LDAsMCwxLC44OC0uODkuMDkuMDksMCwwLDAtLjA2LS4xNiwxMi40NiwxMi40NiwwLDAsMC01LjYxLDIsLjA5LjA5LDAsMCwxLS4xMy0uMDksNi4xNiw2LjE2LDAsMCwxLC41OS0xLjQ1LjA4LjA4LDAsMCwwLS4xMS0uMTFBMjIuNzksMjIuNzksMCwwLDAsMjAsMTYuMjRhLjA5LjA5LDAsMCwwLC4xMi4xM0ExOS41MywxOS41MywwLDAsMSwyNywxMy4zMiwxOS4xLDE5LjEsMCwwLDEsMzUuNSwxMy4yOVoiLz48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik0yOC4zNCw2LjQyUzI2LjIzLDQsMjUuNiwzLjhDMjEuNjksMi43NCwxMy4yNCw4LjU3LDcuODQsMTYuMjcsNS42NiwxOS4zOSwyLjUzLDI0LjksNCwyNy43NGExMS40MywxMS40MywwLDAsMCwxLjc5LDEuNzJBNi42NSw2LjY1LDAsMCwxLDEwLDI2Ljc4LDM0LjIxLDM0LjIxLDAsMCwxLDIwLjgsMTEuNjIsNTUuMDksNTUuMDksMCwwLDEsMjguMzQsNi40MloiLz48L2c+PC9nPjwvc3ZnPg=='
584 );
585
586 // Rename the auto-generated first submenu item to "Form Settings".
587 add_submenu_page(
588 'mailchimp_sf_options',
589 esc_html__( 'Mailchimp Form Settings', 'mailchimp' ),
590 esc_html__( 'Form Settings', 'mailchimp' ),
591 MCSF_CAP_THRESHOLD,
592 'mailchimp_sf_options',
593 array( $this, 'settings_page' )
594 );
595
596 add_submenu_page(
597 'admin.php',
598 esc_html__( 'Create Mailchimp Account', 'mailchimp' ),
599 esc_html__( 'Create Mailchimp Account', 'mailchimp' ),
600 'manage_options',
601 'mailchimp_sf_create_account',
602 array( $this, 'create_account_page' )
603 );
604 }
605
606 /**
607 * Create account page.
608 *
609 * @since 1.6.0
610 *
611 * @return void
612 */
613 public function create_account_page() {
614 $countries = $this->get_countries();
615 $timezones = $this->get_timezones();
616 ?>
617 <div id="mailchimp-sf-settings-page">
618 <?php
619 include_once MCSF_DIR . 'includes/admin/templates/create-account-page.php';
620 ?>
621 </div>
622 <?php
623 }
624
625 /**
626 * Render the settings page.
627 *
628 * @since 1.9.0
629 *
630 * @return void
631 */
632 public function settings_page() {
633 include_once MCSF_DIR . 'includes/admin/templates/settings.php';
634 }
635
636 /**
637 * Get a list of timezones.
638 *
639 * @since 1.6.0
640 *
641 * @return array
642 */
643 private function get_timezones() {
644 return timezone_identifiers_list();
645 }
646
647 /**
648 * Get a list of countries.
649 *
650 * @since 1.6.0
651 *
652 * @return array
653 */
654 public function get_countries() {
655 return array(
656 'AF' => __( 'Afghanistan', 'mailchimp' ),
657 'AX' => __( '�
658 land Islands', 'mailchimp' ),
659 'AL' => __( 'Albania', 'mailchimp' ),
660 'DZ' => __( 'Algeria', 'mailchimp' ),
661 'AS' => __( 'American Samoa', 'mailchimp' ),
662 'AD' => __( 'Andorra', 'mailchimp' ),
663 'AO' => __( 'Angola', 'mailchimp' ),
664 'AI' => __( 'Anguilla', 'mailchimp' ),
665 'AQ' => __( 'Antarctica', 'mailchimp' ),
666 'AG' => __( 'Antigua and Barbuda', 'mailchimp' ),
667 'AR' => __( 'Argentina', 'mailchimp' ),
668 'AM' => __( 'Armenia', 'mailchimp' ),
669 'AW' => __( 'Aruba', 'mailchimp' ),
670 'AU' => __( 'Australia', 'mailchimp' ),
671 'AT' => __( 'Austria', 'mailchimp' ),
672 'AZ' => __( 'Azerbaijan', 'mailchimp' ),
673 'BS' => __( 'Bahamas', 'mailchimp' ),
674 'BH' => __( 'Bahrain', 'mailchimp' ),
675 'BD' => __( 'Bangladesh', 'mailchimp' ),
676 'BB' => __( 'Barbados', 'mailchimp' ),
677 'BY' => __( 'Belarus', 'mailchimp' ),
678 'BE' => __( 'Belgium', 'mailchimp' ),
679 'PW' => __( 'Belau', 'mailchimp' ),
680 'BZ' => __( 'Belize', 'mailchimp' ),
681 'BJ' => __( 'Benin', 'mailchimp' ),
682 'BM' => __( 'Bermuda', 'mailchimp' ),
683 'BT' => __( 'Bhutan', 'mailchimp' ),
684 'BO' => __( 'Bolivia', 'mailchimp' ),
685 'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'mailchimp' ),
686 'BA' => __( 'Bosnia and Herzegovina', 'mailchimp' ),
687 'BW' => __( 'Botswana', 'mailchimp' ),
688 'BV' => __( 'Bouvet Island', 'mailchimp' ),
689 'BR' => __( 'Brazil', 'mailchimp' ),
690 'IO' => __( 'British Indian Ocean Territory', 'mailchimp' ),
691 'BN' => __( 'Brunei', 'mailchimp' ),
692 'BG' => __( 'Bulgaria', 'mailchimp' ),
693 'BF' => __( 'Burkina Faso', 'mailchimp' ),
694 'BI' => __( 'Burundi', 'mailchimp' ),
695 'KH' => __( 'Cambodia', 'mailchimp' ),
696 'CM' => __( 'Cameroon', 'mailchimp' ),
697 'CA' => __( 'Canada', 'mailchimp' ),
698 'CV' => __( 'Cape Verde', 'mailchimp' ),
699 'KY' => __( 'Cayman Islands', 'mailchimp' ),
700 'CF' => __( 'Central African Republic', 'mailchimp' ),
701 'TD' => __( 'Chad', 'mailchimp' ),
702 'CL' => __( 'Chile', 'mailchimp' ),
703 'CN' => __( 'China', 'mailchimp' ),
704 'CX' => __( 'Christmas Island', 'mailchimp' ),
705 'CC' => __( 'Cocos (Keeling) Islands', 'mailchimp' ),
706 'CO' => __( 'Colombia', 'mailchimp' ),
707 'KM' => __( 'Comoros', 'mailchimp' ),
708 'CG' => __( 'Congo (Brazzaville)', 'mailchimp' ),
709 'CD' => __( 'Congo (Kinshasa)', 'mailchimp' ),
710 'CK' => __( 'Cook Islands', 'mailchimp' ),
711 'CR' => __( 'Costa Rica', 'mailchimp' ),
712 'HR' => __( 'Croatia', 'mailchimp' ),
713 'CU' => __( 'Cuba', 'mailchimp' ),
714 'CW' => __( 'Cura&ccedil;ao', 'mailchimp' ),
715 'CY' => __( 'Cyprus', 'mailchimp' ),
716 'CZ' => __( 'Czech Republic', 'mailchimp' ),
717 'DK' => __( 'Denmark', 'mailchimp' ),
718 'DJ' => __( 'Djibouti', 'mailchimp' ),
719 'DM' => __( 'Dominica', 'mailchimp' ),
720 'DO' => __( 'Dominican Republic', 'mailchimp' ),
721 'EC' => __( 'Ecuador', 'mailchimp' ),
722 'EG' => __( 'Egypt', 'mailchimp' ),
723 'SV' => __( 'El Salvador', 'mailchimp' ),
724 'GQ' => __( 'Equatorial Guinea', 'mailchimp' ),
725 'ER' => __( 'Eritrea', 'mailchimp' ),
726 'EE' => __( 'Estonia', 'mailchimp' ),
727 'ET' => __( 'Ethiopia', 'mailchimp' ),
728 'FK' => __( 'Falkland Islands', 'mailchimp' ),
729 'FO' => __( 'Faroe Islands', 'mailchimp' ),
730 'FJ' => __( 'Fiji', 'mailchimp' ),
731 'FI' => __( 'Finland', 'mailchimp' ),
732 'FR' => __( 'France', 'mailchimp' ),
733 'GF' => __( 'French Guiana', 'mailchimp' ),
734 'PF' => __( 'French Polynesia', 'mailchimp' ),
735 'TF' => __( 'French Southern Territories', 'mailchimp' ),
736 'GA' => __( 'Gabon', 'mailchimp' ),
737 'GM' => __( 'Gambia', 'mailchimp' ),
738 'GE' => __( 'Georgia', 'mailchimp' ),
739 'DE' => __( 'Germany', 'mailchimp' ),
740 'GH' => __( 'Ghana', 'mailchimp' ),
741 'GI' => __( 'Gibraltar', 'mailchimp' ),
742 'GR' => __( 'Greece', 'mailchimp' ),
743 'GL' => __( 'Greenland', 'mailchimp' ),
744 'GD' => __( 'Grenada', 'mailchimp' ),
745 'GP' => __( 'Guadeloupe', 'mailchimp' ),
746 'GU' => __( 'Guam', 'mailchimp' ),
747 'GT' => __( 'Guatemala', 'mailchimp' ),
748 'GG' => __( 'Guernsey', 'mailchimp' ),
749 'GN' => __( 'Guinea', 'mailchimp' ),
750 'GW' => __( 'Guinea-Bissau', 'mailchimp' ),
751 'GY' => __( 'Guyana', 'mailchimp' ),
752 'HT' => __( 'Haiti', 'mailchimp' ),
753 'HM' => __( 'Heard Island and McDonald Islands', 'mailchimp' ),
754 'HN' => __( 'Honduras', 'mailchimp' ),
755 'HK' => __( 'Hong Kong', 'mailchimp' ),
756 'HU' => __( 'Hungary', 'mailchimp' ),
757 'IS' => __( 'Iceland', 'mailchimp' ),
758 'IN' => __( 'India', 'mailchimp' ),
759 'ID' => __( 'Indonesia', 'mailchimp' ),
760 'IR' => __( 'Iran', 'mailchimp' ),
761 'IQ' => __( 'Iraq', 'mailchimp' ),
762 'IE' => __( 'Ireland', 'mailchimp' ),
763 'IM' => __( 'Isle of Man', 'mailchimp' ),
764 'IL' => __( 'Israel', 'mailchimp' ),
765 'IT' => __( 'Italy', 'mailchimp' ),
766 'CI' => __( 'Ivory Coast', 'mailchimp' ),
767 'JM' => __( 'Jamaica', 'mailchimp' ),
768 'JP' => __( 'Japan', 'mailchimp' ),
769 'JE' => __( 'Jersey', 'mailchimp' ),
770 'JO' => __( 'Jordan', 'mailchimp' ),
771 'KZ' => __( 'Kazakhstan', 'mailchimp' ),
772 'KE' => __( 'Kenya', 'mailchimp' ),
773 'KI' => __( 'Kiribati', 'mailchimp' ),
774 'KW' => __( 'Kuwait', 'mailchimp' ),
775 'KG' => __( 'Kyrgyzstan', 'mailchimp' ),
776 'LA' => __( 'Laos', 'mailchimp' ),
777 'LV' => __( 'Latvia', 'mailchimp' ),
778 'LB' => __( 'Lebanon', 'mailchimp' ),
779 'LS' => __( 'Lesotho', 'mailchimp' ),
780 'LR' => __( 'Liberia', 'mailchimp' ),
781 'LY' => __( 'Libya', 'mailchimp' ),
782 'LI' => __( 'Liechtenstein', 'mailchimp' ),
783 'LT' => __( 'Lithuania', 'mailchimp' ),
784 'LU' => __( 'Luxembourg', 'mailchimp' ),
785 'MO' => __( 'Macao', 'mailchimp' ),
786 'MK' => __( 'North Macedonia', 'mailchimp' ),
787 'MG' => __( 'Madagascar', 'mailchimp' ),
788 'MW' => __( 'Malawi', 'mailchimp' ),
789 'MY' => __( 'Malaysia', 'mailchimp' ),
790 'MV' => __( 'Maldives', 'mailchimp' ),
791 'ML' => __( 'Mali', 'mailchimp' ),
792 'MT' => __( 'Malta', 'mailchimp' ),
793 'MH' => __( 'Marshall Islands', 'mailchimp' ),
794 'MQ' => __( 'Martinique', 'mailchimp' ),
795 'MR' => __( 'Mauritania', 'mailchimp' ),
796 'MU' => __( 'Mauritius', 'mailchimp' ),
797 'YT' => __( 'Mayotte', 'mailchimp' ),
798 'MX' => __( 'Mexico', 'mailchimp' ),
799 'FM' => __( 'Micronesia', 'mailchimp' ),
800 'MD' => __( 'Moldova', 'mailchimp' ),
801 'MC' => __( 'Monaco', 'mailchimp' ),
802 'MN' => __( 'Mongolia', 'mailchimp' ),
803 'ME' => __( 'Montenegro', 'mailchimp' ),
804 'MS' => __( 'Montserrat', 'mailchimp' ),
805 'MA' => __( 'Morocco', 'mailchimp' ),
806 'MZ' => __( 'Mozambique', 'mailchimp' ),
807 'MM' => __( 'Myanmar', 'mailchimp' ),
808 'NA' => __( 'Namibia', 'mailchimp' ),
809 'NR' => __( 'Nauru', 'mailchimp' ),
810 'NP' => __( 'Nepal', 'mailchimp' ),
811 'NL' => __( 'Netherlands', 'mailchimp' ),
812 'NC' => __( 'New Caledonia', 'mailchimp' ),
813 'NZ' => __( 'New Zealand', 'mailchimp' ),
814 'NI' => __( 'Nicaragua', 'mailchimp' ),
815 'NE' => __( 'Niger', 'mailchimp' ),
816 'NG' => __( 'Nigeria', 'mailchimp' ),
817 'NU' => __( 'Niue', 'mailchimp' ),
818 'NF' => __( 'Norfolk Island', 'mailchimp' ),
819 'MP' => __( 'Northern Mariana Islands', 'mailchimp' ),
820 'KP' => __( 'North Korea', 'mailchimp' ),
821 'NO' => __( 'Norway', 'mailchimp' ),
822 'OM' => __( 'Oman', 'mailchimp' ),
823 'PK' => __( 'Pakistan', 'mailchimp' ),
824 'PS' => __( 'Palestinian Territory', 'mailchimp' ),
825 'PA' => __( 'Panama', 'mailchimp' ),
826 'PG' => __( 'Papua New Guinea', 'mailchimp' ),
827 'PY' => __( 'Paraguay', 'mailchimp' ),
828 'PE' => __( 'Peru', 'mailchimp' ),
829 'PH' => __( 'Philippines', 'mailchimp' ),
830 'PN' => __( 'Pitcairn', 'mailchimp' ),
831 'PL' => __( 'Poland', 'mailchimp' ),
832 'PT' => __( 'Portugal', 'mailchimp' ),
833 'PR' => __( 'Puerto Rico', 'mailchimp' ),
834 'QA' => __( 'Qatar', 'mailchimp' ),
835 'RE' => __( 'Reunion', 'mailchimp' ),
836 'RO' => __( 'Romania', 'mailchimp' ),
837 'RU' => __( 'Russia', 'mailchimp' ),
838 'RW' => __( 'Rwanda', 'mailchimp' ),
839 'BL' => __( 'Saint Barth&eacute;lemy', 'mailchimp' ),
840 'SH' => __( 'Saint Helena', 'mailchimp' ),
841 'KN' => __( 'Saint Kitts and Nevis', 'mailchimp' ),
842 'LC' => __( 'Saint Lucia', 'mailchimp' ),
843 'MF' => __( 'Saint Martin (French part)', 'mailchimp' ),
844 'SX' => __( 'Saint Martin (Dutch part)', 'mailchimp' ),
845 'PM' => __( 'Saint Pierre and Miquelon', 'mailchimp' ),
846 'VC' => __( 'Saint Vincent and the Grenadines', 'mailchimp' ),
847 'SM' => __( 'San Marino', 'mailchimp' ),
848 'ST' => __( 'S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'mailchimp' ),
849 'SA' => __( 'Saudi Arabia', 'mailchimp' ),
850 'SN' => __( 'Senegal', 'mailchimp' ),
851 'RS' => __( 'Serbia', 'mailchimp' ),
852 'SC' => __( 'Seychelles', 'mailchimp' ),
853 'SL' => __( 'Sierra Leone', 'mailchimp' ),
854 'SG' => __( 'Singapore', 'mailchimp' ),
855 'SK' => __( 'Slovakia', 'mailchimp' ),
856 'SI' => __( 'Slovenia', 'mailchimp' ),
857 'SB' => __( 'Solomon Islands', 'mailchimp' ),
858 'SO' => __( 'Somalia', 'mailchimp' ),
859 'ZA' => __( 'South Africa', 'mailchimp' ),
860 'GS' => __( 'South Georgia/Sandwich Islands', 'mailchimp' ),
861 'KR' => __( 'South Korea', 'mailchimp' ),
862 'SS' => __( 'South Sudan', 'mailchimp' ),
863 'ES' => __( 'Spain', 'mailchimp' ),
864 'LK' => __( 'Sri Lanka', 'mailchimp' ),
865 'SD' => __( 'Sudan', 'mailchimp' ),
866 'SR' => __( 'Suriname', 'mailchimp' ),
867 'SJ' => __( 'Svalbard and Jan Mayen', 'mailchimp' ),
868 'SZ' => __( 'Eswatini', 'mailchimp' ),
869 'SE' => __( 'Sweden', 'mailchimp' ),
870 'CH' => __( 'Switzerland', 'mailchimp' ),
871 'SY' => __( 'Syria', 'mailchimp' ),
872 'TW' => __( 'Taiwan', 'mailchimp' ),
873 'TJ' => __( 'Tajikistan', 'mailchimp' ),
874 'TZ' => __( 'Tanzania', 'mailchimp' ),
875 'TH' => __( 'Thailand', 'mailchimp' ),
876 'TL' => __( 'Timor-Leste', 'mailchimp' ),
877 'TG' => __( 'Togo', 'mailchimp' ),
878 'TK' => __( 'Tokelau', 'mailchimp' ),
879 'TO' => __( 'Tonga', 'mailchimp' ),
880 'TT' => __( 'Trinidad and Tobago', 'mailchimp' ),
881 'TN' => __( 'Tunisia', 'mailchimp' ),
882 'TR' => __( 'Turkey', 'mailchimp' ),
883 'TM' => __( 'Turkmenistan', 'mailchimp' ),
884 'TC' => __( 'Turks and Caicos Islands', 'mailchimp' ),
885 'TV' => __( 'Tuvalu', 'mailchimp' ),
886 'UG' => __( 'Uganda', 'mailchimp' ),
887 'UA' => __( 'Ukraine', 'mailchimp' ),
888 'AE' => __( 'United Arab Emirates', 'mailchimp' ),
889 'GB' => __( 'United Kingdom (UK)', 'mailchimp' ),
890 'US' => __( 'United States (US)', 'mailchimp' ),
891 'UM' => __( 'United States (US) Minor Outlying Islands', 'mailchimp' ),
892 'UY' => __( 'Uruguay', 'mailchimp' ),
893 'UZ' => __( 'Uzbekistan', 'mailchimp' ),
894 'VU' => __( 'Vanuatu', 'mailchimp' ),
895 'VA' => __( 'Vatican', 'mailchimp' ),
896 'VE' => __( 'Venezuela', 'mailchimp' ),
897 'VN' => __( 'Vietnam', 'mailchimp' ),
898 'VG' => __( 'Virgin Islands (British)', 'mailchimp' ),
899 'VI' => __( 'Virgin Islands (US)', 'mailchimp' ),
900 'WF' => __( 'Wallis and Futuna', 'mailchimp' ),
901 'EH' => __( 'Western Sahara', 'mailchimp' ),
902 'WS' => __( 'Samoa', 'mailchimp' ),
903 'YE' => __( 'Yemen', 'mailchimp' ),
904 'ZM' => __( 'Zambia', 'mailchimp' ),
905 'ZW' => __( 'Zimbabwe', 'mailchimp' ),
906 );
907 }
908
909 /**
910 * Display the Mailchimp footer text on the Mailchimp admin pages.
911 *
912 * @since 1.6.0
913 *
914 * @param string $text The current footer text.
915 * @return string The modified footer text.
916 */
917 public function admin_footer_text( $text ) {
918 $current_screen = get_current_screen();
919 $current_screen_id = $current_screen ? $current_screen->id : '';
920 if ( ! in_array( $current_screen_id, array( 'toplevel_page_mailchimp_sf_options', 'admin_page_mailchimp_sf_create_account', 'mailchimp_page_mailchimp_sf_analytics' ), true ) ) {
921 return $text;
922 }
923
924 return wp_kses(
925 sprintf(
926 /* translators: %d - Current year, %s - Mailchimp legal links */
927 __( '©%1$d Intuit Inc. All rights reserved. Mailchimp® is a registered trademark of The Rocket Science Group, <a href="%2$s" target="_blank" rel="noopener noreferrer">Cookie Preferences</a>, <a href="%3$s" target="_blank" rel="noopener noreferrer">Privacy</a>, and <a href="%4$s" target="_blank" rel="noopener noreferrer">Terms</a>.', 'mailchimp' ),
928 gmdate( 'Y' ),
929 esc_url( 'https://mailchimp.com/legal/cookies/#optanon-toggle-display/' ),
930 esc_url( 'https://www.intuit.com/privacy/statement/' ),
931 esc_url( 'https://mailchimp.com/legal/terms' )
932 ),
933 array(
934 'a' => array(
935 'href' => array(),
936 'target' => array(),
937 'rel' => array(),
938 ),
939 )
940 );
941 }
942 }
943