MailChimp for WordPress - Version 4.7.1

Version Description

Download this release

Release Info

Developer DvanKooten
Plugin Icon 128x128 MailChimp for WordPress
Version 4.7.1
Comparing to
See all releases

Code changes from version 4.7 to 4.7.1

Files changed (132) hide show
  1. CHANGELOG.md +12 -2
  2. config/default-form-content.php +4 -4
  3. config/default-form-messages.php +36 -36
  4. config/default-form-settings.php +9 -9
  5. config/default-settings.php +3 -3
  6. includes/admin/class-admin-ajax.php +57 -60
  7. includes/admin/class-admin-messages.php +61 -67
  8. includes/admin/class-admin-texts.php +78 -79
  9. includes/admin/class-admin-tools.php +60 -64
  10. includes/admin/class-admin.php +514 -541
  11. includes/admin/class-ads.php +144 -153
  12. includes/admin/class-review-notice.php +71 -76
  13. includes/admin/class-update-optin.php +174 -181
  14. includes/admin/class-upgrade-routines.php +59 -63
  15. includes/admin/class-usage-tracking.php +185 -200
  16. includes/admin/migrations/3.0.0-form-1-post-type.php +48 -48
  17. includes/admin/migrations/3.0.0-form-2-options.php +42 -42
  18. includes/admin/migrations/3.0.0-form-3-messages.php +26 -26
  19. includes/admin/migrations/3.0.0-general-options.php +6 -6
  20. includes/admin/migrations/3.0.0-integration-options.php +41 -41
  21. includes/admin/migrations/3.0.0-styles-builder.php +20 -20
  22. includes/admin/migrations/3.0.0-widget-base-id.php +25 -25
  23. includes/admin/migrations/3.0.3-usage-tracking-schedule.php +13 -14
  24. includes/admin/migrations/3.1.6-woocommerce-position-prefix.php +5 -5
  25. includes/admin/migrations/4.0.0-groupings-to-interests.php +73 -75
  26. includes/admin/migrations/4.0.0-hidden-fields-value-delimiter.php +20 -16
  27. includes/admin/migrations/4.0.7-rename-debug-log-file.php +19 -19
  28. includes/admin/migrations/4.1.2-flush-list-cache.php +6 -6
  29. includes/admin/migrations/4.1.3-reschedule-event.php +4 -4
  30. includes/admin/migrations/4.6.0-remove-lists-from-options.php +1 -1
  31. includes/api/class-api-v3-client.php +237 -250
  32. includes/api/class-api-v3.php +1250 -1332
  33. includes/api/class-api.php +567 -590
  34. includes/api/class-connection-exception.php +2 -2
  35. includes/api/class-exception.php +106 -109
  36. includes/api/class-resource-not-found-exception.php +3 -3
  37. includes/class-container.php +100 -106
  38. includes/class-debug-log-reader.php +150 -156
  39. includes/class-debug-log.php +242 -218
  40. includes/class-dynamic-content-tags.php +241 -254
  41. includes/class-field-formatter.php +139 -144
  42. includes/class-field-guesser.php +121 -126
  43. includes/class-list-data-mapper.php +152 -153
  44. includes/class-mailchimp-subscriber.php +50 -51
  45. includes/class-mailchimp.php +409 -385
  46. includes/class-plugin.php +58 -63
  47. includes/class-queue-job.php +27 -28
  48. includes/class-queue.php +171 -180
  49. includes/class-tools.php +274 -276
  50. includes/default-actions.php +2 -2
  51. includes/default-filters.php +8 -8
  52. includes/deprecated-functions.php +13 -17
  53. includes/forms/admin-functions.php +9 -11
  54. includes/forms/class-admin.php +464 -472
  55. includes/forms/class-asset-manager.php +227 -239
  56. includes/forms/class-form-element.php +355 -366
  57. includes/forms/class-form-listener.php +310 -318
  58. includes/forms/class-form-manager.php +139 -146
  59. includes/forms/class-form-message.php +26 -28
  60. includes/forms/class-form-previewer.php +29 -32
  61. includes/forms/class-form-tags.php +112 -120
  62. includes/forms/class-form.php +748 -777
  63. includes/forms/class-google-recaptcha.php +208 -197
  64. includes/forms/class-output-manager.php +114 -132
  65. includes/forms/class-widget.php +115 -118
  66. includes/forms/functions.php +47 -53
  67. includes/forms/views/add-form.php +26 -22
  68. includes/forms/views/edit-form.php +90 -86
  69. includes/forms/views/js/date-fields.js +7 -8
  70. includes/forms/views/js/dummy-api.js +7 -5
  71. includes/forms/views/js/general-form-enhancements.js +5 -5
  72. includes/forms/views/js/url-fields.js +6 -6
  73. includes/forms/views/parts/add-fields-help.php +19 -17
  74. includes/forms/views/parts/dynamic-content-tags.php +13 -10
  75. includes/forms/views/preview.php +36 -36
  76. includes/forms/views/tabs/form-appearance.php +33 -31
  77. includes/forms/views/tabs/form-fields.php +13 -13
  78. includes/forms/views/tabs/form-messages.php +43 -38
  79. includes/forms/views/tabs/form-settings.php +81 -70
  80. includes/functions.php +252 -271
  81. includes/integrations/class-admin.php +175 -185
  82. includes/integrations/class-integration-fixture.php +78 -82
  83. includes/integrations/class-integration-manager.php +168 -180
  84. includes/integrations/class-integration-tags.php +44 -48
  85. includes/integrations/class-integration.php +116 -134
  86. includes/integrations/class-user-integration.php +39 -40
  87. includes/integrations/functions.php +8 -12
  88. includes/integrations/views/integration-settings.php +197 -149
  89. includes/integrations/views/integrations.php +83 -77
  90. includes/views/extensions.php +5 -5
  91. includes/views/general-settings.php +42 -38
  92. includes/views/other-settings.php +69 -69
  93. includes/views/parts/admin-footer.php +25 -28
  94. includes/views/parts/admin-sidebar.php +30 -32
  95. includes/views/parts/lists-overview.php +45 -42
  96. integrations/affiliatewp/class-affiliatewp.php +76 -80
  97. integrations/bootstrap.php +27 -29
  98. integrations/buddypress/class-buddypress.php +169 -175
  99. integrations/contact-form-7/admin-before.php +2 -2
  100. integrations/contact-form-7/class-contact-form-7.php +160 -170
  101. integrations/custom/admin-before.php +3 -3
  102. integrations/custom/class-custom.php +102 -108
  103. integrations/easy-digital-downloads/class-easy-digital-downloads.php +107 -112
  104. integrations/events-manager/class-events-manager.php +69 -72
  105. integrations/give/class-give.php +39 -42
  106. integrations/gravity-forms/admin-before.php +5 -2
  107. integrations/gravity-forms/bootstrap.php +4 -4
  108. integrations/gravity-forms/class-field.php +122 -122
  109. integrations/gravity-forms/class-gravity-forms.php +155 -157
  110. integrations/memberpress/class-memberpress.php +53 -49
  111. integrations/ninja-forms-2/admin-before.php +2 -2
  112. integrations/ninja-forms-2/class-ninja-forms.php +143 -136
  113. integrations/ninja-forms/admin-before.php +2 -2
  114. integrations/ninja-forms/bootstrap.php +9 -9
  115. integrations/ninja-forms/class-action.php +143 -147
  116. integrations/ninja-forms/class-field.php +89 -92
  117. integrations/ninja-forms/class-ninja-forms.php +50 -55
  118. integrations/woocommerce/admin-after.php +23 -13
  119. integrations/woocommerce/class-woocommerce.php +153 -153
  120. integrations/wp-comment-form/class-comment-form.php +107 -113
  121. integrations/wp-registration-form/class-registration-form.php +84 -88
  122. integrations/wpforms/admin-before.php +2 -2
  123. integrations/wpforms/bootstrap.php +7 -8
  124. integrations/wpforms/class-field.php +249 -263
  125. integrations/wpforms/class-wpforms.php +56 -62
  126. languages/index.php +7 -0
  127. languages/mailchimp-for-wp-af_ZA.mo +0 -0
  128. languages/mailchimp-for-wp-af_ZA.po +0 -1634
  129. languages/mailchimp-for-wp-bg_BG.mo +0 -0
  130. languages/mailchimp-for-wp-bg_BG.po +0 -1094
  131. languages/mailchimp-for-wp-ca_ES.mo +0 -0
  132. languages/mailchimp-for-wp-ca_ES.po +0 -954
CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
  Changelog
2
  =========
3
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  #### 4.7 - Nov 7, 2019
6
 
@@ -1252,7 +1262,7 @@ Before upgrading, please go through the [upgrade guide](https://mc4wp.com/kb/upg
1252
 
1253
  **Improvements**
1254
 
1255
- - Updated Italian, Russian & Turkish translations. [Want to help translate the plugin? Full translations get a free Pro license](https://www.transifex.com/projects/p/mailchimp-for-wordpress/).
1256
 
1257
  #### 2.2.8 - March 24, 2015
1258
 
@@ -1342,7 +1352,7 @@ A huge thank you to [Stefan Oderbolz](http://metaodi.ch/) for various fixed and
1342
 
1343
  - Moved third-party scripts to their own directory for easier exclusion
1344
  - All code is now adhering to the WP Code Standards
1345
- - Updated [Dutch, German, Spanish, Hungarian, French, Italian and Turkish translations](https://www.transifex.com/projects/p/mailchimp-for-wordpress/).
1346
 
1347
  **Additions**
1348
 
1
  Changelog
2
  =========
3
 
4
+ #### 4.7.1 - Nov 26, 2019
5
+
6
+ **Improvements**
7
+
8
+ - Update MemberPress hook names. Thanks [Ian Heggaton](https://github.com/pixelated-au)!
9
+ - Use WordPress.org translations instead of bundling translation files in plugin itself.
10
+ - Write .htaccess to directory of debug log file, to prevent file access.
11
+ - Add some convenient hooks for Checkout for WooCommerce.
12
+ - Stop parsing shortcodes in text widgets as WordPress core does this since version 4.9.
13
+
14
 
15
  #### 4.7 - Nov 7, 2019
16
 
1262
 
1263
  **Improvements**
1264
 
1265
+ - Updated Italian, Russian & Turkish translations.
1266
 
1267
  #### 2.2.8 - March 24, 2015
1268
 
1352
 
1353
  - Moved third-party scripts to their own directory for easier exclusion
1354
  - All code is now adhering to the WP Code Standards
1355
+ - Updated Dutch, German, Spanish, Hungarian, French, Italian and Turkish translations.
1356
 
1357
  **Additions**
1358
 
config/default-form-content.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
- $email_label = __('Email address', 'mailchimp-for-wp');
4
- $email_placeholder = __('Your email address', 'mailchimp-for-wp');
5
- $signup_button = __('Sign up', 'mailchimp-for-wp');
6
 
7
- $content = "<p>\n\t<label>{$email_label}: \n";
8
  $content .= "\t\t<input type=\"email\" name=\"EMAIL\" placeholder=\"{$email_placeholder}\" required />\n</label>\n</p>\n\n";
9
  $content .= "<p>\n\t<input type=\"submit\" value=\"{$signup_button}\" />\n</p>";
10
 
1
  <?php
2
 
3
+ $email_label = __( 'Email address', 'mailchimp-for-wp' );
4
+ $email_placeholder = __( 'Your email address', 'mailchimp-for-wp' );
5
+ $signup_button = __( 'Sign up', 'mailchimp-for-wp' );
6
 
7
+ $content = "<p>\n\t<label>{$email_label}: \n";
8
  $content .= "\t\t<input type=\"email\" name=\"EMAIL\" placeholder=\"{$email_placeholder}\" required />\n</label>\n</p>\n\n";
9
  $content .= "<p>\n\t<input type=\"submit\" value=\"{$signup_button}\" />\n</p>";
10
 
config/default-form-messages.php CHANGED
@@ -1,39 +1,39 @@
1
  <?php
2
  return array(
3
- 'subscribed' => array(
4
- 'type' => 'success',
5
- 'text' => __('Thank you, your sign-up request was successful! Please check your email inbox to confirm.', 'mailchimp-for-wp')
6
- ),
7
- 'updated' => array(
8
- 'type' => 'success',
9
- 'text' => __('Thank you, your records have been updated!', 'mailchimp-for-wp'),
10
- ),
11
- 'unsubscribed' => array(
12
- 'type' => 'success',
13
- 'text' => __('You were successfully unsubscribed.', 'mailchimp-for-wp'),
14
- ),
15
- 'not_subscribed' => array(
16
- 'type' => 'notice',
17
- 'text' => __('Given email address is not subscribed.', 'mailchimp-for-wp'),
18
- ),
19
- 'error' => array(
20
- 'type' => 'error',
21
- 'text' => __('Oops. Something went wrong. Please try again later.', 'mailchimp-for-wp'),
22
- ),
23
- 'invalid_email' => array(
24
- 'type' => 'error',
25
- 'text' => __('Please provide a valid email address.', 'mailchimp-for-wp'),
26
- ),
27
- 'already_subscribed' => array(
28
- 'type' => 'notice',
29
- 'text' => __('Given email address is already subscribed, thank you!', 'mailchimp-for-wp'),
30
- ),
31
- 'required_field_missing' => array(
32
- 'type' => 'error',
33
- 'text' => __('Please fill in the required fields.', 'mailchimp-for-wp'),
34
- ),
35
- 'no_lists_selected' => array(
36
- 'type' => 'error',
37
- 'text' => __('Please select at least one list.', 'mailchimp-for-wp')
38
- ),
39
  );
1
  <?php
2
  return array(
3
+ 'subscribed' => array(
4
+ 'type' => 'success',
5
+ 'text' => __( 'Thank you, your sign-up request was successful! Please check your email inbox to confirm.', 'mailchimp-for-wp' ),
6
+ ),
7
+ 'updated' => array(
8
+ 'type' => 'success',
9
+ 'text' => __( 'Thank you, your records have been updated!', 'mailchimp-for-wp' ),
10
+ ),
11
+ 'unsubscribed' => array(
12
+ 'type' => 'success',
13
+ 'text' => __( 'You were successfully unsubscribed.', 'mailchimp-for-wp' ),
14
+ ),
15
+ 'not_subscribed' => array(
16
+ 'type' => 'notice',
17
+ 'text' => __( 'Given email address is not subscribed.', 'mailchimp-for-wp' ),
18
+ ),
19
+ 'error' => array(
20
+ 'type' => 'error',
21
+ 'text' => __( 'Oops. Something went wrong. Please try again later.', 'mailchimp-for-wp' ),
22
+ ),
23
+ 'invalid_email' => array(
24
+ 'type' => 'error',
25
+ 'text' => __( 'Please provide a valid email address.', 'mailchimp-for-wp' ),
26
+ ),
27
+ 'already_subscribed' => array(
28
+ 'type' => 'notice',
29
+ 'text' => __( 'Given email address is already subscribed, thank you!', 'mailchimp-for-wp' ),
30
+ ),
31
+ 'required_field_missing' => array(
32
+ 'type' => 'error',
33
+ 'text' => __( 'Please fill in the required fields.', 'mailchimp-for-wp' ),
34
+ ),
35
+ 'no_lists_selected' => array(
36
+ 'type' => 'error',
37
+ 'text' => __( 'Please select at least one list.', 'mailchimp-for-wp' ),
38
+ ),
39
  );
config/default-form-settings.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
  return array(
3
- 'css' => 0,
4
- 'double_optin' => 1,
5
- 'hide_after_success' => 0,
6
- 'lists' => array(),
7
- 'redirect' => '',
8
- 'replace_interests' => 1,
9
- 'required_fields' => '',
10
- 'update_existing' => 0,
11
- 'subscriber_tags' => '',
12
  );
1
  <?php
2
  return array(
3
+ 'css' => 0,
4
+ 'double_optin' => 1,
5
+ 'hide_after_success' => 0,
6
+ 'lists' => array(),
7
+ 'redirect' => '',
8
+ 'replace_interests' => 1,
9
+ 'required_fields' => '',
10
+ 'update_existing' => 0,
11
+ 'subscriber_tags' => '',
12
  );
config/default-settings.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  return array(
3
- 'api_key' => '',
4
- 'allow_usage_tracking' => 0,
5
- 'debug_log_level' => 'warning',
6
  );
1
  <?php
2
  return array(
3
+ 'api_key' => '',
4
+ 'allow_usage_tracking' => 0,
5
+ 'debug_log_level' => 'warning',
6
  );
includes/admin/class-admin-ajax.php CHANGED
@@ -1,63 +1,60 @@
1
  <?php
2
 
3
- class MC4WP_Admin_Ajax
4
- {
5
-
6
- /**
7
- * @var MC4WP_Admin_Tools
8
- */
9
- protected $tools;
10
-
11
- /**
12
- * MC4WP_Admin_Ajax constructor.
13
- *
14
- * @param MC4WP_Admin_Tools $tools
15
- */
16
- public function __construct(MC4WP_Admin_Tools $tools)
17
- {
18
- $this->tools = $tools;
19
- }
20
-
21
- /**
22
- * Hook AJAX actions
23
- */
24
- public function add_hooks()
25
- {
26
- add_action('wp_ajax_mc4wp_renew_mailchimp_lists', array($this, 'refresh_mailchimp_lists'));
27
- add_action('wp_ajax_mc4wp_get_list_details', array($this, 'get_list_details'));
28
- }
29
-
30
- /**
31
- * Empty lists cache & fetch lists again.
32
- */
33
- public function refresh_mailchimp_lists()
34
- {
35
- if (! $this->tools->is_user_authorized()) {
36
- wp_send_json(false);
37
- }
38
-
39
- $mailchimp = new MC4WP_MailChimp();
40
- $success = $mailchimp->refresh_lists();
41
- wp_send_json($success);
42
- }
43
-
44
- /**
45
- * Retrieve details (merge fields and interest categories) for one or multiple lists in Mailchimp
46
- * @throws MC4WP_API_Exception
47
- */
48
- public function get_list_details() {
49
- $list_ids = (array) explode(',', $_GET['ids']);
50
- $data = array();
51
- $mailchimp = new MC4WP_MailChimp();
52
- foreach($list_ids as $list_id) {
53
- $merge_fields = $mailchimp->get_list_merge_fields($list_id);
54
- $interest_categories = $mailchimp->get_list_interest_categories($list_id);
55
- $data[] = (object) array(
56
- 'id' => $list_id,
57
- 'merge_fields' => $merge_fields,
58
- 'interest_categories' => $interest_categories,
59
- );
60
- }
61
- wp_send_json($data);
62
- }
63
  }
1
  <?php
2
 
3
+ class MC4WP_Admin_Ajax {
4
+
5
+
6
+ /**
7
+ * @var MC4WP_Admin_Tools
8
+ */
9
+ protected $tools;
10
+
11
+ /**
12
+ * MC4WP_Admin_Ajax constructor.
13
+ *
14
+ * @param MC4WP_Admin_Tools $tools
15
+ */
16
+ public function __construct( MC4WP_Admin_Tools $tools ) {
17
+ $this->tools = $tools;
18
+ }
19
+
20
+ /**
21
+ * Hook AJAX actions
22
+ */
23
+ public function add_hooks() {
24
+ add_action( 'wp_ajax_mc4wp_renew_mailchimp_lists', array( $this, 'refresh_mailchimp_lists' ) );
25
+ add_action( 'wp_ajax_mc4wp_get_list_details', array( $this, 'get_list_details' ) );
26
+ }
27
+
28
+ /**
29
+ * Empty lists cache & fetch lists again.
30
+ */
31
+ public function refresh_mailchimp_lists() {
32
+ if ( ! $this->tools->is_user_authorized() ) {
33
+ wp_send_json( false );
34
+ }
35
+
36
+ $mailchimp = new MC4WP_MailChimp();
37
+ $success = $mailchimp->refresh_lists();
38
+ wp_send_json( $success );
39
+ }
40
+
41
+ /**
42
+ * Retrieve details (merge fields and interest categories) for one or multiple lists in Mailchimp
43
+ * @throws MC4WP_API_Exception
44
+ */
45
+ public function get_list_details() {
46
+ $list_ids = (array) explode( ',', $_GET['ids'] );
47
+ $data = array();
48
+ $mailchimp = new MC4WP_MailChimp();
49
+ foreach ( $list_ids as $list_id ) {
50
+ $merge_fields = $mailchimp->get_list_merge_fields( $list_id );
51
+ $interest_categories = $mailchimp->get_list_interest_categories( $list_id );
52
+ $data[] = (object) array(
53
+ 'id' => $list_id,
54
+ 'merge_fields' => $merge_fields,
55
+ 'interest_categories' => $interest_categories,
56
+ );
57
+ }
58
+ wp_send_json( $data );
59
+ }
 
 
 
60
  }
includes/admin/class-admin-messages.php CHANGED
@@ -6,83 +6,77 @@
6
  * @ignore
7
  * @since 3.0
8
  */
9
- class MC4WP_Admin_Messages
10
- {
11
 
12
- /**
13
- * @var array
14
- */
15
- protected $bag;
16
 
17
- /**
18
- * @var bool
19
- */
20
- protected $dirty = false;
21
 
22
- /**
23
- * Add hooks
24
- */
25
- public function add_hooks()
26
- {
27
- add_action('admin_notices', array( $this, 'show' ));
28
- register_shutdown_function(array( $this, 'save' ));
29
- }
30
 
31
- private function load()
32
- {
33
- if (is_null($this->bag)) {
34
- $this->bag = get_option('mc4wp_flash_messages', array());
35
- }
36
- }
 
37
 
38
- // empty flash bag
39
- private function reset()
40
- {
41
- $this->bag = array();
42
- $this->dirty = true;
43
- }
44
 
45
- /**
46
- * Flash a message (shows on next pageload)
47
- *
48
- * @param $message
49
- * @param string $type
50
- */
51
- public function flash($message, $type = 'success')
52
- {
53
- $this->load();
54
- $this->bag[] = array(
55
- 'text' => $message,
56
- 'type' => $type
57
- );
58
- $this->dirty = true;
59
- }
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
 
63
- /**
64
- * Show queued flash messages
65
- */
66
- public function show()
67
- {
68
- $this->load();
69
 
70
- foreach ($this->bag as $message) {
71
- echo sprintf('<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $message['type'], $message['text']);
72
- }
 
 
73
 
74
- $this->reset();
75
- }
 
76
 
77
- /**
78
- * Save queued messages
79
- *
80
- * @hooked `shutdown`
81
- */
82
- public function save()
83
- {
84
- if ($this->dirty) {
85
- update_option('mc4wp_flash_messages', $this->bag, false);
86
- }
87
- }
 
 
88
  }
6
  * @ignore
7
  * @since 3.0
8
  */
9
+ class MC4WP_Admin_Messages {
 
10
 
 
 
 
 
11
 
12
+ /**
13
+ * @var array
14
+ */
15
+ protected $bag;
16
 
17
+ /**
18
+ * @var bool
19
+ */
20
+ protected $dirty = false;
 
 
 
 
21
 
22
+ /**
23
+ * Add hooks
24
+ */
25
+ public function add_hooks() {
26
+ add_action( 'admin_notices', array( $this, 'show' ) );
27
+ register_shutdown_function( array( $this, 'save' ) );
28
+ }
29
 
30
+ private function load() {
31
+ if ( is_null( $this->bag ) ) {
32
+ $this->bag = get_option( 'mc4wp_flash_messages', array() );
33
+ }
34
+ }
 
35
 
36
+ // empty flash bag
37
+ private function reset() {
38
+ $this->bag = array();
39
+ $this->dirty = true;
40
+ }
 
 
 
 
 
 
 
 
 
 
41
 
42
+ /**
43
+ * Flash a message (shows on next pageload)
44
+ *
45
+ * @param $message
46
+ * @param string $type
47
+ */
48
+ public function flash( $message, $type = 'success' ) {
49
+ $this->load();
50
+ $this->bag[] = array(
51
+ 'text' => $message,
52
+ 'type' => $type,
53
+ );
54
+ $this->dirty = true;
55
+ }
56
 
57
 
 
 
 
 
 
 
58
 
59
+ /**
60
+ * Show queued flash messages
61
+ */
62
+ public function show() {
63
+ $this->load();
64
 
65
+ foreach ( $this->bag as $message ) {
66
+ echo sprintf( '<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $message['type'], $message['text'] );
67
+ }
68
 
69
+ $this->reset();
70
+ }
71
+
72
+ /**
73
+ * Save queued messages
74
+ *
75
+ * @hooked `shutdown`
76
+ */
77
+ public function save() {
78
+ if ( $this->dirty ) {
79
+ update_option( 'mc4wp_flash_messages', $this->bag, false );
80
+ }
81
+ }
82
  }
includes/admin/class-admin-texts.php CHANGED
@@ -6,95 +6,94 @@
6
  * @ignore
7
  * @since 3.0
8
  */
9
- class MC4WP_Admin_Texts
10
- {
11
 
12
- /**
13
- * @param string $plugin_file
14
- */
15
- public function __construct($plugin_file)
16
- {
17
- $this->plugin_file = $plugin_file;
18
- }
19
 
20
- /**
21
- * Add hooks
22
- */
23
- public function add_hooks()
24
- {
25
- global $pagenow;
26
 
27
- add_filter('admin_footer_text', array( $this, 'footer_text' ));
 
 
 
 
28
 
29
- // Hooks for Plugins overview page
30
- if ($pagenow === 'plugins.php') {
31
- add_filter('plugin_action_links_' . $this->plugin_file, array( $this, 'add_plugin_settings_link' ), 10, 2);
32
- add_filter('plugin_row_meta', array( $this, 'add_plugin_meta_links'), 10, 2);
33
- }
34
- }
35
 
36
- /**
37
- * Ask for a plugin review in the WP Admin footer, if this is one of the plugin pages.
38
- *
39
- * @param $text
40
- *
41
- * @return string
42
- */
43
- public function footer_text($text)
44
- {
45
- if (! empty($_GET['page']) && strpos($_GET['page'], 'mailchimp-for-wp') === 0) {
46
- $text = sprintf('If you enjoy using <strong>Mailchimp for WordPress</strong>, please <a href="%s" target="_blank">leave us a ★★★★★ rating</a>. A <strong style="text-decoration: underline;">huge</strong> thank you in advance!', 'https://wordpress.org/support/view/plugin-reviews/mailchimp-for-wp?rate=5#postform');
47
- }
48
 
49
- return $text;
50
- }
 
 
 
 
 
 
 
 
 
51
 
52
- /**
53
- * Add the settings link to the Plugins overview
54
- *
55
- * @param array $links
56
- * @param $file
57
- *
58
- * @return array
59
- */
60
- public function add_plugin_settings_link($links, $file)
61
- {
62
- if ($file !== $this->plugin_file) {
63
- return $links;
64
- }
65
 
66
- $settings_link = '<a href="' . admin_url('admin.php?page=mailchimp-for-wp') . '">'. __('Settings', 'mailchimp-for-wp') . '</a>';
67
- array_unshift($links, $settings_link);
68
- return $links;
69
- }
 
 
 
 
 
 
 
 
70
 
71
- /**
72
- * Adds meta links to the plugin in the WP Admin > Plugins screen
73
- *
74
- * @param array $links
75
- * @param string $file
76
- *
77
- * @return array
78
- */
79
- public function add_plugin_meta_links($links, $file)
80
- {
81
- if ($file !== $this->plugin_file) {
82
- return $links;
83
- }
84
 
85
- $links[] = '<a href="https://kb.mc4wp.com/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-page">'. __('Documentation', 'mailchimp-for-wp') . '</a>';
 
 
 
 
 
 
 
 
 
 
 
86
 
87
- /**
88
- * Filters meta links shown on the Plugins overview page
89
- *
90
- * This takes an array of strings
91
- *
92
- * @since 3.0
93
- * @param array $links
94
- * @ignore
95
- */
96
- $links = (array) apply_filters('mc4wp_admin_plugin_meta_links', $links);
97
 
98
- return $links;
99
- }
 
 
 
 
 
 
 
 
 
 
 
100
  }
6
  * @ignore
7
  * @since 3.0
8
  */
9
+ class MC4WP_Admin_Texts {
 
10
 
11
+ /**
12
+ * @var string
13
+ */
14
+ protected $plugin_file;
 
 
 
15
 
16
+ /**
17
+ * @param string $plugin_file
18
+ */
19
+ public function __construct( $plugin_file ) {
20
+ $this->plugin_file = $plugin_file;
21
+ }
22
 
23
+ /**
24
+ * Add hooks
25
+ */
26
+ public function add_hooks() {
27
+ global $pagenow;
28
 
29
+ add_filter( 'admin_footer_text', array( $this, 'footer_text' ) );
 
 
 
 
 
30
 
31
+ // Hooks for Plugins overview page
32
+ if ( $pagenow === 'plugins.php' ) {
33
+ add_filter( 'plugin_action_links_' . $this->plugin_file, array( $this, 'add_plugin_settings_link' ), 10, 2 );
34
+ add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
35
+ }
36
+ }
 
 
 
 
 
 
37
 
38
+ /**
39
+ * Ask for a plugin review in the WP Admin footer, if this is one of the plugin pages.
40
+ *
41
+ * @param $text
42
+ *
43
+ * @return string
44
+ */
45
+ public function footer_text( $text ) {
46
+ if ( ! empty( $_GET['page'] ) && strpos( $_GET['page'], 'mailchimp-for-wp' ) === 0 ) {
47
+ $text = sprintf( 'If you enjoy using <strong>Mailchimp for WordPress</strong>, please <a href="%s" target="_blank">leave us a ★★★★★ rating</a>. A <strong style="text-decoration: underline;">huge</strong> thank you in advance!', 'https://wordpress.org/support/view/plugin-reviews/mailchimp-for-wp?rate=5#postform' );
48
+ }
49
 
50
+ return $text;
51
+ }
 
 
 
 
 
 
 
 
 
 
 
52
 
53
+ /**
54
+ * Add the settings link to the Plugins overview
55
+ *
56
+ * @param array $links
57
+ * @param $file
58
+ *
59
+ * @return array
60
+ */
61
+ public function add_plugin_settings_link( $links, $file ) {
62
+ if ( $file !== $this->plugin_file ) {
63
+ return $links;
64
+ }
65
 
66
+ $settings_link = '<a href="' . admin_url( 'admin.php?page=mailchimp-for-wp' ) . '">' . __( 'Settings', 'mailchimp-for-wp' ) . '</a>';
67
+ array_unshift( $links, $settings_link );
68
+ return $links;
69
+ }
 
 
 
 
 
 
 
 
 
70
 
71
+ /**
72
+ * Adds meta links to the plugin in the WP Admin > Plugins screen
73
+ *
74
+ * @param array $links
75
+ * @param string $file
76
+ *
77
+ * @return array
78
+ */
79
+ public function add_plugin_meta_links( $links, $file ) {
80
+ if ( $file !== $this->plugin_file ) {
81
+ return $links;
82
+ }
83
 
84
+ $links[] = '<a href="https://kb.mc4wp.com/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-page">' . __( 'Documentation', 'mailchimp-for-wp' ) . '</a>';
 
 
 
 
 
 
 
 
 
85
 
86
+ /**
87
+ * Filters meta links shown on the Plugins overview page
88
+ *
89
+ * This takes an array of strings
90
+ *
91
+ * @since 3.0
92
+ * @param array $links
93
+ * @ignore
94
+ */
95
+ $links = (array) apply_filters( 'mc4wp_admin_plugin_meta_links', $links );
96
+
97
+ return $links;
98
+ }
99
  }
includes/admin/class-admin-tools.php CHANGED
@@ -1,76 +1,72 @@
1
  <?php
2
 
3
- class MC4WP_Admin_Tools
4
- {
5
 
6
- /**
7
- * @return string
8
- */
9
- public function get_plugin_page()
10
- {
11
- if (empty($_GET['page'])) {
12
- return '';
13
- }
14
 
15
- $prefix = 'mailchimp-for-wp';
16
- $page = ltrim(substr($_GET['page'], strlen($prefix)), '-');
17
- return $page;
18
- }
 
 
 
19
 
20
- /**
21
- * @param string $page
22
- *
23
- * @return bool
24
- */
25
- public function on_plugin_page($page = null)
26
- {
27
- // any settings page
28
- if (is_null($page)) {
29
- return isset($_GET['page']) && strpos($_GET['page'], 'mailchimp-for-wp') === 0;
30
- }
31
 
32
- // specific page
33
- return $this->get_plugin_page() === $page;
34
- }
 
 
 
 
 
 
 
35
 
36
- /**
37
- * Does the logged-in user have the required capability?
38
- *
39
- * @return bool
40
- */
41
- public function is_user_authorized()
42
- {
43
- return current_user_can($this->get_required_capability());
44
- }
45
 
46
- /**
47
- * Get required capability to access settings page and view dashboard widgets.
48
- *
49
- * @return string
50
- */
51
- public function get_required_capability()
52
- {
53
- $capability = 'manage_options';
54
 
55
- /**
56
- * Filters the required user capability to access the settings pages & dashboard widgets.
57
- *
58
- * @ignore
59
- * @deprecated 3.0
60
- */
61
- $capability = apply_filters('mc4wp_settings_cap', $capability);
62
 
63
- /**
64
- * Filters the required user capability to access the Mailchimp for WordPress' settings pages, view the dashboard widgets.
65
- *
66
- * Defaults to `manage_options`
67
- *
68
- * @since 3.0
69
- * @param string $capability
70
- * @see https://codex.wordpress.org/Roles_and_Capabilities
71
- */
72
- $capability = (string) apply_filters('mc4wp_admin_required_capability', $capability);
73
 
74
- return $capability;
75
- }
 
 
 
 
 
 
 
 
 
 
 
76
  }
1
  <?php
2
 
3
+ class MC4WP_Admin_Tools {
 
4
 
 
 
 
 
 
 
 
 
5
 
6
+ /**
7
+ * @return string
8
+ */
9
+ public function get_plugin_page() {
10
+ if ( empty( $_GET['page'] ) ) {
11
+ return '';
12
+ }
13
 
14
+ $prefix = 'mailchimp-for-wp';
15
+ $page = ltrim( substr( $_GET['page'], strlen( $prefix ) ), '-' );
16
+ return $page;
17
+ }
 
 
 
 
 
 
 
18
 
19
+ /**
20
+ * @param string $page
21
+ *
22
+ * @return bool
23
+ */
24
+ public function on_plugin_page( $page = null ) {
25
+ // any settings page
26
+ if ( is_null( $page ) ) {
27
+ return isset( $_GET['page'] ) && strpos( $_GET['page'], 'mailchimp-for-wp' ) === 0;
28
+ }
29
 
30
+ // specific page
31
+ return $this->get_plugin_page() === $page;
32
+ }
 
 
 
 
 
 
33
 
34
+ /**
35
+ * Does the logged-in user have the required capability?
36
+ *
37
+ * @return bool
38
+ */
39
+ public function is_user_authorized() {
40
+ return current_user_can( $this->get_required_capability() );
41
+ }
42
 
43
+ /**
44
+ * Get required capability to access settings page and view dashboard widgets.
45
+ *
46
+ * @return string
47
+ */
48
+ public function get_required_capability() {
49
+ $capability = 'manage_options';
50
 
51
+ /**
52
+ * Filters the required user capability to access the settings pages & dashboard widgets.
53
+ *
54
+ * @ignore
55
+ * @deprecated 3.0
56
+ */
57
+ $capability = apply_filters( 'mc4wp_settings_cap', $capability );
 
 
 
58
 
59
+ /**
60
+ * Filters the required user capability to access the Mailchimp for WordPress' settings pages, view the dashboard widgets.
61
+ *
62
+ * Defaults to `manage_options`
63
+ *
64
+ * @since 3.0
65
+ * @param string $capability
66
+ * @see https://codex.wordpress.org/Roles_and_Capabilities
67
+ */
68
+ $capability = (string) apply_filters( 'mc4wp_admin_required_capability', $capability );
69
+
70
+ return $capability;
71
+ }
72
  }
includes/admin/class-admin.php CHANGED
@@ -6,545 +6,518 @@
6
  * @ignore
7
  * @access private
8
  */
9
- class MC4WP_Admin
10
- {
11
-
12
- /**
13
- * @var string The relative path to the main plugin file from the plugins dir
14
- */
15
- protected $plugin_file;
16
-
17
- /**
18
- * @var MC4WP_Admin_Messages
19
- */
20
- protected $messages;
21
-
22
- /**
23
- * @var MC4WP_Admin_Ads
24
- */
25
- protected $ads;
26
-
27
- /**
28
- * @var MC4WP_Admin_Tools
29
- */
30
- protected $tools;
31
-
32
- /**
33
- * @var MC4WP_Admin_Review_Notice
34
- */
35
- protected $review_notice;
36
-
37
- /**
38
- * Constructor
39
- *
40
- * @param MC4WP_Admin_Tools $tools
41
- * @param MC4WP_Admin_Messages $messages
42
- */
43
- public function __construct(MC4WP_Admin_Tools $tools, MC4WP_Admin_Messages $messages)
44
- {
45
- $this->tools = $tools;
46
- $this->messages = $messages;
47
- $this->plugin_file = plugin_basename(MC4WP_PLUGIN_FILE);
48
- $this->ads = new MC4WP_Admin_Ads();
49
- $this->review_notice = new MC4WP_Admin_Review_Notice($tools);
50
- $this->load_translations();
51
- }
52
-
53
- /**
54
- * Registers all hooks
55
- */
56
- public function add_hooks()
57
- {
58
-
59
- // Actions used globally throughout WP Admin
60
- add_action('admin_menu', array( $this, 'build_menu' ));
61
- add_action('admin_init', array( $this, 'initialize' ));
62
-
63
- add_action('current_screen', array( $this, 'customize_admin_texts' ));
64
- add_action('wp_dashboard_setup', array( $this, 'register_dashboard_widgets' ));
65
- add_action('mc4wp_admin_empty_lists_cache', array( $this, 'renew_lists_cache' ));
66
- add_action('mc4wp_admin_empty_debug_log', array( $this, 'empty_debug_log' ));
67
-
68
- add_action('admin_notices', array( $this, 'show_api_key_notice' ));
69
- add_action('mc4wp_admin_dismiss_api_key_notice', array( $this, 'dismiss_api_key_notice' ));
70
- add_action('admin_enqueue_scripts', array( $this, 'enqueue_assets' ));
71
-
72
- $this->ads->add_hooks();
73
- $this->messages->add_hooks();
74
- $this->review_notice->add_hooks();
75
- }
76
-
77
- /**
78
- * Initializes various stuff used in WP Admin
79
- *
80
- * - Registers settings
81
- */
82
- public function initialize()
83
- {
84
-
85
- // register settings
86
- register_setting('mc4wp_settings', 'mc4wp', array( $this, 'save_general_settings' ));
87
-
88
- // Load upgrader
89
- $this->init_upgrade_routines();
90
-
91
- // listen for custom actions
92
- $this->listen_for_actions();
93
- }
94
-
95
-
96
- /**
97
- * Listen for `_mc4wp_action` requests
98
- */
99
- public function listen_for_actions()
100
- {
101
-
102
- // listen for any action (if user is authorised)
103
- if (! $this->tools->is_user_authorized() || ! isset($_REQUEST['_mc4wp_action'])) {
104
- return false;
105
- }
106
-
107
- $action = (string) $_REQUEST['_mc4wp_action'];
108
-
109
- /**
110
- * Allows you to hook into requests containing `_mc4wp_action` => action name.
111
- *
112
- * The dynamic portion of the hook name, `$action`, refers to the action name.
113
- *
114
- * By the time this hook is fired, the user is already authorized. After processing all the registered hooks,
115
- * the request is redirected back to the referring URL.
116
- *
117
- * @since 3.0
118
- */
119
- do_action('mc4wp_admin_' . $action);
120
-
121
- // redirect back to where we came from
122
- $redirect_url = isset($_REQUEST['_redirect_to']) ? $_REQUEST['_redirect_to'] : remove_query_arg('_mc4wp_action');
123
- if ($redirect_url) {
124
- wp_redirect($redirect_url);
125
- exit;
126
- }
127
- }
128
-
129
- /**
130
- * Register dashboard widgets
131
- */
132
- public function register_dashboard_widgets()
133
- {
134
- if (! $this->tools->is_user_authorized()) {
135
- return false;
136
- }
137
-
138
- /**
139
- * Setup dashboard widget, users are authorized by now.
140
- *
141
- * Use this hook to register your own dashboard widgets for users with the required capability.
142
- *
143
- * @since 3.0
144
- * @ignore
145
- */
146
- do_action('mc4wp_dashboard_setup');
147
-
148
- return true;
149
- }
150
-
151
- /**
152
- * Upgrade routine
153
- */
154
- private function init_upgrade_routines()
155
- {
156
-
157
- // upgrade routine for upgrade routine....
158
- $previous_version = get_option('mc4wp_lite_version', 0);
159
- if ($previous_version) {
160
- delete_option('mc4wp_lite_version');
161
- update_option('mc4wp_version', $previous_version);
162
- }
163
-
164
- $previous_version = get_option('mc4wp_version', 0);
165
-
166
- // allow setting migration version from URL, to easily re-run previous migrations.
167
- if (isset($_GET['mc4wp_run_migration'])) {
168
- $previous_version = $_GET['mc4wp_run_migration'];
169
- }
170
-
171
- // Ran upgrade routines before?
172
- if (empty($previous_version)) {
173
- update_option('mc4wp_version', MC4WP_VERSION);
174
-
175
- // if we have at least one form, we're going to run upgrade routine for v3 => v4 anyway.
176
- // TODO: Remove this once we hit 4.2.x
177
- $posts = get_posts(array( 'post_type' => 'mc4wp-form', 'numberposts' => 1 ));
178
- if (empty($posts)) {
179
- return false;
180
- }
181
-
182
- $previous_version = '3.9';
183
- }
184
-
185
- // Rollback'ed?
186
- if (version_compare($previous_version, MC4WP_VERSION, '>')) {
187
- update_option('mc4wp_version', MC4WP_VERSION);
188
- return false;
189
- }
190
-
191
- // This means we're good!
192
- if (version_compare($previous_version, MC4WP_VERSION) > -1) {
193
- return false;
194
- }
195
-
196
- define('MC4WP_DOING_UPGRADE', true);
197
- $upgrade_routines = new MC4WP_Upgrade_Routines($previous_version, MC4WP_VERSION, dirname(__FILE__) . '/migrations');
198
- $upgrade_routines->run();
199
- update_option('mc4wp_version', MC4WP_VERSION);
200
- }
201
-
202
- /**
203
- * Renew Mailchimp lists cache
204
- */
205
- public function renew_lists_cache()
206
- {
207
- // try getting new lists to fill cache again
208
- $mailchimp = new MC4WP_MailChimp();
209
- $lists = $mailchimp->refresh_lists();
210
-
211
- if (! empty($lists)) {
212
- $this->messages->flash(__('Success! The cached configuration for your Mailchimp lists has been renewed.', 'mailchimp-for-wp'));
213
- }
214
- }
215
-
216
- /**
217
- * Load the plugin translations
218
- */
219
- private function load_translations()
220
- {
221
- // load the plugin text domain
222
- load_plugin_textdomain('mailchimp-for-wp', false, dirname($this->plugin_file) . '/languages');
223
- }
224
-
225
- /**
226
- * Customize texts throughout WP Admin
227
- */
228
- public function customize_admin_texts()
229
- {
230
- $texts = new MC4WP_Admin_Texts($this->plugin_file);
231
- $texts->add_hooks();
232
- }
233
-
234
- /**
235
- * Validates the General settings
236
- * @param array $settings
237
- * @return array
238
- */
239
- public function save_general_settings(array $settings)
240
- {
241
- $current = mc4wp_get_options();
242
-
243
- // merge with current settings to allow passing partial arrays to this method
244
- $settings = array_merge($current, $settings);
245
-
246
- // toggle usage tracking
247
- if ($settings['allow_usage_tracking'] !== $current['allow_usage_tracking']) {
248
- MC4WP_Usage_Tracking::instance()->toggle($settings['allow_usage_tracking']);
249
- }
250
-
251
- // Make sure not to use obfuscated key
252
- if (strpos($settings['api_key'], '*') !== false) {
253
- $settings['api_key'] = $current['api_key'];
254
- }
255
-
256
- // Sanitize API key
257
- $settings['api_key'] = sanitize_text_field($settings['api_key']);
258
-
259
- // if API key changed, empty Mailchimp cache
260
- if ($settings['api_key'] !== $current['api_key']) {
261
- $mailchimp = new MC4WP_MailChimp();
262
- $mailchimp->refresh_lists();
263
- }
264
-
265
-
266
- /**
267
- * Runs right before general settings are saved.
268
- *
269
- * @param array $settings The updated settings array
270
- * @param array $current The old settings array
271
- */
272
- do_action('mc4wp_save_settings', $settings, $current);
273
-
274
- return $settings;
275
- }
276
-
277
- /**
278
- * Load scripts and stylesheet on Mailchimp for WP Admin pages
279
- *
280
- * @return bool
281
- */
282
- public function enqueue_assets()
283
- {
284
- global $wp_scripts;
285
-
286
-
287
- if (! $this->tools->on_plugin_page()) {
288
- return false;
289
- }
290
-
291
- $opts = mc4wp_get_options();
292
- $page = $this->tools->get_plugin_page();
293
- $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
294
- $mailchimp = new MC4WP_MailChimp();
295
-
296
- // css
297
- wp_register_style('mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/css/admin-styles' . $suffix . '.css', array(), MC4WP_VERSION);
298
- wp_enqueue_style('mc4wp-admin');
299
-
300
- // js
301
- wp_register_script('es5-shim', MC4WP_PLUGIN_URL . 'assets/js/third-party/es5-shim.min.js', array(), MC4WP_VERSION);
302
- $wp_scripts->add_data('es5-shim', 'conditional', 'lt IE 9');
303
-
304
- wp_register_script('mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('es5-shim'), MC4WP_VERSION, true);
305
- wp_enqueue_script('mc4wp-admin');
306
- wp_localize_script(
307
- 'mc4wp-admin',
308
- 'mc4wp_vars',
309
- array(
310
- 'ajaxurl' => admin_url('admin-ajax.php'),
311
- 'mailchimp' => array(
312
- 'api_connected' => ! empty($opts['api_key']),
313
- 'lists' => $mailchimp->get_lists()
314
- ),
315
- 'countries' => MC4WP_Tools::get_countries(),
316
- 'i18n' => array(
317
- 'invalid_api_key' => __('The given value does not look like a valid Mailchimp API key.', 'mailchimp-for-wp'),
318
- 'pro_only' => __('This is a premium feature. Please upgrade to Mailchimp for WordPress Premium to be able to use it.', 'mailchimp-for-wp'),
319
- 'renew_mailchimp_lists' => __('Renew Mailchimp lists', 'mailchimp-for-wp'),
320
- 'fetching_mailchimp_lists' => __('Fetching Mailchimp lists', 'mailchimp-for-wp'),
321
- 'fetching_mailchimp_lists_done' => __('Done! Mailchimp lists renewed.', 'mailchimp-for-wp'),
322
- 'fetching_mailchimp_lists_error' => __('Failed to renew your lists. An error occured.', 'mailchimp-for-wp'),
323
- )
324
- )
325
- );
326
-
327
- /**
328
- * Hook to enqueue your own custom assets on the Mailchimp for WordPress setting pages.
329
- *
330
- * @since 3.0
331
- *
332
- * @param string $suffix
333
- * @param string $page
334
- */
335
- do_action('mc4wp_admin_enqueue_assets', $suffix, $page);
336
-
337
- return true;
338
- }
339
-
340
-
341
-
342
- /**
343
- * Register the setting pages and their menu items
344
- */
345
- public function build_menu()
346
- {
347
- $required_cap = $this->tools->get_required_capability();
348
-
349
- $menu_items = array(
350
- array(
351
- 'title' => __('Mailchimp API Settings', 'mailchimp-for-wp'),
352
- 'text' => __('Mailchimp', 'mailchimp-for-wp'),
353
- 'slug' => '',
354
- 'callback' => array( $this, 'show_generals_setting_page' ),
355
- 'position' => 0
356
- ),
357
- array(
358
- 'title' => __('Other Settings', 'mailchimp-for-wp'),
359
- 'text' => __('Other', 'mailchimp-for-wp'),
360
- 'slug' => 'other',
361
- 'callback' => array( $this, 'show_other_setting_page' ),
362
- 'position' => 90
363
- ),
364
-
365
- );
366
-
367
- /**
368
- * Filters the menu items to appear under the main menu item.
369
- *
370
- * To add your own item, add an associative array in the following format.
371
- *
372
- * $menu_items[] = array(
373
- * 'title' => 'Page title',
374
- * 'text' => 'Menu text',
375
- * 'slug' => 'Page slug',
376
- * 'callback' => 'my_page_function',
377
- * 'position' => 50
378
- * );
379
- *
380
- * @param array $menu_items
381
- * @since 3.0
382
- */
383
- $menu_items = (array) apply_filters('mc4wp_admin_menu_items', $menu_items);
384
-
385
- // add top menu item
386
- $icon = file_get_contents(MC4WP_PLUGIN_DIR . 'assets/img/icon.svg');
387
- add_menu_page('Mailchimp for WP', 'MC4WP', $required_cap, 'mailchimp-for-wp', array( $this, 'show_generals_setting_page' ), 'data:image/svg+xml;base64,'.base64_encode($icon), '99.68491');
388
-
389
- // sort submenu items by 'position'
390
- usort($menu_items, array( $this, 'sort_menu_items_by_position' ));
391
-
392
- // add sub-menu items
393
- foreach ($menu_items as $item) {
394
- $this->add_menu_item($item);
395
- }
396
- }
397
-
398
- /**
399
- * @param array $item
400
- */
401
- public function add_menu_item(array $item)
402
- {
403
-
404
- // generate menu slug
405
- $slug = 'mailchimp-for-wp';
406
- if (! empty($item['slug'])) {
407
- $slug .= '-' . $item['slug'];
408
- }
409
-
410
- // provide some defaults
411
- $parent_slug = ! empty($item['parent_slug']) ? $item['parent_slug'] : 'mailchimp-for-wp';
412
- $capability = ! empty($item['capability']) ? $item['capability'] : $this->tools->get_required_capability();
413
-
414
- // register page
415
- $hook = add_submenu_page($parent_slug, $item['title'] . ' - Mailchimp for WordPress', $item['text'], $capability, $slug, $item['callback']);
416
-
417
- // register callback for loading this page, if given
418
- if (array_key_exists('load_callback', $item)) {
419
- add_action('load-' . $hook, $item['load_callback']);
420
- }
421
- }
422
-
423
- /**
424
- * Show the API Settings page
425
- */
426
- public function show_generals_setting_page()
427
- {
428
- $opts = mc4wp_get_options();
429
- $api_key = mc4wp_get_api_key();
430
- $lists = array();
431
- $connected = ! empty($api_key);
432
-
433
- if ($connected) {
434
- try {
435
- $connected = $this->get_api()->is_connected();
436
- $mailchimp = new MC4WP_MailChimp();
437
- $lists = $mailchimp->get_lists();
438
- } catch (MC4WP_API_Connection_Exception $e) {
439
- $message = sprintf("<strong>%s</strong> %s %s ", __("Error connecting to Mailchimp:", 'mailchimp-for-wp'), $e->getCode(), $e->getMessage());
440
-
441
- if (is_object($e->data) && ! empty($e->data->ref_no)) {
442
- $message .= '<br />' . sprintf(__('Looks like your server is blocked by Mailchimp\'s firewall. Please contact Mailchimp support and include the following reference number: %s', 'mailchimp-for-wp'), $e->data->ref_no);
443
- }
444
-
445
- $message .= '<br /><br />' . sprintf('<a href="%s">' . __('Here\'s some info on solving common connectivity issues.', 'mailchimp-for-wp') . '</a>', 'https://kb.mc4wp.com/solving-connectivity-issues/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=settings-notice');
446
-
447
- $this->messages->flash($message, 'error');
448
- $connected = false;
449
- } catch (MC4WP_API_Exception $e) {
450
- $this->messages->flash(sprintf("<strong>%s</strong><br /> %s", __("Mailchimp returned the following error:", 'mailchimp-for-wp'), $e), 'error');
451
- $connected = false;
452
- }
453
- }
454
-
455
- $obfuscated_api_key = mc4wp_obfuscate_string($api_key);
456
- require MC4WP_PLUGIN_DIR . 'includes/views/general-settings.php';
457
- }
458
-
459
- /**
460
- * Show the Other Settings page
461
- */
462
- public function show_other_setting_page()
463
- {
464
- $opts = mc4wp_get_options();
465
- $log = $this->get_log();
466
- $log_reader = new MC4WP_Debug_Log_Reader($log->file);
467
- require MC4WP_PLUGIN_DIR . 'includes/views/other-settings.php';
468
- }
469
-
470
- /**
471
- * @param $a
472
- * @param $b
473
- *
474
- * @return int
475
- */
476
- public function sort_menu_items_by_position($a, $b)
477
- {
478
- $pos_a = isset($a['position']) ? $a['position'] : 80;
479
- $pos_b = isset($b['position']) ? $b['position'] : 90;
480
- return $pos_a < $pos_b ? -1 : 1;
481
- }
482
-
483
- /**
484
- * Empties the log file
485
- */
486
- public function empty_debug_log()
487
- {
488
- $log = $this->get_log();
489
- file_put_contents($log->file, '');
490
-
491
- $this->messages->flash(__('Log successfully emptied.', 'mailchimp-for-wp'));
492
- }
493
-
494
- /**
495
- * Shows a notice when API key is not set.
496
- */
497
- public function show_api_key_notice()
498
- {
499
-
500
- // don't show if on settings page already
501
- if ($this->tools->on_plugin_page('')) {
502
- return;
503
- }
504
-
505
- // only show to user with proper permissions
506
- if (! $this->tools->is_user_authorized()) {
507
- return;
508
- }
509
-
510
- // don't show if dismissed
511
- if (get_transient('mc4wp_api_key_notice_dismissed')) {
512
- return;
513
- }
514
-
515
- // don't show if api key is set already
516
- $api_key = mc4wp_get_api_key();
517
- if (! empty($api_key)) {
518
- return;
519
- }
520
-
521
- echo '<div class="notice notice-warning mc4wp-is-dismissible">';
522
- echo '<p>' . sprintf(__('To get started with Mailchimp for WordPress, please <a href="%s">enter your Mailchimp API key on the settings page of the plugin</a>.', 'mailchimp-for-wp'), admin_url('admin.php?page=mailchimp-for-wp')) . '</p>';
523
- echo '<form method="post"><input type="hidden" name="_mc4wp_action" value="dismiss_api_key_notice" /><button type="submit" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></form>';
524
- echo '</div>';
525
- }
526
-
527
- /**
528
- * Dismisses the API key notice for 1 week
529
- */
530
- public function dismiss_api_key_notice()
531
- {
532
- set_transient('mc4wp_api_key_notice_dismissed', 1, 3600 * 24 * 7);
533
- }
534
-
535
- /**
536
- * @return MC4WP_Debug_Log
537
- */
538
- protected function get_log()
539
- {
540
- return mc4wp('log');
541
- }
542
-
543
- /**
544
- * @return MC4WP_API_v3
545
- */
546
- protected function get_api()
547
- {
548
- return mc4wp('api');
549
- }
550
  }
6
  * @ignore
7
  * @access private
8
  */
9
+ class MC4WP_Admin {
10
+
11
+
12
+ /**
13
+ * @var string The relative path to the main plugin file from the plugins dir
14
+ */
15
+ protected $plugin_file;
16
+
17
+ /**
18
+ * @var MC4WP_Admin_Messages
19
+ */
20
+ protected $messages;
21
+
22
+ /**
23
+ * @var MC4WP_Admin_Ads
24
+ */
25
+ protected $ads;
26
+
27
+ /**
28
+ * @var MC4WP_Admin_Tools
29
+ */
30
+ protected $tools;
31
+
32
+ /**
33
+ * @var MC4WP_Admin_Review_Notice
34
+ */
35
+ protected $review_notice;
36
+
37
+ /**
38
+ * Constructor
39
+ *
40
+ * @param MC4WP_Admin_Tools $tools
41
+ * @param MC4WP_Admin_Messages $messages
42
+ */
43
+ public function __construct( MC4WP_Admin_Tools $tools, MC4WP_Admin_Messages $messages ) {
44
+ $this->tools = $tools;
45
+ $this->messages = $messages;
46
+ $this->plugin_file = plugin_basename( MC4WP_PLUGIN_FILE );
47
+ $this->ads = new MC4WP_Admin_Ads();
48
+ $this->review_notice = new MC4WP_Admin_Review_Notice( $tools );
49
+ }
50
+
51
+ /**
52
+ * Registers all hooks
53
+ */
54
+ public function add_hooks() {
55
+
56
+ // Actions used globally throughout WP Admin
57
+ add_action( 'admin_menu', array( $this, 'build_menu' ) );
58
+ add_action( 'admin_init', array( $this, 'initialize' ) );
59
+
60
+ add_action( 'current_screen', array( $this, 'customize_admin_texts' ) );
61
+ add_action( 'wp_dashboard_setup', array( $this, 'register_dashboard_widgets' ) );
62
+ add_action( 'mc4wp_admin_empty_lists_cache', array( $this, 'renew_lists_cache' ) );
63
+ add_action( 'mc4wp_admin_empty_debug_log', array( $this, 'empty_debug_log' ) );
64
+
65
+ add_action( 'admin_notices', array( $this, 'show_api_key_notice' ) );
66
+ add_action( 'mc4wp_admin_dismiss_api_key_notice', array( $this, 'dismiss_api_key_notice' ) );
67
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
68
+
69
+ $this->ads->add_hooks();
70
+ $this->messages->add_hooks();
71
+ $this->review_notice->add_hooks();
72
+ }
73
+
74
+ /**
75
+ * Initializes various stuff used in WP Admin
76
+ *
77
+ * - Registers settings
78
+ */
79
+ public function initialize() {
80
+
81
+ // register settings
82
+ register_setting( 'mc4wp_settings', 'mc4wp', array( $this, 'save_general_settings' ) );
83
+
84
+ // Load upgrader
85
+ $this->init_upgrade_routines();
86
+
87
+ // listen for custom actions
88
+ $this->listen_for_actions();
89
+ }
90
+
91
+
92
+ /**
93
+ * Listen for `_mc4wp_action` requests
94
+ */
95
+ public function listen_for_actions() {
96
+
97
+ // listen for any action (if user is authorised)
98
+ if ( ! $this->tools->is_user_authorized() || ! isset( $_REQUEST['_mc4wp_action'] ) ) {
99
+ return false;
100
+ }
101
+
102
+ $action = (string) $_REQUEST['_mc4wp_action'];
103
+
104
+ /**
105
+ * Allows you to hook into requests containing `_mc4wp_action` => action name.
106
+ *
107
+ * The dynamic portion of the hook name, `$action`, refers to the action name.
108
+ *
109
+ * By the time this hook is fired, the user is already authorized. After processing all the registered hooks,
110
+ * the request is redirected back to the referring URL.
111
+ *
112
+ * @since 3.0
113
+ */
114
+ do_action( 'mc4wp_admin_' . $action );
115
+
116
+ // redirect back to where we came from
117
+ $redirect_url = isset( $_REQUEST['_redirect_to'] ) ? $_REQUEST['_redirect_to'] : remove_query_arg( '_mc4wp_action' );
118
+ if ( $redirect_url ) {
119
+ wp_redirect( $redirect_url );
120
+ exit;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Register dashboard widgets
126
+ */
127
+ public function register_dashboard_widgets() {
128
+ if ( ! $this->tools->is_user_authorized() ) {
129
+ return false;
130
+ }
131
+
132
+ /**
133
+ * Setup dashboard widget, users are authorized by now.
134
+ *
135
+ * Use this hook to register your own dashboard widgets for users with the required capability.
136
+ *
137
+ * @since 3.0
138
+ * @ignore
139
+ */
140
+ do_action( 'mc4wp_dashboard_setup' );
141
+
142
+ return true;
143
+ }
144
+
145
+ /**
146
+ * Upgrade routine
147
+ */
148
+ private function init_upgrade_routines() {
149
+
150
+ // upgrade routine for upgrade routine....
151
+ $previous_version = get_option( 'mc4wp_lite_version', 0 );
152
+ if ( $previous_version ) {
153
+ delete_option( 'mc4wp_lite_version' );
154
+ update_option( 'mc4wp_version', $previous_version );
155
+ }
156
+
157
+ $previous_version = get_option( 'mc4wp_version', 0 );
158
+
159
+ // allow setting migration version from URL, to easily re-run previous migrations.
160
+ if ( isset( $_GET['mc4wp_run_migration'] ) ) {
161
+ $previous_version = $_GET['mc4wp_run_migration'];
162
+ }
163
+
164
+ // Ran upgrade routines before?
165
+ if ( empty( $previous_version ) ) {
166
+ update_option( 'mc4wp_version', MC4WP_VERSION );
167
+
168
+ // if we have at least one form, we're going to run upgrade routine for v3 => v4 anyway.
169
+ // TODO: Remove this once we hit 4.2.x
170
+ $posts = get_posts(
171
+ array(
172
+ 'post_type' => 'mc4wp-form',
173
+ 'numberposts' => 1,
174
+ )
175
+ );
176
+ if ( empty( $posts ) ) {
177
+ return false;
178
+ }
179
+
180
+ $previous_version = '3.9';
181
+ }
182
+
183
+ // Rollback'ed?
184
+ if ( version_compare( $previous_version, MC4WP_VERSION, '>' ) ) {
185
+ update_option( 'mc4wp_version', MC4WP_VERSION );
186
+ return false;
187
+ }
188
+
189
+ // This means we're good!
190
+ if ( version_compare( $previous_version, MC4WP_VERSION ) > -1 ) {
191
+ return false;
192
+ }
193
+
194
+ define( 'MC4WP_DOING_UPGRADE', true );
195
+ $upgrade_routines = new MC4WP_Upgrade_Routines( $previous_version, MC4WP_VERSION, dirname( __FILE__ ) . '/migrations' );
196
+ $upgrade_routines->run();
197
+ update_option( 'mc4wp_version', MC4WP_VERSION );
198
+ }
199
+
200
+ /**
201
+ * Renew Mailchimp lists cache
202
+ */
203
+ public function renew_lists_cache() {
204
+ // try getting new lists to fill cache again
205
+ $mailchimp = new MC4WP_MailChimp();
206
+ $lists = $mailchimp->refresh_lists();
207
+
208
+ if ( ! empty( $lists ) ) {
209
+ $this->messages->flash( __( 'Success! The cached configuration for your Mailchimp lists has been renewed.', 'mailchimp-for-wp' ) );
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Customize texts throughout WP Admin
215
+ */
216
+ public function customize_admin_texts() {
217
+ $texts = new MC4WP_Admin_Texts( $this->plugin_file );
218
+ $texts->add_hooks();
219
+ }
220
+
221
+ /**
222
+ * Validates the General settings
223
+ * @param array $settings
224
+ * @return array
225
+ */
226
+ public function save_general_settings( array $settings ) {
227
+ $current = mc4wp_get_options();
228
+
229
+ // merge with current settings to allow passing partial arrays to this method
230
+ $settings = array_merge( $current, $settings );
231
+
232
+ // toggle usage tracking
233
+ if ( $settings['allow_usage_tracking'] !== $current['allow_usage_tracking'] ) {
234
+ MC4WP_Usage_Tracking::instance()->toggle( $settings['allow_usage_tracking'] );
235
+ }
236
+
237
+ // Make sure not to use obfuscated key
238
+ if ( strpos( $settings['api_key'], '*' ) !== false ) {
239
+ $settings['api_key'] = $current['api_key'];
240
+ }
241
+
242
+ // Sanitize API key
243
+ $settings['api_key'] = sanitize_text_field( $settings['api_key'] );
244
+
245
+ // if API key changed, empty Mailchimp cache
246
+ if ( $settings['api_key'] !== $current['api_key'] ) {
247
+ $mailchimp = new MC4WP_MailChimp();
248
+ $mailchimp->refresh_lists();
249
+ }
250
+
251
+ /**
252
+ * Runs right before general settings are saved.
253
+ *
254
+ * @param array $settings The updated settings array
255
+ * @param array $current The old settings array
256
+ */
257
+ do_action( 'mc4wp_save_settings', $settings, $current );
258
+
259
+ return $settings;
260
+ }
261
+
262
+ /**
263
+ * Load scripts and stylesheet on Mailchimp for WP Admin pages
264
+ *
265
+ * @return bool
266
+ */
267
+ public function enqueue_assets() {
268
+ global $wp_scripts;
269
+
270
+ if ( ! $this->tools->on_plugin_page() ) {
271
+ return false;
272
+ }
273
+
274
+ $opts = mc4wp_get_options();
275
+ $page = $this->tools->get_plugin_page();
276
+ $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
277
+ $mailchimp = new MC4WP_MailChimp();
278
+
279
+ // css
280
+ wp_register_style( 'mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/css/admin-styles' . $suffix . '.css', array(), MC4WP_VERSION );
281
+ wp_enqueue_style( 'mc4wp-admin' );
282
+
283
+ // js
284
+ wp_register_script( 'es5-shim', MC4WP_PLUGIN_URL . 'assets/js/third-party/es5-shim.min.js', array(), MC4WP_VERSION );
285
+ $wp_scripts->add_data( 'es5-shim', 'conditional', 'lt IE 9' );
286
+
287
+ wp_register_script( 'mc4wp-admin', MC4WP_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'es5-shim' ), MC4WP_VERSION, true );
288
+ wp_enqueue_script( 'mc4wp-admin' );
289
+ wp_localize_script(
290
+ 'mc4wp-admin',
291
+ 'mc4wp_vars',
292
+ array(
293
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
294
+ 'mailchimp' => array(
295
+ 'api_connected' => ! empty( $opts['api_key'] ),
296
+ 'lists' => $mailchimp->get_lists(),
297
+ ),
298
+ 'countries' => MC4WP_Tools::get_countries(),
299
+ 'i18n' => array(
300
+ 'invalid_api_key' => __( 'The given value does not look like a valid Mailchimp API key.', 'mailchimp-for-wp' ),
301
+ 'pro_only' => __( 'This is a premium feature. Please upgrade to Mailchimp for WordPress Premium to be able to use it.', 'mailchimp-for-wp' ),
302
+ 'renew_mailchimp_lists' => __( 'Renew Mailchimp lists', 'mailchimp-for-wp' ),
303
+ 'fetching_mailchimp_lists' => __( 'Fetching Mailchimp lists', 'mailchimp-for-wp' ),
304
+ 'fetching_mailchimp_lists_done' => __( 'Done! Mailchimp lists renewed.', 'mailchimp-for-wp' ),
305
+ 'fetching_mailchimp_lists_error' => __( 'Failed to renew your lists. An error occured.', 'mailchimp-for-wp' ),
306
+ ),
307
+ )
308
+ );
309
+
310
+ /**
311
+ * Hook to enqueue your own custom assets on the Mailchimp for WordPress setting pages.
312
+ *
313
+ * @since 3.0
314
+ *
315
+ * @param string $suffix
316
+ * @param string $page
317
+ */
318
+ do_action( 'mc4wp_admin_enqueue_assets', $suffix, $page );
319
+
320
+ return true;
321
+ }
322
+
323
+
324
+
325
+ /**
326
+ * Register the setting pages and their menu items
327
+ */
328
+ public function build_menu() {
329
+ $required_cap = $this->tools->get_required_capability();
330
+
331
+ $menu_items = array(
332
+ array(
333
+ 'title' => __( 'Mailchimp API Settings', 'mailchimp-for-wp' ),
334
+ 'text' => __( 'Mailchimp', 'mailchimp-for-wp' ),
335
+ 'slug' => '',
336
+ 'callback' => array( $this, 'show_generals_setting_page' ),
337
+ 'position' => 0,
338
+ ),
339
+ array(
340
+ 'title' => __( 'Other Settings', 'mailchimp-for-wp' ),
341
+ 'text' => __( 'Other', 'mailchimp-for-wp' ),
342
+ 'slug' => 'other',
343
+ 'callback' => array( $this, 'show_other_setting_page' ),
344
+ 'position' => 90,
345
+ ),
346
+
347
+ );
348
+
349
+ /**
350
+ * Filters the menu items to appear under the main menu item.
351
+ *
352
+ * To add your own item, add an associative array in the following format.
353
+ *
354
+ * $menu_items[] = array(
355
+ * 'title' => 'Page title',
356
+ * 'text' => 'Menu text',
357
+ * 'slug' => 'Page slug',
358
+ * 'callback' => 'my_page_function',
359
+ * 'position' => 50
360
+ * );
361
+ *
362
+ * @param array $menu_items
363
+ * @since 3.0
364
+ */
365
+ $menu_items = (array) apply_filters( 'mc4wp_admin_menu_items', $menu_items );
366
+
367
+ // add top menu item
368
+ $icon = file_get_contents( MC4WP_PLUGIN_DIR . 'assets/img/icon.svg' );
369
+ add_menu_page( 'Mailchimp for WP', 'MC4WP', $required_cap, 'mailchimp-for-wp', array( $this, 'show_generals_setting_page' ), 'data:image/svg+xml;base64,' . base64_encode( $icon ), '99.68491' );
370
+
371
+ // sort submenu items by 'position'
372
+ usort( $menu_items, array( $this, 'sort_menu_items_by_position' ) );
373
+
374
+ // add sub-menu items
375
+ foreach ( $menu_items as $item ) {
376
+ $this->add_menu_item( $item );
377
+ }
378
+ }
379
+
380
+ /**
381
+ * @param array $item
382
+ */
383
+ public function add_menu_item( array $item ) {
384
+
385
+ // generate menu slug
386
+ $slug = 'mailchimp-for-wp';
387
+ if ( ! empty( $item['slug'] ) ) {
388
+ $slug .= '-' . $item['slug'];
389
+ }
390
+
391
+ // provide some defaults
392
+ $parent_slug = ! empty( $item['parent_slug'] ) ? $item['parent_slug'] : 'mailchimp-for-wp';
393
+ $capability = ! empty( $item['capability'] ) ? $item['capability'] : $this->tools->get_required_capability();
394
+
395
+ // register page
396
+ $hook = add_submenu_page( $parent_slug, $item['title'] . ' - Mailchimp for WordPress', $item['text'], $capability, $slug, $item['callback'] );
397
+
398
+ // register callback for loading this page, if given
399
+ if ( array_key_exists( 'load_callback', $item ) ) {
400
+ add_action( 'load-' . $hook, $item['load_callback'] );
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Show the API Settings page
406
+ */
407
+ public function show_generals_setting_page() {
408
+ $opts = mc4wp_get_options();
409
+ $api_key = mc4wp_get_api_key();
410
+ $lists = array();
411
+ $connected = ! empty( $api_key );
412
+
413
+ if ( $connected ) {
414
+ try {
415
+ $connected = $this->get_api()->is_connected();
416
+ $mailchimp = new MC4WP_MailChimp();
417
+ $lists = $mailchimp->get_lists();
418
+ } catch ( MC4WP_API_Connection_Exception $e ) {
419
+ $message = sprintf( '<strong>%s</strong> %s %s ', __( 'Error connecting to Mailchimp:', 'mailchimp-for-wp' ), $e->getCode(), $e->getMessage() );
420
+
421
+ if ( is_object( $e->data ) && ! empty( $e->data->ref_no ) ) {
422
+ $message .= '<br />' . sprintf( __( 'Looks like your server is blocked by Mailchimp\'s firewall. Please contact Mailchimp support and include the following reference number: %s', 'mailchimp-for-wp' ), $e->data->ref_no );
423
+ }
424
+
425
+ $message .= '<br /><br />' . sprintf( '<a href="%s">' . __( 'Here\'s some info on solving common connectivity issues.', 'mailchimp-for-wp' ) . '</a>', 'https://kb.mc4wp.com/solving-connectivity-issues/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=settings-notice' );
426
+
427
+ $this->messages->flash( $message, 'error' );
428
+ $connected = false;
429
+ } catch ( MC4WP_API_Exception $e ) {
430
+ $this->messages->flash( sprintf( '<strong>%s</strong><br /> %s', __( 'Mailchimp returned the following error:', 'mailchimp-for-wp' ), $e ), 'error' );
431
+ $connected = false;
432
+ }
433
+ }
434
+
435
+ $obfuscated_api_key = mc4wp_obfuscate_string( $api_key );
436
+ require MC4WP_PLUGIN_DIR . 'includes/views/general-settings.php';
437
+ }
438
+
439
+ /**
440
+ * Show the Other Settings page
441
+ */
442
+ public function show_other_setting_page() {
443
+ $opts = mc4wp_get_options();
444
+ $log = $this->get_log();
445
+ $log_reader = new MC4WP_Debug_Log_Reader( $log->file );
446
+ require MC4WP_PLUGIN_DIR . 'includes/views/other-settings.php';
447
+ }
448
+
449
+ /**
450
+ * @param $a
451
+ * @param $b
452
+ *
453
+ * @return int
454
+ */
455
+ public function sort_menu_items_by_position( $a, $b ) {
456
+ $pos_a = isset( $a['position'] ) ? $a['position'] : 80;
457
+ $pos_b = isset( $b['position'] ) ? $b['position'] : 90;
458
+ return $pos_a < $pos_b ? -1 : 1;
459
+ }
460
+
461
+ /**
462
+ * Empties the log file
463
+ */
464
+ public function empty_debug_log() {
465
+ $log = $this->get_log();
466
+ file_put_contents( $log->file, '' );
467
+
468
+ $this->messages->flash( __( 'Log successfully emptied.', 'mailchimp-for-wp' ) );
469
+ }
470
+
471
+ /**
472
+ * Shows a notice when API key is not set.
473
+ */
474
+ public function show_api_key_notice() {
475
+
476
+ // don't show if on settings page already
477
+ if ( $this->tools->on_plugin_page( '' ) ) {
478
+ return;
479
+ }
480
+
481
+ // only show to user with proper permissions
482
+ if ( ! $this->tools->is_user_authorized() ) {
483
+ return;
484
+ }
485
+
486
+ // don't show if dismissed
487
+ if ( get_transient( 'mc4wp_api_key_notice_dismissed' ) ) {
488
+ return;
489
+ }
490
+
491
+ // don't show if api key is set already
492
+ $api_key = mc4wp_get_api_key();
493
+ if ( ! empty( $api_key ) ) {
494
+ return;
495
+ }
496
+
497
+ echo '<div class="notice notice-warning mc4wp-is-dismissible">';
498
+ echo '<p>' . sprintf( __( 'To get started with Mailchimp for WordPress, please <a href="%s">enter your Mailchimp API key on the settings page of the plugin</a>.', 'mailchimp-for-wp' ), admin_url( 'admin.php?page=mailchimp-for-wp' ) ) . '</p>';
499
+ echo '<form method="post"><input type="hidden" name="_mc4wp_action" value="dismiss_api_key_notice" /><button type="submit" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></form>';
500
+ echo '</div>';
501
+ }
502
+
503
+ /**
504
+ * Dismisses the API key notice for 1 week
505
+ */
506
+ public function dismiss_api_key_notice() {
507
+ set_transient( 'mc4wp_api_key_notice_dismissed', 1, 3600 * 24 * 7 );
508
+ }
509
+
510
+ /**
511
+ * @return MC4WP_Debug_Log
512
+ */
513
+ protected function get_log() {
514
+ return mc4wp( 'log' );
515
+ }
516
+
517
+ /**
518
+ * @return MC4WP_API_V3
519
+ */
520
+ protected function get_api() {
521
+ return mc4wp( 'api' );
522
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  }
includes/admin/class-ads.php CHANGED
@@ -6,145 +6,138 @@
6
  * @ignore
7
  * @access private
8
  */
9
- class MC4WP_Admin_Ads
10
- {
11
-
12
- /**
13
- * @return bool Adds hooks
14
- */
15
- public function add_hooks()
16
- {
17
-
18
- // don't hook if Premium is activated
19
- if (defined('MC4WP_PREMIUM_VERSION')) {
20
- return false;
21
- }
22
-
23
- add_filter('mc4wp_admin_plugin_meta_links', array( $this, 'plugin_meta_links' ));
24
- add_action('mc4wp_admin_form_after_behaviour_settings_rows', array( $this, 'after_form_settings_rows' ));
25
- add_action('mc4wp_admin_form_after_appearance_settings_rows', array( $this, 'after_form_appearance_settings_rows' ));
26
- add_action('mc4wp_admin_sidebar', array( $this, 'admin_sidebar' ));
27
- add_action('mc4wp_admin_footer', array( $this, 'admin_footer' ));
28
- add_action('mc4wp_admin_other_settings', array( $this, 'ecommerce' ), 90);
29
-
30
- add_filter('mc4wp_admin_menu_items', array( $this, 'add_menu_item' ));
31
-
32
- add_action('mc4wp_admin_after_woocommerce_integration_settings', array( $this, 'ecommerce' ));
33
- return true;
34
- }
35
-
36
- public function add_menu_item($items)
37
- {
38
- $items['extensions'] = array(
39
- 'title' => __('Add-ons', 'mailchimp-for-wp'),
40
- 'text' => __('Add-ons', 'mailchimp-for-wp'),
41
- 'slug' => 'extensions',
42
- 'callback' => array( $this, 'show_extensions_page' ),
43
- 'position' => 100
44
- );
45
-
46
- return $items;
47
- }
48
-
49
- /**
50
- * Add text row to "Form > Appearance" tab.
51
- */
52
- public function after_form_appearance_settings_rows()
53
- {
54
- echo '<tr valign="top">';
55
- echo '<td colspan="2">';
56
- echo '<p class="help">';
57
- echo sprintf(__('Want to customize the style of your form? <a href="%s">Try our Styles Builder</a> & edit the look of your forms with just a few clicks.', 'mailchimp-for-wp'), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=form-settings-link');
58
- echo '</p>';
59
- echo '</td>';
60
- echo '</tr>';
61
- }
62
-
63
- /**
64
- * Add text row to "Form > Settings" tab.
65
- */
66
- public function after_form_settings_rows()
67
- {
68
- echo '<tr valign="top">';
69
- echo '<td colspan="2">';
70
- echo '<p class="help">';
71
-
72
- if (rand(1, 2) === 1) {
73
- echo sprintf(__('Be notified whenever someone subscribes? <a href="%s">Mailchimp for WordPress Premium</a> allows you to set up email notifications for your forms.', 'mailchimp-for-wp'), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link');
74
- } else {
75
- echo sprintf(__('Increased conversions? <a href="%s">Mailchimp for WordPress Premium</a> submits forms without reloading the entire page, resulting in a much better experience for your visitors.', 'mailchimp-for-wp'), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=form-settings-link');
76
- }
77
-
78
- echo '</p>';
79
- echo '</td>';
80
- echo '</tr>';
81
- }
82
-
83
- /**
84
- * @param array $links
85
- *
86
- * @return array
87
- */
88
- public function plugin_meta_links($links)
89
- {
90
- $links[] = '<a href="https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-upgrade-link">' . __('Upgrade to Premium', 'mailchimp-for-wp') . '</a>';
91
- return $links;
92
- }
93
-
94
- /**
95
- * Add several texts to admin footer.
96
- */
97
- public function admin_footer()
98
- {
99
- if (isset($_GET['view']) && $_GET['view'] === 'edit-form') {
100
-
101
- // WPML & Polylang specific message
102
- if (defined('ICL_LANGUAGE_CODE')) {
103
- echo '<p class="help">' . sprintf(__('Do you want translated forms for all of your languages? <a href="%s">Try Mailchimp for WordPress Premium</a>, which does just that plus more.', 'mailchimp-for-wp'), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link') . '</p>';
104
- return;
105
- }
106
-
107
- // General "edit form" message
108
- echo '<p class="help">' . sprintf(__('Do you want to create more than one form? Our Premium add-on does just that! <a href="%s">Have a look at all Premium benefits</a>.', 'mailchimp-for-wp'), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link') . '</p>';
109
- return;
110
- }
111
-
112
- // General message
113
- echo '<p class="help">' . sprintf(__('Are you enjoying this plugin? The Premium add-on unlocks several powerful features. <a href="%s">Find out about all benefits now</a>.', 'mailchimp-for-wp'), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link') . '</p>';
114
- }
115
-
116
- /**
117
- * Add email opt-in form to sidebar
118
- */
119
- public function admin_sidebar()
120
- {
121
- echo '<div class="mc4wp-box">';
122
- echo '<div style="border: 5px dotted #cc4444; padding: 0 20px; background: white;">';
123
- echo '<h3>Mailchimp for WordPress Premium</h3>';
124
- echo '<p>This plugin has a Premium add-on, unlocking several powerful features. <a href="https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=upgrade-box">Have a look at its benefits</a>!</p>';
125
- echo '</div>';
126
- echo '</div>'; ?>
127
  <div class="mc4wp-box" id="mc4wp-optin-box">
128
 
129
  <?php $user = wp_get_current_user(); ?>
130
  <!-- Begin Mailchimp Signup Form -->
131
  <div id="mc_embed_signup">
132
- <h4 class="mc4wp-title"><?php _e('More subscribers, better newsletters.', 'mailchimp-for-wp'); ?></h4>
133
- <p><?php _e('Learn how to best grow your lists & write better emails by subscribing to our monthly tips.', 'mailchimp-for-wp'); ?></p>
134
  <form action="//mc4wp.us1.list-manage.com/subscribe/post?u=a2d08947dcd3683512ce174c5&amp;id=a940232df9" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" target="_blank">
135
  <p>
136
- <label for="mc4wp-email"><?php _e('Email Address', 'mailchimp-for-wp'); ?></label>
137
- <input type="email" value="<?php echo esc_attr($user->user_email); ?>" name="EMAIL" class="regular-text" id="mc4wp-email" required>
138
  </p>
139
  <p>
140
- <label for="mc4wp-fname"><?php _e('First Name', 'mailchimp-for-wp'); ?></label>
141
- <input type="text" value="<?php echo esc_attr($user->user_firstname); ?>" name="FNAME" class="regular-text" id="mc4wp-fname">
142
  </p>
143
  <div style="position: absolute; left: -5000px;">
144
  <input type="text" name="b_a2d08947dcd3683512ce174c5_a940232df9" tabindex="-1" value="" autocomplete="off" />
145
  </div>
146
  <p>
147
- <input type="submit" value="<?php esc_attr_e('Subscribe', 'mailchimp-for-wp'); ?>" name="subscribe" class="button">
148
  </p>
149
 
150
  <input type="hidden" name="SOURCE" value="free-plugin" />
@@ -152,32 +145,30 @@ class MC4WP_Admin_Ads
152
  </div>
153
  </div>
154
  <?php
155
- }
156
-
157
- /**
158
- * Show notice about E-Commerce integration in Premium.
159
- */
160
- public function ecommerce()
161
- {
162
-
163
- // detect whether WooCommerce is installed & activated.
164
- if (! class_exists('WooCommerce')) {
165
- return;
166
- }
167
-
168
- echo '<div class="medium-margin">';
169
- echo '<h3>Advanced WooCommerce integration for Mailchimp</h3>';
170
- echo '<p>';
171
- echo __('Do you want to track all WooCommerce orders in Mailchimp so you can send emails based on the purchase activity of your subscribers?', 'mailchimp-for-wp');
172
- echo '</p>';
173
- echo '<p>';
174
- echo sprintf(__('<a href="%s">Upgrade to Mailchimp for WordPress Premium</a> or <a href="%s">read more about Mailchimp\'s E-Commerce features</a>.', 'mailchimp-for-wp') . '</p>', 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=other-settings-link', 'https://kb.mc4wp.com/what-is-ecommerce360/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=other-settings-link');
175
- echo '</p>';
176
- echo '</div>';
177
- }
178
-
179
- public function show_extensions_page()
180
- {
181
- require MC4WP_PLUGIN_DIR . 'includes/views/extensions.php';
182
- }
183
  }
6
  * @ignore
7
  * @access private
8
  */
9
+ class MC4WP_Admin_Ads {
10
+
11
+
12
+ /**
13
+ * @return bool Adds hooks
14
+ */
15
+ public function add_hooks() {
16
+
17
+ // don't hook if Premium is activated
18
+ if ( defined( 'MC4WP_PREMIUM_VERSION' ) ) {
19
+ return false;
20
+ }
21
+
22
+ add_filter( 'mc4wp_admin_plugin_meta_links', array( $this, 'plugin_meta_links' ) );
23
+ add_action( 'mc4wp_admin_form_after_behaviour_settings_rows', array( $this, 'after_form_settings_rows' ) );
24
+ add_action( 'mc4wp_admin_form_after_appearance_settings_rows', array( $this, 'after_form_appearance_settings_rows' ) );
25
+ add_action( 'mc4wp_admin_sidebar', array( $this, 'admin_sidebar' ) );
26
+ add_action( 'mc4wp_admin_footer', array( $this, 'admin_footer' ) );
27
+ add_action( 'mc4wp_admin_other_settings', array( $this, 'ecommerce' ), 90 );
28
+
29
+ add_filter( 'mc4wp_admin_menu_items', array( $this, 'add_menu_item' ) );
30
+
31
+ add_action( 'mc4wp_admin_after_woocommerce_integration_settings', array( $this, 'ecommerce' ) );
32
+ return true;
33
+ }
34
+
35
+ public function add_menu_item( $items ) {
36
+ $items['extensions'] = array(
37
+ 'title' => __( 'Add-ons', 'mailchimp-for-wp' ),
38
+ 'text' => __( 'Add-ons', 'mailchimp-for-wp' ),
39
+ 'slug' => 'extensions',
40
+ 'callback' => array( $this, 'show_extensions_page' ),
41
+ 'position' => 100,
42
+ );
43
+
44
+ return $items;
45
+ }
46
+
47
+ /**
48
+ * Add text row to "Form > Appearance" tab.
49
+ */
50
+ public function after_form_appearance_settings_rows() {
51
+ echo '<tr valign="top">';
52
+ echo '<td colspan="2">';
53
+ echo '<p class="help">';
54
+ echo sprintf( __( 'Want to customize the style of your form? <a href="%s">Try our Styles Builder</a> & edit the look of your forms with just a few clicks.', 'mailchimp-for-wp' ), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=form-settings-link' );
55
+ echo '</p>';
56
+ echo '</td>';
57
+ echo '</tr>';
58
+ }
59
+
60
+ /**
61
+ * Add text row to "Form > Settings" tab.
62
+ */
63
+ public function after_form_settings_rows() {
64
+ echo '<tr valign="top">';
65
+ echo '<td colspan="2">';
66
+ echo '<p class="help">';
67
+
68
+ if ( rand( 1, 2 ) === 1 ) {
69
+ echo sprintf( __( 'Be notified whenever someone subscribes? <a href="%s">Mailchimp for WordPress Premium</a> allows you to set up email notifications for your forms.', 'mailchimp-for-wp' ), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' );
70
+ } else {
71
+ echo sprintf( __( 'Increased conversions? <a href="%s">Mailchimp for WordPress Premium</a> submits forms without reloading the entire page, resulting in a much better experience for your visitors.', 'mailchimp-for-wp' ), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=form-settings-link' );
72
+ }
73
+
74
+ echo '</p>';
75
+ echo '</td>';
76
+ echo '</tr>';
77
+ }
78
+
79
+ /**
80
+ * @param array $links
81
+ *
82
+ * @return array
83
+ */
84
+ public function plugin_meta_links( $links ) {
85
+ $links[] = '<a href="https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-upgrade-link">' . __( 'Upgrade to Premium', 'mailchimp-for-wp' ) . '</a>';
86
+ return $links;
87
+ }
88
+
89
+ /**
90
+ * Add several texts to admin footer.
91
+ */
92
+ public function admin_footer() {
93
+ if ( isset( $_GET['view'] ) && $_GET['view'] === 'edit-form' ) {
94
+
95
+ // WPML & Polylang specific message
96
+ if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
97
+ echo '<p class="help">' . sprintf( __( 'Do you want translated forms for all of your languages? <a href="%s">Try Mailchimp for WordPress Premium</a>, which does just that plus more.', 'mailchimp-for-wp' ), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' ) . '</p>';
98
+ return;
99
+ }
100
+
101
+ // General "edit form" message
102
+ echo '<p class="help">' . sprintf( __( 'Do you want to create more than one form? Our Premium add-on does just that! <a href="%s">Have a look at all Premium benefits</a>.', 'mailchimp-for-wp' ), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' ) . '</p>';
103
+ return;
104
+ }
105
+
106
+ // General message
107
+ echo '<p class="help">' . sprintf( __( 'Are you enjoying this plugin? The Premium add-on unlocks several powerful features. <a href="%s">Find out about all benefits now</a>.', 'mailchimp-for-wp' ), 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' ) . '</p>';
108
+ }
109
+
110
+ /**
111
+ * Add email opt-in form to sidebar
112
+ */
113
+ public function admin_sidebar() {
114
+ echo '<div class="mc4wp-box">';
115
+ echo '<div style="border: 5px dotted #cc4444; padding: 0 20px; background: white;">';
116
+ echo '<h3>Mailchimp for WordPress Premium</h3>';
117
+ echo '<p>This plugin has a Premium add-on, unlocking several powerful features. <a href="https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=upgrade-box">Have a look at its benefits</a>!</p>';
118
+ echo '</div>';
119
+ echo '</div>'; ?>
 
 
 
 
 
 
 
120
  <div class="mc4wp-box" id="mc4wp-optin-box">
121
 
122
  <?php $user = wp_get_current_user(); ?>
123
  <!-- Begin Mailchimp Signup Form -->
124
  <div id="mc_embed_signup">
125
+ <h4 class="mc4wp-title"><?php _e( 'More subscribers, better newsletters.', 'mailchimp-for-wp' ); ?></h4>
126
+ <p><?php _e( 'Learn how to best grow your lists & write better emails by subscribing to our monthly tips.', 'mailchimp-for-wp' ); ?></p>
127
  <form action="//mc4wp.us1.list-manage.com/subscribe/post?u=a2d08947dcd3683512ce174c5&amp;id=a940232df9" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" target="_blank">
128
  <p>
129
+ <label for="mc4wp-email"><?php _e( 'Email Address', 'mailchimp-for-wp' ); ?></label>
130
+ <input type="email" value="<?php echo esc_attr( $user->user_email ); ?>" name="EMAIL" class="regular-text" id="mc4wp-email" required>
131
  </p>
132
  <p>
133
+ <label for="mc4wp-fname"><?php _e( 'First Name', 'mailchimp-for-wp' ); ?></label>
134
+ <input type="text" value="<?php echo esc_attr( $user->user_firstname ); ?>" name="FNAME" class="regular-text" id="mc4wp-fname">
135
  </p>
136
  <div style="position: absolute; left: -5000px;">
137
  <input type="text" name="b_a2d08947dcd3683512ce174c5_a940232df9" tabindex="-1" value="" autocomplete="off" />
138
  </div>
139
  <p>
140
+ <input type="submit" value="<?php esc_attr_e( 'Subscribe', 'mailchimp-for-wp' ); ?>" name="subscribe" class="button">
141
  </p>
142
 
143
  <input type="hidden" name="SOURCE" value="free-plugin" />
145
  </div>
146
  </div>
147
  <?php
148
+ }
149
+
150
+ /**
151
+ * Show notice about E-Commerce integration in Premium.
152
+ */
153
+ public function ecommerce() {
154
+
155
+ // detect whether WooCommerce is installed & activated.
156
+ if ( ! class_exists( 'WooCommerce' ) ) {
157
+ return;
158
+ }
159
+
160
+ echo '<div class="medium-margin">';
161
+ echo '<h3>Advanced WooCommerce integration for Mailchimp</h3>';
162
+ echo '<p>';
163
+ echo __( 'Do you want to track all WooCommerce orders in Mailchimp so you can send emails based on the purchase activity of your subscribers?', 'mailchimp-for-wp' );
164
+ echo '</p>';
165
+ echo '<p>';
166
+ echo sprintf( __( '<a href="%1$s">Upgrade to Mailchimp for WordPress Premium</a> or <a href="%2$s">read more about Mailchimp\'s E-Commerce features</a>.', 'mailchimp-for-wp' ) . '</p>', 'https://mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=other-settings-link', 'https://kb.mc4wp.com/what-is-ecommerce360/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=other-settings-link' );
167
+ echo '</p>';
168
+ echo '</div>';
169
+ }
170
+
171
+ public function show_extensions_page() {
172
+ require MC4WP_PLUGIN_DIR . 'includes/views/extensions.php';
173
+ }
 
 
174
  }
includes/admin/class-review-notice.php CHANGED
@@ -5,92 +5,87 @@
5
  *
6
  * @ignore
7
  */
8
- class MC4WP_Admin_Review_Notice
9
- {
10
 
11
- /**
12
- * @var MC4WP_Admin_Tools
13
- */
14
- protected $tools;
15
 
16
- /**
17
- * @var string
18
- */
19
- protected $meta_key_dismissed = '_mc4wp_review_notice_dismissed';
20
 
21
- /**
22
- * MC4WP_Admin_Review_Notice constructor.
23
- *
24
- * @param MC4WP_Admin_Tools $tools
25
- */
26
- public function __construct(MC4WP_Admin_Tools $tools)
27
- {
28
- $this->tools = $tools;
29
- }
30
 
31
- /**
32
- * Add action & filter hooks.
33
- */
34
- public function add_hooks()
35
- {
36
- add_action('admin_notices', array( $this, 'show' ));
37
- add_action('mc4wp_admin_dismiss_review_notice', array( $this, 'dismiss' ));
38
- }
39
 
40
- /**
41
- * Set flag in user meta so notice won't be shown.
42
- */
43
- public function dismiss()
44
- {
45
- $user = wp_get_current_user();
46
- update_user_meta($user->ID, $this->meta_key_dismissed, 1);
47
- }
48
 
49
- /**
50
- * @return bool
51
- */
52
- public function show()
53
- {
54