Call Now Button - Version 0.3.0

Version Description

Download this release

Release Info

Developer jgrietveld
Plugin Icon 128x128 Call Now Button
Version 0.3.0
Comparing to
See all releases

Code changes from version 0.2.1 to 0.3.0

Files changed (4) hide show
  1. call-now-button.css +0 -0
  2. call-now-button.js +36 -1
  3. call-now-button.php +162 -81
  4. readme.txt +20 -8
call-now-button.css CHANGED
File without changes
call-now-button.js CHANGED
@@ -25,4 +25,39 @@ jQuery(document).ready(function($){
25
  scrollTop: $("tr.classic").offset().top
26
  }, 500);
27
  });
28
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  scrollTop: $("tr.classic").offset().top
26
  }, 500);
27
  });
28
+ });
29
+
30
+ const textButtonField = document.querySelector("#buttonTextField");
31
+
32
+ textFieldChars();
33
+
34
+ textButtonField.addEventListener("keyup", textFieldChars);
35
+
36
+ function textFieldChars() {
37
+ chars = textButtonField.value.length;
38
+ if(chars>0) {
39
+ toggleVisibility('.appearance-options', 'none');
40
+ toggleVisibility('.classic', 'none');
41
+ toggleVisibility('.appearanceDesc', 'block');
42
+ toggleVisibility('.notempty', 'block')
43
+ } else {
44
+ toggleVisibility('.appearance-options', 'block');
45
+ toggleVisibility('.classic', 'table-row');
46
+ toggleVisibility('.appearanceDesc', 'none');
47
+ toggleVisibility('.notempty', 'none')
48
+ }
49
+ if( chars > 15 ) {
50
+ document.querySelector('.lengthwarning').innerHTML = "Your text is " + chars + " characters.";
51
+ document.querySelector('.lengthwarning').style.color = '#C00';
52
+ } else if(chars > 0) {
53
+ document.querySelector('.lengthwarning').innerHTML = "Your text is " + chars + " character(s).";
54
+ document.querySelector('.lengthwarning').style.color = '#444';
55
+ } else {
56
+ document.querySelector('.lengthwarning').innerHTML = "Leave blank to only show the button with icon.";
57
+ document.querySelector('.lengthwarning').style.color = '#444';
58
+ }
59
+ }
60
+
61
+ function toggleVisibility(selector, value) {
62
+ document.querySelector(selector).style.display = value;
63
+ }
call-now-button.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Call Now Button
4
  Plugin URI: http://callnowbutton.com
5
  Description: Mobile visitors will see a call now button fixed at the bottom of your site
6
- Version: 0.2.1
7
  Author: Jerry Rietveld
8
  Author URI: http://www.jgrietveld.com
9
  License: GPL2
@@ -26,18 +26,26 @@ License: GPL2
26
  */
27
  ?>
28
  <?php
29
- define('CNB_VERSION','0.2.1');
30
  add_action('admin_menu', 'register_cnb_page');
31
  add_action('admin_init', 'cnb_options_init');
32
 
33
- $cnb_options = cnb_get_options();
 
 
 
 
 
 
 
 
34
 
35
  $cnb_options['active'] = isset($cnb_options['active']) ? 1 : 0;
36
  $cnb_options['classic'] = isset($cnb_options['classic']) ? 1 : 0;
37
 
38
  $plugin_title = apply_filters( 'cnb_plugin_title', 'Call Now Button');
39
 
40
- $cnb_updated = set_basic_options();
41
 
42
  add_action( 'admin_enqueue_scripts', 'cnb_enqueue_color_picker' ); // add the color picker
43
 
@@ -61,10 +69,11 @@ function call_now_settings_page() {
61
  global $cnb_options;
62
  global $plugin_title;
63
  global $cnb_updated;
 
64
  ?>
65
 
66
  <div class="wrap">
67
- <h1>Call Now Button <span class="version">v.<?php echo CNB_VERSION;?></span></h1>
68
  <!--## NOTIFICATION BARS ## -->
69
  <?php
70
  // Display notification that the button is active or inactive
@@ -81,9 +90,17 @@ function call_now_settings_page() {
81
 
82
 
83
  // inform exisiting users about update to the button design
84
- if($cnb_updated) { ?>
85
  <div class="notice-warning notice is-dismissible">
86
- <p>The Call Now Button has a fresh new look! If you prefer the old button, you can <span class="cnb-switch-back">switch back</span> in the Advanced Settings. <a href="http://callnowbutton.com/new-button-design/" target="_blank" class="cnb-external"><i>See the difference &raquo;</i></a></p>
 
 
 
 
 
 
 
 
87
  </div>
88
  <?php } ?>
89
 
@@ -97,33 +114,46 @@ function call_now_settings_page() {
97
  <input id="activated" name="cnb[active]" type="checkbox" value="1" <?php checked('1', $cnb_options['active']); ?> /> <label title="Enable" for="activated">Enabled</label> &nbsp; &nbsp;
98
  </td>
99
  </tr>
100
- <tr valign="top"><th scope="row">Phone number:</th>
 
101
  <td><input type="text" name="cnb[number]" value="<?php echo $cnb_options['number']; ?>" /></td>
102
  </tr>
 
 
 
 
 
 
 
 
103
  </table>
104
  <div id="settings">
105
  <table class="form-table">
106
- <tr valign="top"><th scope="row">Button color:</th>
 
107
  <td><input name="cnb[color]" type="text" value="<?php echo $cnb_options['color']; ?>" class="cnb-color-field" data-default-color="#009900" /></td>
108
  </tr>
109
  <tr valign="top"><th scope="row">Position</th>
110
  <td class="appearance">
111
- <div class="radio-item">
112
- <input type="radio" id="appearance1" name="cnb[appearance]" value="right" <?php checked('right', $cnb_options['appearance']); ?>>
113
- <label title="right" for="appearance1">Right corner</label>
114
- </div>
115
- <div class="radio-item">
116
- <input type="radio" id="appearance2" name="cnb[appearance]" value="left" <?php checked('left', $cnb_options['appearance']); ?>>
117
- <label title="left" for="appearance2">Left corner</label>
118
- </div>
119
- <div class="radio-item">
120
- <input type="radio" id="appearance3" name="cnb[appearance]" value="middle" <?php checked('middle', $cnb_options['appearance']); ?>>
121
- <label title="middle" for="appearance3">Center bottom</label>
 
 
 
 
 
 
122
  </div>
123
- <div class="radio-item">
124
- <input type="radio" id="appearance4" name="cnb[appearance]" value="full" <?php checked('full', $cnb_options['appearance']); ?>>
125
- <label title="full" for="appearance4">Full bottom</label>
126
- </div>
127
  </td>
128
  </tr>
129
  <tr valign="top">
@@ -131,24 +161,37 @@ function call_now_settings_page() {
131
  <td>
132
  <div class="radio-item">
133
  <input id="tracking3" type="radio" name="cnb[tracking]" value="0" <?php checked('0', $cnb_options['tracking']); ?> />
134
- <label for="tracking3">Disabled</label><br />
135
  </div>
136
  <div class="radio-item">
137
  <input id="tracking1" type="radio" name="cnb[tracking]" value="2" <?php checked('2', $cnb_options['tracking']); ?> />
138
- <label for="tracking1">Google Universal Analytics (analytics.js)</label><br />
 
 
 
 
139
  </div>
140
  <div class="radio-item">
141
  <input id="tracking2" type="radio" name="cnb[tracking]" value="1" <?php checked('1', $cnb_options['tracking']); ?> />
142
- <label for="tracking2">Google Classic Analytics (ga.js)</label>
143
  </div>
144
  <p class="description">Click tracking turned on? Wait for about a day then log into your Google Analytics accunt and click in the <strong>Behavior</strong> section on <strong>Events</strong>. <span class="whatsThis">(<a href="https://support.google.com/analytics/answer/1033068#SeeAlerts" target="_blank">What's this?</a>)</span></p>
145
  </td>
146
  </tr>
147
  <tr valign="top" class="appearance">
148
  <th scope="row">Limit appearance:</th>
149
- <td>
150
  <input type="text" name="cnb[show]" value="<?php echo $cnb_options['show']; ?>" />
151
- <p class="description">Enter IDs of the posts &amp; pages the Call Now Button should appear on (leave blank for all).</p>
 
 
 
 
 
 
 
 
 
152
  </td>
153
  </tr>
154
  <tr valign="top" class="classic">
@@ -176,8 +219,8 @@ function call_now_settings_page() {
176
  </p>
177
  <!--// Display notification about the testing program -->
178
  <div class="postbox cnb-alert-box cnb-center">
179
- <p>We're looking for testers for the Call&nbsp;Now&nbsp;Button&nbsp;<b>Pro</b>!
180
- <a class="cnb-external" href="http://callnowbutton.com/join-test-team/" rel="help" target="_blank">Join us here &raquo;</a>
181
  </p>
182
  </div>
183
 
@@ -195,21 +238,6 @@ function call_now_settings_page() {
195
  <?php }
196
  if(get_option('cnb') && !is_admin()) {
197
 
198
- // Color functions to calculate borders
199
- function changeColor($color, $direction) {
200
- if(!preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i', $color, $parts));
201
- if(!isset($direction) || $direction == "lighter") { $change = 45; } else { $change = -50; }
202
- for($i = 1; $i <= 3; $i++) {
203
- $parts[$i] = hexdec($parts[$i]);
204
- $parts[$i] = round($parts[$i] + $change);
205
- if($parts[$i] > 255) { $parts[$i] = 255; } elseif($parts[$i] < 0) { $parts[$i] = 0; }
206
- $parts[$i] = dechex($parts[$i]);
207
- }
208
- $output = '#' . str_pad($parts[1],2,"0",STR_PAD_LEFT) . str_pad($parts[2],2,"0",STR_PAD_LEFT) . str_pad($parts[3],2,"0",STR_PAD_LEFT);
209
- return $output;
210
- }
211
-
212
-
213
  $cnb_options = get_option('cnb');
214
  if(isset($cnb_options['active'])) $enabled = $cnb_options['active']; else $enabled = 0;
215
  if($enabled == '1') {
@@ -218,39 +246,57 @@ if(get_option('cnb') && !is_admin()) {
218
  $cnb_options = get_option('cnb');
219
  if(isset($cnb_options['classic'])) $classic = $cnb_options['classic']; else $classic = 0;
220
  $credits = "\n<!-- Call Now Button ".CNB_VERSION." by Jerry Rietveld (callnowbutton.com) -->\n";
 
221
  $ButtonExtra = "";
222
- if($classic == 1) {
223
 
224
  // OLD BUTTON DESIGN
225
- if($cnb_options['appearance'] == 'full' || $cnb_options['appearance'] == 'middle') {
226
  $ButtonAppearance = "width:100%;left:0;";
227
  $ButtonExtra = "body {padding-bottom:60px;}";
228
  }
229
- elseif($cnb_options['appearance'] == 'left') { $ButtonAppearance = "width:100px;left:0;border-bottom-right-radius:40px; border-top-right-radius:40px;"; }
230
- else { $ButtonAppearance = "width:100px;right:0;border-bottom-left-radius:40px; border-top-left-radius:40px;"; }
 
 
 
231
 
232
- $credits .= "<style>#callnowbutton {display:none;} @media screen and (max-width:650px){#callnowbutton {display:block; ".$ButtonAppearance." height:80px; position:fixed; bottom:-20px; border-top:2px solid ".changeColor($cnb_options['color'],'lighter')."; background:url(data:image/svg+xml;base64,".svg(changeColor($cnb_options['color'], 'darker') ).") center 2px no-repeat ".$cnb_options['color']."; text-decoration:none; box-shadow:0 0 5px #888; z-index:9999;background-size:58px 58px}".$ButtonExtra."}</style>\n";
233
 
234
  } else {
235
-
236
- // NEW BUTTON DESIGN
237
  $credits = "\n<!-- Call Now Button ".CNB_VERSION." by Jerry Rietveld (callnowbutton.com) -->\n";
238
- $ButtonShape = "width:65px; height:65px; border-radius:80px; border:2px solid #fff; bottom:15px;";
239
- if($cnb_options['appearance'] == 'full') {
 
 
240
  $ButtonAppearance = "width:100%;left:0;bottom:0;height:60px;border-top:1px solid ".changeColor($cnb_options['color'], 'lighter')."; border-bottom:1px solid ".changeColor($cnb_options['color'], 'darker').";";
241
  $ButtonExtra = "body {padding-bottom:60px;}";
 
 
 
242
  }
243
- elseif($cnb_options['appearance'] == 'left' ) { $ButtonAppearance = $ButtonShape . "left:20px;"; }
244
- elseif($cnb_options['appearance'] == 'middle') { $ButtonAppearance = $ButtonShape . "left:50%; margin-left:-33px;"; }
245
- else { $ButtonAppearance = $ButtonShape . "right:20px;"; }
 
 
 
 
 
 
246
 
247
  $credits = $credits ."<style>";
248
- $credits .= "#callnowbutton {display:none;} @media screen and (max-width:650px){#callnowbutton {display:block; position:fixed; text-decoration:none; z-index:9999;";
249
  $credits .= $ButtonAppearance;
250
- $credits .= "background:url(data:image/svg+xml;base64,".svg(changeColor($cnb_options['color'], 'darker') ).") center/50px 50px no-repeat ".$cnb_options['color'].";";
 
 
 
 
251
  $credits .= "}" . $ButtonExtra . "}";
252
  $credits .= "</style>\n";
253
- }
254
  echo $credits;
255
  }
256
  add_action('wp_head', 'cnb_head');
@@ -261,23 +307,34 @@ if(get_option('cnb') && !is_admin()) {
261
  if(isset($alloptions['show']) && $alloptions['show'] != "") {
262
  $show = explode(',', str_replace(' ', '' ,$alloptions['show']));
263
  $limited = TRUE;
 
264
  } else {
265
  $limited = FALSE;
266
  }
267
 
268
- if($alloptions['tracking'] == '1') {
269
  $tracking = "onclick=\"_gaq.push(['_trackEvent', 'Contact', 'Call Now Button', 'Phone']);\"";
270
- } elseif($alloptions['tracking'] == '2') {
271
  $tracking = "onclick=\"ga('send', 'event', 'Contact', 'Call Now Button', 'Phone');\"";
 
 
272
  } else {
273
  $tracking = "";
274
  }
275
 
276
- $callLink = '<a href="tel:'.$alloptions['number'].'" id="callnowbutton" '.$tracking.'>&nbsp;</a>';
 
 
277
 
278
  if($limited) {
279
- if(is_single($show) || is_page($show)) {
280
- echo $callLink;
 
 
 
 
 
 
281
  }
282
  } else {
283
  echo $callLink;
@@ -287,47 +344,71 @@ if(get_option('cnb') && !is_admin()) {
287
  }
288
  }
289
 
290
- function cnb_get_options() { // Checking and setting the default options
291
- if(!get_option('cnb')) {
292
  $default_options = array(
293
  'active',
294
  'number' => '',
 
295
  'color' => '#009900',
296
  'appearance' => 'right',
297
  'tracking' => 0,
298
  'show' => '',
 
299
  'version' => CNB_VERSION
300
  );
301
  add_option('cnb',$default_options);
302
- $cnb_options = get_option('cnb');
303
- }
304
-
305
- $cnb_options = get_option('cnb');
306
-
307
  return $cnb_options;
308
  }
309
- function set_basic_options() {
310
- if(!array_key_exists('version', get_option('cnb'))) {
311
- $cnb_options = get_option('cnb');
 
 
312
  $cnb_options['active'] = isset($cnb_options['active']) ? 1 : 0;
313
  $default_options = array(
314
  'active' => $cnb_options['active'],
315
  'number' => $cnb_options['number'],
 
316
  'color' => $cnb_options['color'],
317
  'appearance' => $cnb_options['appearance'],
318
  'tracking' => $cnb_options['tracking'],
319
  'show' => $cnb_options['show'],
 
320
  'version' => CNB_VERSION
321
  );
 
 
 
322
  update_option('cnb',$default_options);
323
- return true; // plugin was updated
324
  } else {
325
- return false; // no update
326
  }
 
327
  }
328
- function svg($color2) {
329
- $phone1 = '<path d="M7.104 14.032l15.586 1.984c0 0-0.019 0.5 0 0.953c0.029 0.756-0.26 1.534-0.809 2.1 l-4.74 4.742c2.361 3.3 16.5 17.4 19.8 19.8l16.813 1.141c0 0 0 0.4 0 1.1 c-0.002 0.479-0.176 0.953-0.549 1.327l-6.504 6.505c0 0-11.261 0.988-25.925-13.674C6.117 25.3 7.1 14 7.1 14" fill="'.$color2.'"/><path d="M7.104 13.032l6.504-6.505c0.896-0.895 2.334-0.678 3.1 0.35l5.563 7.8 c0.738 1 0.5 2.531-0.36 3.426l-4.74 4.742c2.361 3.3 5.3 6.9 9.1 10.699c3.842 3.8 7.4 6.7 10.7 9.1 l4.74-4.742c0.897-0.895 2.471-1.026 3.498-0.289l7.646 5.455c1.025 0.7 1.3 2.2 0.4 3.105l-6.504 6.5 c0 0-11.262 0.988-25.925-13.674C6.117 24.3 7.1 13 7.1 13" fill="#fff"/>';
330
- $svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 60 60">' . $phone1 . '</svg>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  return base64_encode($svg);
332
  }
333
  function buttonActive() {
3
  Plugin Name: Call Now Button
4
  Plugin URI: http://callnowbutton.com
5
  Description: Mobile visitors will see a call now button fixed at the bottom of your site
6
+ Version: 0.3.0
7
  Author: Jerry Rietveld
8
  Author URI: http://www.jgrietveld.com
9
  License: GPL2
26
  */
27
  ?>
28
  <?php
29
+ define('CNB_VERSION','0.3');
30
  add_action('admin_menu', 'register_cnb_page');
31
  add_action('admin_init', 'cnb_options_init');
32
 
33
+ $cnb_changelog = array(
34
+ '0.3' => 'You can now add text to your button and it\'s possible to switch between including and excluding specific pages.',
35
+ '0.2' => 'The Call Now Button has a fresh new look! If you prefer the old button, you can <span class="cnb-switch-back">switch back</span> in the Advanced Settings. <a href="http://callnowbutton.com/new-button-design/" target="_blank" class="cnb-external"><i>See the difference &raquo;</i></a>'
36
+ );
37
+
38
+ $cnb_settings = cnb_get_options(); // Grabbing the settins and checking for latest version OR creating the options file for first time installations
39
+ $cnb_options = $cnb_settings['options'];
40
+ $cnb_updated = $cnb_settings['updated'];
41
+
42
 
43
  $cnb_options['active'] = isset($cnb_options['active']) ? 1 : 0;
44
  $cnb_options['classic'] = isset($cnb_options['classic']) ? 1 : 0;
45
 
46
  $plugin_title = apply_filters( 'cnb_plugin_title', 'Call Now Button');
47
 
48
+
49
 
50
  add_action( 'admin_enqueue_scripts', 'cnb_enqueue_color_picker' ); // add the color picker
51
 
69
  global $cnb_options;
70
  global $plugin_title;
71
  global $cnb_updated;
72
+ global $cnb_changelog;
73
  ?>
74
 
75
  <div class="wrap">
76
+ <h1>Call Now Button <span class="version">v<?php echo CNB_VERSION;?></span></h1>
77
  <!--## NOTIFICATION BARS ## -->
78
  <?php
79
  // Display notification that the button is active or inactive
90
 
91
 
92
  // inform exisiting users about update to the button design
93
+ if($cnb_updated[0]) { ?>
94
  <div class="notice-warning notice is-dismissible">
95
+ <?php
96
+ foreach ($cnb_changelog as $key => $value) { // Only on first run after update show list of changes since last update
97
+ if($cnb_updated[1] == $key) {
98
+ break;
99
+ } else {
100
+ echo '<p><span class="dashicons dashicons-yes"></span> ' . $value . '</p>';
101
+ }
102
+ }
103
+ ?>
104
  </div>
105
  <?php } ?>
106
 
114
  <input id="activated" name="cnb[active]" type="checkbox" value="1" <?php checked('1', $cnb_options['active']); ?> /> <label title="Enable" for="activated">Enabled</label> &nbsp; &nbsp;
115
  </td>
116
  </tr>
117
+ <tr valign="top">
118
+ <th scope="row">Phone number:</th>
119
  <td><input type="text" name="cnb[number]" value="<?php echo $cnb_options['number']; ?>" /></td>
120
  </tr>
121
+ <tr valign="top" class="button-text">
122
+ <th scope="row">Button text:</th>
123
+ <td>
124
+ <input id="buttonTextField" type="text" name="cnb[text]" value="<?php echo $cnb_options['text']; ?>" maxlength="30" />
125
+ <p class="description lengthwarning " style="color:#C00"></p>
126
+ <p class="description notempty">We recommend that you stay under 15 character and that you always check if the text fits on your button. <span class="whatsThis">(<a href="http://callnowbutton.com/call-now-button-text-buttons/" target="_blank">Learn why...</a>)</span></p>
127
+ </td>
128
+ </tr>
129
  </table>
130
  <div id="settings">
131
  <table class="form-table">
132
+ <tr valign="top">
133
+ <th scope="row">Button color:</th>
134
  <td><input name="cnb[color]" type="text" value="<?php echo $cnb_options['color']; ?>" class="cnb-color-field" data-default-color="#009900" /></td>
135
  </tr>
136
  <tr valign="top"><th scope="row">Position</th>
137
  <td class="appearance">
138
+ <div class="appearance-options">
139
+ <div class="radio-item">
140
+ <input type="radio" id="appearance1" name="cnb[appearance]" value="right" <?php checked('right', $cnb_options['appearance']); ?>>
141
+ <label title="right" for="appearance1">Right corner</label>
142
+ </div>
143
+ <div class="radio-item">
144
+ <input type="radio" id="appearance2" name="cnb[appearance]" value="left" <?php checked('left', $cnb_options['appearance']); ?>>
145
+ <label title="left" for="appearance2">Left corner</label>
146
+ </div>
147
+ <div class="radio-item">
148
+ <input type="radio" id="appearance3" name="cnb[appearance]" value="middle" <?php checked('middle', $cnb_options['appearance']); ?>>
149
+ <label title="middle" for="appearance3">Center bottom</label>
150
+ </div>
151
+ <div class="radio-item">
152
+ <input type="radio" id="appearance4" name="cnb[appearance]" value="full" <?php checked('full', $cnb_options['appearance']); ?>>
153
+ <label title="full" for="appearance4">Full bottom</label>
154
+ </div>
155
  </div>
156
+ <p class="description appearanceDesc">This setting is ignored because you have text entered into the <b>Button text</b> field.</p>
 
 
 
157
  </td>
158
  </tr>
159
  <tr valign="top">
161
  <td>
162
  <div class="radio-item">
163
  <input id="tracking3" type="radio" name="cnb[tracking]" value="0" <?php checked('0', $cnb_options['tracking']); ?> />
164
+ <label for="tracking3">Disabled</label>
165
  </div>
166
  <div class="radio-item">
167
  <input id="tracking1" type="radio" name="cnb[tracking]" value="2" <?php checked('2', $cnb_options['tracking']); ?> />
168
+ <label for="tracking1">Google Universal Analytics (analytics.js)</label>
169
+ </div>
170
+ <div class="radio-item">
171
+ <input id="tracking4" type="radio" name="cnb[tracking]" value="3" <?php checked('3', $cnb_options['tracking']); ?> />
172
+ <label for="tracking4">Latest Google Analytics (gtag.js)</label>
173
  </div>
174
  <div class="radio-item">
175
  <input id="tracking2" type="radio" name="cnb[tracking]" value="1" <?php checked('1', $cnb_options['tracking']); ?> />
176
+ <label for="tracking2">Classic Google Analytics (ga.js)</label>
177
  </div>
178
  <p class="description">Click tracking turned on? Wait for about a day then log into your Google Analytics accunt and click in the <strong>Behavior</strong> section on <strong>Events</strong>. <span class="whatsThis">(<a href="https://support.google.com/analytics/answer/1033068#SeeAlerts" target="_blank">What's this?</a>)</span></p>
179
  </td>
180
  </tr>
181
  <tr valign="top" class="appearance">
182
  <th scope="row">Limit appearance:</th>
183
+ <td>
184
  <input type="text" name="cnb[show]" value="<?php echo $cnb_options['show']; ?>" />
185
+ <p class="description">Enter IDs of the posts &amp; pages, separated by commas (leave blank for all).</p>
186
+ <div class="radio-item">
187
+ <input id="limit1" type="radio" name="cnb[limit]" value="include" <?php checked('include', $cnb_options['limit']);?> />
188
+ <label for="limit1">Limit to these posts and pages.</label>
189
+ </div>
190
+ <div class="radio-item">
191
+ <input id="limit2" type="radio" name="cnb[limit]" value="exclude" <?php checked('exclude', $cnb_options['limit']);?> />
192
+ <label for="limit2">Exclude these posts and pages.</label>
193
+ </div>
194
+
195
  </td>
196
  </tr>
197
  <tr valign="top" class="classic">
219
  </p>
220
  <!--// Display notification about the testing program -->
221
  <div class="postbox cnb-alert-box cnb-center">
222
+ <p>The Call&nbsp;Now&nbsp;Button&nbsp;<b>Pro</b> is launching soon!
223
+ <a class="cnb-external" href="http://callnowbutton.com/be-notified-call-now-button-pro/" rel="help" target="_blank">Be notified when it does!</a>
224
  </p>
225
  </div>
226
 
238
  <?php }
239
  if(get_option('cnb') && !is_admin()) {
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  $cnb_options = get_option('cnb');
242
  if(isset($cnb_options['active'])) $enabled = $cnb_options['active']; else $enabled = 0;
243
  if($enabled == '1') {
246
  $cnb_options = get_option('cnb');
247
  if(isset($cnb_options['classic'])) $classic = $cnb_options['classic']; else $classic = 0;
248
  $credits = "\n<!-- Call Now Button ".CNB_VERSION." by Jerry Rietveld (callnowbutton.com) -->\n";
249
+ $showTextButton = ($cnb_options['text'] == '') ? false : true;
250
  $ButtonExtra = "";
251
+ if($classic == 1 && !$showTextButton) {
252
 
253
  // OLD BUTTON DESIGN
254
+ if($cnb_options['appearance'] == 'full' || $cnb_options['appearance'] == 'middle' || $showTextButton) {
255
  $ButtonAppearance = "width:100%;left:0;";
256
  $ButtonExtra = "body {padding-bottom:60px;}";
257
  }
258
+ elseif($cnb_options['appearance'] == 'left') {
259
+ $ButtonAppearance = "width:100px;left:0;border-bottom-right-radius:40px; border-top-right-radius:40px;";
260
+ } else {
261
+ $ButtonAppearance = "width:100px;right:0;border-bottom-left-radius:40px; border-top-left-radius:40px;";
262
+ }
263
 
264
+ $credits .= "<style>#callnowbutton {display:none;} @media screen and (max-width:650px){#callnowbutton {display:block; ".$ButtonAppearance." height:80px; position:fixed; bottom:-20px; border-top:2px solid ".changeColor($cnb_options['color'],'lighter')."; background:url(data:image/svg+xml;base64,".svg(changeColor($cnb_options['color'], 'darker') ).") center 2px no-repeat ".$cnb_options['color']."; text-decoration:none; box-shadow:0 0 5px #888; z-index:2147483647;background-size:58px 58px}".$ButtonExtra."}</style>\n";
265
 
266
  } else {
267
+ // NEWEST BUTTON DESIGN
 
268
  $credits = "\n<!-- Call Now Button ".CNB_VERSION." by Jerry Rietveld (callnowbutton.com) -->\n";
269
+
270
+ $ButtonShape = "width:65px; height:65px; border-radius:80px; border-top:1px solid ".changeColor($cnb_options['color'], 'lighter')."; border-bottom: 1px solid ".changeColor($cnb_options['color'], 'darker')."; bottom:15px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);";
271
+
272
+ if($cnb_options['appearance'] == 'full' || $showTextButton) {
273
  $ButtonAppearance = "width:100%;left:0;bottom:0;height:60px;border-top:1px solid ".changeColor($cnb_options['color'], 'lighter')."; border-bottom:1px solid ".changeColor($cnb_options['color'], 'darker').";";
274
  $ButtonExtra = "body {padding-bottom:60px;}";
275
+ if($showTextButton) {
276
+ $ButtonAppearance .= $ButtonAppearance . "text-shadow: 0 1px ".changeColor($cnb_options['color'], 'darker')."; text-align:center;color:#fff; font-weight:600; font-size:120%; padding-right:27px; overflow: hidden;";
277
+ }
278
  }
279
+ elseif($cnb_options['appearance'] == 'left' ) {
280
+ $ButtonAppearance = $ButtonShape . "left:20px;";
281
+ }
282
+ elseif($cnb_options['appearance'] == 'middle') {
283
+ $ButtonAppearance = $ButtonShape . "left:50%; margin-left:-33px;";
284
+ }
285
+ else {
286
+ $ButtonAppearance = $ButtonShape . "right:20px;";
287
+ }
288
 
289
  $credits = $credits ."<style>";
290
+ $credits .= "#callnowbutton {display:none;} @media screen and (max-width:650px){#callnowbutton {display:block; position:fixed; text-decoration:none; z-index:2147483647;";
291
  $credits .= $ButtonAppearance;
292
+ if(!$showTextButton) {
293
+ $credits .= "background:url(data:image/svg+xml;base64,".svg(changeColor($cnb_options['color'], 'darker') ).") center/50px 50px no-repeat ".$cnb_options['color'].";";
294
+ } else {
295
+ $credits .= "background:".$cnb_options['color'].";display: flex; justify-content: center; align-items: center;";
296
+ }
297
  $credits .= "}" . $ButtonExtra . "}";
298
  $credits .= "</style>\n";
299
+ }
300
  echo $credits;
301
  }
302
  add_action('wp_head', 'cnb_head');
307
  if(isset($alloptions['show']) && $alloptions['show'] != "") {
308
  $show = explode(',', str_replace(' ', '' ,$alloptions['show']));
309
  $limited = TRUE;
310
+ $include = ($alloptions['limit'] == 'include') ? TRUE : FALSE; // FALSE meanse IDs should be excluded
311
  } else {
312
  $limited = FALSE;
313
  }
314
 
315
+ if($alloptions['tracking'] == '1') { // for ga.js
316
  $tracking = "onclick=\"_gaq.push(['_trackEvent', 'Contact', 'Call Now Button', 'Phone']);\"";
317
+ } elseif($alloptions['tracking'] == '2') { // for analytics.js
318
  $tracking = "onclick=\"ga('send', 'event', 'Contact', 'Call Now Button', 'Phone');\"";
319
+ } elseif($alloptions['tracking'] == '3') { // for gtag.js
320
+ $tracking = "onclick=\"gtag('event', 'Call Now Button', {'event_category': 'contact', 'event_label': 'phone'});\"";
321
  } else {
322
  $tracking = "";
323
  }
324
 
325
+ $buttonText = ($alloptions['text'] == '') ? '&nbsp;' : '<img src="data:image/svg+xml;base64,'.svg(changeColor($alloptions['color'], 'darker')).'" width="55">'. $alloptions['text'];
326
+
327
+ $callLink = '<a href="tel:'.$alloptions['number'].'" id="callnowbutton" '.$tracking.'>'.$buttonText.'</a>';
328
 
329
  if($limited) {
330
+ if($include) {
331
+ if(is_single($show) || is_page($show)) {
332
+ echo $callLink;
333
+ }
334
+ } else {
335
+ if(!is_single($show) && !is_page($show)) {
336
+ echo $callLink;
337
+ }
338
  }
339
  } else {
340
  echo $callLink;
344
  }
345
  }
346
 
347
+ function cnb_get_options() { // Grabbing existing settings and creating them if it's a first time installation
348
+ if(!get_option('cnb')) { // Doesn't exist -> set defaults
349
  $default_options = array(
350
  'active',
351
  'number' => '',
352
+ 'text' => '',
353
  'color' => '#009900',
354
  'appearance' => 'right',
355
  'tracking' => 0,
356
  'show' => '',
357
+ 'limit' => 'include',
358
  'version' => CNB_VERSION
359
  );
360
  add_option('cnb',$default_options);
361
+ } else { // Does exist -> see if update is needed
362
+ $updated = cnb_update_options();
363
+ }
364
+ $cnb_options['options'] = get_option('cnb');
365
+ $cnb_options['updated'] = isset($updated) ? $updated : array(false, substr(CNB_VERSION, 0, 3));
366
  return $cnb_options;
367
  }
368
+
369
+ function cnb_update_options() {
370
+ $cnb_options = get_option('cnb');
371
+ if(!array_key_exists('version', $cnb_options) || $cnb_options['version'] != CNB_VERSION) { // Check current version and if it needs an update
372
+ $version = array_key_exists('version', $cnb_options) ? substr($cnb_options['version'], 0, 3) : 0.1;
373
  $cnb_options['active'] = isset($cnb_options['active']) ? 1 : 0;
374
  $default_options = array(
375
  'active' => $cnb_options['active'],
376
  'number' => $cnb_options['number'],
377
+ 'text' => '',
378
  'color' => $cnb_options['color'],
379
  'appearance' => $cnb_options['appearance'],
380
  'tracking' => $cnb_options['tracking'],
381
  'show' => $cnb_options['show'],
382
+ 'limit' => 'include',
383
  'version' => CNB_VERSION
384
  );
385
+ if(array_key_exists('classic', $cnb_options) && $cnb_options['classic'] == 1 ) {
386
+ $default_options['classic'] = 1;
387
+ }
388
  update_option('cnb',$default_options);
389
+ $updated = array(true, $version); // Updated and previous version number
390
  } else {
391
+ $updated = array(false, $version); // Not updated and current version number
392
  }
393
+ return $updated;
394
  }
395
+ // Color functions to calculate borders
396
+ function changeColor($color, $direction) {
397
+ if(!preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i', $color, $parts));
398
+ if(!isset($direction) || $direction == "lighter") { $change = 45; } else { $change = -50; }
399
+ for($i = 1; $i <= 3; $i++) {
400
+ $parts[$i] = hexdec($parts[$i]);
401
+ $parts[$i] = round($parts[$i] + $change);
402
+ if($parts[$i] > 255) { $parts[$i] = 255; } elseif($parts[$i] < 0) { $parts[$i] = 0; }
403
+ $parts[$i] = dechex($parts[$i]);
404
+ }
405
+ $output = '#' . str_pad($parts[1],2,"0",STR_PAD_LEFT) . str_pad($parts[2],2,"0",STR_PAD_LEFT) . str_pad($parts[3],2,"0",STR_PAD_LEFT);
406
+ return $output;
407
+ }
408
+
409
+ function svg($color) {
410
+ $phone = '<path d="M7.104 14.032l15.586 1.984c0 0-0.019 0.5 0 0.953c0.029 0.756-0.26 1.534-0.809 2.1 l-4.74 4.742c2.361 3.3 16.5 17.4 19.8 19.8l16.813 1.141c0 0 0 0.4 0 1.1 c-0.002 0.479-0.176 0.953-0.549 1.327l-6.504 6.505c0 0-11.261 0.988-25.925-13.674C6.117 25.3 7.1 14 7.1 14" fill="'.$color.'"/><path d="M7.104 13.032l6.504-6.505c0.896-0.895 2.334-0.678 3.1 0.35l5.563 7.8 c0.738 1 0.5 2.531-0.36 3.426l-4.74 4.742c2.361 3.3 5.3 6.9 9.1 10.699c3.842 3.8 7.4 6.7 10.7 9.1 l4.74-4.742c0.897-0.895 2.471-1.026 3.498-0.289l7.646 5.455c1.025 0.7 1.3 2.2 0.4 3.105l-6.504 6.5 c0 0-11.262 0.988-25.925-13.674C6.117 24.3 7.1 13 7.1 13" fill="#fff"/>';
411
+ $svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 60 60">' . $phone . '</svg>';
412
  return base64_encode($svg);
413
  }
414
  function buttonActive() {
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Plugin Name ===
2
  Contributors: jgrietveld
3
  Donate link: http://callnowbutton.com/donate/
4
- Tags: call, contact, customers, sell, sales, leads, convert, conversions
5
  Requires at least: 2.7
6
  Tested up to: 4.9
7
- Stable tag: 0.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -20,7 +20,9 @@ No more complicated copy-and-pasting or memorizing the phone number!
20
  ###Could not be easier!
21
  The settings are very easy: enable and enter your phone number. That's it!
22
 
23
- But if you want more control, you can always open up the Advanced Settings and change the default behavior.
 
 
24
 
25
  ###Only for mobile optimized themes
26
  Usage at this point is only for responsive websites (websites optimized for display on mobile devices).
@@ -52,7 +54,7 @@ In the Settings section on your WordPress Dashboard you'll find a new addition:
52
 
53
  The button will only work on websites that use a responsive theme. Responsive means that the website adapts to the size of the screen it's being viewed on. Simply put, if you need to zoom in to be able to read the text of your website on your mobile phone, the plugin will not work.
54
 
55
- = Do I add a country code to my phone number? =
56
 
57
  You don't have to but i recommend that you do to increase your options internationally.
58
 
@@ -64,6 +66,10 @@ Up to you. Your phone will understand both!
64
 
65
  Yes! You can easily change the color of the button and make it sit in the left or right corner. Or spread it out over the full bottom of the phone screen.
66
 
 
 
 
 
67
  = I need way more flexibility! Isn't there a PRO version that I can use? =
68
 
69
  Yes, this is coming soon. We're currently looking for testers so if you want to give it a try already, please sign up at callnowbutton.com
@@ -71,14 +77,20 @@ Yes, this is coming soon. We're currently looking for testers so if you want to
71
 
72
  == Screenshots ==
73
 
74
- 1. What the Call Now Button will look like
75
- 2. All the required settings
76
- 3. Advanced Settings: Set your button's color
77
- 4. Advanced Settings: More options
 
78
 
79
 
80
  == Changelog ==
81
 
 
 
 
 
 
82
  = 0.2.1 =
83
  * Fix for conflict with certain 3rd party plugins
84
 
1
  === Plugin Name ===
2
  Contributors: jgrietveld
3
  Donate link: http://callnowbutton.com/donate/
4
+ Tags: call, contact, customers, sell, sales, leads, convert, conversions, call now button
5
  Requires at least: 2.7
6
  Tested up to: 4.9
7
+ Stable tag: 0.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
20
  ###Could not be easier!
21
  The settings are very easy: enable and enter your phone number. That's it!
22
 
23
+ If you want to add some text to your button, that's possible. Entering text is fully optional - leaving it empty will show a nice phone icon to your visitors.
24
+
25
+ You want even more control? Open up the Advanced Settings and change the default behavior.
26
 
27
  ###Only for mobile optimized themes
28
  Usage at this point is only for responsive websites (websites optimized for display on mobile devices).
54
 
55
  The button will only work on websites that use a responsive theme. Responsive means that the website adapts to the size of the screen it's being viewed on. Simply put, if you need to zoom in to be able to read the text of your website on your mobile phone, the plugin will not work.
56
 
57
+ = Do I have to add a country code to my phone number? =
58
 
59
  You don't have to but i recommend that you do to increase your options internationally.
60
 
66
 
67
  Yes! You can easily change the color of the button and make it sit in the left or right corner. Or spread it out over the full bottom of the phone screen.
68
 
69
+ = I only want to show the button on a few pages. Is that possible?
70
+
71
+ Yes, you can now enter the IDs of posts and pages you wish to include or exclude.
72
+
73
  = I need way more flexibility! Isn't there a PRO version that I can use? =
74
 
75
  Yes, this is coming soon. We're currently looking for testers so if you want to give it a try already, please sign up at callnowbutton.com
77
 
78
  == Screenshots ==
79
 
80
+ 1. The default look of the Call Now Button
81
+ 2. The Call Now Button with Text
82
+ 3. All the required settings
83
+ 4. Advanced Settings: Set your button's color
84
+ 5. Advanced Settings: More options
85
 
86
 
87
  == Changelog ==
88
 
89
+ = 0.3 =
90
+ * Added the option to add text to your button
91
+ * Added option to either include or exclude certain posts and pages to show the button on (this used to be just exclude)
92
+ * Some small design changes to the button
93
+
94
  = 0.2.1 =
95
  * Fix for conflict with certain 3rd party plugins
96