Call Now Button - Version 1.1.6

Version Description

  • Improved WP Rocket cache handling
  • Improved WP Super Cache handling
  • Fix for resizing of full width button
  • Small U/I improvements
Download this release

Release Info

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

Code changes from version 1.1.5 to 1.1.6

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.5
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.5');
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.6
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.6');
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.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -111,8 +111,14 @@ Yes, you can upgrade to Premium to enable tons of extra features. Checkout [call
111
 
112
 
113
  == Changelog ==
 
 
 
 
 
 
114
  = 1.1.5 =
115
- * Fix for W3 Total Cache lazy-loading breaking the button styling
116
 
117
  = 1.1.4 =
118
  * New phone icon on call button
5
  Requires at least: 3.9
6
  Requires PHP: 5.4
7
  Tested up to: 6.0
8
+ Stable tag: 1.1.6
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.6 =
115
+ * Improved WP Rocket cache handling
116
+ * Improved WP Super Cache handling
117
+ * Fix for resizing of full width button
118
+ * Small U/I improvements
119
+
120
  = 1.1.5 =
121
+ * Fix for W3 Total Cache lazy-loading breaking the button styling
122
 
123
  = 1.1.4 =
124
  * New phone icon on call button
resources/style/call-now-button.css CHANGED
@@ -1044,6 +1044,16 @@ Welcome banner styling
1044
  }
1045
 
1046
  }
 
 
 
 
 
 
 
 
 
 
1047
 
1048
  a.cnb-nav-tab {
1049
  float: left;
1044
  }
1045
 
1046
  }
1047
+ @media screen and (min-width:783px) {
1048
+ .welcome-banner .screen-reader-text {
1049
+ width: 55px;
1050
+ height: 14px;
1051
+ right: 26px;
1052
+ top: 11px;
1053
+ clip-path: none;
1054
+ clip: unset;
1055
+ }
1056
+ }
1057
 
1058
  a.cnb-nav-tab {
1059
  float: left;
resources/style/modern.css CHANGED
@@ -126,7 +126,6 @@
126
  .cnb-single:not(.cnb-text) span {
127
  display: none;
128
  }
129
-
130
  .cnb-full.cnb-text {
131
  text-align: center;
132
  color: #FFF;
@@ -135,4 +134,83 @@
135
  overflow: hidden;
136
  white-space: nowrap;
137
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
126
  .cnb-single:not(.cnb-text) span {
127
  display: none;
128
  }
 
129
  .cnb-full.cnb-text {
130
  text-align: center;
131
  color: #FFF;
134
  overflow: hidden;
135
  white-space: nowrap;
136
  }
137
+
138
+ .cnb-full.cnb-zoom-110 img,
139
+ .cnb-full.cnb-zoom-120 img,
140
+ .cnb-full.cnb-zoom-130 img {
141
+ transform-origin: right;
142
+ }
143
+ .cnb-single.cnb-zoom-70,
144
+ .cnb-full.cnb-zoom-70 img {
145
+ transform: scale(0.7);
146
+ }
147
+ .cnb-single.cnb-zoom-80,
148
+ .cnb-full.cnb-zoom-80 img {
149
+ transform: scale(0.8);
150
+ }
151
+ .cnb-single.cnb-zoom-90,
152
+ .cnb-full.cnb-zoom-90 img {
153
+ transform: scale(0.9);
154
+ }
155
+ .cnb-single.cnb-zoom-110,
156
+ .cnb-full.cnb-zoom-110 img {
157
+ transform: scale(1.1);
158
+ }
159
+ .cnb-single.cnb-zoom-120,
160
+ .cnb-full.cnb-zoom-120 img {
161
+ transform: scale(1.2);
162
+ }
163
+ .cnb-single.cnb-zoom-130,
164
+ .cnb-full.cnb-zoom-130 img {
165
+ transform: scale(1.3);
166
+ }
167
+ .cnb-full.cnb-zoom-70 span {
168
+ font-size: 70%;
169
+ }
170
+ .cnb-full.cnb-zoom-80 span {
171
+ font-size: 80%;
172
+ }
173
+ .cnb-full.cnb-zoom-90 span {
174
+ font-size: 90%;
175
+ }
176
+ .cnb-full.cnb-zoom-110 span {
177
+ font-size: 110%;
178
+ }
179
+ .cnb-full.cnb-zoom-120 span {
180
+ font-size: 120%;
181
+ }
182
+ .cnb-full.cnb-zoom-130 span {
183
+ font-size: 130%;
184
+ }
185
+
186
+ .cnb-zindex-10 {
187
+ z-index: 2147483647;
188
+ }
189
+ .cnb-zindex-9 {
190
+ z-index: 214748365;
191
+ }
192
+ .cnb-zindex-8 {
193
+ z-index: 21474836;
194
+ }
195
+ .cnb-zindex-7 {
196
+ z-index: 2147484;
197
+ }
198
+ .cnb-zindex-6 {
199
+ z-index: 214748;
200
+ }
201
+ .cnb-zindex-5 {
202
+ z-index: 21475;
203
+ }
204
+ .cnb-zindex-4 {
205
+ z-index: 2147;
206
+ }
207
+ .cnb-zindex-3 {
208
+ z-index: 215;
209
+ }
210
+ .cnb-zindex-2 {
211
+ z-index: 21;
212
+ }
213
+ .cnb-zindex-1 {
214
+ z-index: 2;
215
+ }
216
  }
src/admin/api/CnbAppRemote.php CHANGED
@@ -248,6 +248,7 @@ class CnbAppRemote {
248
  $url = self::cnb_get_api_base() . $rest_endpoint;
249
  $response = self::wp_remote_patch( $url, $args );
250
  self::cnb_incr_transient_base();
 
251
 
252
  return self::cnb_remote_handle_response( $response );
253
  }
@@ -265,6 +266,7 @@ class CnbAppRemote {
265
  $url = self::cnb_get_api_base() . $rest_endpoint;
266
  $response = self::wp_remote_delete( $url, $args );
267
  self::cnb_incr_transient_base();
 
268
 
269
  return self::cnb_remote_handle_response( $response );
270
  }
@@ -283,6 +285,7 @@ class CnbAppRemote {
283
  $timer = new RemoteTrace( $url );
284
  $response = wp_remote_post( $url, $args );
285
  self::cnb_incr_transient_base();
 
286
  $timer->end();
287
 
288
  return self::cnb_remote_handle_response( $response );
248
  $url = self::cnb_get_api_base() . $rest_endpoint;
249
  $response = self::wp_remote_patch( $url, $args );
250
  self::cnb_incr_transient_base();
251
+ do_action('cnb_after_button_changed');
252
 
253
  return self::cnb_remote_handle_response( $response );
254
  }
266
  $url = self::cnb_get_api_base() . $rest_endpoint;
267
  $response = self::wp_remote_delete( $url, $args );
268
  self::cnb_incr_transient_base();
269
+ do_action('cnb_after_button_changed');
270
 
271
  return self::cnb_remote_handle_response( $response );
272
  }
285
  $timer = new RemoteTrace( $url );
286
  $response = wp_remote_post( $url, $args );
287
  self::cnb_incr_transient_base();
288
+ do_action('cnb_after_button_changed');
289
  $timer->end();
290
 
291
  return self::cnb_remote_handle_response( $response );
src/admin/api/CnbMigration.php CHANGED
@@ -8,6 +8,7 @@ use cnb\admin\button\CnbButton;
8
  use cnb\admin\button\CnbButtonOptions;
9
  use cnb\admin\condition\CnbCondition;
10
  use cnb\admin\domain\CnbDomain;
 
11
  use cnb\admin\domain\CnbDomainProperties;
12
  use cnb\admin\models\CnbActivation;
13
  use cnb\notices\CnbNotice;
@@ -104,7 +105,7 @@ class CnbMigration {
104
  $domain->trackConversion = isset( $cnb_options['conversions'] ) && $cnb_options['conversions'] != 0;
105
  $domain->properties = $existing_domain !== null ? $existing_domain->properties : new CnbDomainProperties();
106
  $domain->properties->allowMultipleButtons = $existing_domain !== null ? $existing_domain->properties->allowMultipleButtons : true;
107
- $domain->properties->zindex = ( new CnbUtils() )->zindex( $cnb_options['z-index'] );
108
  $domain->properties->scale = $cnb_options['zoom'];
109
 
110
  if ( $existing_domain !== null ) {
8
  use cnb\admin\button\CnbButtonOptions;
9
  use cnb\admin\condition\CnbCondition;
10
  use cnb\admin\domain\CnbDomain;
11
+ use cnb\admin\domain\CnbDomainController;
12
  use cnb\admin\domain\CnbDomainProperties;
13
  use cnb\admin\models\CnbActivation;
14
  use cnb\notices\CnbNotice;
105
  $domain->trackConversion = isset( $cnb_options['conversions'] ) && $cnb_options['conversions'] != 0;
106
  $domain->properties = $existing_domain !== null ? $existing_domain->properties : new CnbDomainProperties();
107
  $domain->properties->allowMultipleButtons = $existing_domain !== null ? $existing_domain->properties->allowMultipleButtons : true;
108
+ $domain->properties->zindex = ( new CnbDomainController() )->order_to_zindex( $cnb_options['z-index'] );
109
  $domain->properties->scale = $cnb_options['zoom'];
110
 
111
  if ( $existing_domain !== null ) {
src/admin/domain/CnbDomainController.php CHANGED
@@ -17,6 +17,7 @@ class CnbDomainController {
17
  * This is called to create the Domain
18
  */
19
  public static function create() {
 
20
  $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
21
  $action = 'cnb_create_domain';
22
  $nonce_verified = wp_verify_nonce( $nonce, $action );
@@ -31,7 +32,7 @@ class CnbDomainController {
31
 
32
  $processed_domain = CnbDomain::fromObject( $domain );
33
  // Alligator alert - this is different from other update functions!!
34
- $processed_domain->properties->zindex = ( new CnbUtils() )->zindex( $processed_domain->properties->zindex );
35
  // do the processing
36
  $result = CnbAdminCloud::cnb_create_domain( $cnb_cloud_notifications, $processed_domain );
37
 
@@ -63,6 +64,7 @@ class CnbDomainController {
63
  }
64
 
65
  private static function getDomainFromRequest() {
 
66
  // sanitize the input
67
  $domain = filter_input(
68
  INPUT_POST,
@@ -72,7 +74,7 @@ class CnbDomainController {
72
 
73
  $processed_domain = CnbDomain::fromObject( $domain );
74
  // Alligator alert - this is different from other update functions!!
75
- $processed_domain->properties->zindex = ( new CnbUtils() )->zindex( $processed_domain->properties->zindex );
76
 
77
  return $processed_domain;
78
  }
@@ -242,4 +244,65 @@ class CnbDomainController {
242
  );
243
  }
244
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  }
17
  * This is called to create the Domain
18
  */
19
  public static function create() {
20
+ $domain_controller = new CnbDomainController();
21
  $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
22
  $action = 'cnb_create_domain';
23
  $nonce_verified = wp_verify_nonce( $nonce, $action );
32
 
33
  $processed_domain = CnbDomain::fromObject( $domain );
34
  // Alligator alert - this is different from other update functions!!
35
+ $processed_domain->properties->zindex = $domain_controller->order_to_zindex( $processed_domain->properties->zindex );
36
  // do the processing
37
  $result = CnbAdminCloud::cnb_create_domain( $cnb_cloud_notifications, $processed_domain );
38
 
64
  }
65
 
66
  private static function getDomainFromRequest() {
67
+ $domain_controller = new CnbDomainController();
68
  // sanitize the input
69
  $domain = filter_input(
70
  INPUT_POST,
74
 
75
  $processed_domain = CnbDomain::fromObject( $domain );
76
  // Alligator alert - this is different from other update functions!!
77
+ $processed_domain->properties->zindex = $domain_controller->order_to_zindex( $processed_domain->properties->zindex );
78
 
79
  return $processed_domain;
80
  }
244
  );
245
  }
246
  }
247
+
248
+
249
+ /**
250
+ * Convert an "order" integer into a proper zIndex (10 to 2147483647, for example)
251
+ *
252
+ * This is the reverse operation of zindex_to_order
253
+ *
254
+ * @param $value int 1-10
255
+ *
256
+ * @return int 2-2147483647
257
+ */
258
+ function order_to_zindex( $value ) {
259
+ $zindexMap = $this->get_zindex_map();
260
+ $default = 10;
261
+ if (array_key_exists($value, $zindexMap)) {
262
+ return $zindexMap[ $value ];
263
+ }
264
+ return $zindexMap[$default];
265
+ }
266
+
267
+
268
+ /**
269
+ * Convert zIndex into an "order" int (2147483647 to 10, for example)
270
+ *
271
+ * This is the reverse operation of order_to_zindex
272
+ *
273
+ * @param $zindex int 2-2147483647
274
+ *
275
+ * @return int 1-10
276
+ */
277
+ function zindex_to_order( $zindex ) {
278
+ // This starts at the higher number
279
+ foreach ( $this->get_zindex_map() as $order => $value ) {
280
+ if ( $zindex >= $value ) {
281
+ return $order;
282
+ }
283
+ }
284
+
285
+ return 1;
286
+ }
287
+
288
+ /**
289
+ * Returns the conversion map from the internal zindex number (1-10)
290
+ * to the actual z-index (2 - 2147483647).
291
+ *
292
+ * @return int[]
293
+ */
294
+ private function get_zindex_map() {
295
+ return array(
296
+ 10 => 2147483647,
297
+ 9 => 214748365,
298
+ 8 => 21474836,
299
+ 7 => 2147484,
300
+ 6 => 214748,
301
+ 5 => 21475,
302
+ 4 => 2147,
303
+ 3 => 215,
304
+ 2 => 21,
305
+ 1 => 2
306
+ );
307
+ }
308
  }
src/admin/domain/CnbDomainViewEdit.php CHANGED
@@ -149,7 +149,8 @@ class CnbDomainViewEdit {
149
  }
150
 
151
  function render_form_button_display( $domain ) {
152
- $domain_properties_zindex_order = ( new CnbUtils() )->zindexToOrder( $domain->properties->zindex );
 
153
  ?>
154
  <tr>
155
  <th colspan="2"><h2>Button display</h2></th>
149
  }
150
 
151
  function render_form_button_display( $domain ) {
152
+ $domain_controller = new CnbDomainController();
153
+ $domain_properties_zindex_order = $domain_controller->zindex_to_order( $domain->properties->zindex );
154
  ?>
155
  <tr>
156
  <th colspan="2"><h2>Button display</h2></th>
src/admin/partials/CnbHeaderNotices.php CHANGED
@@ -295,25 +295,35 @@ class CnbHeaderNotices {
295
  }
296
 
297
  public function warn_about_caching_plugins( &$notices ) {
298
- $cnb_caching_check = $this->check_for_caching();
299
- if ( $cnb_caching_check ) {
300
- $this->caching_plugin_warning_notice( $cnb_caching_check, $notices );
301
  }
302
  }
303
 
304
- private function caching_plugin_warning_notice( $caching_plugin_name, &$notices ) {
305
  $plugins = get_plugins();
306
- $plugin = $plugins[ $caching_plugin_name ];
307
- $name = $plugin['Name'];
 
 
 
 
308
 
309
- $message = '<p><span class="dashicons dashicons-warning"></span> ';
310
- $message .= 'Your website is using a <strong><i>Caching Plugin</i></strong> (' . $name . '). ';
311
- $message .= "If you're not seeing your button or your changes, make sure you empty your cache first.</p>";
312
 
313
- $notices[] = new CnbNotice( 'error', $message, true, 'cnb-caching-' . $name );
 
314
  }
315
 
 
 
 
 
316
  private function check_for_caching() {
 
317
  $caching_plugins = array(
318
  'autoptimize/autoptimize.php',
319
  'breeze/breeze.php',
@@ -326,15 +336,16 @@ class CnbHeaderNotices {
326
  'simple-cache/simple-cache.php',
327
  'w3-total-cache/w3-total-cache.php',
328
  'wp-fastest-cache/wpFastestCache.php',
329
- 'wp-super-cache/wp-cache.php'
 
330
  );
331
  foreach ( $caching_plugins as $plugin ) {
332
  if ( is_plugin_active( $plugin ) ) {
333
- return $plugin;
334
  }
335
  }
336
 
337
- return null;
338
  }
339
 
340
  public function is_timezone_missing( $domain ) {
295
  }
296
 
297
  public function warn_about_caching_plugins( &$notices ) {
298
+ $active_caching_plugins = $this->check_for_caching();
299
+ if ( $active_caching_plugins ) {
300
+ $this->caching_plugin_warning_notice( $active_caching_plugins, $notices );
301
  }
302
  }
303
 
304
+ private function caching_plugin_warning_notice( $caching_plugin_names, &$notices ) {
305
  $plugins = get_plugins();
306
+ foreach ($caching_plugin_names as $caching_plugin_name ) {
307
+ if ( ! is_array($plugins) || ! array_key_exists($caching_plugin_name, $plugins)) {
308
+ continue;
309
+ }
310
+ $plugin = $plugins[ $caching_plugin_name ];
311
+ $name = $plugin['Name'];
312
 
313
+ $message = '<p><span class="dashicons dashicons-warning"></span> ';
314
+ $message .= 'Your website is using a <strong><i>Caching Plugin</i></strong> (' . $name . '). ';
315
+ $message .= "If you're not seeing your button or your changes, make sure you empty your cache first.</p>";
316
 
317
+ $notices[] = new CnbNotice( 'error', $message, true, 'cnb-caching-' . $name );
318
+ }
319
  }
320
 
321
+ /**
322
+ * Return all active Caching plugins
323
+ * @return array
324
+ */
325
  private function check_for_caching() {
326
+ $active_plugins = array();
327
  $caching_plugins = array(
328
  'autoptimize/autoptimize.php',
329
  'breeze/breeze.php',
336
  'simple-cache/simple-cache.php',
337
  'w3-total-cache/w3-total-cache.php',
338
  'wp-fastest-cache/wpFastestCache.php',
339
+ 'wp-super-cache/wp-cache.php',
340
+ 'wp-rocket/wp-rocket.php',
341
  );
342
  foreach ( $caching_plugins as $plugin ) {
343
  if ( is_plugin_active( $plugin ) ) {
344
+ $active_plugins[] = $plugin;
345
  }
346
  }
347
 
348
+ return $active_plugins;
349
  }
350
 
351
  public function is_timezone_missing( $domain ) {
src/admin/settings/CnbSettingsController.php CHANGED
@@ -180,6 +180,8 @@ class CnbSettingsController {
180
  // We do not actually store this value in the DB!
181
  unset( $updated_options['status'] );
182
 
 
 
183
  return $updated_options;
184
  }
185
 
180
  // We do not actually store this value in the DB!
181
  unset( $updated_options['status'] );
182
 
183
+ do_action('cnb_after_button_changed');
184
+
185
  return $updated_options;
186
  }
187
 
src/autoload.php CHANGED
@@ -70,6 +70,7 @@ spl_autoload_register(
70
  'cnb\\admin\\settings\\cnbsettingscontroller' => '/admin/settings/CnbSettingsController.php',
71
  'cnb\\admin\\settings\\cnbsettingsrouter' => '/admin/settings/CnbSettingsRouter.php',
72
  'cnb\\admin\\settings\\cnbsettingsviewedit' => '/admin/settings/CnbSettingsViewEdit.php',
 
73
  'cnb\\callnowbutton' => '/CallNowButton.php',
74
  'cnb\\cli\\cnb_cli' => '/cli/CNB_CLI.php',
75
  'cnb\\cli\\cnb_cli_api' => '/cli/CNB_CLI_Api.php',
70
  'cnb\\admin\\settings\\cnbsettingscontroller' => '/admin/settings/CnbSettingsController.php',
71
  'cnb\\admin\\settings\\cnbsettingsrouter' => '/admin/settings/CnbSettingsRouter.php',
72
  'cnb\\admin\\settings\\cnbsettingsviewedit' => '/admin/settings/CnbSettingsViewEdit.php',
73
+ 'cnb\\cache\\cachehandler' => '/utils/class-cachehandler.php',
74
  'cnb\\callnowbutton' => '/CallNowButton.php',
75
  'cnb\\cli\\cnb_cli' => '/cli/CNB_CLI.php',
76
  'cnb\\cli\\cnb_cli_api' => '/cli/CNB_CLI_Api.php',
src/call-now-button.php CHANGED
@@ -16,5 +16,8 @@ add_action( 'plugins_loaded', array( 'cnb\CallNowButton', 'registerHeaderAndFoot
16
  add_action( 'plugins_loaded', array( 'cnb\CallNowButton', 'registerPostActions' ) );
17
  add_action( 'plugins_loaded', array( 'cnb\CallNowButton', 'registerAjax' ) );
18
 
 
 
 
19
  // This queues the front-end to be rendered (`wp_loaded` should only fire on the front-end facing site)
20
  add_action( 'wp_loaded', array( 'cnb\renderer\RendererFactory', 'register' ) );
16
  add_action( 'plugins_loaded', array( 'cnb\CallNowButton', 'registerPostActions' ) );
17
  add_action( 'plugins_loaded', array( 'cnb\CallNowButton', 'registerAjax' ) );
18
 
19
+ // Ensure we are excluded from certain Caching plugins
20
+ add_action( 'plugins_loaded', array( 'cnb\cache\CacheHandler', 'exclude' ) );
21
+
22
  // This queues the front-end to be rendered (`wp_loaded` should only fire on the front-end facing site)
23
  add_action( 'wp_loaded', array( 'cnb\renderer\RendererFactory', 'register' ) );
src/renderers/modern/class-modernrenderer.php CHANGED
@@ -17,7 +17,7 @@ class ModernRenderer extends Renderer {
17
  private function enqueue_frontend_style() {
18
  wp_register_style(
19
  CNB_SLUG . '-modern-style',
20
- plugins_url( CNB_SLUG . '/resources/style/modern.css' ),
21
  array(),
22
  CNB_VERSION
23
  );
@@ -116,9 +116,6 @@ class ModernRenderer extends Renderer {
116
  $cnb_click_tracking = $cnb_tracking_id > 0;
117
  $cnb_conversion_tracking = $cnb_conversion_id > 0;
118
  $cnb_number = isset( $cnb_options['number'] ) ? $cnb_options['number'] : null;
119
- $cnb_zoom = isset( $cnb_options['zoom'] ) ? $cnb_options['zoom'] : 1;
120
- $cnb_zindex = isset( $cnb_options['z-index'] ) ? $cnb_options['z-index'] : 10;
121
- $cnb_zindex_val = $cnb_utils->zindex( $cnb_zindex );
122
 
123
  $cnb_classnames = $this->get_class_names();
124
 
@@ -134,8 +131,6 @@ class ModernRenderer extends Renderer {
134
  $cnb_call_link .= ' class="' . esc_attr( $cnb_classnames ) . '"';
135
 
136
  $cnb_call_link .= ' style="';
137
- $cnb_call_link .= 'transform: scale(' . esc_attr( $cnb_zoom ) . ');';
138
- $cnb_call_link .= 'z-index:' . esc_attr( $cnb_zindex_val ) . ';';
139
  $cnb_call_link .= $cnb_button_background;
140
  $cnb_call_link .= '"';
141
 
@@ -295,10 +290,39 @@ class ModernRenderer extends Renderer {
295
  );
296
  }
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  private function get_class_names() {
299
  $cnb_options = get_option( 'cnb' );
300
  $cnb_classnames = 'call-now-button';
301
 
 
 
 
 
 
 
302
  // Button has text?
303
  if ( $cnb_options['text'] !== '' ) {
304
  $cnb_classnames .= ' cnb-text';
17
  private function enqueue_frontend_style() {
18
  wp_register_style(
19
  CNB_SLUG . '-modern-style',
20
+ plugins_url( '../../../resources/style/modern.css', __FILE__ ),
21
  array(),
22
  CNB_VERSION
23
  );
116
  $cnb_click_tracking = $cnb_tracking_id > 0;
117
  $cnb_conversion_tracking = $cnb_conversion_id > 0;
118
  $cnb_number = isset( $cnb_options['number'] ) ? $cnb_options['number'] : null;
 
 
 
119
 
120
  $cnb_classnames = $this->get_class_names();
121
 
131
  $cnb_call_link .= ' class="' . esc_attr( $cnb_classnames ) . '"';
132
 
133
  $cnb_call_link .= ' style="';
 
 
134
  $cnb_call_link .= $cnb_button_background;
135
  $cnb_call_link .= '"';
136
 
290
  );
291
  }
292
 
293
+ /**
294
+ * Get the zoom level for the Modern button.
295
+ *
296
+ * The internal values are 0.7 - 1.3 and it defaults to 1.0
297
+ *
298
+ * @return int 70 - 130, defaults to 100
299
+ */
300
+ private function get_zoom() {
301
+ $cnb_options = get_option( 'cnb' );
302
+ $cnb_zoom = isset( $cnb_options['zoom'] ) ? (float) $cnb_options['zoom'] : 1.0;
303
+ return (int) ($cnb_zoom * 100);
304
+ }
305
+
306
+ /**
307
+ * Get the z-index meta number for the Modern button.
308
+ *
309
+ * @return int 1-10, defaults to 10
310
+ */
311
+ private function get_zindex() {
312
+ $cnb_options = get_option( 'cnb' );
313
+ return isset( $cnb_options['z-index'] ) ? (int) $cnb_options['z-index'] : 10;
314
+ }
315
+
316
  private function get_class_names() {
317
  $cnb_options = get_option( 'cnb' );
318
  $cnb_classnames = 'call-now-button';
319
 
320
+ // Button zoom
321
+ $cnb_classnames .= ' cnb-zoom-' . esc_attr( $this->get_zoom() );
322
+
323
+ // Button z-index
324
+ $cnb_classnames .= ' cnb-zindex-' . esc_attr( $this->get_zindex() );
325
+
326
  // Button has text?
327
  if ( $cnb_options['text'] !== '' ) {
328
  $cnb_classnames .= ' cnb-text';
src/utils/CnbUtils.php CHANGED
@@ -92,55 +92,6 @@ class CnbUtils {
92
  return isset( $cnb_options['cloud_use_id'] ) && ! empty( $cnb_options['cloud_use_id'] ) ? $cnb_options['cloud_use_id'] : 0;
93
  }
94
 
95
- /**
96
- * Convert an "order" integer into a proper zIndex (10 to 2147483647, for example)
97
- *
98
- * @param $value int 1-10
99
- *
100
- * @return int 2-2147483647
101
- */
102
- function zindex( $value ) {
103
- $zindexMap = $this->getZindexMap();
104
- $default = 10;
105
- if (array_key_exists($value, $zindexMap)) {
106
- return $zindexMap[ $value ];
107
- }
108
- return $zindexMap[$default];
109
- }
110
-
111
- private function getZindexMap() {
112
- return array(
113
- 10 => 2147483647,
114
- 9 => 214748365,
115
- 8 => 21474836,
116
- 7 => 2147484,
117
- 6 => 214748,
118
- 5 => 21475,
119
- 4 => 2147,
120
- 3 => 215,
121
- 2 => 21,
122
- 1 => 2
123
- );
124
- }
125
-
126
- /**
127
- * Convert zIndex into an "order" int (2147483647 to 10, for example)
128
- *
129
- * @param $zindex int 2-2147483647
130
- *
131
- * @return int 1-10
132
- */
133
- function zindexToOrder( $zindex ) {
134
- // This starts at the higher number
135
- foreach ( $this->getZindexMap() as $order => $value ) {
136
- if ( $zindex >= $value ) {
137
- return $order;
138
- }
139
- }
140
-
141
- return 1;
142
- }
143
-
144
  /**
145
  * Get the default glyph for a particular action type.
146
  *
92
  return isset( $cnb_options['cloud_use_id'] ) && ! empty( $cnb_options['cloud_use_id'] ) ? $cnb_options['cloud_use_id'] : 0;
93
  }
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  /**
96
  * Get the default glyph for a particular action type.
97
  *
src/utils/class-cachehandler.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace cnb\cache;
4
+
5
+ use cnb\utils\CnbUtils;
6
+
7
+ class CacheHandler {
8
+
9
+ /**
10
+ * Exclude the cloud version from the WP Rocket cache
11
+ *
12
+ * Since this JS file is managed externally and
13
+ * modified via the API (not via WordPress).
14
+ *
15
+ * @return void
16
+ */
17
+ private function excludeCloudFromWpRocket() {
18
+ add_filter( 'rocket_minify_excluded_external_js',
19
+ function ( $excluded_external_js ) {
20
+ $excluded_external_js[] = 'user.callnowbutton.com';
21
+
22
+ return $excluded_external_js;
23
+ }
24
+ );
25
+ }
26
+
27
+ /**
28
+ * Clean the cache for WP Super Cache
29
+ *
30
+ * Ref https://github.com/Automattic/wp-super-cache/blob/master/wp-cache.php#L2430
31
+ *
32
+ * @return void
33
+ */
34
+ public function clearWpSuperCache() {
35
+ if ( function_exists( 'wp_cache_clean_cache' ) ) {
36
+ global $file_prefix;
37
+ wp_cache_clean_cache( $file_prefix );
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Clean the cache for WP Rocket
43
+ *
44
+ * @return void
45
+ */
46
+ public function clearWpRocketCacheAfterSave() {
47
+ $cnb_options = get_option( 'cnb' );
48
+ $cnb_utils = new CnbUtils();
49
+ // This action doesn't work - since it requires some args and a nonce
50
+ // do_action('admin_post_purge_cache');
51
+
52
+ // However, we can simply call the function that clears the cache after a save
53
+
54
+ // rocket_clean_domain is called to remove all cached pages
55
+ if ( function_exists( 'rocket_clean_domain' ) ) {
56
+ rocket_clean_domain(); // Check if we need "all" as well?
57
+ }
58
+
59
+ // rocket_clean_minify & rocket_clean_cache_busting are only needed if the Premium version is active,
60
+ // since the Modern version does not have any JS enabled.
61
+ if ( ! $cnb_utils->isCloudActive( $cnb_options ) ) {
62
+ return;
63
+ }
64
+
65
+ // rocket_clean_minify is called to ensure our cached (Cloud) JS file is cleared
66
+ if ( function_exists( 'rocket_clean_minify' ) ) {
67
+ rocket_clean_minify( [ 'js' ] );
68
+ }
69
+
70
+ if ( function_exists( 'rocket_clean_cache_busting' ) ) {
71
+ rocket_clean_cache_busting( [ 'js' ] );
72
+ }
73
+ }
74
+
75
+ public static function exclude() {
76
+ $handler = new CacheHandler();
77
+ $handler->excludeCloudFromWpRocket();
78
+
79
+ add_action( 'cnb_after_button_changed', array( $handler, 'clearWpRocketCacheAfterSave' ) );
80
+ add_action( 'cnb_after_button_changed', array( $handler, 'clearWpSuperCache' ) );
81
+
82
+ }
83
+ }