Call Now Button - Version 1.1.8

Version Description

  • Added missing media query for body padding when using Full Width button
Download this release

Release Info

Developer jasperroel
Plugin Icon 128x128 Call Now Button
Version 1.1.8
Comparing to
See all releases

Code changes from version 1.1.7 to 1.1.8

call-now-button.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Call Now Button
4
  Plugin URI: https://callnowbutton.com
5
  Description: Mobile visitors will see a <strong>Call Now Button</strong> on your website. Easy to use but flexible to meet more demanding requirements. Change placement and color, hide on specific pages, track how many people click them or conversions of your Google Ads campaigns. It's all optional but possible.
6
- Version: 1.1.7
7
  Author: Jerry Rietveld
8
  Author URI: https://www.callnowbutton.com
9
  GitHub Plugin URI: https://github.com/callnowbutton/wp-plugin
@@ -26,7 +26,7 @@ License: GPL2
26
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
- define('CNB_VERSION', '1.1.7');
30
  define('CNB_NAME', 'Call Now Button');
31
  define('CNB_BASENAME', plugin_basename(__FILE__));
32
  define('CNB_BASEFOLDER', plugin_basename(dirname(__FILE__)));
3
  Plugin Name: Call Now Button
4
  Plugin URI: https://callnowbutton.com
5
  Description: Mobile visitors will see a <strong>Call Now Button</strong> on your website. Easy to use but flexible to meet more demanding requirements. Change placement and color, hide on specific pages, track how many people click them or conversions of your Google Ads campaigns. It's all optional but possible.
6
+ Version: 1.1.8
7
  Author: Jerry Rietveld
8
  Author URI: https://www.callnowbutton.com
9
  GitHub Plugin URI: https://github.com/callnowbutton/wp-plugin
26
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
+ define('CNB_VERSION', '1.1.8');
30
  define('CNB_NAME', 'Call Now Button');
31
  define('CNB_BASENAME', plugin_basename(__FILE__));
32
  define('CNB_BASEFOLDER', plugin_basename(dirname(__FILE__)));
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: call button, click to call, convert, call now button, contact button
5
  Requires at least: 3.9
6
  Requires PHP: 5.4
7
  Tested up to: 6.0
8
- Stable tag: 1.1.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -111,6 +111,9 @@ Yes, you can upgrade to Premium to enable tons of extra features. Checkout [call
111
 
112
 
113
  == Changelog ==
 
 
 
114
  = 1.1.7 =
115
  * Fix for websites using WP Rocket LazyLoad
116
 
5
  Requires at least: 3.9
6
  Requires PHP: 5.4
7
  Tested up to: 6.0
8
+ Stable tag: 1.1.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
111
 
112
 
113
  == Changelog ==
114
+ = 1.1.8 =
115
+ * Added missing media query for body padding when using Full Width button
116
+
117
  = 1.1.7 =
118
  * Fix for websites using WP Rocket LazyLoad
119
 
src/admin/api/CnbAdminCloud.php CHANGED
@@ -137,6 +137,7 @@ class CnbAdminCloud {
137
  $message = self::cnb_admin_get_success_message( 'updated', 'button', $result->name );
138
  }
139
  $cnb_cloud_notifications[] = $message;
 
140
 
141
  return $result;
142
  }
@@ -209,6 +210,7 @@ class CnbAdminCloud {
209
  $message = self::cnb_admin_get_success_message( 'created', 'button', $result->name );
210
  }
211
  $cnb_cloud_notifications[] = $message;
 
212
 
213
  return $result;
214
  }
@@ -227,6 +229,7 @@ class CnbAdminCloud {
227
  $message = self::cnb_admin_get_success_message( 'deleted', 'button', $result->name );
228
  }
229
  $cnb_cloud_notifications[] = $message;
 
230
 
231
  return $result;
232
  }
137
  $message = self::cnb_admin_get_success_message( 'updated', 'button', $result->name );
138
  }
139
  $cnb_cloud_notifications[] = $message;
140
+ $cnb_cloud_notifications = apply_filters( 'cnb_after_save', $cnb_cloud_notifications );
141
 
142
  return $result;
143
  }
210
  $message = self::cnb_admin_get_success_message( 'created', 'button', $result->name );
211
  }
212
  $cnb_cloud_notifications[] = $message;
213
+ $cnb_cloud_notifications = apply_filters( 'cnb_after_save', $cnb_cloud_notifications );
214
 
215
  return $result;
216
  }
229
  $message = self::cnb_admin_get_success_message( 'deleted', 'button', $result->name );
230
  }
231
  $cnb_cloud_notifications[] = $message;
232
+ $cnb_cloud_notifications = apply_filters( 'cnb_after_save', $cnb_cloud_notifications );
233
 
234
  return $result;
235
  }
src/admin/partials/CnbHeaderNotices.php CHANGED
@@ -9,6 +9,7 @@ use cnb\admin\api\CnbAdminCloud;
9
  use cnb\admin\api\CnbAppRemote;
10
  use cnb\admin\domain\CnbDomain;
11
  use cnb\admin\settings\CnbSettingsController;
 
12
  use cnb\notices\CnbAdminNotices;
13
  use cnb\notices\CnbNotice;
14
  use cnb\utils\CnbUtils;
@@ -78,18 +79,18 @@ class CnbHeaderNotices {
78
 
79
  private function cnb_settings_get_account_missing_notice() {
80
  $cnb_utils = new CnbUtils();
81
- $register_url = $cnb_utils->get_app_url( 'register', 'upgrade-to-premium-options', 'callnowbutton.com');
82
- $url = $cnb_utils->get_app_url( '', 'manual_activation', 'sign-up-for-api');
83
 
84
  $message = '<h3 class="title cnb-remove-add-new">Activating Premium</h3>';
85
- $message .= '<p>To activate Premium, you\'ll need a <a href="' . esc_url($register_url) . '" target="_blank">callnowbutton.com</a> account and an API key. There\'s 2 ways to do this:</p>';
86
  $message .= '<h4>Option 1: Email activation (easy and fast!)</h4>';
87
  $message .= self::cnb_settings_email_activation_input();
88
 
89
  $message .= '<hr>';
90
  $message .= '<h4>Option 2: Web activation (manual process)</h4>';
91
  $message .= '<ol>';
92
- $message .= '<li>Create your account at <a href="' . esc_url($url) . '">https://app.callnowbutton.com</a></li>';
93
  $message .= '<li>Go to your profile info by clicking on the user icon in the top right corner and then click <strong>Create new API key</strong>.</li>';
94
  $message .= '<li>Copy the API key that appears, paste it into the field below and click <strong>Store API key</strong>.</li>';
95
  $message .= '</ol>';
@@ -101,16 +102,16 @@ class CnbHeaderNotices {
101
 
102
  private function cnb_settings_api_key_invalid_notice() {
103
  $cnb_utils = new CnbUtils();
104
- $url = $cnb_utils->get_app_url( '', 'manual_activation', 'sign-up-for-api');
105
- $message = '<h3 class="title cnb-remove-add-new">Ooops, that API key doesn\'t seem right</h3>';
106
- $message .= '<p>The saved API key is invalid. Let\'s give it another try:</p>';
107
- $message .= '<h4>Option 1: Email activation</h4>';
108
- $message .= self::cnb_settings_email_activation_input();
109
 
110
  $message .= '<hr>';
111
  $message .= '<h4>Option 2: Web activation (manual process)</h4>';
112
  $message .= '<ol>';
113
- $message .= '<li>Create your account at <a href="' . esc_url($url) . '">https://app.callnowbutton.com</a></li>';
114
  $message .= '<li>Go to your profile info by clicking on the user icon in the top right corner and then click <strong>Create new API key</strong>.</li>';
115
  $message .= '<li>Copy the API key that appears, paste it into the field below and click <strong>Store API key</strong>.</li>';
116
  $message .= '</ol>';
@@ -123,17 +124,17 @@ class CnbHeaderNotices {
123
 
124
  public static function cnb_settings_email_activation_input() {
125
  $cnb_utils = new CnbUtils();
126
- $terms_url = $cnb_utils->get_website_url('terms.html', 'email-activation', 'terms');
127
- $privacy_url = $cnb_utils->get_website_url('privacy.html', 'email-activation', 'privacy');
128
- $message = '<form class="cnb-container" onsubmit="return cnb_email_activation_submit()">';
129
- $message .= '<div id="cnb_email_activation_alternate_formd">';
130
- $message .= '<p style="margin-top: 0;"><strong>Email address</strong> (for sending you an activation link):</p>';
131
- $message .= '<input type="text" required="required" class="cnb_activation_input_field" name="cnb_email_activation_alternate_address" id="cnb_email_activation_alternate_address" placeholder="Your email address" /> ';
132
- $message .= get_submit_button( __( 'Activate Premium' ), 'primary', 'cnb_email_activation_alternate', false );
133
- $message .= '</div>';
134
- $message .= '<p id="cnb_email_activation"></p>';
135
-
136
- $message .= '<p class="nonessential">By clicking <u>Activate Premium</u> an account will be created with your email address on callnowbutton.com and you agree to our <a href="' . esc_url( $terms_url ) . '" target="_blank">Terms & Conditions</a> and <a href="' . esc_url( $privacy_url) . '" target="_blank">Privacy statement</a>.</p>';
137
  $message .= '</form>';
138
 
139
  return $message;
@@ -224,7 +225,7 @@ class CnbHeaderNotices {
224
 
225
  function get_generic_changelog_message() {
226
  $cnb_utils = new CnbUtils();
227
- $changelog_link = $cnb_utils->get_website_url('wordpress/changelog/', 'update_notice');
228
  $changelog_message = '<a href="' . esc_url( $changelog_link ) . '">Click here to see what changed</a>';
229
  $message = '<p><span class="dashicons dashicons-yes"></span> ';
230
  $message .= 'The plugin has been updated. ';
@@ -244,9 +245,9 @@ class CnbHeaderNotices {
244
  * @return boolean
245
  */
246
  public function upgrade_notice( &$notices = array() ) {
247
- $cnb_options = get_option( 'cnb' );
248
- $cnb_changelog = $this->get_show_changelog_versions();
249
- $message = $this->cnb_get_changelog_message( $cnb_changelog, $this->get_changelog_version( $cnb_options ) );
250
 
251
  if ( empty( $message ) ) {
252
  return false;
@@ -297,7 +298,8 @@ class CnbHeaderNotices {
297
  }
298
 
299
  public function warn_about_caching_plugins( &$notices ) {
300
- $active_caching_plugins = $this->check_for_caching();
 
301
  if ( $active_caching_plugins ) {
302
  $this->caching_plugin_warning_notice( $active_caching_plugins, $notices );
303
  }
@@ -305,49 +307,28 @@ class CnbHeaderNotices {
305
 
306
  private function caching_plugin_warning_notice( $caching_plugin_names, &$notices ) {
307
  $plugins = get_plugins();
308
- foreach ($caching_plugin_names as $caching_plugin_name ) {
309
- if ( ! is_array($plugins) || ! array_key_exists($caching_plugin_name, $plugins)) {
310
  continue;
311
  }
312
- $plugin = $plugins[ $caching_plugin_name ];
313
- $name = $plugin['Name'];
314
-
315
- $message = '<p><span class="dashicons dashicons-warning"></span> ';
316
- $message .= 'Your website is using a <strong><i>Caching Plugin</i></strong> (' . $name . '). ';
317
- $message .= "If you're not seeing your button or your changes, make sure you empty your cache first.</p>";
318
-
319
- $notices[] = new CnbNotice( 'error', $message, true, 'cnb-caching-' . $name );
320
  }
321
  }
322
 
323
  /**
324
- * Return all active Caching plugins
325
- * @return array
 
326
  */
327
- private function check_for_caching() {
328
- $active_plugins = array();
329
- $caching_plugins = array(
330
- 'autoptimize/autoptimize.php',
331
- 'breeze/breeze.php',
332
- 'cache-control/cache-control.php',
333
- 'cache-enabler/cache-enabler.php',
334
- 'comet-cache/comet-cache.php',
335
- 'fast-velocity-minify/fvm.php',
336
- 'hyper-cache/plugin.php',
337
- 'litespeed-cache/litespeed-cache.php',
338
- 'simple-cache/simple-cache.php',
339
- 'w3-total-cache/w3-total-cache.php',
340
- 'wp-fastest-cache/wpFastestCache.php',
341
- 'wp-super-cache/wp-cache.php',
342
- 'wp-rocket/wp-rocket.php',
343
- );
344
- foreach ( $caching_plugins as $plugin ) {
345
- if ( is_plugin_active( $plugin ) ) {
346
- $active_plugins[] = $plugin;
347
- }
348
- }
349
 
350
- return $active_plugins;
 
 
 
 
351
  }
352
 
353
  public function is_timezone_missing( $domain ) {
@@ -442,8 +423,8 @@ class CnbHeaderNotices {
442
  }
443
 
444
  private function get_cnb_generic_error_notice() {
445
- $cnb_utils = new CnbUtils();
446
- $support_url = $cnb_utils->get_support_url('', 'notice-error', 'help-center');
447
 
448
  return '<h3 class="title">Something went wrong!</h3>
449
  <p>Something has gone wrong and we do not know why...</p>
9
  use cnb\admin\api\CnbAppRemote;
10
  use cnb\admin\domain\CnbDomain;
11
  use cnb\admin\settings\CnbSettingsController;
12
+ use cnb\cache\CacheHandler;
13
  use cnb\notices\CnbAdminNotices;
14
  use cnb\notices\CnbNotice;
15
  use cnb\utils\CnbUtils;
79
 
80
  private function cnb_settings_get_account_missing_notice() {
81
  $cnb_utils = new CnbUtils();
82
+ $register_url = $cnb_utils->get_app_url( 'register', 'upgrade-to-premium-options', 'callnowbutton.com' );
83
+ $url = $cnb_utils->get_app_url( '', 'manual_activation', 'sign-up-for-api' );
84
 
85
  $message = '<h3 class="title cnb-remove-add-new">Activating Premium</h3>';
86
+ $message .= '<p>To activate Premium, you\'ll need a <a href="' . esc_url( $register_url ) . '" target="_blank">callnowbutton.com</a> account and an API key. There\'s 2 ways to do this:</p>';
87
  $message .= '<h4>Option 1: Email activation (easy and fast!)</h4>';
88
  $message .= self::cnb_settings_email_activation_input();
89
 
90
  $message .= '<hr>';
91
  $message .= '<h4>Option 2: Web activation (manual process)</h4>';
92
  $message .= '<ol>';
93
+ $message .= '<li>Create your account at <a href="' . esc_url( $url ) . '">https://app.callnowbutton.com</a></li>';
94
  $message .= '<li>Go to your profile info by clicking on the user icon in the top right corner and then click <strong>Create new API key</strong>.</li>';
95
  $message .= '<li>Copy the API key that appears, paste it into the field below and click <strong>Store API key</strong>.</li>';
96
  $message .= '</ol>';
102
 
103
  private function cnb_settings_api_key_invalid_notice() {
104
  $cnb_utils = new CnbUtils();
105
+ $url = $cnb_utils->get_app_url( '', 'manual_activation', 'sign-up-for-api' );
106
+ $message = '<h3 class="title cnb-remove-add-new">Ooops, that API key doesn\'t seem right</h3>';
107
+ $message .= '<p>The saved API key is invalid. Let\'s give it another try:</p>';
108
+ $message .= '<h4>Option 1: Email activation</h4>';
109
+ $message .= self::cnb_settings_email_activation_input();
110
 
111
  $message .= '<hr>';
112
  $message .= '<h4>Option 2: Web activation (manual process)</h4>';
113
  $message .= '<ol>';
114
+ $message .= '<li>Create your account at <a href="' . esc_url( $url ) . '">https://app.callnowbutton.com</a></li>';
115
  $message .= '<li>Go to your profile info by clicking on the user icon in the top right corner and then click <strong>Create new API key</strong>.</li>';
116
  $message .= '<li>Copy the API key that appears, paste it into the field below and click <strong>Store API key</strong>.</li>';
117
  $message .= '</ol>';
124
 
125
  public static function cnb_settings_email_activation_input() {
126
  $cnb_utils = new CnbUtils();
127
+ $terms_url = $cnb_utils->get_website_url( 'terms.html', 'email-activation', 'terms' );
128
+ $privacy_url = $cnb_utils->get_website_url( 'privacy.html', 'email-activation', 'privacy' );
129
+ $message = '<form class="cnb-container" onsubmit="return cnb_email_activation_submit()">';
130
+ $message .= '<div id="cnb_email_activation_alternate_formd">';
131
+ $message .= '<p style="margin-top: 0;"><strong>Email address</strong> (for sending you an activation link):</p>';
132
+ $message .= '<input type="text" required="required" class="cnb_activation_input_field" name="cnb_email_activation_alternate_address" id="cnb_email_activation_alternate_address" placeholder="Your email address" /> ';
133
+ $message .= get_submit_button( __( 'Activate Premium' ), 'primary', 'cnb_email_activation_alternate', false );
134
+ $message .= '</div>';
135
+ $message .= '<p id="cnb_email_activation"></p>';
136
+
137
+ $message .= '<p class="nonessential">By clicking <u>Activate Premium</u> an account will be created with your email address on callnowbutton.com and you agree to our <a href="' . esc_url( $terms_url ) . '" target="_blank">Terms & Conditions</a> and <a href="' . esc_url( $privacy_url ) . '" target="_blank">Privacy statement</a>.</p>';
138
  $message .= '</form>';
139
 
140
  return $message;
225
 
226
  function get_generic_changelog_message() {
227
  $cnb_utils = new CnbUtils();
228
+ $changelog_link = $cnb_utils->get_website_url( 'wordpress/changelog/', 'update_notice' );
229
  $changelog_message = '<a href="' . esc_url( $changelog_link ) . '">Click here to see what changed</a>';
230
  $message = '<p><span class="dashicons dashicons-yes"></span> ';
231
  $message .= 'The plugin has been updated. ';
245
  * @return boolean
246
  */
247
  public function upgrade_notice( &$notices = array() ) {
248
+ $cnb_options = get_option( 'cnb' );
249
+ $cnb_changelog = $this->get_show_changelog_versions();
250
+ $message = $this->cnb_get_changelog_message( $cnb_changelog, $this->get_changelog_version( $cnb_options ) );
251
 
252
  if ( empty( $message ) ) {
253
  return false;
298
  }
299
 
300
  public function warn_about_caching_plugins( &$notices ) {
301
+ $cache_handler = new CacheHandler();
302
+ $active_caching_plugins = $cache_handler->get_active_caching_plugins();
303
  if ( $active_caching_plugins ) {
304
  $this->caching_plugin_warning_notice( $active_caching_plugins, $notices );
305
  }
307
 
308
  private function caching_plugin_warning_notice( $caching_plugin_names, &$notices ) {
309
  $plugins = get_plugins();
310
+ foreach ( $caching_plugin_names as $caching_plugin_name ) {
311
+ if ( ! is_array( $plugins ) || ! array_key_exists( $caching_plugin_name, $plugins ) ) {
312
  continue;
313
  }
314
+ $plugin = $plugins[ $caching_plugin_name ];
315
+ $notices[] = $this->get_caching_plugin_warning_notice( $plugin );
 
 
 
 
 
 
316
  }
317
  }
318
 
319
  /**
320
+ * @param $plugin array expects the array with a single plugin found via get_plugins()
321
+ *
322
+ * @return CnbNotice
323
  */
324
+ private function get_caching_plugin_warning_notice( $plugin ) {
325
+ $name = $plugin['Name'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
+ $message = '<p><span class="dashicons dashicons-warning"></span> ';
328
+ $message .= 'Your website is using a <strong><i>Caching Plugin</i></strong> (' . $name . '). ';
329
+ $message .= "If you're not seeing your button or your changes, make sure you empty your cache first.</p>";
330
+
331
+ return new CnbNotice( 'error', $message, true, 'cnb-caching-' . $name );
332
  }
333
 
334
  public function is_timezone_missing( $domain ) {
423
  }
424
 
425
  private function get_cnb_generic_error_notice() {
426
+ $cnb_utils = new CnbUtils();
427
+ $support_url = $cnb_utils->get_support_url( '', 'notice-error', 'help-center' );
428
 
429
  return '<h3 class="title">Something went wrong!</h3>
430
  <p>Something has gone wrong and we do not know why...</p>
src/admin/settings/CnbSettingsController.php CHANGED
@@ -175,6 +175,7 @@ class CnbSettingsController {
175
  }
176
 
177
  $transient_id = 'cnb-options';
 
178
  set_transient( $transient_id, $messages, HOUR_IN_SECONDS );
179
 
180
  // We do not actually store this value in the DB!
175
  }
176
 
177
  $transient_id = 'cnb-options';
178
+ $messages = apply_filters( 'cnb_after_save', $messages );
179
  set_transient( $transient_id, $messages, HOUR_IN_SECONDS );
180
 
181
  // We do not actually store this value in the DB!
src/notices/CnbAdminNotices.php CHANGED
@@ -68,7 +68,7 @@ class CnbAdminNotices {
68
  }
69
 
70
  $dismiss_classes = '';
71
- $dismiss_url = '';
72
  if ( $notice->dismiss_option ) {
73
  $notice->dismissable = true;
74
  $url = admin_url( 'admin.php' );
@@ -88,7 +88,7 @@ class CnbAdminNotices {
88
  esc_attr( $dismiss_classes ) .
89
  '"' .
90
  // phpcs:ignore WordPress.Security
91
- ( $notice->dismissable === true
92
  ? ' data-dismiss-url="' . esc_url( $dismiss_url ) . '"'
93
  : ''
94
  ) . '>';
68
  }
69
 
70
  $dismiss_classes = '';
71
+ $dismiss_url = null;
72
  if ( $notice->dismiss_option ) {
73
  $notice->dismissable = true;
74
  $url = admin_url( 'admin.php' );
88
  esc_attr( $dismiss_classes ) .
89
  '"' .
90
  // phpcs:ignore WordPress.Security
91
+ ( $notice->dismissable === true && $dismiss_url
92
  ? ' data-dismiss-url="' . esc_url( $dismiss_url ) . '"'
93
  : ''
94
  ) . '>';
src/renderers/modern/class-modernrenderer.php CHANGED
@@ -151,11 +151,11 @@ class ModernRenderer extends Renderer {
151
  if ( 'full' === $appearance || 'tfull' === $appearance ) {
152
  switch ( $appearance ) {
153
  case 'tfull':
154
- echo '<style>body {padding-top:60px;}</style>';
155
  break;
156
  case 'full':
157
  default:
158
- echo '<style>body {padding-bottom:60px;}</style>';
159
  break;
160
  }
161
  }
151
  if ( 'full' === $appearance || 'tfull' === $appearance ) {
152
  switch ( $appearance ) {
153
  case 'tfull':
154
+ echo '<style>@media screen and (max-width: 650px) {body {padding-top:60px;}}</style>';
155
  break;
156
  case 'full':
157
  default:
158
+ echo '<style>@media screen and (max-width: 650px) {body {padding-bottom:60px;}}</style>';
159
  break;
160
  }
161
  }
src/utils/class-cachehandler.php CHANGED
@@ -2,11 +2,52 @@
2
 
3
  namespace cnb\cache;
4
 
 
5
  use cnb\utils\CnbUtils;
6
  use Exception;
7
 
8
  class CacheHandler {
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  /**
11
  * Exclude the cloud version from the WP Rocket cache
12
  *
@@ -15,7 +56,7 @@ class CacheHandler {
15
  *
16
  * @return void
17
  */
18
- private function excludeCloudFromWpRocket() {
19
  // Exclude our CDN hosted JS file(s)
20
  add_filter( 'rocket_minify_excluded_external_js',
21
  function ( $excluded_external_js ) {
@@ -28,9 +69,10 @@ class CacheHandler {
28
  // This removes lazyloading from our Modern renderer,
29
  // which is incompatbile with our base64-ended background image
30
  // See https://github.com/wp-media/wp-rocket/blob/develop/inc/Dependencies/RocketLazyload/Image.php#L379
31
- add_filter('rocket_lazyload_excluded_attributes',
32
- function ($excluded_attributes) {
33
  $excluded_attributes[] = 'id="callnowbutton"';
 
34
  return $excluded_attributes;
35
  }
36
  );
@@ -43,7 +85,7 @@ class CacheHandler {
43
  *
44
  * @return void
45
  */
46
- public function clearWpSuperCache() {
47
  try {
48
  if ( function_exists( 'wp_cache_clean_cache' ) ) {
49
  global $file_prefix;
@@ -59,7 +101,7 @@ class CacheHandler {
59
  *
60
  * @return void
61
  */
62
- public function clearWpRocketCacheAfterSave() {
63
  $cnb_options = get_option( 'cnb' );
64
  $cnb_utils = new CnbUtils();
65
  // This action doesn't work - since it requires some args and a nonce
@@ -88,12 +130,48 @@ class CacheHandler {
88
  }
89
  }
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  public static function exclude() {
92
  $handler = new CacheHandler();
93
- $handler->excludeCloudFromWpRocket();
94
 
95
- add_action( 'cnb_after_button_changed', array( $handler, 'clearWpRocketCacheAfterSave' ) );
96
- add_action( 'cnb_after_button_changed', array( $handler, 'clearWpSuperCache' ) );
97
 
 
98
  }
99
  }
2
 
3
  namespace cnb\cache;
4
 
5
+ use cnb\notices\CnbNotice;
6
  use cnb\utils\CnbUtils;
7
  use Exception;
8
 
9
  class CacheHandler {
10
 
11
+ /**
12
+ * Returns all plugins that the Call Now Button is incompatible with.
13
+ *
14
+ * @return string[]
15
+ */
16
+ private function get_conflicting_cache_plugins() {
17
+ return array(
18
+ 'autoptimize/autoptimize.php',
19
+ 'breeze/breeze.php',
20
+ 'cache-control/cache-control.php',
21
+ 'cache-enabler/cache-enabler.php',
22
+ 'comet-cache/comet-cache.php',
23
+ 'fast-velocity-minify/fvm.php',
24
+ 'hyper-cache/plugin.php',
25
+ 'litespeed-cache/litespeed-cache.php',
26
+ 'simple-cache/simple-cache.php',
27
+ 'w3-total-cache/w3-total-cache.php',
28
+ 'wp-fastest-cache/wpFastestCache.php',
29
+ 'wp-super-cache/wp-cache.php',
30
+ 'wp-rocket/wp-rocket.php',
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Return all active Caching plugins.
36
+ *
37
+ * @return array
38
+ */
39
+ function get_active_caching_plugins() {
40
+ $active_plugins = array();
41
+ $caching_plugins = $this->get_conflicting_cache_plugins();
42
+ foreach ( $caching_plugins as $plugin ) {
43
+ if ( is_plugin_active( $plugin ) ) {
44
+ $active_plugins[] = $plugin;
45
+ }
46
+ }
47
+
48
+ return $active_plugins;
49
+ }
50
+
51
  /**
52
  * Exclude the cloud version from the WP Rocket cache
53
  *
56
  *
57
  * @return void
58
  */
59
+ private function exclude_cloud_from_wprocket() {
60
  // Exclude our CDN hosted JS file(s)
61
  add_filter( 'rocket_minify_excluded_external_js',
62
  function ( $excluded_external_js ) {
69
  // This removes lazyloading from our Modern renderer,
70
  // which is incompatbile with our base64-ended background image
71
  // See https://github.com/wp-media/wp-rocket/blob/develop/inc/Dependencies/RocketLazyload/Image.php#L379
72
+ add_filter( 'rocket_lazyload_excluded_attributes',
73
+ function ( $excluded_attributes ) {
74
  $excluded_attributes[] = 'id="callnowbutton"';
75
+
76
  return $excluded_attributes;
77
  }
78
  );
85
  *
86
  * @return void
87
  */
88
+ public function clear_wpsupercache() {
89
  try {
90
  if ( function_exists( 'wp_cache_clean_cache' ) ) {
91
  global $file_prefix;
101
  *
102
  * @return void
103
  */
104
+ public function clear_wprocketcache() {
105
  $cnb_options = get_option( 'cnb' );
106
  $cnb_utils = new CnbUtils();
107
  // This action doesn't work - since it requires some args and a nonce
130
  }
131
  }
132
 
133
+ /**
134
+ * @param $plugin array expects the array with a single plugin found via get_plugins()
135
+ *
136
+ * @return CnbNotice
137
+ */
138
+ private function get_notice_after_save( $plugin ) {
139
+ $cnb_utils = new CnbUtils();
140
+ $name = $plugin['Name'];
141
+
142
+ $url = $cnb_utils->get_support_url( 'wordpress/empty-cache/', 'save-notification', 'learn-more' );
143
+
144
+ $message = '<p><span class="dashicons dashicons-warning"></span> ';
145
+ $message .= 'You are using a <strong><i>Caching Plugin</i></strong> (' . $name . '). ';
146
+ $message .= "If you're not seeing your changes, please empty your cache.";
147
+ $message .= ' (<a href="' . esc_url( $url ) . '">Learn more...</a>)</p>';
148
+
149
+ return new CnbNotice( 'warning', $message, true );
150
+ }
151
+
152
+ public function add_warning_if_cache_plugin_active( $messages ) {
153
+ $active_caching_plugins = $this->get_active_caching_plugins();
154
+ if ( $active_caching_plugins ) {
155
+ $plugins = get_plugins();
156
+ foreach ( $active_caching_plugins as $caching_plugin_name ) {
157
+ if ( ! is_array( $plugins ) || ! array_key_exists( $caching_plugin_name, $plugins ) ) {
158
+ continue;
159
+ }
160
+ $plugin = $plugins[ $caching_plugin_name ];
161
+ $messages[] = $this->get_notice_after_save( $plugin );
162
+ }
163
+ }
164
+
165
+ return $messages;
166
+ }
167
+
168
  public static function exclude() {
169
  $handler = new CacheHandler();
170
+ $handler->exclude_cloud_from_wprocket();
171
 
172
+ add_action( 'cnb_after_button_changed', array( $handler, 'clear_wprocketcache' ) );
173
+ add_action( 'cnb_after_button_changed', array( $handler, 'clear_wpsupercache' ) );
174
 
175
+ add_filter( 'cnb_after_save', array( $handler, 'add_warning_if_cache_plugin_active' ) );
176
  }
177
  }