Call Now Button - Version 1.0.0

Version Description

Download this release

Release Info

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

Code changes from version 0.5.0 to 1.0.0

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: 0.5.0
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', '0.5.0');
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.0.0
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.0.0');
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: 5.8
8
- Stable tag: 0.5.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -28,8 +28,9 @@ Under the **Presentation tab** you can change the color of the button, move it t
28
 
29
  Under the **Settings menu** you'll find a bunch of features that allow you to enable click tracking in Google Analytics, fire a conversion tag so a call is registered as a conversion in Google Ads, adjust the size of the button or move the button further backwards in case you want something else to sit on top of it (e.g. your privacy notice).
30
 
31
- ### For mobile optimized (responsive) themes
32
- The button is super light and fully build in CSS. The **only requirement is that your website's theme is responsive**, meaning it adapts to the size of the screen.
 
33
 
34
 
35
  == Installation ==
@@ -98,7 +99,7 @@ Yes, you can enter the IDs of posts and pages you wish to include or exclude.
98
 
99
  = I need way more flexibility! Isn't there a PRO version that I can use? =
100
 
101
- This is coming before the end of this year. We're currently looking for testers so if you want to give it a try already, please sign up at [callnowbutton.com](https://callnowbutton.com/).
102
 
103
 
104
  == Screenshots ==
5
  Requires at least: 3.9
6
  Requires PHP: 5.4
7
  Tested up to: 5.8
8
+ Stable tag: 1.0.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
28
 
29
  Under the **Settings menu** you'll find a bunch of features that allow you to enable click tracking in Google Analytics, fire a conversion tag so a call is registered as a conversion in Google Ads, adjust the size of the button or move the button further backwards in case you want something else to sit on top of it (e.g. your privacy notice).
30
 
31
+ ###Need even more control?
32
+ Easily upgrade the plugin to Premium to add additional features such as multiple buttons, additional actions such as mail, WhatsApp, Maps and links, a button scheduler, more advanced page selection options, Buttonbars and Multibuttons, and much more!
33
+
34
 
35
 
36
  == Installation ==
99
 
100
  = I need way more flexibility! Isn't there a PRO version that I can use? =
101
 
102
+ Yes, you can upgrade to Premium to enable tons of extra features. Checkout [callnowbutton.com](https://callnowbutton.com/) to see what's included or just give it a try.
103
 
104
 
105
  == Screenshots ==
resources/js/call-now-button.js CHANGED
@@ -4,7 +4,7 @@ function cnb_setup_colors() {
4
  jQuery('.cnb-iconcolor-field').wpColorPicker();
5
 
6
  // Reveal additional button placements when clicking "more"
7
- jQuery("#cnb-more-placements").click(function(e){
8
  e.preventDefault();
9
  jQuery(".cnb-extra-placement").css("display","block");
10
  jQuery("#cnb-more-placements").remove();
@@ -12,17 +12,17 @@ function cnb_setup_colors() {
12
 
13
  // TODO The input names AND radioValue might have to be changed to reflect new values
14
  // Option to Hide Icon is only visible when the full width button is selected
15
- var radioValue = jQuery("input[name='cnb[appearance]']:checked").val();
16
- var textValue = jQuery("input[name='cnb[text]']").val();
17
- if(radioValue != 'full' && radioValue != 'tfull') {
18
  jQuery('#hideIconTR').hide();
19
  } else if(textValue.length < 1) {
20
  jQuery('#hideIconTR').hide();
21
  }
22
  jQuery('input[name="cnb[appearance]"]').on("change",function(){
23
- var radioValue = jQuery("input[name='cnb[appearance]']:checked").val();
24
- var textValue = jQuery("input[name='cnb[text]']").val();
25
- if(radioValue != 'full' && radioValue != 'tfull') {
26
  jQuery('#hideIconTR').hide();
27
  } else if(textValue.length > 0 ) {
28
  jQuery('#hideIconTR').show();
@@ -42,16 +42,16 @@ function cnb_setup_sliders() {
42
 
43
  function cnb_update_sliders() {
44
  // Zoom slider - show percentage
45
- var cnb_slider = document.getElementById("cnb_slider");
46
  if (cnb_slider && cnb_slider.value) {
47
- var cnb_slider_value = document.getElementById("cnb_slider_value");
48
  cnb_slider_value.innerHTML = '(' + Math.round(cnb_slider.value * 100) + '%)';
49
  }
50
 
51
  // Z-index slider - show steps
52
- var cnb_order_slider = document.getElementById("cnb_order_slider");
53
  if (cnb_order_slider && cnb_order_slider.value) {
54
- var cnb_order_value = document.getElementById("cnb_order_value");
55
  cnb_order_value.innerHTML = cnb_order_slider.value;
56
  }
57
  }
@@ -80,30 +80,56 @@ function cnb_disable_api_key_when_cloud_hosting_is_disabled() {
80
  }
81
  }
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  let cnb_add_condition_counter = 0;
84
  function cnb_add_condition() {
85
  let template = `
86
- <th scope="row">Condition <div class="cnb_font_normal cnb_font_90">new/unsaved</div></th>
87
- <td>
88
- <input type="hidden" name="condition[${cnb_add_condition_counter}][id]" value="" />
89
- <input type="hidden" name="condition[${cnb_add_condition_counter}][conditionType]" value="URL" />
90
- <input type="hidden" name="condition[${cnb_add_condition_counter}][delete]" id="cnb_condition_${cnb_add_condition_counter}_delete" value="" />
91
- <select name="condition[${cnb_add_condition_counter}][filterType]">
92
- <option value="INCLUDE">Include</option>
93
- <option value="EXCLUDE">Exclude</option>
94
- </select><br />
95
-
96
- <select name="condition[${cnb_add_condition_counter}][matchType]">
97
- <option value="SIMPLE">Page path is:</option>
98
- <option value="EXACT">Page URL is:</option>
99
- <option value="SUBSTRING">Page URL contains:</option>
100
- <option value="REGEX">Page URL matches RegEx:</option>
101
- </select><br />
102
-
103
- <input type="text" name="condition[${cnb_add_condition_counter}][matchValue]" value=""/><br />
104
-
105
- <input type="button" onclick="return cnb_remove_condition('${cnb_add_condition_counter}');" value="Remove Condition" class="button-link button-link-delete"></td>
106
- </td>
 
 
 
 
 
 
 
 
 
107
  `;
108
 
109
  let table = document.getElementById('cnb_form_table_visibility');
@@ -116,9 +142,36 @@ function cnb_add_condition() {
116
  table.insertBefore(rowElement, container);
117
 
118
  cnb_add_condition_counter++;
 
119
  return false;
120
  }
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  function cnb_remove_condition(id) {
123
  let container = document.getElementById('cnb_condition_' + id);
124
  let deleteElement = document.getElementById('cnb_condition_' + id + '_delete');
@@ -133,7 +186,7 @@ function cnb_remove_condition(id) {
133
  }
134
 
135
  function cnb_action_appearance() {
136
- jQuery('#cnb_action_type').change(function (obj) {
137
  cnb_action_update_appearance(obj.target.value);
138
  });
139
 
@@ -201,41 +254,64 @@ function cnb_action_appearance() {
201
  }
202
 
203
  function cnb_action_update_appearance(value) {
204
- jQuery('.cnb-action-properties-email').hide();
205
- jQuery('.cnb-action-properties-email-extra').hide();
206
- jQuery('.cnb-action-properties-whatsapp').hide();
207
- jQuery('.cnb-action-properties-whatsapp-extra').hide();
208
- jQuery('.cnb-action-properties-map').hide();
209
- jQuery('.cnb-action-value').show();
210
- jQuery('#cnb_action_value_input').prop( 'disabled', false );
211
- jQuery('#cnb_action_value_input_whatsapp').prop( 'disabled', true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  switch (value) {
213
  case 'PHONE':
214
- jQuery('#cnb_action_value').text('Phone number');
 
215
  break
216
  case 'ANCHOR':
217
- jQuery('#cnb_action_value').text('On-page anchor');
 
218
  break
219
  case 'LINK':
220
- jQuery('#cnb_action_value').text('Full URL');
 
221
  break
222
  case 'EMAIL':
223
- jQuery('#cnb_action_value').text('E-mail address');
224
- jQuery('.cnb-action-properties-email').show()
 
225
  break
226
  case 'WHATSAPP':
227
- jQuery('#cnb_action_value').text('Whatsapp number');
228
- jQuery('.cnb-action-value').hide();
229
- jQuery('#cnb_action_value_input').prop( 'disabled', true );
230
- jQuery('#cnb_action_value_input_whatsapp').prop( 'disabled', false );
231
- jQuery('.cnb-action-properties-whatsapp').show();
 
232
  break
233
  case 'MAP':
234
- jQuery('#cnb_action_value').text('Address');
235
- jQuery('.cnb-action-properties-map').show();
 
236
  break
237
  default:
238
- jQuery('#cnb_action_value').text('Action value');
 
239
  }
240
  }
241
 
@@ -244,7 +320,7 @@ function cnb_action_update_map_link(element) {
244
  }
245
 
246
  function cnb_hide_edit_action_if_advanced() {
247
- var element = jQuery('#toplevel_page_call-now-button li.current a');
248
  if (element.text() === 'Edit action') {
249
  element.removeAttr('href');
250
  element.css('cursor', 'default');
@@ -252,7 +328,7 @@ function cnb_hide_edit_action_if_advanced() {
252
  }
253
 
254
  function cnb_hide_edit_domain_upgrade_if_advanced() {
255
- var element = jQuery('#toplevel_page_call-now-button li.current a');
256
  if (element.text() === 'Upgrade domain') {
257
  element.removeAttr('href');
258
  element.css('cursor', 'default');
@@ -261,6 +337,7 @@ function cnb_hide_edit_domain_upgrade_if_advanced() {
261
 
262
  function cnb_hide_on_modal() {
263
  jQuery('.cnb_hide_on_modal').hide();
 
264
  }
265
 
266
  function show_advanced_view_only() {
@@ -268,14 +345,18 @@ function show_advanced_view_only() {
268
  }
269
 
270
  function cnb_strip_beta_from_referrer() {
271
- var referer = jQuery('input[name="_wp_http_referer"]');
272
  if (referer && referer.val()) {
273
  referer.val(referer.val().replace('&beta', ''))
274
  }
275
  }
276
 
 
 
 
277
  function cnb_delete_action() {
278
- jQuery('.cnb-button-edit-action-table tbody[data-wp-lists="list:cnb_list_action"]#the-list span.delete a[data-ajax="true"]').click(function(){
 
279
  // Prep data
280
  const id = jQuery(this).data('id');
281
  const bid = jQuery(this).data('bid');
@@ -304,6 +385,8 @@ function cnb_delete_action() {
304
  }
305
  });
306
 
 
 
307
  return false;
308
  });
309
  }
@@ -312,80 +395,129 @@ function cnb_delete_action() {
312
  * function for the button type selection in the New button modal
313
  */
314
  function cnb_button_overview_modal() {
315
- jQuery(".cnb_type_selector_item").click(function(){
316
  jQuery(".cnb_type_selector_item").removeClass('cnb_type_selector_active');
317
  jQuery(this).addClass("cnb_type_selector_active");
318
- var cnbType = jQuery(this).attr("data-cnb-selection");
319
  jQuery('#cnb_type').val(cnbType);
320
  });
321
- }
322
 
323
- /**
324
- * function for the currency selector on the Upgrade page
325
- */
326
- function cnb_domain_upgrade_currency() {
327
- jQuery(".cnb-currency-select").click(function(){
328
- jQuery(".cnb-currency-select").removeClass('nav-tab-active');
329
- jQuery(".currency-box").removeClass('currency-box-active');
330
- jQuery(this).addClass("nav-tab-active");
331
- var currencyType = jQuery(this).attr("data-cnb-currency");
332
- var currencySelector = 'currency-box-' + currencyType;
333
- jQuery('.' + currencySelector).addClass('currency-box-active');
334
  });
335
  }
336
 
337
 
 
338
  /**
339
- * Request a Stripe Checkout Session ID for a given domain and a selected plan
340
- *
341
- * Used on the Domain upgrade page.
342
- * @param planId
343
  */
344
- function cnb_get_checkout(planId) {
345
- const data = {
346
- 'action': 'cnb_get_checkout',
347
- 'planId': planId,
348
- 'domainId': jQuery('#cnb_domain_id').val()
349
- };
350
- const cnb_notice = jQuery('.cnb-message');
 
 
 
 
 
 
 
 
 
 
 
351
 
352
- cnb_notice.hide();
353
- jQuery('.cnb-error-message').text('Processing your request, please wait...');
354
- cnb_notice.addClass('notice notice-success');
355
- cnb_notice.removeClass('notice-warning');
356
- cnb_notice.show();
 
 
 
 
357
 
358
- console.log(cnb_notice);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
 
360
- jQuery.post(ajaxurl, data, function(response) {
361
- cnb_goto_checkout(response)
362
- });
363
  }
364
 
365
  /**
366
- * The callback function once an API response for a Stripe Checkout Session ID is received.
367
- * @param response
 
368
  */
369
- function cnb_goto_checkout(response) {
370
- const cnb_notice = jQuery('.cnb-message');
371
-
372
- if (response.status === 'success') {
373
- jQuery('.cnb-error-message').text('Redirecting you...');
374
- cnb_notice.addClass('notice notice-success');
375
- cnb_notice.removeClass('notice-warning');
376
- cnb_notice.show();
377
-
378
- stripe.redirectToCheckout({sessionId: response.message});
379
- }
380
- if (response.status === 'error') {
381
- jQuery('.cnb-error-message').text(response.message);
382
- cnb_notice.addClass('notice notice-warning');
383
- cnb_notice.removeClass('notice-success');
384
- cnb_notice.show();
385
- }
386
  }
387
 
388
- jQuery( document ).ready(function() {
 
389
  cnb_setup_colors();
390
  cnb_setup_sliders();
391
  cnb_hide_on_show_always();
@@ -395,16 +527,23 @@ jQuery( document ).ready(function() {
395
  cnb_hide_edit_action_if_advanced();
396
  cnb_hide_edit_domain_upgrade_if_advanced();
397
  cnb_strip_beta_from_referrer();
398
-
399
- if (typeof cnb_hide_on_modal_set !== 'undefined' && cnb_hide_on_modal_set === 1) {
400
- cnb_hide_on_modal();
401
- }
402
 
403
  if (typeof show_advanced_view_only_set !== 'undefined' && show_advanced_view_only_set && show_advanced_view_only_set === 1) {
404
  show_advanced_view_only()
405
  }
 
 
 
 
406
 
407
  cnb_delete_action();
408
  cnb_button_overview_modal();
409
- cnb_domain_upgrade_currency();
410
- });
 
 
 
 
 
4
  jQuery('.cnb-iconcolor-field').wpColorPicker();
5
 
6
  // Reveal additional button placements when clicking "more"
7
+ jQuery("#cnb-more-placements").on('click', function(e){
8
  e.preventDefault();
9
  jQuery(".cnb-extra-placement").css("display","block");
10
  jQuery("#cnb-more-placements").remove();
12
 
13
  // TODO The input names AND radioValue might have to be changed to reflect new values
14
  // Option to Hide Icon is only visible when the full width button is selected
15
+ const radioValue = jQuery("input[name='cnb[appearance]']:checked").val();
16
+ const textValue = jQuery("input[name='cnb[text]']").val();
17
+ if(radioValue !== 'full' && radioValue !== 'tfull') {
18
  jQuery('#hideIconTR').hide();
19
  } else if(textValue.length < 1) {
20
  jQuery('#hideIconTR').hide();
21
  }
22
  jQuery('input[name="cnb[appearance]"]').on("change",function(){
23
+ const radioValue = jQuery("input[name='cnb[appearance]']:checked").val();
24
+ const textValue = jQuery("input[name='cnb[text]']").val();
25
+ if(radioValue !== 'full' && radioValue !== 'tfull') {
26
  jQuery('#hideIconTR').hide();
27
  } else if(textValue.length > 0 ) {
28
  jQuery('#hideIconTR').show();
42
 
43
  function cnb_update_sliders() {
44
  // Zoom slider - show percentage
45
+ const cnb_slider = document.getElementById("cnb_slider");
46
  if (cnb_slider && cnb_slider.value) {
47
+ const cnb_slider_value = document.getElementById("cnb_slider_value");
48
  cnb_slider_value.innerHTML = '(' + Math.round(cnb_slider.value * 100) + '%)';
49
  }
50
 
51
  // Z-index slider - show steps
52
+ const cnb_order_slider = document.getElementById("cnb_order_slider");
53
  if (cnb_order_slider && cnb_order_slider.value) {
54
+ const cnb_order_value = document.getElementById("cnb_order_value");
55
  cnb_order_value.innerHTML = cnb_order_slider.value;
56
  }
57
  }
80
  }
81
  }
82
 
83
+ function cnb_animate_saving() {
84
+ jQuery('.call-now-button #submit').on('click', function (event) {
85
+ // if value is saving, skip...
86
+ if (jQuery(this).prop('value') === 'Saving...') {
87
+ event.preventDefault();
88
+ return;
89
+ }
90
+ // Check if the form will actually subbmit...
91
+ const valid = jQuery(this).closest('form')[0].checkValidity();
92
+ if (valid) {
93
+ jQuery(this).addClass('is-busy');
94
+ jQuery(this).prop('value', 'Saving...');
95
+ jQuery(this).prop('aria-disabled', 'true');
96
+ }
97
+ })
98
+ }
99
+
100
  let cnb_add_condition_counter = 0;
101
  function cnb_add_condition() {
102
  let template = `
103
+ <td colspan="2" style="padding: 0;">
104
+ <table class="cnb_condition_rule">
105
+ <tbody>
106
+ <tr>
107
+ <td>
108
+ <input type="hidden" name="condition[${cnb_add_condition_counter}][id]" value="" />
109
+ <input type="hidden" name="condition[${cnb_add_condition_counter}][conditionType]" value="URL" />
110
+ <input type="hidden" name="condition[${cnb_add_condition_counter}][delete]" id="cnb_condition_${cnb_add_condition_counter}_delete" value="" />
111
+ <select name="condition[${cnb_add_condition_counter}][filterType]">
112
+ <option value="INCLUDE">Include</option>
113
+ <option value="EXCLUDE">Exclude</option>
114
+ </select>
115
+ </td>
116
+ <td>
117
+ <select class="js-condition-matchtype" data-cnb-condition-id="${cnb_add_condition_counter}" name="condition[${cnb_add_condition_counter}][matchType]">
118
+ <option value="SIMPLE">Page path is:</option>
119
+ <option value="EXACT">Page URL is:</option>
120
+ <option value="SUBSTRING">Page URL contains:</option>
121
+ <option value="REGEX">Page URL matches RegEx:</option>
122
+ </select>
123
+ </td>
124
+ <td class="max_width_column">
125
+ <input class="js-condition-matchvalue-${cnb_add_condition_counter}" type="text" name="condition[${cnb_add_condition_counter}][matchValue]" value="" placeholder="e.g. /blog/" />
126
+ <a onclick="return cnb_remove_condition('${cnb_add_condition_counter}');" title="Remove Condition" class="button-link button-link-delete"><span class="dashicons dashicons-no" style="padding-top: 5px;"></span>
127
+ </a>
128
+ </td>
129
+ </tr>
130
+ </tbody>
131
+ </table>
132
+ </td>
133
  `;
134
 
135
  let table = document.getElementById('cnb_form_table_visibility');
142
  table.insertBefore(rowElement, container);
143
 
144
  cnb_add_condition_counter++;
145
+ cnb_show_condition_placeholder();
146
  return false;
147
  }
148
 
149
+ // Show an example condition in the form field for each of the match types
150
+ function cnb_show_condition_placeholder() {
151
+ jQuery('.js-condition-matchtype').on('change', function () {
152
+ const optionSelected = jQuery(this).val();
153
+ const conditionId = jQuery(this).data('cnb-condition-id');
154
+ let placeholderText;
155
+ if(optionSelected === 'SIMPLE') {
156
+ placeholderText = '/blog/';
157
+ } else if(optionSelected === 'EXACT') {
158
+ placeholderText = 'https://www.example.com/sample-page/';
159
+ } else if(optionSelected === 'SUBSTRING') {
160
+ placeholderText = 'category/';
161
+ } else if(optionSelected === 'REGEX') {
162
+ placeholderText = '/(index|about)(\?id=[0-9]+)?$';
163
+ }
164
+ jQuery('.js-condition-matchvalue-' + conditionId).attr('placeholder', 'e.g. ' + placeholderText);
165
+ });
166
+ }
167
+
168
+ function cnb_setup_toggle_label_clicks() {
169
+ jQuery('.cnb_toggle_state').on( "click", function() {
170
+ const stateLabel = jQuery(this).data('cnb_toggle_state_label');
171
+ jQuery('#' + stateLabel).trigger('click');
172
+ });
173
+ }
174
+
175
  function cnb_remove_condition(id) {
176
  let container = document.getElementById('cnb_condition_' + id);
177
  let deleteElement = document.getElementById('cnb_condition_' + id + '_delete');
186
  }
187
 
188
  function cnb_action_appearance() {
189
+ jQuery('#cnb_action_type').on('change', function (obj) {
190
  cnb_action_update_appearance(obj.target.value);
191
  });
192
 
254
  }
255
 
256
  function cnb_action_update_appearance(value) {
257
+ const emailEle = jQuery('.cnb-action-properties-email');
258
+ const emailExtraEle = jQuery('.cnb-action-properties-email-extra');
259
+ const whatsappEle = jQuery('.cnb-action-properties-whatsapp');
260
+ const whatsappExtraEle = jQuery('.cnb-action-properties-whatsapp-extra');
261
+
262
+ const propertiesEle = jQuery('.cnb-action-properties-map');
263
+ const valueEle = jQuery('.cnb-action-value');
264
+ const valueTextEle = jQuery('#cnb_action_value_input');
265
+ const valuelabelEle = jQuery('#cnb_action_value');
266
+ const whatsappValueEle = jQuery('#cnb_action_value_input_whatsapp')
267
+ emailEle.hide();
268
+ emailExtraEle.hide();
269
+ whatsappEle.hide();
270
+ whatsappExtraEle.hide();
271
+ propertiesEle.hide();
272
+
273
+
274
+ valueEle.show();
275
+ valueTextEle.prop( 'disabled', false );
276
+ whatsappValueEle.prop( 'disabled', true );
277
+
278
+ valueTextEle.removeAttr("required")
279
+ whatsappValueEle.removeAttr("required")
280
+
281
  switch (value) {
282
  case 'PHONE':
283
+ valuelabelEle.text('Phone number');
284
+ valueTextEle.attr("required", "required");
285
  break
286
  case 'ANCHOR':
287
+ valuelabelEle.text('On-page anchor');
288
+ valueTextEle.attr("required", "required");
289
  break
290
  case 'LINK':
291
+ valuelabelEle.text('Full URL');
292
+ valueTextEle.attr("required", "required");
293
  break
294
  case 'EMAIL':
295
+ valuelabelEle.text('E-mail address');
296
+ valueTextEle.attr("required", "required");
297
+ emailEle.show()
298
  break
299
  case 'WHATSAPP':
300
+ valuelabelEle.text('Whatsapp number');
301
+ valueEle.hide();
302
+ valueTextEle.prop( 'disabled', true );
303
+ whatsappValueEle.prop( 'disabled', false );
304
+ whatsappEle.show();
305
+ whatsappValueEle.attr("required", "required");
306
  break
307
  case 'MAP':
308
+ valuelabelEle.text('Address');
309
+ valueTextEle.attr("required", "required");
310
+ propertiesEle.show();
311
  break
312
  default:
313
+ valuelabelEle.text('Action value');
314
+ valueTextEle.attr("required", "required");
315
  }
316
  }
317
 
320
  }
321
 
322
  function cnb_hide_edit_action_if_advanced() {
323
+ const element = jQuery('#toplevel_page_call-now-button li.current a');
324
  if (element.text() === 'Edit action') {
325
  element.removeAttr('href');
326
  element.css('cursor', 'default');
328
  }
329
 
330
  function cnb_hide_edit_domain_upgrade_if_advanced() {
331
+ const element = jQuery('#toplevel_page_call-now-button li.current a');
332
  if (element.text() === 'Upgrade domain') {
333
  element.removeAttr('href');
334
  element.css('cursor', 'default');
337
 
338
  function cnb_hide_on_modal() {
339
  jQuery('.cnb_hide_on_modal').hide();
340
+ jQuery('.cnb_hide_on_modal input').removeAttr('required');
341
  }
342
 
343
  function show_advanced_view_only() {
345
  }
346
 
347
  function cnb_strip_beta_from_referrer() {
348
+ const referer = jQuery('input[name="_wp_http_referer"]');
349
  if (referer && referer.val()) {
350
  referer.val(referer.val().replace('&beta', ''))
351
  }
352
  }
353
 
354
+ /**
355
+ * This calls the admin-ajax action called 'cnb_delete_action'
356
+ */
357
  function cnb_delete_action() {
358
+ jQuery('.cnb-button-edit-action-table tbody[data-wp-lists="list:cnb_list_action"]#the-list span.delete a[data-ajax="true"]')
359
+ .on('click', function(){
360
  // Prep data
361
  const id = jQuery(this).data('id');
362
  const bid = jQuery(this).data('bid');
385
  }
386
  });
387
 
388
+ // Remove ID from Button array
389
+ jQuery('input[name^="actions['+id+']"').remove();
390
  return false;
391
  });
392
  }
395
  * function for the button type selection in the New button modal
396
  */
397
  function cnb_button_overview_modal() {
398
+ jQuery(".cnb_type_selector_item").on('click', function(){
399
  jQuery(".cnb_type_selector_item").removeClass('cnb_type_selector_active');
400
  jQuery(this).addClass("cnb_type_selector_active");
401
+ const cnbType = jQuery(this).attr("data-cnb-selection");
402
  jQuery('#cnb_type').val(cnbType);
403
  });
 
404
 
405
+ jQuery("#cnb-button-overview-modal-add-new").on("click", function() {
406
+ setTimeout(function () {
407
+ jQuery("input[name='cnb[name]']").trigger("focus");
408
+ });
 
 
 
 
 
 
 
409
  });
410
  }
411
 
412
 
413
+
414
  /**
415
+ * Logic for the profile form.
416
+ * Toggles visibility and requirements based on selected country and VAT setting.
417
+ * Erases values when switching to a different country during data entry (e.g. state value will be dropped when country is switched from USA to Belgium)
 
418
  */
419
+ function cnb_profile_edit_setup() {
420
+ const countryEle = jQuery('#cnb_profile_country')
421
+ const euVatEle = jQuery("#cnb-euvatbusiness")
422
+ // First time setup of page
423
+ const currentCountry = countryEle.val();
424
+ cnb_profile_show_hide_fields(currentCountry);
425
+
426
+ cnb_profile_show_hide_tax_fields(euVatEle)
427
+
428
+ countryEle.on('change',function() {
429
+ const currentCountry = jQuery(this).val();
430
+ cnb_profile_show_hide_fields(currentCountry);
431
+ });
432
+ euVatEle.on('change',function() {
433
+ const element = jQuery(this);
434
+ cnb_profile_show_hide_tax_fields(element)
435
+ });
436
+ }
437
 
438
+ function cnb_profile_show_hide_tax_fields(element) {
439
+ if(element.is(":checked")) {
440
+ jQuery(".cnb_vat_companies_show").show();
441
+ jQuery(".cnb_vat_companies_required").attr("required","required");
442
+ } else {
443
+ jQuery(".cnb_vat_companies_show").hide();
444
+ jQuery(".cnb_vat_companies_required").removeAttr("required");
445
+ }
446
+ }
447
 
448
+ function cnb_profile_show_hide_fields(currentCountry) {
449
+ const euCountries = [
450
+ "AT",
451
+ "BE",
452
+ "BG",
453
+ "HR",
454
+ "CY",
455
+ "CZ",
456
+ "DK",
457
+ "EE",
458
+ "FI",
459
+ "FR",
460
+ "DE",
461
+ "GR",
462
+ "HU",
463
+ "IE",
464
+ "IT",
465
+ "LV",
466
+ "LT",
467
+ "LU",
468
+ "MT",
469
+ "NL",
470
+ "PL",
471
+ "PT",
472
+ "RO",
473
+ "SK",
474
+ "SI",
475
+ "ES",
476
+ "SE",
477
+ ]; // source https://www.belastingdienst.nl/wps/wcm/connect/bldcontentnl/belastingdienst/zakelijk/btw/zakendoen_met_het_buitenland/goederen_en_diensten_naar_andere_eu_landen/eu-landen_en_-gebieden/
478
+
479
+ if(jQuery.inArray(currentCountry,euCountries) !== -1) {
480
+ jQuery(".cnb_show_vat_toggle").show();
481
+ jQuery(".cnb_us_required").removeAttr("required");
482
+ //jQuery(".cnb_us_values_only").val('');
483
+ if(currentCountry === 'IE') {
484
+ jQuery(".cnb_ie_only").show();
485
+ }
486
+ } else if(currentCountry === 'US') {
487
+ jQuery(".cnb_show_vat_toggle, .cnb_vat_companies_show").hide();
488
+ jQuery(".cnb_us_show").show();
489
+ jQuery(".cnb_us_required").attr("required","required");
490
+ jQuery("#cnb-euvatbusiness, .cnb_vat_companies_required, #cnb_profile_vat").removeAttr("required checked");
491
+ //jQuery(".cnb_eu_values_only").val('');
492
+ } else {
493
+ jQuery(".cnb_us_show, .cnb_show_vat_toggle, .cnb_vat_companies_show").hide();
494
+ jQuery("#cnb-euvatbusiness, .cnb_us_required, .cnb_vat_companies_required, #cnb_profile_vat").removeAttr("required checked");
495
+ //jQuery(".cnb_eu_values_only, .cnb_us_values_only, .cnb_useu_values_only").val('');
496
+ }
497
+ }
498
 
499
+ function cnb_button_overview_add_new_click() {
500
+ jQuery("#cnb-button-overview-modal-add-new").trigger("click");
501
+ return false;
502
  }
503
 
504
  /**
505
+ * The equivalent of the PHP function `get_cnb_wordpress_upgrade_link`
506
+ *
507
+ * @return string URL of the upgrade URL
508
  */
509
+ function set_cnb_wordpress_upgrade_link() {
510
+ const action = jQuery('#admin_url').attr('value');
511
+ const email = jQuery('#admin_email').prop('value')
512
+ jQuery('#cnb-go-create-account').prop('href',
513
+ 'https://www.callnowbutton.com/wordpress'
514
+ + '?e=' + encodeURIComponent(email)
515
+ + '&a=' + encodeURIComponent(action)
516
+ + '&utm_source=wp-plugin&utm_medium=referral&utm_campaign=beta_tester&utm_term=sign-up-for-api');
 
 
 
 
 
 
 
 
 
517
  }
518
 
519
+ jQuery( function() {
520
+ // Generic
521
  cnb_setup_colors();
522
  cnb_setup_sliders();
523
  cnb_hide_on_show_always();
527
  cnb_hide_edit_action_if_advanced();
528
  cnb_hide_edit_domain_upgrade_if_advanced();
529
  cnb_strip_beta_from_referrer();
530
+ cnb_animate_saving();
531
+ cnb_setup_toggle_label_clicks();
 
 
532
 
533
  if (typeof show_advanced_view_only_set !== 'undefined' && show_advanced_view_only_set && show_advanced_view_only_set === 1) {
534
  show_advanced_view_only()
535
  }
536
+ // This needs to go AFTER the "advanced_view" check so a modal does not get additional (unneeded) "advanced" items
537
+ if (typeof cnb_hide_on_modal_set !== 'undefined' && cnb_hide_on_modal_set === 1) {
538
+ cnb_hide_on_modal();
539
+ }
540
 
541
  cnb_delete_action();
542
  cnb_button_overview_modal();
543
+
544
+ // page: settings
545
+ set_cnb_wordpress_upgrade_link();
546
+
547
+ // page: Profile edit (and domain-upgrade, since it's in a modal there)
548
+ cnb_profile_edit_setup();
549
+ });
resources/js/domain-upgrade.js ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function cnb_domain_upgrade_hide_notice() {
2
+ const cnb_notice = jQuery('.cnb-message');
3
+ const message = jQuery('.cnb-error-message').text();
4
+ if (!message) {
5
+ cnb_notice.hide();
6
+ }
7
+ }
8
+
9
+ function showMessage(type='success', message='') {
10
+ const cnb_notice = jQuery('.cnb-message');
11
+
12
+ cnb_notice.hide();
13
+ jQuery('.cnb-error-message').text(message);
14
+ cnb_notice.removeClass('notice-error notice-warning notice-success');
15
+ cnb_notice.addClass('notice notice-' + type);
16
+ cnb_notice.show();
17
+ }
18
+ /**
19
+ * function for the currency selector on the Upgrade page
20
+ */
21
+ function cnb_domain_upgrade_currency() {
22
+ jQuery(".cnb-currency-select").on('click', function(){
23
+ jQuery(".cnb-currency-select").removeClass('nav-tab-active');
24
+ jQuery(".currency-box").removeClass('currency-box-active');
25
+ jQuery(this).addClass("nav-tab-active");
26
+ const currencyType = jQuery(this).attr("data-cnb-currency");
27
+ const currencySelector = 'currency-box-' + currencyType;
28
+ jQuery('.' + currencySelector).addClass('currency-box-active');
29
+ });
30
+ }
31
+
32
+ /**
33
+ * Request a Stripe Checkout Session ID for a given domain and a selected plan
34
+ *
35
+ * Used on the Domain upgrade page.
36
+ * @param planId
37
+ */
38
+ function cnb_get_checkout(planId) {
39
+ showMessage('warning', 'Processing your request, please wait...')
40
+
41
+ const data = {
42
+ 'action': 'cnb_get_checkout',
43
+ 'planId': planId,
44
+ 'domainId': jQuery('#cnb_domain_id').val()
45
+ };
46
+
47
+ jQuery.post(ajaxurl, data, function(response) {
48
+ cnb_goto_checkout(response)
49
+ });
50
+ }
51
+
52
+ /**
53
+ * The callback function once an API response for a Stripe Checkout Session ID is received.
54
+ * @param response
55
+ */
56
+ function cnb_goto_checkout(response) {
57
+ if (typeof stripe === 'undefined') {
58
+ showMessage('warning', 'Using alternate provider...');
59
+ location.href = 'https://www.callnowbutton.com/stripe.html?s=' + response.message;
60
+ }else if (response.status === 'success') {
61
+ showMessage('success', 'Redirecting you...')
62
+ stripe.redirectToCheckout({sessionId: response.message});
63
+ }else if (response.status === 'error') {
64
+ showMessage('warning', response.message)
65
+ }
66
+ }
67
+
68
+ function cnb_domain_upgrade_notice_profile_saved() {
69
+ showMessage('success', 'Your profile has been saved, click Upgrade to finish your order.')
70
+
71
+ // Also go straight to checkout
72
+ if (cnb_btn) {
73
+ const className = '.' + cnb_btn;
74
+ const ele = jQuery(className)
75
+ ele.trigger('click');
76
+ }
77
+ }
78
+
79
+ /**
80
+ * This calls the admin-ajax action called 'cnb_settings_profile_save'
81
+ */
82
+ function cnb_ajax_submit_profile() {
83
+ jQuery('.buttons_page_call-now-button-domains .cnb-settings-profile #submit')
84
+ .on('click', function(){
85
+ const form = jQuery('.buttons_page_call-now-button-domains .cnb-settings-profile');
86
+
87
+ // Prep data
88
+ const formData = form.serialize();
89
+ const data = {
90
+ action: 'cnb_settings_profile_save',
91
+ data: formData
92
+ };
93
+
94
+ try {
95
+ jQuery.post({
96
+ url: ajaxurl,
97
+ data: data,
98
+ success: function () {
99
+ // Close box
100
+ cnb_domain_upgrade_notice_profile_saved();
101
+ jQuery('#TB_closeWindowButton').trigger('click');
102
+ }
103
+ });
104
+ } catch (e) {
105
+ showMessage('error', e.message);
106
+ }
107
+ return false;
108
+ });
109
+ }
110
+
111
+ jQuery(function () {
112
+ cnb_domain_upgrade_hide_notice();
113
+ cnb_domain_upgrade_currency();
114
+ cnb_ajax_submit_profile();
115
+ });
resources/style/call-now-button.css CHANGED
@@ -68,11 +68,22 @@ Other styling
68
  padding: 0;
69
  }
70
 
 
 
 
 
 
 
 
 
 
 
 
71
  .cnb-button-name-field {
72
  padding: 20px 10px 20px 0;
73
  }
74
 
75
- #cnb\[name\] {
76
  padding: 3px 8px;
77
  font-size: 1.7em;
78
  line-height: 100%;
@@ -111,7 +122,7 @@ table.form-table,
111
 
112
  table.form-table.nav-tab-active,
113
  .notice table.form-table {
114
- display: initial;
115
  }
116
  .notice > form {
117
  margin: .5em 0;
@@ -122,6 +133,19 @@ table.form-table.nav-tab-active,
122
  .cnb-button-name-field.nav-tab-active {
123
  display: block;
124
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  table.form-table.nav-tab-only {
127
  display: table;
@@ -314,3 +338,302 @@ input[type='range'] {
314
  .cnb-price-plans .currency-box.currency-box-active {
315
  display: flex;
316
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  padding: 0;
69
  }
70
 
71
+ .cnb-postbox-container .postbox-header {
72
+ background-color: #2371b1;
73
+ color:#fff;
74
+ }
75
+ .cnb-postbox-container .postbox-header .dashicons {
76
+ margin-left:12px;
77
+ }
78
+ .cnb-postbox-container .postbox-header h2 {
79
+ color: #fff;
80
+ }
81
+
82
  .cnb-button-name-field {
83
  padding: 20px 10px 20px 0;
84
  }
85
 
86
+ #TB_ajaxContent #cnb\[name\] {
87
  padding: 3px 8px;
88
  font-size: 1.7em;
89
  line-height: 100%;
122
 
123
  table.form-table.nav-tab-active,
124
  .notice table.form-table {
125
+ display: table;
126
  }
127
  .notice > form {
128
  margin: .5em 0;
133
  .cnb-button-name-field.nav-tab-active {
134
  display: block;
135
  }
136
+ .cnb-on-active-tab {
137
+ display: none;
138
+ }
139
+ .cnb-on-active-tab.nav-tab-active {
140
+ display: block;
141
+ }
142
+
143
+
144
+ #TB_window #TB_title {
145
+ background-color:#f4f4f4;
146
+ color: #1d2327;
147
+ font-size: 14px;
148
+ }
149
 
150
  table.form-table.nav-tab-only {
151
  display: table;
338
  .cnb-price-plans .currency-box.currency-box-active {
339
  display: flex;
340
  }
341
+
342
+ /* Styling of the Conditions */
343
+ .cnb_condition_rule {
344
+ position: relative;
345
+ border: 1px solid #c3c4c7;
346
+ box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
347
+ background: #fff;
348
+ margin-bottom: 10px;
349
+ max-width:1000px;
350
+ }
351
+
352
+ .cnb_condition_rule,
353
+ .cnb_condition_rule .max_width_column {
354
+ width: 100%;
355
+ }
356
+
357
+ @media screen and (min-width: 783px) {
358
+ .cnb_condition_rule .max_width_column input[type=text] {
359
+ width: calc(100% - 30px);
360
+ }
361
+ }
362
+ @media screen and (max-width: 782px) {
363
+ .cnb_condition_rule {
364
+ padding: 25px 12px 10px 10px;
365
+ }
366
+ .cnb_condition_rule .button-link-delete {
367
+ position: absolute;
368
+ top:0;
369
+ right: 5px;
370
+ }
371
+ }
372
+
373
+ .cnb_condition_rule .button-link-delete {
374
+ text-decoration: none;
375
+ }
376
+ .cnb_condition_rule .button-link-delete .dashicons {
377
+ padding-top:5px;
378
+ }
379
+ .cnb_condition_new .cnb_condition_rule {
380
+ background: repeating-linear-gradient(45deg,#eee, #eee 10px,#f4f4f4 10px, #f4f4f4 20px);
381
+ border: 1px solid #c3c4c7;
382
+ box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
383
+ }
384
+ /* Title of edit button screens */
385
+ h1 span.cnb_button_name {
386
+ display: inline-block;
387
+ color: #777;
388
+ padding: 0px 5px;
389
+ border-radius: 5px;
390
+ border: 2px solid #999;
391
+ }
392
+ /* Paragraph copy inside a settings table */
393
+ .form-table p.cnb_paragraph {
394
+ font-size: 13px;
395
+ line-height: 1.5;
396
+ margin: 1em 0;
397
+ }
398
+
399
+ /* Checkbox toggle styling */
400
+ input[type=checkbox].cnb_toggle_checkbox {
401
+ height: 0;
402
+ width: 0;
403
+ visibility: hidden;
404
+ }
405
+
406
+ label.cnb_toggle_label {
407
+ cursor: pointer;
408
+ text-indent: -9999px;
409
+ width: 40px;
410
+ height: 23px;
411
+ background: #b3afaf;
412
+ display: block;
413
+ border-radius: 25px;
414
+ position: relative;
415
+ display: inline-block;
416
+ margin-left: -20px;
417
+ }
418
+
419
+ label.cnb_toggle_label:after {
420
+ content: '';
421
+ position: absolute;
422
+ top: 2px;
423
+ left: 2px;
424
+ width: 19px;
425
+ height: 19px;
426
+ background: #fff;
427
+ border-radius: 20px;
428
+ transition: 0.3s;
429
+ }
430
+
431
+ input[type=checkbox].cnb_toggle_checkbox:checked + label.cnb_toggle_label {
432
+ background: #3582c4;
433
+ }
434
+
435
+ input[type=checkbox].cnb_toggle_checkbox:checked + label.cnb_toggle_label:after {
436
+ left: calc(100% - 2px);
437
+ transform: translateX(-100%);
438
+ }
439
+
440
+ label.cnb_toggle_label:active:after {
441
+ width: 37px;
442
+ }
443
+
444
+ .cnb_toggle_false,
445
+ .cnb_toggle_true {
446
+ display: none;
447
+ margin-top: 5px;
448
+ cursor: pointer;
449
+ }
450
+ input[type=checkbox].cnb_toggle_checkbox:checked ~ .cnb_toggle_true {
451
+ display: inline-block;
452
+ font-weight: bold;
453
+ }
454
+ input[type=checkbox].cnb_toggle_checkbox:not(:checked) ~ .cnb_toggle_false {
455
+ display: inline-block;
456
+ }
457
+ /* Scheduler Weekdays checkbox styling */
458
+ input[type=checkbox].cnb_day_selector {
459
+ height: 0;
460
+ width: 0;
461
+ visibility: hidden;
462
+ }
463
+
464
+ label.cnb_day_selector {
465
+ cursor: pointer;
466
+ display: flex;
467
+ align-items: center;
468
+ justify-content: center;
469
+ width: 35px;
470
+ height: 35px;
471
+ border-radius: 3px;
472
+ user-select: none;
473
+ font-size: 12px;
474
+ float: left;
475
+ margin-right: 10px;
476
+ background-color: #ddd;
477
+ color: #555;
478
+ }
479
+
480
+ input[type=checkbox].cnb_day_selector:checked + label.cnb_day_selector {
481
+ background: #3582c4;
482
+ color: #fff;
483
+ }
484
+
485
+ /* main section with or without sidebar */
486
+ .cnb-one-column-section,
487
+ .cnb-two-column-section {
488
+ padding-top: 10px;
489
+ }
490
+ .cnb-two-column-section {
491
+ min-width: 763px;
492
+ }
493
+ .cnb-one-column-section::after,
494
+ .cnb-two-column-section::after {
495
+ content:'';
496
+ display: block;
497
+ clear: both;
498
+ }
499
+ .cnb-two-column-section .cnb-body-column {
500
+ margin-right: 300px;
501
+ padding: 0;
502
+ }
503
+ .cnb-one-column-section .cnb-body-column .cnb-body-content,
504
+ .cnb-two-column-section .cnb-body-column .cnb-body-content {
505
+ width: 100%;
506
+ min-width: 463px;
507
+ float: left;
508
+ margin-bottom: 20px;
509
+ position: relative;
510
+ }
511
+ .cnb-two-column-section .cnb-side-column {
512
+ float: right;
513
+ width: 280px;
514
+ }
515
+
516
+ .cnb-side-column .cnb-promobox {
517
+ min-width: 255px;
518
+ }
519
+ .cnb-promobox {
520
+ position: relative;
521
+ margin-bottom: 20px;
522
+ padding: 0;
523
+ line-height: 1;
524
+ }
525
+ .cnb-promobox .cnb-promobox-header {
526
+ display: flex;
527
+ align-items: center;
528
+ border: 1px solid #c3c4c7;
529
+ background-color: #f0f0f1;
530
+ }
531
+ .cnb-promobox .cnb-promobox-header-blue {
532
+ background-color: #2371b1;
533
+ border: 1px solid #2371b1;
534
+ color: #fff;
535
+ }
536
+ .cnb-promobox .cnb-promobox-header .dashicons {
537
+ margin-left: 12px;
538
+ }
539
+ .cnb-one-column-section .cnb-promobox h2,
540
+ .cnb-one-column-section .cnb-promobox h3 {
541
+ font-size: 16px;
542
+ padding: 8px 12px;
543
+ margin: 0;
544
+ line-height: 1.4;
545
+ }
546
+
547
+ .cnb-two-column-section .cnb-promobox h2,
548
+ .cnb-two-column-section .cnb-promobox h3 {
549
+ font-size: 14px;
550
+ padding: 8px 12px;
551
+ margin: 0;
552
+ line-height: 1.4;
553
+ }
554
+ .cnb-promobox .cnb-promobox-header-blue h2,
555
+ .cnb-promobox .cnb-promobox-header-blue h3 {
556
+ color:#fff;
557
+ }
558
+ .cnb-one-column-section .cnb-promobox .inside,
559
+ .cnb-two-column-section .cnb-promobox .inside {
560
+ margin: 0;
561
+ padding: 0;
562
+ position: relative;
563
+ line-height: 1.4;
564
+ font-size: 13px;
565
+ border: 1px solid #c3c4c7;
566
+ border-top:none;
567
+ background-color: #fff;
568
+ box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
569
+ }
570
+ .cnb-one-column-section .cnb-promobox .inside,
571
+ .cnb-one-column-section .cnb-promobox .inside p,
572
+ .cnb-one-column-section .cnb-promobox .inside li {
573
+ font-size: 14px;
574
+ }
575
+ .inside .cnb_description {
576
+ display: block;
577
+ font-size: 12px;
578
+ margin-left: 16px;
579
+ }
580
+ .cnb-one-column-section .cnb-promobox .inside .cnb-promobox-copy,
581
+ .cnb-two-column-section .cnb-promobox .inside .cnb-promobox-copy {
582
+ padding: 6px 0 0;
583
+ }
584
+ .cnb-promobox-copy .cnb-promobox-item {
585
+ margin: 5px 10px;
586
+ }
587
+ .cnb-one-column-section .cnb-promobox .inside .cnb-promobox-action,
588
+ .cnb-two-column-section .cnb-promobox .inside .cnb-promobox-action {
589
+ padding: 10px;
590
+ clear: both;
591
+ border-top: 1px solid #dcdcde;
592
+ background: #f6f7f7;
593
+ }
594
+ .cnb-promobox-action .cnb-promobox-action-left {
595
+ margin-top: 8px;
596
+ display: inline-block;
597
+ }
598
+ .cnb-promobox-action .cnb-promobox-action-left.larger {
599
+ margin-top: 5px;
600
+ font-size: 110%;
601
+ }
602
+ .cnb-promobox-action .cnb-promobox-action-right {
603
+ text-align: right;
604
+ float: right;
605
+ line-height: 1.9;
606
+ }
607
+
608
+ .cnb-two-promobox-row {
609
+ display: flex;
610
+ flex-wrap: wrap;
611
+ justify-content: space-between;
612
+ }
613
+ .cnb-two-promobox-row .cnb-body-column {
614
+ width:49%;
615
+ }
616
+
617
+ @media only screen and (max-width: 850px) {
618
+ .cnb-two-column-section {
619
+ min-width: 0;
620
+ }
621
+ .cnb-one-column-section .cnb-body-column,
622
+ .cnb-two-column-section .cnb-body-column {
623
+ margin: 0;
624
+ }
625
+ .cnb-two-column-section .cnb-body-column .cnb-body-content {
626
+ min-width: 0;
627
+ }
628
+ .cnb-two-column-section .cnb-side-column {
629
+ float: right;
630
+ margin-right: 0;
631
+ width: 100%;
632
+ }
633
+ .cnb-two-promobox-row .cnb-body-column {
634
+ width:100%;
635
+ }
636
+ .hide-on-mobile {
637
+ display: none;
638
+ }
639
+ }
src/admin/action-edit.php CHANGED
@@ -243,28 +243,19 @@ function cnb_action_edit_create_tab_url($button, $tab) {
243
 
244
  /**
245
  * @param $action CnbAction
246
- * @param $button CnbButton
 
247
  * @param $show_table boolean
248
  */
249
- function cnb_render_form_action($action, $button=null, $show_table=true) {
 
 
250
  /**
251
  * @global WP_Locale $wp_locale WordPress date and time locale object.
252
  */
253
  global $wp_locale;
254
  // CNB week starts on Monday
255
  $cnb_days_of_week_order = array(1,2,3,4,5,6,0);
256
-
257
- if ($button) {
258
- $url = admin_url('admin.php');
259
- $upgrade_link =
260
- add_query_arg(array(
261
- 'page' => 'call-now-button-domains',
262
- 'action' => 'upgrade',
263
- 'id' => $button->domain->id
264
- ),
265
- $url);
266
- $upgrade_url = esc_url($upgrade_link);
267
- }
268
  ?>
269
  <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][id]" value="<?php if ($action->id !== null && $action->id !== 'new') { esc_attr_e($action->id); } ?>" />
270
  <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][delete]" id="cnb_action_<?php esc_attr_e($action->id) ?>_delete" value="" />
@@ -298,10 +289,7 @@ function cnb_render_form_action($action, $button=null, $show_table=true) {
298
  <label for="cnb_action_value_input">
299
  <span id="cnb_action_value">Action value</span>
300
  </label>
301
- <a href="<?php echo CNB_SUPPORT; ?>phone-number/<?php cnb_utm_params("question-mark", "phone-number"); ?>"
302
- target="_blank" class="cnb-nounderscore">
303
- <span class="dashicons dashicons-editor-help"></span>
304
- </a>
305
  </th>
306
  <td>
307
  <input type="text" id="cnb_action_value_input" name="actions[<?php esc_attr_e($action->id) ?>][actionValue]" value="<?php esc_attr_e($action->actionValue) ?>"/>
@@ -318,11 +306,7 @@ function cnb_render_form_action($action, $button=null, $show_table=true) {
318
  </td>
319
  </tr>
320
  <tr class="button-text cnb_hide_on_modal">
321
- <th scope="row"><label for="buttonTextField">Button label</label><a
322
- href="<?php echo CNB_SUPPORT; ?>using-text-buttons/<?php cnb_utm_params("question-mark", "using-text-buttons"); ?>"
323
- target="_blank" class="cnb-nounderscore">
324
- <span class="dashicons dashicons-editor-help"></span>
325
- </a></th>
326
  <td>
327
  <input id="buttonTextField" type="text" name="actions[<?php esc_attr_e($action->id) ?>][labelText]"
328
  value="<?php esc_attr_e($action->labelText) ?>" maxlength="30" placeholder="optional" />
@@ -388,7 +372,7 @@ function cnb_render_form_action($action, $button=null, $show_table=true) {
388
  <tr class="cnb_hide_on_modal">
389
  <th></th>
390
  <td></td>
391
- </tr>
392
  <tr>
393
  <th scope="row"><label for="actions[<?php esc_attr_e($action->id) ?>][backgroundColor]">Background color</label></th>
394
  <td>
@@ -409,8 +393,11 @@ function cnb_render_form_action($action, $button=null, $show_table=true) {
409
  <tr>
410
  <th scope="row"></th>
411
  <td>
412
- <input type="checkbox" name="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]" id="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]" value="true" <?php checked(true, $action->iconEnabled); ?>>
413
- <label title="right" for="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]">Show icon</label>
 
 
 
414
  </td>
415
  </tr>
416
  <?php } // End Multi/Buttonbar ?>
@@ -419,76 +406,77 @@ function cnb_render_form_action($action, $button=null, $show_table=true) {
419
  <tr class="cnb_hide_on_modal">
420
  <th scope="row"><h3>Scheduling</h3> </th>
421
  <td>
422
- <div class="cnb-radio-item">
423
- <?php if (!isset($button) || $button->domain->type !== 'FREE') { ?>
424
- <input name="actions[<?php esc_attr_e($action->id) ?>][schedule][showAlways]" type="hidden" value="false" />
425
- <input id="actions_schedule_show_always" onchange="return cnb_hide_on_show_always();" name="actions[<?php esc_attr_e($action->id) ?>][schedule][showAlways]" type="checkbox"
426
- value="true" <?php checked(true, $action->id === 'new' || $action->schedule->showAlways); ?> />
427
- <label title="Show always" for="actions_schedule_show_always">Show always</label>
428
- <?php } else { ?>
429
- <input id="actions_schedule_show_always" name="actions[<?php esc_attr_e($action->id) ?>][schedule][showAlways]" type="hidden" value="true" />
430
- <label title="Show always" for="actions_schedule_show_always">Show always.
431
- <?php
432
- if ($button->domain->type !== 'PRO') {
433
- echo '<a href="' . $upgrade_url . '">Upgrade!</a>';
434
- }
435
- ?>
436
- to enable scheduling.</label>
437
- <?php } ?>
438
- </div>
439
  </td>
440
  </tr>
441
- <?php if (!isset($button) || $button->domain->type !== 'FREE') { ?>
442
- <tr class="cnb_hide_on_show_always">
443
- <th>Show on these days</th>
444
- <td>
445
- <?php
446
- foreach ($cnb_days_of_week_order as $cnb_days_of_week) {
447
- $selected = '';
448
- if (isset($action->schedule) && isset($action->schedule->daysOfWeek)) {
449
- $selected = ($action->schedule->daysOfWeek[$cnb_days_of_week] == true) ? 'checked="checked"' : '';
450
- }
451
- echo "<input type='checkbox' name='actions[" . esc_attr($action->id) . "][schedule][daysOfWeek][" . esc_attr($cnb_days_of_week) . "]' value='true' $selected>" . $wp_locale->get_weekday($cnb_days_of_week) . '<br/>';
452
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
  ?>
454
- </td>
455
- </tr>
456
- <tr class="cnb_hide_on_show_always">
457
- <th><label for="actions[<?php esc_attr_e($action->id) ?>][schedule][start]">Start time</label></th>
458
- <td><input type="time" name="actions[<?php esc_attr_e($action->id) ?>][schedule][start]" id="actions[<?php esc_attr_e($action->id) ?>][schedule][start]" value="<?php if (isset($action->schedule)) { esc_attr_e($action->schedule->start); } ?>"></td>
459
- </tr>
460
- <tr class="cnb_hide_on_show_always">
461
- <th><label for="actions[<?php esc_attr_e($action->id) ?>][schedule][stop]">End time</label></th>
462
- <td><input type="time" name="actions[<?php esc_attr_e($action->id) ?>][schedule][stop]" id="actions[<?php esc_attr_e($action->id) ?>][schedule][stop]" value="<?php if (isset($action->schedule)) { esc_attr_e($action->schedule->stop); } ?>"></td>
463
- </tr>
464
- <tr class="cnb_hide_on_show_always">
465
- <th><label for="actions[<?php esc_attr_e($action->id) ?>][schedule][timezone]">Timezone</label></th>
466
- <td>
467
- <select name="actions[<?php esc_attr_e($action->id) ?>][schedule][timezone]" id="actions[<?php esc_attr_e($action->id) ?>][schedule][timezone]">
468
- <?php
469
- $timezone = (isset($action->schedule) && isset($action->schedule->timezone)) ? $action->schedule->timezone : null;
470
- echo wp_timezone_choice($timezone);
471
- ?>
472
- </select>
473
- <p class="description" id="domain_timezone-description">
474
- <?php if (empty($timezone)) { ?>
475
- Please select your timezone.
476
- <?php } else { ?>
477
- Currently set to <code><?php esc_html_e($timezone)?></code>.
478
- <?php } ?>
479
  </p>
480
- </td>
481
- </tr>
482
- <tr class="cnb_hide_on_show_always">
483
- <th></th>
484
- <td>
485
- <input id="actions_schedule_outside_hours" name="actions[<?php esc_attr_e($action->id) ?>][schedule][outsideHours]" type="checkbox"
486
- value="true" <?php checked(true, isset($action->schedule) && $action->schedule->outsideHours); ?> />
487
- <label title="Show always" for="actions_schedule_outside_hours">Show button outside these hours</label>
488
- </td>
489
- </tr>
490
- <?php } ?>
491
- <?php if ($show_table) { ?>
 
 
 
492
  </table>
493
  <?php } ?>
494
  <?php
@@ -497,9 +485,10 @@ function cnb_render_form_action($action, $button=null, $show_table=true) {
497
  /**
498
  * @param $action CnbAction
499
  * @param $button CnbButton
 
500
  * @param $show_table boolean
501
  */
502
- function cnb_admin_page_action_edit_render_main($action, $button, $show_table=true) {
503
  $bid = !empty($_GET["bid"]) ? sanitize_text_field($_GET["bid"]) : null;
504
  // Set some sane defaults
505
  $action->backgroundColor = !empty($action->backgroundColor)
@@ -519,7 +508,7 @@ function cnb_admin_page_action_edit_render_main($action, $button, $show_table=tr
519
  <input type="hidden" name="action_id" value="<?php echo $action->id ?>" />
520
  <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('cnb-action-edit')?>" />
521
  <?php
522
- cnb_render_form_action($action, $button, $show_table);
523
  }
524
 
525
  function cnb_admin_page_action_edit_render() {
@@ -554,9 +543,9 @@ function cnb_admin_page_action_edit_render() {
554
  $url ));
555
 
556
  $action_verb = $action->id === 'new' ? 'adding' : 'editing';
557
- $mesage = '<strong>You are '.$action_verb.' an Action</strong>.
558
- Click <a href="'.$redirect_link.'">here</a> to go back to continue configuring the Button.';
559
- CnbAdminNotices::get_instance()->renderInfo($mesage);
560
  }
561
 
562
  $url = admin_url('admin-post.php');
243
 
244
  /**
245
  * @param $action CnbAction
246
+ * @param $button CnbButton
247
+ * @param $domain CnbDomain
248
  * @param $show_table boolean
249
  */
250
+ function cnb_render_form_action($action, $button=null, $domain=null, $show_table=true) {
251
+ // In case a domain is not passed, we take it from the button
252
+ $domain = isset($domain) ? $domain : (isset($button) ? $button->domain : null);
253
  /**
254
  * @global WP_Locale $wp_locale WordPress date and time locale object.
255
  */
256
  global $wp_locale;
257
  // CNB week starts on Monday
258
  $cnb_days_of_week_order = array(1,2,3,4,5,6,0);
 
 
 
 
 
 
 
 
 
 
 
 
259
  ?>
260
  <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][id]" value="<?php if ($action->id !== null && $action->id !== 'new') { esc_attr_e($action->id); } ?>" />
261
  <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][delete]" id="cnb_action_<?php esc_attr_e($action->id) ?>_delete" value="" />
289
  <label for="cnb_action_value_input">
290
  <span id="cnb_action_value">Action value</span>
291
  </label>
292
+
 
 
 
293
  </th>
294
  <td>
295
  <input type="text" id="cnb_action_value_input" name="actions[<?php esc_attr_e($action->id) ?>][actionValue]" value="<?php esc_attr_e($action->actionValue) ?>"/>
306
  </td>
307
  </tr>
308
  <tr class="button-text cnb_hide_on_modal">
309
+ <th scope="row"><label for="buttonTextField">Button label</label></th>
 
 
 
 
310
  <td>
311
  <input id="buttonTextField" type="text" name="actions[<?php esc_attr_e($action->id) ?>][labelText]"
312
  value="<?php esc_attr_e($action->labelText) ?>" maxlength="30" placeholder="optional" />
372
  <tr class="cnb_hide_on_modal">
373
  <th></th>
374
  <td></td>
375
+ </tr>
376
  <tr>
377
  <th scope="row"><label for="actions[<?php esc_attr_e($action->id) ?>][backgroundColor]">Background color</label></th>
378
  <td>
393
  <tr>
394
  <th scope="row"></th>
395
  <td>
396
+ <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]" id="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]" value="0" />
397
+ <input id="cnb-action-icon-enabled" class="cnb_toggle_checkbox" type="checkbox" name="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]" id="actions[<?php esc_attr_e($action->id) ?>][iconEnabled]" value="true" <?php checked(true, $action->iconEnabled); ?>>
398
+ <label for="cnb-action-icon-enabled" class="cnb_toggle_label">Toggle</label>
399
+ <span data-cnb_toggle_state_label="cnb-action-icon-enabled" class="cnb_toggle_state cnb_toggle_false">Hide icon</span>
400
+ <span data-cnb_toggle_state_label="cnb-action-icon-enabled" class="cnb_toggle_state cnb_toggle_true">Show icon</span>
401
  </td>
402
  </tr>
403
  <?php } // End Multi/Buttonbar ?>
406
  <tr class="cnb_hide_on_modal">
407
  <th scope="row"><h3>Scheduling</h3> </th>
408
  <td>
409
+ <input name="actions[<?php esc_attr_e($action->id) ?>][schedule][showAlways]" type="hidden" value="false" />
410
+ <input id="actions_schedule_show_always" class="cnb_toggle_checkbox" onchange="return cnb_hide_on_show_always();" name="actions[<?php esc_attr_e($action->id) ?>][schedule][showAlways]" type="checkbox"
411
+ value="true" <?php checked(true, $action->id === 'new' || $action->schedule->showAlways); ?> />
412
+ <label for="actions_schedule_show_always" class="cnb_toggle_label">Toggle</label>
413
+ <span data-cnb_toggle_state_label="actions_schedule_show_always" class="cnb_toggle_state cnb_toggle_false">Button shows at set times</span>
414
+ <span data-cnb_toggle_state_label="actions_schedule_show_always" class="cnb_toggle_state cnb_toggle_true">Always on</span>
415
+
 
 
 
 
 
 
 
 
 
 
416
  </td>
417
  </tr>
418
+ <tr class="cnb_hide_on_show_always">
419
+ <th>Show on these days</th>
420
+ <td>
421
+ <?php
422
+ foreach ($cnb_days_of_week_order as $cnb_days_of_week) {
423
+ $selected = '';
424
+ if (isset($action->schedule) && isset($action->schedule->daysOfWeek)) {
425
+ $selected = (isset($action->schedule->daysOfWeek[$cnb_days_of_week]) && $action->schedule->daysOfWeek[$cnb_days_of_week] == true) ? 'checked="checked"' : '';
 
 
 
426
  }
427
+ echo '
428
+ <input class="cnb_day_selector" id="cnb_weekday_'.esc_attr($cnb_days_of_week).'" type="checkbox" name="actions[' . esc_attr($action->id) . '][schedule][daysOfWeek][' . esc_attr($cnb_days_of_week) . ']" value="true" '.$selected.'>
429
+ <label title="'.$wp_locale->get_weekday($cnb_days_of_week).'" class="cnb_day_selector" for="cnb_weekday_'.esc_attr($cnb_days_of_week).'">'.strtoupper(substr($wp_locale->get_weekday($cnb_days_of_week),0,2)).'</label>
430
+ ';
431
+ }
432
+
433
+ ?>
434
+ </td>
435
+ </tr>
436
+ <tr class="cnb_hide_on_show_always">
437
+ <th><label for="actions[<?php esc_attr_e($action->id) ?>][schedule][start]">Start time</label></th>
438
+ <td><input type="time" name="actions[<?php esc_attr_e($action->id) ?>][schedule][start]" id="actions[<?php esc_attr_e($action->id) ?>][schedule][start]" value="<?php if (isset($action->schedule)) { esc_attr_e($action->schedule->start); } ?>"></td>
439
+ </tr>
440
+ <tr class="cnb_hide_on_show_always">
441
+ <th><label for="actions[<?php esc_attr_e($action->id) ?>][schedule][stop]">End time</label></th>
442
+ <td><input type="time" name="actions[<?php esc_attr_e($action->id) ?>][schedule][stop]" id="actions[<?php esc_attr_e($action->id) ?>][schedule][stop]" value="<?php if (isset($action->schedule)) { esc_attr_e($action->schedule->stop); } ?>"></td>
443
+ </tr>
444
+ <tr class="cnb_hide_on_show_always">
445
+ <th><label for="actions[<?php esc_attr_e($action->id) ?>][schedule][timezone]">Timezone</label></th>
446
+ <td>
447
+ <select name="actions[<?php esc_attr_e($action->id) ?>][schedule][timezone]" id="actions[<?php esc_attr_e($action->id) ?>][schedule][timezone]">
448
+ <?php
449
+ // Uses domain timezone if no timezone can be found
450
+ $timezone = (isset($action->schedule) && !empty($action->schedule->timezone)) ? $action->schedule->timezone : (isset($domain) ? $domain->timezone : null);
451
+ echo wp_timezone_choice($timezone);
452
  ?>
453
+ </select>
454
+ <p class="description" id="domain_timezone-description">
455
+ <?php if (empty($timezone)) { ?>
456
+ Please select your timezone.
457
+ <?php } else { ?>
458
+ Currently set to <code><?php esc_html_e($timezone)?></code>.
459
+ <?php } ?>
460
+ </p>
461
+ <?php if (isset($domain) && !empty($domain->timezone) && $domain->timezone !== $timezone) { ?>
462
+ <p class="notice notice-warning">
463
+ Be aware that the timezone for this action (<code><?php esc_html_e($timezone)?></code>) is different from the timezone for your domain (<code><?php esc_html_e($domain->timezone)?></code>).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  </p>
465
+ <?php } ?>
466
+ </td>
467
+ </tr>
468
+ <tr class="cnb_hide_on_show_always">
469
+ <th><label for="actions_schedule_outside_hours">After hours</label></th>
470
+ <td>
471
+ <input id="actions_schedule_outside_hours" class="cnb_toggle_checkbox" name="actions[<?php esc_attr_e($action->id) ?>][schedule][outsideHours]" type="checkbox"
472
+ value="true" <?php checked(true, isset($action->schedule) && $action->schedule->outsideHours); ?> />
473
+ <label for="actions_schedule_outside_hours" class="cnb_toggle_label">Toggle</label>
474
+ <span data-cnb_toggle_state_label="actions_schedule_outside_hours" class="cnb_toggle_state cnb_toggle_false">Button shows between set hours</span>
475
+ <span data-cnb_toggle_state_label="actions_schedule_outside_hours" class="cnb_toggle_state cnb_toggle_true">Button shows outside set hours</span>
476
+
477
+ </td>
478
+ </tr>
479
+ <?php if ($show_table) { ?>
480
  </table>
481
  <?php } ?>
482
  <?php
485
  /**
486
  * @param $action CnbAction
487
  * @param $button CnbButton
488
+ * @param $domain CnbDomain
489
  * @param $show_table boolean
490
  */
491
+ function cnb_admin_page_action_edit_render_main($action, $button, $domain=null, $show_table=true) {
492
  $bid = !empty($_GET["bid"]) ? sanitize_text_field($_GET["bid"]) : null;
493
  // Set some sane defaults
494
  $action->backgroundColor = !empty($action->backgroundColor)
508
  <input type="hidden" name="action_id" value="<?php echo $action->id ?>" />
509
  <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('cnb-action-edit')?>" />
510
  <?php
511
+ cnb_render_form_action($action, $button, $domain, $show_table);
512
  }
513
 
514
  function cnb_admin_page_action_edit_render() {
543
  $url ));
544
 
545
  $action_verb = $action->id === 'new' ? 'adding' : 'editing';
546
+ $message = '<p><strong>You are '.$action_verb.' an Action</strong>.
547
+ Click <a href="'.$redirect_link.'">here</a> to go back to continue configuring the Button.</p>';
548
+ CnbAdminNotices::get_instance()->renderInfo($message);
549
  }
550
 
551
  $url = admin_url('admin-post.php');
src/admin/action-overview.php CHANGED
@@ -69,14 +69,19 @@ class Cnb_Action_List_Table extends WP_List_Table {
69
  * @return array $columns, the array of columns to use with the table
70
  */
71
  function get_columns() {
 
72
  $columns = array(
73
  'cb' => '<input type="checkbox">',
74
  'id' => __('ID'),
75
  'actionType' => __('Type'),
76
  'actionValue' => __('Value'),
77
- 'labelText' => __('Label'),
78
  );
79
  if ($this->button) { unset($columns['cb']); }
 
 
 
 
80
  return $columns;
81
  }
82
 
@@ -145,8 +150,7 @@ class Cnb_Action_List_Table extends WP_List_Table {
145
  return null;
146
  }
147
 
148
- function column_default( $item, $column_name )
149
- {
150
  switch( $column_name ) {
151
  case 'id':
152
  case 'actionValue':
@@ -155,12 +159,33 @@ class Cnb_Action_List_Table extends WP_List_Table {
155
  // Handled by column_actionType
156
  case 'actionType':
157
  return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  default:
159
  return '<em>Unknown column ' .esc_html($column_name) . '</em>';
160
  }
161
  }
162
 
163
  private function get_data() {
 
164
  $actions = array();
165
  if ($this->button === null) {
166
  $actions = CnbAppRemote::cnb_remote_get_actions();
@@ -182,8 +207,15 @@ class Cnb_Action_List_Table extends WP_List_Table {
182
 
183
  $data = array();
184
  foreach ($actions as $action) {
 
 
 
 
 
 
185
  $data[] = array(
186
  'id' => $action->id,
 
187
  'actionType' => $action->actionType,
188
  'actionValue' => $action->actionValue,
189
  'labelText' => $action->labelText
69
  * @return array $columns, the array of columns to use with the table
70
  */
71
  function get_columns() {
72
+ global $cnb_options;
73
  $columns = array(
74
  'cb' => '<input type="checkbox">',
75
  'id' => __('ID'),
76
  'actionType' => __('Type'),
77
  'actionValue' => __('Value'),
78
+ 'labelText' => __('Label')
79
  );
80
  if ($this->button) { unset($columns['cb']); }
81
+
82
+ if ($cnb_options['advanced_view'] === 1) {
83
+ $columns['actionButton'] = __('Button');
84
+ }
85
  return $columns;
86
  }
87
 
150
  return null;
151
  }
152
 
153
+ function column_default( $item, $column_name ) {
 
154
  switch( $column_name ) {
155
  case 'id':
156
  case 'actionValue':
159
  // Handled by column_actionType
160
  case 'actionType':
161
  return null;
162
+ case 'actionButton':
163
+ $url = admin_url('admin.php');
164
+ $buttons = $item[$column_name];
165
+ if ($buttons && is_array($buttons)) {
166
+ foreach ($buttons as $button) {
167
+ if (!is_wp_error($button)) {
168
+ $new_link =
169
+ add_query_arg(
170
+ array(
171
+ 'page' => 'call-now-button',
172
+ 'action' => 'edit',
173
+ 'id' => $button->id,
174
+ ),
175
+ $url);
176
+ $new_url = esc_url_raw($new_link);
177
+ return '<a href="'.$new_url.'">' . esc_html($button->name) . '</a>';
178
+ }
179
+ }
180
+ }
181
+ break;
182
  default:
183
  return '<em>Unknown column ' .esc_html($column_name) . '</em>';
184
  }
185
  }
186
 
187
  private function get_data() {
188
+ global $cnb_options;
189
  $actions = array();
190
  if ($this->button === null) {
191
  $actions = CnbAppRemote::cnb_remote_get_actions();
207
 
208
  $data = array();
209
  foreach ($actions as $action) {
210
+ // Button info
211
+ $button = array();
212
+ if ($cnb_options['advanced_view'] === 1) {
213
+ $button = CnbAppRemote::cnb_remote_get_button_for_action($action->id);
214
+ }
215
+
216
  $data[] = array(
217
  'id' => $action->id,
218
+ 'actionButton' => $button,
219
  'actionType' => $action->actionType,
220
  'actionValue' => $action->actionValue,
221
  'labelText' => $action->labelText
src/admin/admin-ajax.php CHANGED
@@ -2,6 +2,7 @@
2
  require_once dirname( __FILE__ ) . '/api/CnbAppRemotePayment.php';
3
  require_once dirname( __FILE__ ) . '/api/CnbAppRemote.php';
4
  require_once dirname( __FILE__ ) . '/action-overview.php';
 
5
 
6
  // part of domain-upgrade
7
  function cnb_admin_page_domain_upgrade_get_checkout($arg) {
@@ -62,3 +63,12 @@ function cnb_admin_button_delete_actions() {
62
  }
63
 
64
  add_action( 'wp_ajax_cnb_delete_action', 'cnb_admin_button_delete_actions' );
 
 
 
 
 
 
 
 
 
2
  require_once dirname( __FILE__ ) . '/api/CnbAppRemotePayment.php';
3
  require_once dirname( __FILE__ ) . '/api/CnbAppRemote.php';
4
  require_once dirname( __FILE__ ) . '/action-overview.php';
5
+ require_once dirname( __FILE__ ) . '/settings-profile.php';
6
 
7
  // part of domain-upgrade
8
  function cnb_admin_page_domain_upgrade_get_checkout($arg) {
63
  }
64
 
65
  add_action( 'wp_ajax_cnb_delete_action', 'cnb_admin_button_delete_actions' );
66
+
67
+ function cnb_admin_settings_profile_save() {
68
+ $data = array();
69
+ wp_parse_str($_REQUEST['data'], $data);
70
+ $result = cnb_admin_profile_edit_process_real($data['_wpnonce'], $data['user']);
71
+ wp_send_json($result);
72
+ }
73
+
74
+ add_action( 'wp_ajax_cnb_settings_profile_save', 'cnb_admin_settings_profile_save' );
src/admin/api/CnbAdminCloud.php CHANGED
@@ -14,13 +14,24 @@ class CnbAdminCloud {
14
  * @return string The ID to use for the Cloud Button
15
  */
16
  public static function cnb_set_default_option_for_cloud( $options ) {
 
 
17
  // Check if an ID has already been set. If so, use if and continue
18
  if ( isset( $options['cloud_use_id'] ) && ! empty( $options['cloud_use_id'] ) ) {
19
  return null;
20
  }
 
 
 
 
21
 
 
 
 
22
  // Check if we can talk to the API via a key. If so, use the current user to be safe
23
  $user_info = CnbAppRemote::cnb_remote_get_user_info();
 
 
24
  if ( !is_wp_error($user_info)) {
25
  return $user_info->id;
26
  }
@@ -190,7 +201,7 @@ class CnbAdminCloud {
190
  if ( $result instanceof WP_Error ) {
191
  $message = self::cnb_admin_get_error_message( 'delete', 'domain', $result, 'with ID <code>' . esc_html( $domain_id ) . '</code>' );
192
  } else {
193
- $message = self::cnb_admin_get_success_message( 'deleted', 'domain', $domain_id );
194
  }
195
  array_push( $cnb_cloud_notifications, $message );
196
 
14
  * @return string The ID to use for the Cloud Button
15
  */
16
  public static function cnb_set_default_option_for_cloud( $options ) {
17
+ global $cnb_options;
18
+
19
  // Check if an ID has already been set. If so, use if and continue
20
  if ( isset( $options['cloud_use_id'] ) && ! empty( $options['cloud_use_id'] ) ) {
21
  return null;
22
  }
23
+ // Check if an ID has already been set. If so, use if and continue
24
+ if ( empty( $options['api_key'] ) ) {
25
+ return null;
26
+ }
27
 
28
+ // Ensure that there is an API key to work with on the first call
29
+ $original_key = !empty($cnb_options['api_key']) ? $cnb_options['api_key'] : null;
30
+ $cnb_options['api_key'] = $options['api_key'];
31
  // Check if we can talk to the API via a key. If so, use the current user to be safe
32
  $user_info = CnbAppRemote::cnb_remote_get_user_info();
33
+ // Reset key
34
+ $cnb_options['api_key'] = $original_key;
35
  if ( !is_wp_error($user_info)) {
36
  return $user_info->id;
37
  }
201
  if ( $result instanceof WP_Error ) {
202
  $message = self::cnb_admin_get_error_message( 'delete', 'domain', $result, 'with ID <code>' . esc_html( $domain_id ) . '</code>' );
203
  } else {
204
+ $message = self::cnb_admin_get_success_message( 'deleted', 'domain', $result->object->name );
205
  }
206
  array_push( $cnb_cloud_notifications, $message );
207
 
src/admin/api/CnbAppRemote.php CHANGED
@@ -62,8 +62,9 @@ class CnbAppRemoteHelper {
62
  }
63
 
64
  return array(
 
65
  'actionType' => !empty( $action['actionType'] ) ? $action['actionType'] : 'PHONE',
66
- 'actionValue' => $action['actionValue'],
67
  'schedule' => $schedule,
68
  'backgroundColor' => !empty( $action['backgroundColor'] ) ? $action['backgroundColor'] : '#009900',
69
  'iconColor' => !empty( $action['iconColor'] ) ? $action['iconColor'] : '#ffffff',
@@ -385,6 +386,12 @@ class CnbAppRemote {
385
  return self::cnb_remote_get( $rest_endpoint );
386
  }
387
 
 
 
 
 
 
 
388
  /**
389
  * This returns the domain matching the WordPress domain
390
  * @return mixed|WP_Error
@@ -444,6 +451,12 @@ class CnbAppRemote {
444
  return self::cnb_remote_get( $rest_endpoint );
445
  }
446
 
 
 
 
 
 
 
447
  public static function cnb_remote_get_conditions() {
448
  $rest_endpoint = '/v1/condition';
449
 
@@ -456,6 +469,12 @@ class CnbAppRemote {
456
  return self::cnb_remote_get( $rest_endpoint );
457
  }
458
 
 
 
 
 
 
 
459
  public static function cnb_remote_get_apikeys() {
460
  $rest_endpoint = '/v1/apikey';
461
 
@@ -501,6 +520,11 @@ class CnbAppRemote {
501
  return self::cnb_remote_delete( $rest_endpoint, $button );
502
  }
503
 
 
 
 
 
 
504
  public static function cnb_remote_delete_domain( $domain ) {
505
  // Find the ID in the options
506
  $domainId = $domain['id'];
@@ -565,7 +589,6 @@ class CnbAppRemote {
565
  $body = $helper->convertAction($action);
566
 
567
  $rest_endpoint = '/v1/action/' . $actionId;
568
-
569
  return self::cnb_remote_patch( $rest_endpoint, $body );
570
  }
571
 
62
  }
63
 
64
  return array(
65
+ 'id' => !empty( $action['id'] ) ? $action['id'] : null,
66
  'actionType' => !empty( $action['actionType'] ) ? $action['actionType'] : 'PHONE',
67
+ 'actionValue' => !empty( $action['actionValue'] ) ? $action['actionValue'] : '',
68
  'schedule' => $schedule,
69
  'backgroundColor' => !empty( $action['backgroundColor'] ) ? $action['backgroundColor'] : '#009900',
70
  'iconColor' => !empty( $action['iconColor'] ) ? $action['iconColor'] : '#ffffff',
386
  return self::cnb_remote_get( $rest_endpoint );
387
  }
388
 
389
+ public static function cnb_remote_update_user_info($user) {
390
+ $rest_endpoint = '/v1/user';
391
+
392
+ return self::cnb_remote_patch( $rest_endpoint, $user );
393
+ }
394
+
395
  /**
396
  * This returns the domain matching the WordPress domain
397
  * @return mixed|WP_Error
451
  return self::cnb_remote_get( $rest_endpoint );
452
  }
453
 
454
+ public static function cnb_remote_get_button_for_action( $id ) {
455
+ $rest_endpoint = '/v1/action/button/' . $id;
456
+
457
+ return self::cnb_remote_get( $rest_endpoint );
458
+ }
459
+
460
  public static function cnb_remote_get_conditions() {
461
  $rest_endpoint = '/v1/condition';
462
 
469
  return self::cnb_remote_get( $rest_endpoint );
470
  }
471
 
472
+ public static function cnb_remote_get_button_for_condition( $id ) {
473
+ $rest_endpoint = '/v1/condition/button/' . $id;
474
+
475
+ return self::cnb_remote_get( $rest_endpoint );
476
+ }
477
+
478
  public static function cnb_remote_get_apikeys() {
479
  $rest_endpoint = '/v1/apikey';
480
 
520
  return self::cnb_remote_delete( $rest_endpoint, $button );
521
  }
522
 
523
+ /**
524
+ * @param $domain array with at least `id` set
525
+ *
526
+ * @return mixed|WP_Error
527
+ */
528
  public static function cnb_remote_delete_domain( $domain ) {
529
  // Find the ID in the options
530
  $domainId = $domain['id'];
589
  $body = $helper->convertAction($action);
590
 
591
  $rest_endpoint = '/v1/action/' . $actionId;
 
592
  return self::cnb_remote_patch( $rest_endpoint, $body );
593
  }
594
 
src/admin/button-edit.php CHANGED
@@ -25,7 +25,7 @@ function cnb_add_header_button_edit($button = null) {
25
  }
26
  $buttonTypes = cnb_get_button_types();
27
  $typeName = $buttonTypes[$type];
28
- echo 'Edit ' . esc_html($typeName) . ': "' . esc_html($name) . '"';
29
  }
30
 
31
  function cnb_create_tab_url_button($button, $tab) {
@@ -103,8 +103,7 @@ function cnb_admin_create_button() {
103
  $redirect_url = esc_url_raw( $redirect_link );
104
  wp_safe_redirect( $redirect_url );
105
  exit;
106
- }
107
- else {
108
  wp_die( __( 'Invalid nonce specified', CNB_NAME), __( 'Error', CNB_NAME), array(
109
  'response' => 403,
110
  'back_link' => 'admin.php?page=' . $cnb_slug_base,
@@ -199,16 +198,11 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
199
  $cnb_multi_image = esc_url(plugins_url( '../../resources/images/button-new-multi.png', __FILE__ ));
200
  $cnb_full_image = esc_url(plugins_url( '../../resources/images/button-new-full.png', __FILE__ ));
201
 
202
- $show_submit_button = true;
203
  $submit_button_text = array_key_exists('submit_button_text', $options) ? $options['submit_button_text'] : '';
204
  $hide_on_modal = array_key_exists('modal_view', $options) && $options['modal_view'] === true;
205
- $show_advanced_view_only = array_key_exists('advanced_view', $options) && $options['advanced_view'] === 1;
206
  if($hide_on_modal) {
207
  echo '<script type="text/javascript">cnb_hide_on_modal_set=1</script>';
208
  }
209
- if ($show_advanced_view_only) {
210
- echo '<script type="text/javascript">show_advanced_view_only_set=1</script>';
211
- }
212
 
213
  // Create "add Action" link WITH Button association
214
  $url = admin_url('admin.php');
@@ -246,23 +240,27 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
246
  <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][id]" value="<?php esc_attr_e($action->id) ?>" />
247
  <?php } ?>
248
 
249
- <div class="cnb-button-name-field <?php if(!$hide_on_modal) { echo cnb_is_active_tab('basic_options'); } else { echo 'nav-tab-only'; } ?>">
250
- <label for="cnb[name]"><input type="text" name="cnb[name]" id="cnb[name]" class="large-text" placeholder="Button name" required="required" value="<?php esc_attr_e($button->name); ?>" /></label>
251
- </div>
252
-
253
  <table class="form-table <?php if(!$hide_on_modal) { echo cnb_is_active_tab('basic_options'); } else { echo 'nav-tab-only'; } ?>">
 
 
 
 
 
 
 
 
 
 
 
254
  <tr class="cnb_hide_on_modal">
255
- <th scope="row">Button status</th>
256
 
257
  <td class="activated">
258
- <div class="cnb-radio-item">
259
- <input id="cnb-disable" type="radio" name="cnb[active]" value="0" <?php checked(false, $button->active); ?> />
260
- <label for="cnb-disable">Disabled</label>
261
- </div>
262
- <div class="cnb-radio-item">
263
- <input id="cnb-enable" type="radio" name="cnb[active]" value="1" <?php checked(true, $button->active); ?> />
264
- <label for="cnb-enable">Enabled</label>
265
- </div>
266
  </td>
267
  </tr>
268
  <tr class="cnb_hide_on_modal cnb_advanced_view">
@@ -304,10 +302,10 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
304
  if (sizeof($button->actions) > 0) {
305
  $action = $button->actions[0];
306
  }
307
- cnb_admin_page_action_edit_render_main($action, $button, false);
308
  }
309
  } else {
310
- // Only render the Actions table if that is the active tab (otherwise it's a pretty expensive operation)
311
  if (!empty($is_active_tab_basic_options)) {
312
  ?></table>
313
  <div class="cnb-button-edit-action-table <?php if(!$hide_on_modal) { echo cnb_is_active_tab('basic_options'); } else { echo 'nav-tab-only'; } ?>">
@@ -319,7 +317,6 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
319
  <?php if ($button_id === 'new') { ?>
320
  <tr>
321
  <th scope="row">Select button type</th>
322
-
323
  </tr>
324
  <tr>
325
  <td scope="row" colspan="2" class="cnb_type_selector">
@@ -409,7 +406,7 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
409
  <div class="cnb-radio-item">
410
  <input type="radio" id="appearance3" name="cnb[options][placement]"
411
  value="BOTTOM_CENTER" <?php checked('BOTTOM_CENTER', $button->options->placement); ?>>
412
- <label title="bottom-center" for="appearance3">Center bottom</label>
413
  </div>
414
 
415
  <!-- Extra placement options -->
@@ -449,55 +446,80 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
449
  </table>
450
  <table class="form-table <?php echo cnb_is_active_tab('visibility') ?>">
451
  <tbody id="cnb_form_table_visibility">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  <tr>
453
- <th scope="row"><h2>Conditions <input type="button" onclick="return cnb_add_condition();" value="Add New" class="button button-secondary page-title-action"></h2>
454
  </tr>
455
  <?php if (empty($button->conditions)) { ?>
456
  <tr>
457
  <td colspan="2">
458
- <p>You have no Conditions yet.</p>
459
- <p>Conditions allow you to show/hide the Button on page URLs you specify.</p>
460
- <p>Click <code>Add Condition</code> below to create your first Condition.</p>
461
  </td>
462
  </tr>
463
  <?php } else { ?>
464
  <?php foreach ($button->conditions as $condition) { ?>
465
- <tr class="appearance" id="cnb_condition_<?php esc_attr_e($condition->id) ?>">
466
- <th scope="row"><label for="condition[<?php esc_attr_e($condition->id) ?>][filterType]">Condition
467
- <div class="cnb_font_normal cnb_font_90 cnb_advanced_view">ID: <code class="cnb_font_90"><?php esc_html_e($condition->id) ?></code></div></label></th>
468
- <td>
469
- <input type="hidden" name="condition[<?php esc_attr_e($condition->id) ?>][id]" value="<?php esc_attr_e($condition->id) ?>" />
470
- <input type="hidden" name="condition[<?php esc_attr_e($condition->id) ?>][conditionType]" value="<?php esc_attr_e($condition->conditionType) ?>" />
471
- <input type="hidden" name="condition[<?php esc_attr_e($condition->id) ?>][delete]" id="cnb_condition_<?php esc_attr_e($condition->id) ?>_delete" value="" />
472
- <select name="condition[<?php esc_attr_e($condition->id) ?>][filterType]" id="condition[<?php esc_attr_e($condition->id) ?>][filterType]">
473
- <option value="INCLUDE"<?php selected('INCLUDE', $condition->filterType) ?>>Include</option>
474
- <option value="EXCLUDE"<?php selected('EXCLUDE', $condition->filterType) ?>>Exclude</option>
475
- </select><br />
476
-
477
- <label>
478
- <select name="condition[<?php esc_attr_e($condition->id) ?>][matchType]">
479
- <?php foreach (cnb_get_condition_match_types() as $condition_match_type_key => $condition_match_type_value) { ?>
480
- <option value="<?php esc_attr_e($condition_match_type_key) ?>"<?php selected($condition_match_type_key, $condition->matchType) ?>>
481
- <?php esc_html_e($condition_match_type_value) ?>
482
- </option>
483
- <?php } ?>
484
- </select>
485
- </label><br />
486
-
487
- <label>
488
- <input type="text" name="condition[<?php esc_attr_e($condition->id) ?>][matchValue]" value="<?php esc_attr_e($condition->matchValue); ?>"/>
489
- </label>
490
-
491
- <?php // Match old "Hide button on front page"
492
- if ($condition->conditionType === 'URL' && $condition->filterType === 'EXCLUDE' && $condition->matchType === 'EXACT' && $condition->matchValue === get_home_url()) { ?>
493
- <p class="description"><span class="dashicons dashicons-info"></span> This condition matches the legacy "<strong>Hide button on front page</strong>" checkbox.</p>
494
- <?php } else { ?>
495
- <br />
496
- <?php }?>
497
-
498
- <input type="button" onclick="return cnb_remove_condition('<?php echo esc_js($condition->id) ?>');" value="Remove Condition" class="button-link button-link-delete">
499
- </td>
500
- </tr>
 
 
 
 
 
 
 
501
  <?php } } ?>
502
  <tr id="cnb_form_table_add_condition">
503
  <th></th>
@@ -509,7 +531,7 @@ function cnb_button_edit_form($button_id, $button, $default_domain, $options=arr
509
  </table>
510
 
511
  <input type="hidden" name="cnb[version]" value="<?php echo CNB_VERSION; ?>"/>
512
- <?php if ($show_submit_button) {submit_button($submit_button_text);} ?>
513
  </form>
514
  <?php
515
  }
25
  }
26
  $buttonTypes = cnb_get_button_types();
27
  $typeName = $buttonTypes[$type];
28
+ echo 'Editing ' . esc_html($typeName) . ' <span class="cnb_button_name">' . esc_html($name) . '</span>';
29
  }
30
 
31
  function cnb_create_tab_url_button($button, $tab) {
103
  $redirect_url = esc_url_raw( $redirect_link );
104
  wp_safe_redirect( $redirect_url );
105
  exit;
106
+ } else {
 
107
  wp_die( __( 'Invalid nonce specified', CNB_NAME), __( 'Error', CNB_NAME), array(
108
  'response' => 403,
109
  'back_link' => 'admin.php?page=' . $cnb_slug_base,
198
  $cnb_multi_image = esc_url(plugins_url( '../../resources/images/button-new-multi.png', __FILE__ ));
199
  $cnb_full_image = esc_url(plugins_url( '../../resources/images/button-new-full.png', __FILE__ ));
200
 
 
201
  $submit_button_text = array_key_exists('submit_button_text', $options) ? $options['submit_button_text'] : '';
202
  $hide_on_modal = array_key_exists('modal_view', $options) && $options['modal_view'] === true;
 
203
  if($hide_on_modal) {
204
  echo '<script type="text/javascript">cnb_hide_on_modal_set=1</script>';
205
  }
 
 
 
206
 
207
  // Create "add Action" link WITH Button association
208
  $url = admin_url('admin.php');
240
  <input type="hidden" name="actions[<?php esc_attr_e($action->id) ?>][id]" value="<?php esc_attr_e($action->id) ?>" />
241
  <?php } ?>
242
 
 
 
 
 
243
  <table class="form-table <?php if(!$hide_on_modal) { echo cnb_is_active_tab('basic_options'); } else { echo 'nav-tab-only'; } ?>">
244
+ <tr class="cnb_hide_on_modal">
245
+ <th></th>
246
+ <td></td>
247
+ </tr>
248
+ <tr>
249
+ <th scope="row"><label for="cnb[name]">Button name</label></th>
250
+
251
+ <td class="activated">
252
+ <label for="cnb[name]"><input type="text" name="cnb[name]" id="cnb[name]" required="required" value="<?php esc_attr_e($button->name); ?>" /></label>
253
+ </td>
254
+ </tr>
255
  <tr class="cnb_hide_on_modal">
256
+ <th scope="row"><label for="cnb-enable">Button status</label></th>
257
 
258
  <td class="activated">
259
+ <input type="hidden" name="cnb[active]" value="0" />
260
+ <input id="cnb-enable" class="cnb_toggle_checkbox" type="checkbox" name="cnb[active]" value="1" <?php checked(true, $button->active); ?> />
261
+ <label for="cnb-enable" class="cnb_toggle_label">Toggle</label>
262
+ <span data-cnb_toggle_state_label="cnb-enable" class="cnb_toggle_state cnb_toggle_false">Inactive</span>
263
+ <span data-cnb_toggle_state_label="cnb-enable" class="cnb_toggle_state cnb_toggle_true">Active</span>
 
 
 
264
  </td>
265
  </tr>
266
  <tr class="cnb_hide_on_modal cnb_advanced_view">
302
  if (sizeof($button->actions) > 0) {
303
  $action = $button->actions[0];
304
  }
305
+ cnb_admin_page_action_edit_render_main($action, $button, $default_domain, false);
306
  }
307
  } else {
308
+ // Only render the Actions' table if that is the active tab (otherwise it's a pretty expensive operation)
309
  if (!empty($is_active_tab_basic_options)) {
310
  ?></table>
311
  <div class="cnb-button-edit-action-table <?php if(!$hide_on_modal) { echo cnb_is_active_tab('basic_options'); } else { echo 'nav-tab-only'; } ?>">
317
  <?php if ($button_id === 'new') { ?>
318
  <tr>
319
  <th scope="row">Select button type</th>
 
320
  </tr>
321
  <tr>
322
  <td scope="row" colspan="2" class="cnb_type_selector">
406
  <div class="cnb-radio-item">
407
  <input type="radio" id="appearance3" name="cnb[options][placement]"
408
  value="BOTTOM_CENTER" <?php checked('BOTTOM_CENTER', $button->options->placement); ?>>
409
+ <label title="bottom-center" for="appearance3">Center</label>
410
  </div>
411
 
412
  <!-- Extra placement options -->
446
  </table>
447
  <table class="form-table <?php echo cnb_is_active_tab('visibility') ?>">
448
  <tbody id="cnb_form_table_visibility">
449
+ <tr>
450
+ <td></td>
451
+ </tr>
452
+ <tr>
453
+ <th scope="row"><label for="cnb_button_options_displaymode">Display on </label></th>
454
+ <td class="appearance">
455
+ <select name="cnb[options][displayMode]" id="cnb_button_options_displaymode">
456
+ <option value="MOBILE_ONLY"<?php selected('MOBILE_ONLY', $button->options->displayMode) ?>>Mobile only</option>
457
+ <option value="DESKTOP_ONLY"<?php selected('DESKTOP_ONLY', $button->options->displayMode) ?>>Desktop only</option>
458
+ <option value="ALWAYS"<?php selected('ALWAYS', $button->options->displayMode) ?>>All screens</option>
459
+ </select>
460
+ </td>
461
+ </tr>
462
+ <tr>
463
+ <th>
464
+ <h2>Select pages</h2>
465
+ </th>
466
+ </tr>
467
  <tr>
468
+ <th><input type="button" onclick="return cnb_add_condition();" value="Add New Rule" class="button button-secondary page-title-action"></th>
469
  </tr>
470
  <?php if (empty($button->conditions)) { ?>
471
  <tr>
472
  <td colspan="2">
473
+ <p class="cnb_paragraph">You have no page visibility rules set up. This means that your button will show on all pages.</p>
474
+ <p class="cnb_paragraph">Page visibility rules give you full control over which pages the button should appear on.</p>
475
+ <p class="cnb_paragraph">Click the <code>Add New Rule</code> button above to add a rule. You can freely mix and match rules to meet your requirements.</p>
476
  </td>
477
  </tr>
478
  <?php } else { ?>
479
  <?php foreach ($button->conditions as $condition) { ?>
480
+ <tr class="appearance" id="cnb_condition_<?php esc_attr_e($condition->id) ?>">
481
+ <td colspan="2" style="padding: 0;">
482
+ <table class="cnb_condition_rule">
483
+ <tbody>
484
+ <tr>
485
+ <td>
486
+ <input type="hidden" name="condition[<?php esc_attr_e($condition->id) ?>][id]" value="<?php esc_attr_e($condition->id) ?>" />
487
+ <input type="hidden" name="condition[<?php esc_attr_e($condition->id) ?>][conditionType]" value="<?php esc_attr_e($condition->conditionType) ?>" />
488
+ <input type="hidden" name="condition[<?php esc_attr_e($condition->id) ?>][delete]" id="cnb_condition_<?php esc_attr_e($condition->id) ?>_delete" value="" />
489
+ <label for="condition[<?php esc_attr_e($condition->id) ?>][filterType]">
490
+ <select name="condition[<?php esc_attr_e($condition->id) ?>][filterType]" id="condition[<?php esc_attr_e($condition->id) ?>][filterType]">
491
+ <option value="INCLUDE"<?php selected('INCLUDE', $condition->filterType) ?>>Include</option>
492
+ <option value="EXCLUDE"<?php selected('EXCLUDE', $condition->filterType) ?>>Exclude</option>
493
+ </select>
494
+ </label>
495
+ </td>
496
+ <td>
497
+ <select name="condition[<?php esc_attr_e($condition->id) ?>][matchType]">
498
+ <?php foreach (cnb_get_condition_match_types() as $condition_match_type_key => $condition_match_type_value) { ?>
499
+ <option value="<?php esc_attr_e($condition_match_type_key) ?>"<?php selected($condition_match_type_key, $condition->matchType) ?>>
500
+ <?php esc_html_e($condition_match_type_value) ?>
501
+ </option>
502
+ <?php } ?>
503
+ </select>
504
+ </td>
505
+ <td class="max_width_column">
506
+ <input type="text" name="condition[<?php esc_attr_e($condition->id) ?>][matchValue]" value="<?php esc_attr_e($condition->matchValue); ?>"/>
507
+ <a onclick="return cnb_remove_condition('<?php echo esc_js($condition->id) ?>');" title="Remove Condition" class="button-link button-link-delete"><span class="dashicons dashicons-no"></span></a>
508
+ </td>
509
+ </tr>
510
+ <?php // Match old "Hide button on front page"
511
+ if ($condition->conditionType === 'URL' && $condition->filterType === 'EXCLUDE' && $condition->matchType === 'EXACT' && $condition->matchValue === get_home_url()) { ?>
512
+ <tr>
513
+ <td colspan="3"><p class="description" style="text-align: center;"><span class="dashicons dashicons-info"></span> This condition matches the plugin's "<strong>Hide button on front page</strong>" checkbox.</p></td>
514
+ </tr>
515
+ <?php } ?>
516
+ <tr class="cnb_advanced_view">
517
+ <td colspan="3" style="padding: 5px 10px"><div class="cnb_font_normal cnb_font_90">ID: <code class="cnb_font_90"><?php esc_html_e($condition->id) ?></code></div></td>
518
+ </tr>
519
+ </tbody>
520
+ </table>
521
+ </td>
522
+ </tr>
523
  <?php } } ?>
524
  <tr id="cnb_form_table_add_condition">
525
  <th></th>
531
  </table>
532
 
533
  <input type="hidden" name="cnb[version]" value="<?php echo CNB_VERSION; ?>"/>
534
+ <?php submit_button($submit_button_text); ?>
535
  </form>
536
  <?php
537
  }
src/admin/button-overview.php CHANGED
@@ -17,9 +17,9 @@ function cnb_add_header_button_overview() {
17
  echo 'Buttons ';
18
  }
19
 
20
- function cnb_add_new_modal_action() {
21
  $url = admin_url('admin.php');
22
- $new_link =
23
  add_query_arg(
24
  array(
25
  'TB_inline' => 'true',
@@ -30,15 +30,26 @@ function cnb_add_new_modal_action() {
30
  'type' => 'single',
31
  'id' => 'new' ),
32
  $url );
 
 
 
 
33
  printf(
34
- '<a href="%s" title="%s" class="thickbox open-plugin-details-modal page-title-action" id="cnb-button-overview-modal-add-new" data-title="%s">%s</a>',
35
- $new_link,
36
- __('Create new button', CNB_NAME),
37
- __('Choose a Button type', CNB_NAME),
38
- __('Add New', CNB_NAME)
 
39
  );
40
  }
41
 
 
 
 
 
 
 
42
 
43
  class Cnb_Button_List_Table extends WP_List_Table {
44
 
@@ -402,7 +413,8 @@ class Cnb_Button_List_Table extends WP_List_Table {
402
  }
403
 
404
  function no_items() {
405
- _e( 'No buttons found.' );
 
406
  }
407
  }
408
 
@@ -491,17 +503,7 @@ function cnb_admin_page_overview_render_list() {
491
 
492
  add_action('cnb_header_name', 'cnb_add_header_button_overview');
493
 
494
- if ($cnb_cloud_domain !== null && !($cnb_cloud_domain instanceof WP_Error)) {
495
- $url = admin_url('admin.php');
496
- $upgrade_link =
497
- add_query_arg(array(
498
- 'page' => 'call-now-button-domains',
499
- 'action' => 'upgrade',
500
- 'id' => $cnb_cloud_domain->id
501
- ),
502
- $url);
503
- $upgrade_url = esc_url($upgrade_link);
504
- }
505
 
506
  // CNB: Start content
507
  $data = $wp_list_table->prepare_items();
@@ -523,73 +525,53 @@ function cnb_admin_page_overview_render_list() {
523
 
524
  do_action('cnb_header');
525
 
526
- echo '<div id="poststuff">
527
- <div id="post-body" class="metabox-holder columns-2">
528
- <div id="post-body-content" style="position: relative;">';
529
 
530
  $wp_list_table->views();
531
 
532
  echo '<form id="wp_list_event" method="post">';
533
  $wp_list_table->display(); //Table of elements
534
- echo '</form></div><!--End #post-body-content-->' ?>
535
 
536
- <?php if (isset($upgrade_url)) { ?>
537
- <div id="postbox-container-1" class="postbox-container"> <!-- Sidebar promo boxes -->
538
  <?php if ($cnb_cloud_domain !== null && !($cnb_cloud_domain instanceof WP_Error) && $cnb_cloud_domain->type === 'FREE') { ?>
539
  <!-- Sidebar messages -->
540
- <div id="cnb_upgrade_box" class="postbox "> <!-- Upgrade promobox -->
541
- <div class="postbox-header">
542
- <h2 class="hndle">"Powered by Call Now Button"</h2>
543
- </div>
544
- <div class="inside">
545
- <div class="submitbox" id="submitpost">
546
- <div id="minor-publishing">
547
- <div id="misc-publishing-actions">
548
- <div class="cnb_promobox_item">Remove the "Powered by" mesage from your buttons for just &euro;1.67/$1.99 per month.</div>
549
- </div>
550
- <div class="clear"></div>
551
- </div>
552
- <div id="major-publishing-actions">
553
-
554
- <div id="publishing-action">
555
- <a class="button button-primary button-large" href="<?php echo $upgrade_url ?>">Upgrade</a>
556
- </div>
557
- <div class="clear"></div>
558
- </div>
559
- </div>
560
- </div>
561
- </div>
562
  <?php } ?>
563
- <div id="cnb_support_box" class="postbox "> <!-- support promobox -->
564
- <div class="postbox-header">
565
- <h2 class="hndle">Need help?</h2>
566
- </div>
567
- <div class="inside">
568
- <div class="submitbox" id="submitpost">
569
- <div id="minor-publishing">
570
- <div id="misc-publishing-actions">
571
- <div class="cnb_promobox_item">
572
- Please head over to our <a href="https://help.callnowbutton.com/" target="_blank">Help Center</a> for all your questions.
573
- </div>
574
- <div class="cnb_promobox_item cnb-side-icon cnb-side-checkbox"><a href="https://help.callnowbutton.com/" target="_blank">Help Center</a></div>
575
- <div class="cnb_promobox_item cnb-side-icon cnb-side-checkbox"><a href="https://help.callnowbutton.com/" target="_blank">Support forum</a></div>
576
- <div class="cnb_promobox_item cnb-side-icon cnb-side-checkbox"><a href="https://help.callnowbutton.com/" target="_blank">FAQ</a></div>
577
- </div>
578
- <div class="clear"></div>
579
- </div>
580
- </div>
581
- </div>
582
- </div>
583
- </div><!-- end #postbox-container-1 -->
584
  <?php } ?>
585
 
586
  <br class="clear">
587
  <?php
588
- echo '</div><!--End #post-body-->';
589
- echo '</div><!--End #poststuff-->';
590
  // Do not do this when there are errors!
591
  if (!is_wp_error($data)) {
592
  cnb_admin_page_render_thickbox( $cnb_cloud_domain );
 
593
  }
594
  do_action('cnb_footer');
595
  }
@@ -612,13 +594,28 @@ function cnb_admin_page_render_thickbox($default_domain = null) {
612
  $options = array('modal_view' => true, 'submit_button_text' => 'Next');
613
  cnb_button_edit_form($button_id, $button, $default_domain, $options);
614
  echo '</div></div>';
 
 
 
 
615
  $action = !empty($_GET['action']) ? sanitize_text_field($_GET['action']) : null;
616
  if ($action === 'new') {
617
- echo '
618
- <script>jQuery( document ).ready(function() {
619
- setTimeout(function() {
620
- jQuery("#cnb-button-overview-modal-add-new").click();
621
- });
622
- });</script>';
 
 
 
 
 
 
 
 
 
 
 
623
  }
624
  }
17
  echo 'Buttons ';
18
  }
19
 
20
+ function cnb_get_new_button_link() {
21
  $url = admin_url('admin.php');
22
+ return
23
  add_query_arg(
24
  array(
25
  'TB_inline' => 'true',
30
  'type' => 'single',
31
  'id' => 'new' ),
32
  $url );
33
+ }
34
+
35
+ function cnb_create_new_button($addional_classes='page-title-action', $link_text='Add New') {
36
+ $url = cnb_get_new_button_link();
37
  printf(
38
+ '<a href="%s" title="%s" class="thickbox open-plugin-details-modal %s" id="cnb-button-overview-modal-add-new" data-title="%s">%s</a>',
39
+ $url,
40
+ __('Create new button'),
41
+ $addional_classes,
42
+ __('Choose a Button type'),
43
+ __(esc_html($link_text))
44
  );
45
  }
46
 
47
+ /**
48
+ * This is used so that cnb_create_new_button() is called with the default arguments
49
+ */
50
+ function cnb_add_new_modal_action() {
51
+ cnb_create_new_button();
52
+ }
53
 
54
  class Cnb_Button_List_Table extends WP_List_Table {
55
 
413
  }
414
 
415
  function no_items() {
416
+ _e( 'No buttons found. ' );
417
+ cnb_create_new_button('', 'Let\'s create one!');
418
  }
419
  }
420
 
503
 
504
  add_action('cnb_header_name', 'cnb_add_header_button_overview');
505
 
506
+ $upgrade_url = get_cnb_domain_upgrade($cnb_cloud_domain);
 
 
 
 
 
 
 
 
 
 
507
 
508
  // CNB: Start content
509
  $data = $wp_list_table->prepare_items();
525
 
526
  do_action('cnb_header');
527
 
528
+ echo '<div class="cnb-two-column-section">
529
+ <div class="cnb-body-column">
530
+ <div class="cnb-body-content">';
531
 
532
  $wp_list_table->views();
533
 
534
  echo '<form id="wp_list_event" method="post">';
535
  $wp_list_table->display(); //Table of elements
536
+ echo '</form></div></div>' ?>
537
 
538
+ <?php if (isset($upgrade_url) && $upgrade_url) { ?>
539
+ <div class="cnb-postbox-container cnb-side-column"> <!-- Sidebar promo boxes -->
540
  <?php if ($cnb_cloud_domain !== null && !($cnb_cloud_domain instanceof WP_Error) && $cnb_cloud_domain->type === 'FREE') { ?>
541
  <!-- Sidebar messages -->
542
+ <?php
543
+ cnb_promobox(
544
+ 'blue',
545
+ 'Introduction offer',
546
+ '<p>Remove the <em>powered by</em> branding from your buttons!</p>
547
+ <p>Benefit from our introductory offer and enjoy unlimited access to all features without our branding.</p>',
548
+ 'flag',
549
+ '<strong>&euro;2.49/$2.99 per month</strong>',
550
+ 'Upgrade',
551
+ $upgrade_url
552
+ );
553
+ ?>
 
 
 
 
 
 
 
 
 
 
554
  <?php } ?>
555
+ <?php
556
+ cnb_promobox(
557
+ 'grey',
558
+ 'Need help?',
559
+ '<p>Please head over to our <a href="https://callnowbutton.com/support/" target="_blank">Help Center</a> for all your questions.</p>
560
+ <p>&check; <a href="https://callnowbutton.com/support/" target="_blank">Help Center</a></p>
561
+ <p>&check; <a href="https://callnowbutton.com/support/wordpress-free/index.html#faq" target="_blank">FAQ</a></p>',
562
+ 'welcome-learn-more'
563
+ );
564
+ ?>
565
+ </div>
 
 
 
 
 
 
 
 
 
 
566
  <?php } ?>
567
 
568
  <br class="clear">
569
  <?php
570
+ echo '</div></div>';
 
571
  // Do not do this when there are errors!
572
  if (!is_wp_error($data)) {
573
  cnb_admin_page_render_thickbox( $cnb_cloud_domain );
574
+ cnb_admin_page_button_overview_add_new();
575
  }
576
  do_action('cnb_footer');
577
  }
594
  $options = array('modal_view' => true, 'submit_button_text' => 'Next');
595
  cnb_button_edit_form($button_id, $button, $default_domain, $options);
596
  echo '</div></div>';
597
+
598
+ }
599
+
600
+ function cnb_admin_page_button_overview_add_new() {
601
  $action = !empty($_GET['action']) ? sanitize_text_field($_GET['action']) : null;
602
  if ($action === 'new') {
603
+ ?>
604
+ <script>jQuery(function() {
605
+ setTimeout(cnb_button_overview_add_new_click);
606
+ });</script>
607
+ <?php
608
+ }
609
+
610
+ // Change the click into an actual "onClick" event
611
+ // But only on the button-overview page and Action is not set or to "new"
612
+ if ($action === 'new' || $action == null ) {
613
+ ?>
614
+ <script>jQuery(function() {
615
+ const ele = jQuery("li.toplevel_page_call-now-button li:contains('Add New') a");
616
+ ele.attr('href', '#');
617
+ ele.on("click", cnb_button_overview_add_new_click)
618
+ });</script>
619
+ <?php
620
  }
621
  }
src/admin/condition-overview.php CHANGED
@@ -69,6 +69,7 @@ class Cnb_Condition_List_Table extends WP_List_Table {
69
  * @return array $columns, the array of columns to use with the table
70
  */
71
  function get_columns() {
 
72
  $columns = array(
73
  'cb' => '<input type="checkbox">',
74
  'id' => __('ID'),
@@ -78,6 +79,10 @@ class Cnb_Condition_List_Table extends WP_List_Table {
78
  'matchValue' => __('Match value'),
79
  );
80
  if ($this->button) { unset($columns['cb']); }
 
 
 
 
81
  return $columns;
82
  }
83
 
@@ -157,12 +162,34 @@ class Cnb_Condition_List_Table extends WP_List_Table {
157
  return '<code>' . esc_html($item[ $column_name ]) . '</code>';
158
  case 'matchValue':
159
  return !empty($item[$column_name]) ? esc_html($item[$column_name]) : '<em>No value</em>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  default:
161
  return '<em>Unknown column ' .esc_html($column_name) . '</em>';
162
  }
163
  }
164
 
165
  private function get_data() {
 
166
  $entities = array();
167
  if ($this->button === null) {
168
  $entities = CnbAppRemote::cnb_remote_get_conditions();
@@ -184,9 +211,15 @@ class Cnb_Condition_List_Table extends WP_List_Table {
184
 
185
  $data = array();
186
  foreach ($entities as $entity) {
 
 
 
 
 
187
  $data[] = array(
188
  'id' => $entity->id,
189
  'conditionType' => $entity->conditionType,
 
190
  'filterType' => $entity->filterType,
191
  'matchType' => $entity->matchType,
192
  'matchValue' => $entity->matchValue,
69
  * @return array $columns, the array of columns to use with the table
70
  */
71
  function get_columns() {
72
+ global $cnb_options;
73
  $columns = array(
74
  'cb' => '<input type="checkbox">',
75
  'id' => __('ID'),
79
  'matchValue' => __('Match value'),
80
  );
81
  if ($this->button) { unset($columns['cb']); }
82
+
83
+ if ($cnb_options['advanced_view'] === 1) {
84
+ $columns['conditionButton'] = __('Button');
85
+ }
86
  return $columns;
87
  }
88
 
162
  return '<code>' . esc_html($item[ $column_name ]) . '</code>';
163
  case 'matchValue':
164
  return !empty($item[$column_name]) ? esc_html($item[$column_name]) : '<em>No value</em>';
165
+ case 'conditionButton':
166
+ $url = admin_url('admin.php');
167
+ $buttons = $item[$column_name];
168
+ if ($buttons && is_array($buttons)) {
169
+ foreach ($buttons as $button) {
170
+ if (!is_wp_error($button)) {
171
+ $new_link =
172
+ add_query_arg(
173
+ array(
174
+ 'page' => 'call-now-button',
175
+ 'action' => 'edit',
176
+ 'tab' => 'visibility',
177
+ 'id' => $button->id,
178
+ ),
179
+ $url);
180
+ $new_url = esc_url_raw($new_link);
181
+ return '<a href="'.$new_url.'">' . esc_html($button->name) . '</a>';
182
+ }
183
+ }
184
+ }
185
+ break;
186
  default:
187
  return '<em>Unknown column ' .esc_html($column_name) . '</em>';
188
  }
189
  }
190
 
191
  private function get_data() {
192
+ global $cnb_options;
193
  $entities = array();
194
  if ($this->button === null) {
195
  $entities = CnbAppRemote::cnb_remote_get_conditions();
211
 
212
  $data = array();
213
  foreach ($entities as $entity) {
214
+ // Button info
215
+ $button = array();
216
+ if ($cnb_options['advanced_view'] === 1) {
217
+ $button = CnbAppRemote::cnb_remote_get_button_for_condition($entity->id);
218
+ }
219
  $data[] = array(
220
  'id' => $entity->id,
221
  'conditionType' => $entity->conditionType,
222
+ 'conditionButton' => $button,
223
  'filterType' => $entity->filterType,
224
  'matchType' => $entity->matchType,
225
  'matchValue' => $entity->matchValue,
src/admin/domain-edit.php CHANGED
@@ -216,10 +216,13 @@ function cnb_admin_page_domain_edit_render_form_plan_details($domain) {
216
  </tr>
217
  <?php if ($domain->type != 'FREE') { ?>
218
  <tr>
219
- <th scope="row">Subscription</th>
220
  <td>
221
- <input name="domain[renew]" type="checkbox" id="cnb-renew" value="true" <?php checked('1', $domain->renew); ?> />
222
- <label for="cnb-renew">Renew automatically</label>
 
 
 
223
 
224
  <?php if (!empty($domain->expires)) { ?>
225
  <p class="description" id="domain_expires-description">
@@ -238,11 +241,14 @@ function cnb_admin_page_domain_edit_render_form_tracking($domain) { ?>
238
  <th colspan="2"><h2>Tracking</h2></th>
239
  </tr>
240
  <tr>
241
- <th scope="row">Google Analytics</th>
242
  <td>
243
  <input type="hidden" name="domain[trackGA]" value="0" />
244
- <input name="domain[trackGA]" type="checkbox" id="google_analytics" value="true" <?php checked('1', $domain->trackGA); ?> />
245
- <label for="google_analytics">Enable </label>
 
 
 
246
  <p class="description">
247
  Supports Classic, Universal Analytics and Global site tag (v3 and v4).<br>
248
  Using Google Tag Manager? Set up click tracking in GTM. <a href="https://callnowbutton.com/support/click-tracking/google-tag-manager-event-tracking/?utm_source=wp-plugin&amp;utm_medium=referral&amp;utm_campaign=description_link&amp;utm_term=google-tag-manager-event-tracking" target="_blank">Learn how to do this...</a>
@@ -250,11 +256,14 @@ function cnb_admin_page_domain_edit_render_form_tracking($domain) { ?>
250
  </td>
251
  </tr>
252
  <tr>
253
- <th scope="row">Google Ads conversions</th>
254
  <td>
255
  <input type="hidden" name="domain[trackConversion]" value="0" />
256
- <input name="domain[trackConversion]" type="checkbox" id="conversion_tracking" value="true" <?php checked('1', $domain->trackConversion); ?> />
257
- <label for="conversion_tracking">Enable</label>
 
 
 
258
  <p class="description">Select this option if you want to count clicks on the button as Google Ads conversions. This option requires the Event snippet to be present on the page. <a href="https://support.google.com/google-ads/answer/6331304" target="_blank">Learn more...</a></p>
259
  </td>
260
  </tr>
@@ -262,14 +271,13 @@ function cnb_admin_page_domain_edit_render_form_tracking($domain) { ?>
262
  }
263
 
264
  function cnb_admin_page_domain_edit_render_form_button_display($domain) {
265
- $domain_properties_zindex = !empty($domain->properties->zindex) ? $domain->properties->zindex : 2147483647;
266
- $domain_properties_zindex_order = zindexToOrder($domain_properties_zindex);
267
  ?>
268
  <tr>
269
  <th colspan="2"><h2>Button display</h2></th>
270
  </tr>
271
  <tr class="zoom">
272
- <th scope="row">Button size <span id="cnb_slider_value"></span></th>
273
  <td><fieldset>
274
  <label class="cnb_slider_value" for="cnb_slider" onclick="jQuery('#cnb_slider:enabled')[0].stepDown();cnb_update_sliders()">Smaller&nbsp;&laquo;&nbsp;</label>
275
  <input type="range" min="0.7" max="1.3" step="0.1" name="domain[properties][scale]"
@@ -278,7 +286,7 @@ function cnb_admin_page_domain_edit_render_form_button_display($domain) {
278
  </fieldset></td>
279
  </tr>
280
  <tr class="z-index">
281
- <th scope="row">Order (<span id="cnb_order_value"></span>) <a
282
  href="https://callnowbutton.com/set-order/" target="_blank" class="cnb-nounderscore">
283
  <span class="dashicons dashicons-editor-help"></span>
284
  </a></th>
@@ -337,13 +345,16 @@ function cnb_admin_page_domain_edit_render_form_advanced($domain, $header=true)
337
  </td>
338
  </tr>
339
  <tr>
340
- <th scope="row">Debug mode</th>
341
  <td>
342
  <input type="hidden" name="domain[properties][debug]" value="false" />
343
- <input name="domain[properties][debug]" type="checkbox" id="domain_properties_debug" value="true" <?php checked('true', $domain->properties->debug); ?> />
344
- <label for="domain_properties_debug">Enabled</label>
 
 
 
345
  <p class="description">
346
- This enables some additional information in your browser's console, which can help during troubleshooting.
347
  </p>
348
  </fieldset></td>
349
  </tr>
216
  </tr>
217
  <?php if ($domain->type != 'FREE') { ?>
218
  <tr>
219
+ <th scope="row">Auto renew</th>
220
  <td>
221
+
222
+ <input id="cnb-renew" class="cnb_toggle_checkbox" name="domain[renew]" type="checkbox" value="true" <?php checked('1', $domain->renew); ?> />
223
+ <label for="cnb-renew" class="cnb_toggle_label">Toggle</label>
224
+ <span data-cnb_toggle_state_label="cnb-renew" class="cnb_toggle_state cnb_toggle_false">Inactive</span>
225
+ <span data-cnb_toggle_state_label="cnb-renew" class="cnb_toggle_state cnb_toggle_true">Active</span>
226
 
227
  <?php if (!empty($domain->expires)) { ?>
228
  <p class="description" id="domain_expires-description">
241
  <th colspan="2"><h2>Tracking</h2></th>
242
  </tr>
243
  <tr>
244
+ <th scope="row"><label for="google_analytics">Google Analytics<label</th>
245
  <td>
246
  <input type="hidden" name="domain[trackGA]" value="0" />
247
+ <input id="google_analytics" class="cnb_toggle_checkbox" name="domain[trackGA]" type="checkbox" value="true" <?php checked('1', $domain->trackGA); ?> />
248
+ <label for="google_analytics" class="cnb_toggle_label">Enable GA tracking</label>
249
+ <span data-cnb_toggle_state_label="google_analytics" class="cnb_toggle_state cnb_toggle_false">Click tracking inactive</span>
250
+ <span data-cnb_toggle_state_label="google_analytics" class="cnb_toggle_state cnb_toggle_true">Click tracking active</span>
251
+
252
  <p class="description">
253
  Supports Classic, Universal Analytics and Global site tag (v3 and v4).<br>
254
  Using Google Tag Manager? Set up click tracking in GTM. <a href="https://callnowbutton.com/support/click-tracking/google-tag-manager-event-tracking/?utm_source=wp-plugin&amp;utm_medium=referral&amp;utm_campaign=description_link&amp;utm_term=google-tag-manager-event-tracking" target="_blank">Learn how to do this...</a>
256
  </td>
257
  </tr>
258
  <tr>
259
+ <th scope="row"><label for="conversion_tracking">Google Ads conversions</label></th>
260
  <td>
261
  <input type="hidden" name="domain[trackConversion]" value="0" />
262
+ <input id="conversion_tracking" class="cnb_toggle_checkbox" name="domain[trackConversion]" type="checkbox" value="true" <?php checked('1', $domain->trackConversion); ?> />
263
+ <label for="conversion_tracking" class="cnb_toggle_label">Enable Google Ads conversion tracking</label>
264
+ <span data-cnb_toggle_state_label="conversion_tracking" class="cnb_toggle_state cnb_toggle_false">Conversion tracking inactive</span>
265
+ <span data-cnb_toggle_state_label="conversion_tracking" class="cnb_toggle_state cnb_toggle_true">Conversion tracking active</span>
266
+
267
  <p class="description">Select this option if you want to count clicks on the button as Google Ads conversions. This option requires the Event snippet to be present on the page. <a href="https://support.google.com/google-ads/answer/6331304" target="_blank">Learn more...</a></p>
268
  </td>
269
  </tr>
271
  }
272
 
273
  function cnb_admin_page_domain_edit_render_form_button_display($domain) {
274
+ $domain_properties_zindex_order = zindexToOrder($domain->properties->zindex);
 
275
  ?>
276
  <tr>
277
  <th colspan="2"><h2>Button display</h2></th>
278
  </tr>
279
  <tr class="zoom">
280
+ <th scope="row"><label for="cnb_slider">Button size <span id="cnb_slider_value"></span></label></th>
281
  <td><fieldset>
282
  <label class="cnb_slider_value" for="cnb_slider" onclick="jQuery('#cnb_slider:enabled')[0].stepDown();cnb_update_sliders()">Smaller&nbsp;&laquo;&nbsp;</label>
283
  <input type="range" min="0.7" max="1.3" step="0.1" name="domain[properties][scale]"
286
  </fieldset></td>
287
  </tr>
288
  <tr class="z-index">
289
+ <th scope="row"><label for="cnb_order_slider">Order (<span id="cnb_order_value"></span>)</label> <a
290
  href="https://callnowbutton.com/set-order/" target="_blank" class="cnb-nounderscore">
291
  <span class="dashicons dashicons-editor-help"></span>
292
  </a></th>
345
  </td>
346
  </tr>
347
  <tr>
348
+ <th scope="row"><label for="domain_properties_debug">Debug mode</label></th>
349
  <td>
350
  <input type="hidden" name="domain[properties][debug]" value="false" />
351
+ <input id="domain_properties_debug" class="cnb_toggle_checkbox" name="domain[properties][debug]" type="checkbox" value="true" <?php checked('true', $domain->properties->debug); ?> />
352
+ <label for="domain_properties_debug" class="cnb_toggle_label">Enable debugging mode</label>
353
+ <span data-cnb_toggle_state_label="domain_properties_debug" class="cnb_toggle_state cnb_toggle_false">Disabled</span>
354
+ <span data-cnb_toggle_state_label="domain_properties_debug" class="cnb_toggle_state cnb_toggle_true">Enabled</span>
355
+
356
  <p class="description">
357
+ This setting enables debug information in your browser's console, which can help during troubleshooting.
358
  </p>
359
  </fieldset></td>
360
  </tr>
src/admin/domain-upgrade.php CHANGED
@@ -8,20 +8,16 @@ require_once dirname( __FILE__ ) . '/partials/admin-header.php';
8
  require_once dirname( __FILE__ ) . '/partials/admin-footer.php';
9
  require_once dirname( __FILE__ ) . '/models/CnbDomain.class.php';
10
 
 
 
 
 
 
 
11
  function cnb_add_header_domain_upgrade() {
12
  echo 'Upgrade the Call Now Button';
13
  }
14
 
15
- function cnb_upgrade_create_settings_url() {
16
- $url = admin_url('admin.php');
17
- $tab_link =
18
- add_query_arg(
19
- array(
20
- 'page' => 'call-now-button-settings'),
21
- $url );
22
- return esc_url( $tab_link );
23
- }
24
-
25
  /**
26
  * @return CnbDomain
27
  */
@@ -34,16 +30,6 @@ function cnb_get_domain() {
34
  return $domain;
35
  }
36
 
37
- function cnb_print_domain_upgrade_notice_cache_flush() {
38
- $upgradeStatus = filter_input( INPUT_GET, 'upgrade', FILTER_SANITIZE_STRING );
39
- $checkoutSesionId = filter_input( INPUT_GET, 'checkout_session_id', FILTER_SANITIZE_STRING );
40
- if ($upgradeStatus || $checkoutSesionId) {
41
- // Increase the cache ID
42
- CnbAppRemote::cnb_incr_transient_base();
43
- }
44
- }
45
-
46
-
47
  /**
48
  * @param $domain CnbDomain
49
  *
@@ -55,142 +41,83 @@ function cnb_print_domain_upgrade_notice($domain) {
55
  if ($upgradeStatus === 'success?payment=success') {
56
  // Get checkout Session Details
57
  $session = CnbAppRemotePayment::cnb_remote_get_subscription_session( $checkoutSesionId );
58
- // This results in a subscription (via ->subscriptionId), get that for ->type
59
- $subscription = CnbAppRemotePayment::cnb_remote_get_subscription( $session->subscriptionId );
 
60
 
61
- return new CnbNotice('success', '<p>Your domain <strong>'.esc_html($domain->name).'</strong> has been successfully upgraded to <strong>'.esc_html($subscription->type).'</strong>!</p>');
62
- }
63
- return null;
64
- }
65
 
66
- function cnb_get_plan($plans, $name) {
67
- foreach ($plans as $plan) {
68
- if ($plan->nickname === $name) {
69
- return $plan;
70
  }
71
  }
72
  return null;
73
  }
74
 
75
- function cnb_admin_page_domain_upgrade_render() {
76
-
77
- $domain = cnb_get_domain();
78
- $notice = cnb_print_domain_upgrade_notice($domain);
79
-
80
- add_action('cnb_header_name', 'cnb_add_header_domain_upgrade');
81
-
82
- do_action('cnb_header');
83
 
 
 
 
 
84
 
85
- // If the type is missing, we assume FREE
86
- if (empty($domain->type)) {
87
- $domain->type = 'FREE';
 
 
88
  }
 
 
 
 
89
 
90
  // Stripe integration
91
- ?>
92
- <script src="https://js.stripe.com/v3/"></script>
93
  <script>
94
- const stripe = Stripe("<?php echo esc_js( CnbAppRemotePayment::cnb_remote_get_stripe_key()->key) ?>");
95
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
- <p>Your domain <?php esc_html_e($domain->name) ?> is currently on the <code><?php esc_html_e($domain->type) ?></code> cloud plan.</p>
 
 
 
 
 
 
98
 
 
99
 
100
- <?php if ($domain->type == 'PRO') {
101
- // Render notice if JUST upgraded and show general information about domain (instead of upgrade form)
102
- if ($notice) {
103
- CnbAdminNotices::get_instance()->renderNotice( $notice );
104
- }
105
- $portal_url = CnbAppRemote::cnb_remote_create_billing_portal();
106
- if (!empty($domain->expires)) { ?>
107
- <p class="description" id="domain_expires-description">
108
- Your subscription will
109
- <?php echo $domain->renew == 1 ? ' renew automatically ' : ' expire '; ?>
110
- on <?php echo date('F d, Y', strtotime(esc_html($domain->expires))); ?>.
111
- </p>
112
- <?php } ?>
113
- <p>You can change this on the <a href="<?php esc_html_e(cnb_upgrade_create_settings_url()) ?>">settings page</a>.</p>
114
- <p>If you have any questions about your subscriptions, you can see <a href="<?php esc_html_e($portal_url->url); ?>">your invoice dashboard</a> here or contact us via the <a href="https://help.callnowbutton.com/">support forums</a>.</p>
115
-
116
- <?php
117
- } else {
118
- // Render upgrade form
119
- $plans = CnbAppRemotePayment::cnb_remote_get_plans();
120
- ?>
121
-
122
- <form id="wp_domain_upgrade" method="post">
123
- <input type="hidden" name="cnb_domain_id" id="cnb_domain_id" value="<?php esc_attr_e($domain->id) ?>">
124
-
125
- <h2>Select a plan to remove the "Powered by Call Now Button" message from your buttons</h2>
126
-
127
-
128
- <h2 class="nav-tab-wrapper">
129
- <a href="#" data-cnb-currency="eur" class="cnb-currency-select cnb-currency-eur nav-tab nav-tab-active">Euro (&euro;)</a>
130
- <a href="#" data-cnb-currency="usd" class="cnb-currency-select cnb-currency-usd nav-tab ">US Dollar ($)</a>
131
- </h2>
132
- <div class="cnb-message"><p class="cnb-error-message"></p></div>
133
- <div class="cnb-price-plans">
134
- <div class="currency-box currency-box-eur currency-box-active cnb-flexbox">
135
- <?php $plan = cnb_get_plan($plans, 'powered-by-eur-yearly'); ?>
136
- <div class="pricebox">
137
- <h3 class="yearly">Yearly Plan</h3>
138
- <div class="benefit">All branding removed</div>
139
- <div class="plan-amount"><span class="currency">€</span><span class="euros">1</span><span class="cents">.67</span><span class="timeframe">/month</span></div>
140
- <div class="billingprice">
141
- Billed at €19.99 annually
142
- </div>
143
- <a class="button button-primary" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
144
- </div>
145
-
146
- <?php $plan = cnb_get_plan($plans, 'powered-by-eur-monthly'); ?>
147
- <div class="pricebox">
148
- <h3 class="">Monthly Plan</h3>
149
- <div class="benefit">All branding removed</div>
150
- <div class="plan-amount"><span class="currency">€</span><span class="euros">4</span><span class="cents">.99</span><span class="timeframe">/month</span></div>
151
- <div class="billingprice">
152
- Billed at €4.99 monthly
153
- </div>
154
- <a class="button button-secondary" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
155
- </div>
156
- </div>
157
- <div class="currency-box currency-box-usd cnb-flexbox">
158
- <?php $plan = cnb_get_plan($plans, 'powered-by-usd-yearly'); ?>
159
- <div class="pricebox">
160
- <h3 class="yearly">Yearly Plan</h3>
161
- <div class="benefit">All branding removed</div>
162
- <div class="plan-amount"><span class="currency">$</span><span class="euros">1</span><span class="cents">.99</span><span class="timeframe">/month</span></div>
163
- <div class="billingprice">
164
- Billed at $23.88 annually
165
- </div>
166
- <a class="button button-primary" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
167
- </div>
168
- <?php $plan = cnb_get_plan($plans, 'powered-by-usd-monthly'); ?>
169
- <div class="pricebox">
170
- <h3 class="">Monthly Plan</h3>
171
- <div class="benefit">All branding removed</div>
172
- <div class="plan-amount"><span class="currency">$</span><span class="euros">5</span><span class="cents">.99</span><span class="timeframe">/month</span></div>
173
- <div class="billingprice">
174
- Billed at $5.99 monthly
175
- </div>
176
- <a class="button button-secondary" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
177
- </div>
178
- </div>
179
-
180
- </div>
181
- </form>
182
- <?php } ?>
183
-
184
- <p class="cnb-center">All <u>cloud</u> plans (free and paid) contain the following features:</p>
185
- <div class="cnb-center" style="margin-bottom:50px;">
186
- <div><b>&check;</b> Phone, Email, Location, WhatsApp, Links</div>
187
- <div><b>&check;</b> Unlimited buttons</div>
188
- <div><b>&check;</b> Multibutton</div>
189
- <div><b>&check;</b> Buttonbar (full width with multiple actions)</div>
190
- <div><b>&check;</b> Advanced page targeting options</div>
191
- <div><b>&check;</b> Scheduling</div>
192
- </div>
193
- <?php
194
 
 
 
195
  do_action('cnb_footer');
196
  }
8
  require_once dirname( __FILE__ ) . '/partials/admin-footer.php';
9
  require_once dirname( __FILE__ ) . '/models/CnbDomain.class.php';
10
 
11
+ require_once dirname( __FILE__ ) . '/partials/domain-upgrade/overview.php';
12
+ require_once dirname( __FILE__ ) . '/partials/domain-upgrade/upgraded.php';
13
+ require_once dirname( __FILE__ ) . '/partials/domain-upgrade/upgrading.php';
14
+
15
+ require_once dirname( __FILE__ ) . '/settings-profile.php';
16
+
17
  function cnb_add_header_domain_upgrade() {
18
  echo 'Upgrade the Call Now Button';
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
21
  /**
22
  * @return CnbDomain
23
  */
30
  return $domain;
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
33
  /**
34
  * @param $domain CnbDomain
35
  *
41
  if ($upgradeStatus === 'success?payment=success') {
42
  // Get checkout Session Details
43
  $session = CnbAppRemotePayment::cnb_remote_get_subscription_session( $checkoutSesionId );
44
+ if (!is_wp_error($session)) {
45
+ // This results in a subscription (via ->subscriptionId), get that for ->type
46
+ $subscription = CnbAppRemotePayment::cnb_remote_get_subscription( $session->subscriptionId );
47
 
48
+ // This increases the cache ID if needed, since the Domain cache might have changed
49
+ CnbAppRemote::cnb_incr_transient_base();
 
 
50
 
51
+ return new CnbNotice( 'success', '<p>Your domain <strong>' . esc_html( $domain->name ) . '</strong> has been successfully upgraded to <strong>' . esc_html( $subscription->type ) . '</strong>!</p>' );
52
+ } else {
53
+ return new CnbNotice( 'warning', '<p>Something is going on upgrading domain <strong>' . esc_html( $domain->name ) . '</strong>.</p><p>Error: '.$session->get_error_message().'!</p>' );
 
54
  }
55
  }
56
  return null;
57
  }
58
 
59
+ function cnb_admin_page_domain_upgrade_render_content() {
60
+ $domain = CnbDomain::setSaneDefault(cnb_get_domain());
 
 
 
 
 
 
61
 
62
+ // Bail out in case of error
63
+ if (is_wp_error($domain)) {
64
+ return;
65
+ }
66
 
67
+ // See if the domain is JUST upgraded
68
+ $notice = cnb_print_domain_upgrade_notice( $domain );
69
+ if ( $notice ) {
70
+ // And if so, refetch the domain
71
+ $domain = CnbDomain::setSaneDefault( cnb_get_domain() );
72
  }
73
+ wp_enqueue_script(
74
+ CNB_SLUG . '-domain-upgrade',
75
+ plugins_url( '../../resources/js/domain-upgrade.js', __FILE__ )
76
+ );
77
 
78
  // Stripe integration
79
+ echo '<script src="https://js.stripe.com/v3/"></script>';
80
+ echo '
81
  <script>
82
+ jQuery(() => {
83
+ try {
84
+ stripe = Stripe("' . esc_js( CnbAppRemotePayment::cnb_remote_get_stripe_key()->key ) . '");
85
+ } catch(e) {
86
+ // Do not show "Live Stripe.js integrations must use HTTPS", we deal with that particular error internally
87
+ if (e && e.message.includes("Live Stripe.js integrations must use HTTPS")) {
88
+ return;
89
+ }
90
+
91
+ showMessage("error", e);
92
+ }
93
+ });
94
+ </script>';
95
+
96
+ // Print the content
97
+ if ( $notice && $domain->type != 'PRO' ) {
98
+ // Probably upgraded, but not reflected yet on the API side. Warn about this
99
+ cnb_domain_upgrade_upgrading($domain);
100
+ } else if ( $domain->type == 'PRO' ) {
101
+ cnb_domain_upgrade_upgraded( $domain, $notice );
102
+ } else {
103
+ $user = cnb_admin_page_domain_upgrade_hidden_profile();
104
+ cnb_domain_upgrade_overview( $domain, $user );
105
+ }
106
+ }
107
 
108
+ function cnb_admin_page_domain_upgrade_hidden_profile() {
109
+ add_thickbox();
110
+ echo '<div id="cnb_admin_page_domain_upgrade_profile" style="display: none;"><div>';
111
+ $user = cnb_admin_page_profile_edit_render_form(true);
112
+ echo '</div></div>';
113
+ return $user;
114
+ }
115
 
116
+ function cnb_admin_page_domain_upgrade_render() {
117
 
118
+ add_action('cnb_header_name', 'cnb_add_header_domain_upgrade');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
+ do_action('cnb_header');
121
+ cnb_admin_page_domain_upgrade_render_content();
122
  do_action('cnb_footer');
123
  }
src/admin/legacy-edit.php CHANGED
@@ -112,12 +112,18 @@ function cnb_admin_page_legacy_edit_render() {
112
  do_action('cnb_header');
113
  ?>
114
 
115
- <h2 class="nav-tab-wrapper">
116
- <a href="<?php echo cnb_create_tab_url_legacy('basic_options') ?>"
117
- class="nav-tab <?php echo cnb_is_active_tab('basic_options') ?>">Basics</a>
118
- <a href="<?php echo cnb_create_tab_url_legacy('extra_options') ?>"
119
- class="nav-tab <?php echo cnb_is_active_tab('extra_options') ?>">Presentation</a>
120
- </h2>
 
 
 
 
 
 
121
  <form method="post" action="<?php echo esc_url( admin_url('options.php') ); ?>" class="cnb-container">
122
  <?php settings_fields('cnb_options'); ?>
123
  <table class="form-table <?php echo cnb_is_active_tab('basic_options') ?>">
@@ -133,13 +139,13 @@ function cnb_admin_page_legacy_edit_render() {
133
  </td>
134
  </tr>
135
  <tr>
136
- <th scope="row">Phone number <a href="<?php echo CNB_SUPPORT; ?>phone-number/<?php cnb_utm_params("question-mark", "phone-number"); ?>" target="_blank" class="cnb-nounderscore">
137
  <span class="dashicons dashicons-editor-help"></span>
138
  </a></th>
139
  <td><input type="text" name="cnb[number]" value="<?php esc_attr_e($cnb_options['number']) ?>" /></td>
140
  </tr>
141
  <tr class="button-text">
142
- <th scope="row">Button text <small style="font-weight: 400">(optional)</small> <a href="<?php echo CNB_SUPPORT; ?>using-text-buttons/<?php cnb_utm_params("question-mark", "using-text-buttons"); ?>" target="_blank" class="cnb-nounderscore">
143
  <span class="dashicons dashicons-editor-help"></span>
144
  </a></th>
145
  <td>
@@ -178,7 +184,7 @@ function cnb_admin_page_legacy_edit_render() {
178
  </div>
179
  <div class="cnb-radio-item">
180
  <input type="radio" id="appearance3" name="cnb[appearance]" value="middle" <?php checked('middle', $cnb_options['appearance']); ?>>
181
- <label title="middle" for="appearance3">Center bottom</label>
182
  </div>
183
  <div class="cnb-radio-item">
184
  <input type="radio" id="appearance4" name="cnb[appearance]" value="full" <?php checked('full', $cnb_options['appearance']); ?>>
@@ -272,8 +278,78 @@ function cnb_admin_page_legacy_edit_render() {
272
  </table>
273
 
274
  <input type="hidden" name="cnb[version]" value="<?php echo CNB_VERSION; ?>" />
275
- <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
 
276
  </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
 
278
  <?php
279
  do_action('cnb_footer');
112
  do_action('cnb_header');
113
  ?>
114
 
115
+
116
+ <div class="cnb-two-column-section">
117
+ <div class="cnb-body-column">
118
+ <div class="cnb-body-content">
119
+
120
+ <h2 class="nav-tab-wrapper">
121
+ <a href="<?php echo cnb_create_tab_url_legacy('basic_options') ?>"
122
+ class="nav-tab <?php echo cnb_is_active_tab('basic_options') ?>">Basics</a>
123
+ <a href="<?php echo cnb_create_tab_url_legacy('extra_options') ?>"
124
+ class="nav-tab <?php echo cnb_is_active_tab('extra_options') ?>">Presentation</a>
125
+ </h2>
126
+
127
  <form method="post" action="<?php echo esc_url( admin_url('options.php') ); ?>" class="cnb-container">
128
  <?php settings_fields('cnb_options'); ?>
129
  <table class="form-table <?php echo cnb_is_active_tab('basic_options') ?>">
139
  </td>
140
  </tr>
141
  <tr>
142
+ <th scope="row">Phone number <a href="<?php echo CNB_SUPPORT; ?>wordpress-free/basics/phone-number/<?php cnb_utm_params("question-mark", "phone-number"); ?>" target="_blank" class="cnb-nounderscore">
143
  <span class="dashicons dashicons-editor-help"></span>
144
  </a></th>
145
  <td><input type="text" name="cnb[number]" value="<?php esc_attr_e($cnb_options['number']) ?>" /></td>
146
  </tr>
147
  <tr class="button-text">
148
+ <th scope="row">Button text <small style="font-weight: 400">(optional)</small> <a href="<?php echo CNB_SUPPORT; ?>wordpress-free/basics/using-text-buttons/<?php cnb_utm_params("question-mark", "using-text-buttons"); ?>" target="_blank" class="cnb-nounderscore">
149
  <span class="dashicons dashicons-editor-help"></span>
150
  </a></th>
151
  <td>
184
  </div>
185
  <div class="cnb-radio-item">
186
  <input type="radio" id="appearance3" name="cnb[appearance]" value="middle" <?php checked('middle', $cnb_options['appearance']); ?>>
187
+ <label title="middle" for="appearance3">Center</label>
188
  </div>
189
  <div class="cnb-radio-item">
190
  <input type="radio" id="appearance4" name="cnb[appearance]" value="full" <?php checked('full', $cnb_options['appearance']); ?>>
278
  </table>
279
 
280
  <input type="hidden" name="cnb[version]" value="<?php echo CNB_VERSION; ?>" />
281
+ <?php submit_button(); ?>
282
+
283
  </form>
284
+ </div>
285
+ </div>
286
+ <div class="cnb-postbox-container cnb-side-column">
287
+ <div class="cnb-on-active-tab <?php echo cnb_is_active_tab('basic_options') ?>">
288
+ <?php
289
+ cnb_promobox(
290
+ 'blue',
291
+ 'Unlock extra power',
292
+ '<p>Need more powerful features such as:</p>
293
+ <p>&check; More buttons<br>
294
+ &check; Email, WhatsApp, Maps<br>
295
+ &check; Scheduling<br>
296
+ &check; Buttonbar (multi action full width)<br>
297
+ &check; Multibutton (expandable single button)<br>
298
+ &check; And more!</p>',
299
+ 'unlock',
300
+ '',
301
+ 'Find out more',
302
+ cnb_legacy_upgrade_page()
303
+ );
304
+ ?>
305
+ <?php
306
+ cnb_promobox(
307
+ 'blue',
308
+ 'Enable more actions',
309
+ '<p>Looking for more than just a call button? You can now add the following actions:</p>
310
+ <p>&check; Email<br>
311
+ &check; WhatsApp<br>
312
+ &check; Directions<br>
313
+ &check; Links</p>',
314
+ 'email',
315
+ '',
316
+ 'Learn more',
317
+ cnb_legacy_upgrade_page()
318
+ );
319
+ ?>
320
+ </div>
321
+ <div class="cnb-on-active-tab <?php echo cnb_is_active_tab('extra_options') ?>">
322
+ <?php
323
+ cnb_promobox(
324
+ 'blue',
325
+ 'Phones off at 6pm?',
326
+ '<p>Sign up to enable a scheduler that allows you to set the days and hours that you are available.</p>
327
+ <p>You can even replace it with an email button during your off-hours so people can still contact you.</p>',
328
+ 'clock',
329
+ '<strong>Try it, it\'s free!</strong>',
330
+ 'Learn more',
331
+ cnb_legacy_upgrade_page()
332
+ );
333
+ ?>
334
+ <?php
335
+ cnb_promobox(
336
+ 'blue',
337
+ 'Powerful page targeting',
338
+ '<p>Do you need more flexibility in selecting the pages where you want a button to appear?</p>
339
+ <p>Sign up to unlock 4 methods for selecting the right pages:</p>
340
+ <p>&check; Exact URL<br>
341
+ &check; Path begins with ...<br>
342
+ &check; URL contains<br>
343
+ &check; RegEx</p>',
344
+ 'visibility',
345
+ '',
346
+ 'Learn more',
347
+ cnb_legacy_upgrade_page()
348
+ );
349
+ ?>
350
+ </div>
351
+ </div>
352
+ </div>
353
 
354
  <?php
355
  do_action('cnb_footer');
src/admin/legacy-upgrade.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once dirname( __FILE__ ) . '/partials/admin-functions.php';
3
+ require_once dirname( __FILE__ ) . '/partials/admin-header.php';
4
+ require_once dirname( __FILE__ ) . '/partials/admin-footer.php';
5
+
6
+ function cnb_add_header_legacy_upgrade() {
7
+ echo 'Unlock extra features';
8
+ }
9
+
10
+ function cnb_admin_page_legacy_upgrade_render() {
11
+ global $cnb_options;
12
+
13
+ add_action('cnb_header_name', 'cnb_add_header_legacy_upgrade');
14
+
15
+ do_action('cnb_header');
16
+ ?>
17
+
18
+
19
+ <div class="cnb-one-column-section">
20
+ <div class="cnb-body-content">
21
+
22
+
23
+
24
+ <div class="cnb-two-promobox-row">
25
+ <div class="cnb-body-column hide-on-mobile">
26
+ <?php
27
+ cnb_promobox(
28
+ 'grey',
29
+ 'Standard plugin',
30
+ '<p>&check; One button<br>
31
+ &check; Phone<br>
32
+ &check; Circular<br>
33
+ &check; Full width<br>
34
+ <span class="cnb_description">(single action Buttonbar&#8482;)</span>
35
+ &check; Action label<br>
36
+ </p>
37
+ <hr>
38
+ <p>
39
+ &check; Placement options<br>
40
+ &check; For mobile devices<br>
41
+ &check; Include or exclude pages<br>
42
+ </p>
43
+ <hr>
44
+ <p>
45
+ &check; Google Analytics tracking<br>
46
+ &check; Google Ads conversion tracking<br>
47
+ </p>
48
+ <hr>
49
+ <p>
50
+ &check; Adjust the button size<br>
51
+ &check; Flexible z-index
52
+ </p>',
53
+ 'admin-plugins',
54
+ '<strong>Free</strong>',
55
+ 'Currently active',
56
+ 'disabled'
57
+ );
58
+ ?>
59
+ </div>
60
+
61
+ <div class="cnb-body-column">
62
+ <?php
63
+ cnb_promobox(
64
+ 'blue',
65
+ 'Premium',
66
+ '<p class="cnb_align_center">From <strong>&euro;2.49/$2.99</strong> per month or <strong style="text-decoration:underline">FREE</strong> with subtle "<em>powered by</em>" branding.</p>
67
+ <hr>
68
+ <p><strong>&check; Lots of buttons!</strong><br>
69
+ &check; Phone, Email, WhatsApp, Maps, URLs<br>
70
+ &check; Circular button<br>
71
+ &check; Buttonbar&#8482;
72
+ <span class="cnb_description">(multi action full width button)</span>
73
+ &check; Multibutton&#8482;
74
+ <span class="cnb_description">(single button unfolding into multiple)</span>
75
+ &check; Actions labels<br>
76
+ </p>
77
+ <hr>
78
+ <p>
79
+ &check; Placement options<br>
80
+ &check; For mobile and desktop/laptop<br>
81
+ &check; Scheduling<br>
82
+ &check; Advanced page targeting
83
+ <span class="cnb_description">(for deciding where a button should appear. E.g. only show to Google Ads visitors)</span>
84
+ </p>
85
+ <hr>
86
+ <p>
87
+ &check; Google Analytics tracking<br>
88
+ &check; Google Ads conversion tracking<br>
89
+ </p>
90
+ <hr>
91
+ <p>
92
+ &check; Adjust the button size<br>
93
+ &check; Flexible z-index<br>
94
+ &check; And much more!</p>
95
+ <hr>
96
+ <p class="cnb_align_center">From <strong>&euro;2.49/$2.99</strong> per month or <strong style="text-decoration:underline">FREE</strong> with subtle "<em>powered by</em>" branding.</p>',
97
+ 'cloud',
98
+ '<strong>Free and Paid options</strong>',
99
+ 'Activate Premium',
100
+ get_cnb_wordpress_upgrade_link()
101
+ );
102
+ ?>
103
+ </div>
104
+
105
+
106
+ </div>
107
+
108
+
109
+ <div style="max-width:600px;margin:0 auto">
110
+ <h1 class="cnb-center">FAQ</h1>
111
+ <h3>Can I really get Premium for Free?</h3>
112
+ <p>Yes. It's possible to access all premium features of the Call Now Button for free. No credit card is required. You only need an account for that. The difference with the paid Premium plans is that a small "Powered by Call Now Button" notice is added to your buttons.</p>
113
+ <h3>Does the Premium plan require an account?</h3>
114
+ <p>Yes. We want the Call Now Button to be accessible to all website owners. Even those that do not have a WordPress powered website. The Premium version of the Call Now Button can be used by everyone. You can continue to manage your buttons from your WordPress instance, but you could also do this via our web app. And should you ever move to a different CMS, your button(s) will just move with you.</p>
115
+ <h3>What is the "powered by" notice on the Free Premium plan?</h3>
116
+ <p>Call Now Button Premium is available for a small yearly or annual fee, but it is also possible to get it for <em>free</em>. The free option introduces a small notice to your buttons that says "Powered by Call Now Button". It's very delicate and will not distract the the visitor from your key message.</p>
117
+ </div>
118
+
119
+ </div>
120
+ </div>
121
+ <hr>
122
+ <?php
123
+ do_action('cnb_footer');
124
+ }
src/admin/models/CnbDomain.class.php CHANGED
@@ -31,10 +31,12 @@ class CnbDomain {
31
  *
32
  * @param $domain CnbDomain|null
33
  * @param $domain_id number|null
 
 
34
  */
35
  public static function setSaneDefault( $domain = null, $domain_id = null ) {
36
  if (is_wp_error($domain)) {
37
- return;
38
  }
39
 
40
  if ( $domain === null ) {
@@ -52,9 +54,17 @@ class CnbDomain {
52
  }
53
  if ( empty( $domain->properties ) ) {
54
  $domain->properties = new CnbDomainProperties();
 
 
55
  $domain->properties->scale = '1';
 
 
56
  $domain->properties->debug = false;
57
  }
 
 
 
 
58
  if ( empty( $domain->name ) ) {
59
  $domain->name = null;
60
  }
@@ -64,7 +74,7 @@ class CnbDomain {
64
  if ( ! isset( $domain->trackConversion ) ) {
65
  $domain->trackConversion = true;
66
  }
67
-
68
  }
69
  }
70
 
31
  *
32
  * @param $domain CnbDomain|null
33
  * @param $domain_id number|null
34
+ *
35
+ * @returns CnbDomain
36
  */
37
  public static function setSaneDefault( $domain = null, $domain_id = null ) {
38
  if (is_wp_error($domain)) {
39
+ return $domain;
40
  }
41
 
42
  if ( $domain === null ) {
54
  }
55
  if ( empty( $domain->properties ) ) {
56
  $domain->properties = new CnbDomainProperties();
57
+ }
58
+ if (empty($domain->properties->scale)) {
59
  $domain->properties->scale = '1';
60
+ }
61
+ if (empty($domain->properties->debug)) {
62
  $domain->properties->debug = false;
63
  }
64
+ if (empty($domain->properties->zindex)) {
65
+ $domain->properties->zindex = 2147483647;
66
+ }
67
+
68
  if ( empty( $domain->name ) ) {
69
  $domain->name = null;
70
  }
74
  if ( ! isset( $domain->trackConversion ) ) {
75
  $domain->trackConversion = true;
76
  }
77
+ return $domain;
78
  }
79
  }
80
 
src/admin/partials/admin-footer.php CHANGED
@@ -7,22 +7,27 @@ function cnb_admin_footer() {
7
  }
8
 
9
  function cnb_show_feedback_collection() {
10
- global $cnb_options;
11
- $beta = '';
12
- if (isset($cnb_options['cloud_beta_enabled']) && $cnb_options['cloud_beta_enabled']) {
13
- $beta = '<span class="cnb_footer_beta">beta mode</span>';
14
- }
15
- ?>
 
 
16
  <div class="feedback-collection">
17
  <div class="cnb-clear"></div>
18
- <p class="cnb-url cnb-center"><a href="<?php echo CNB_WEBSITE; ?>" target="_blank">Call Now Button</a><?php echo $beta ?></p>
19
  <p class="cnb-center">Version <?php echo CNB_VERSION; ?></p>
20
  <p class="cnb-center cnb-spacing">
21
  <a href="<?php echo CNB_SUPPORT;
22
  cnb_utm_params("footer-links", "support"); ?>" target="_blank" title="Support">Support</a> &middot;
23
- <a href="<?php echo CNB_WEBSITE; ?>feature-request/<?php cnb_utm_params("footer-links", "suggestions"); ?>"
24
- target="_blank" title="Feature Requests">Suggestions</a> &middot;
25
- <strong><a href="https://www.paypal.com/paypalme/jgrietveld/" target="_blank" title="Thanks or your support">Donate</a></strong>
 
 
 
26
  </p>
27
  </div>
28
  <?php
7
  }
8
 
9
  function cnb_show_feedback_collection() {
10
+ global $cnb_cloud_hosting;
11
+
12
+ $url = admin_url('admin.php');
13
+ $upgrade_link =
14
+ add_query_arg(
15
+ array('page' => 'call-now-button-upgrade'),
16
+ $url );
17
+ $upgrade_url = esc_url( $upgrade_link );?>
18
  <div class="feedback-collection">
19
  <div class="cnb-clear"></div>
20
+ <p class="cnb-url cnb-center"><a href="<?php echo CNB_WEBSITE; ?>" target="_blank">Call Now Button</a></p>
21
  <p class="cnb-center">Version <?php echo CNB_VERSION; ?></p>
22
  <p class="cnb-center cnb-spacing">
23
  <a href="<?php echo CNB_SUPPORT;
24
  cnb_utm_params("footer-links", "support"); ?>" target="_blank" title="Support">Support</a> &middot;
25
+ <a href="<?php echo CNB_SUPPORT; ?>wordpress-free/feature-request/<?php cnb_utm_params("footer-links", "suggestions"); ?>"
26
+ target="_blank" title="Feature Requests">Suggestions</a>
27
+ <?php if (!$cnb_cloud_hosting) { ?>
28
+ &middot;
29
+ <strong><a href="<?php echo $upgrade_url ?>" title="Unlock features">Upgrade</a></strong>
30
+ <?php } ?>
31
  </p>
32
  </div>
33
  <?php
src/admin/partials/admin-functions.php CHANGED
@@ -11,6 +11,7 @@ function cnb_is_active_tab($tab_name) {
11
 
12
  function cnb_get_changelog() {
13
  return array(
 
14
  '0.5.0' => 'Better button creation flow, UI improvements, small fixes',
15
  '0.4.7' => 'Small UI improvements',
16
  '0.4.2' => 'Button styling adjustments, security improvements',
@@ -99,3 +100,92 @@ function cnb_create_days_of_week_array($original) {
99
  }
100
  return $result;
101
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  function cnb_get_changelog() {
13
  return array(
14
+ '1.0.0' => '🎉Introducing Call Now Button Premium!🎉',
15
  '0.5.0' => 'Better button creation flow, UI improvements, small fixes',
16
  '0.4.7' => 'Small UI improvements',
17
  '0.4.2' => 'Button styling adjustments, security improvements',
100
  }
101
  return $result;
102
  }
103
+
104
+ /**
105
+ * <p>Echo the promobox.</p>
106
+ * <p>The CTA block is optional and displays only when there's a link provided or $cta_button_text = 'none'.</p>
107
+ * <p>Defaut CTA text is "Let's go". Default <code>$icon</code> is flag (value should be a dashicon name)</p>
108
+ *
109
+ * <p><strong>NOTE: all values are presumed to be already escaped!</strong></p>
110
+ *
111
+ * @param $color
112
+ * @param $headline
113
+ * @param $body
114
+ * @param $icon
115
+ * @param $cta_pretext
116
+ * @param $cta_button_text
117
+ * @param $cta_button_link
118
+ *
119
+ * @return null It <code>echo</code>s html output of the promobox
120
+ */
121
+ function cnb_promobox($color, $headline, $body, $icon = 'flag', $cta_pretext = null, $cta_button_text = 'Let\'s go', $cta_button_link = null) {
122
+ $output = '
123
+ <div id="cnb_upgrade_box" class="cnb-promobox">
124
+ <div class="cnb-promobox-header cnb-promobox-header-'.$color.'">
125
+ <span class="dashicons dashicons-'.$icon.'"></span>
126
+ <h2 class="hndle">'.
127
+ $headline
128
+ .'</h2>
129
+ </div>
130
+ <div class="inside">
131
+ <div class="cnb-promobox-copy">
132
+ <div class="cnb_promobox_item">'.
133
+ $body
134
+ .'</div>
135
+ <div class="clear"></div>';
136
+ if(!is_null($cta_button_link) || $cta_button_text == 'none') {
137
+ $output .= '
138
+ <div class="cnb-promobox-action">
139
+ <div class="cnb-promobox-action-left">'.
140
+ $cta_pretext
141
+ .'</div>';
142
+ if($cta_button_text != 'none' && $cta_button_link != 'disabled') {
143
+ $output .= '
144
+ <div class="cnb-promobox-action-right">
145
+ <a class="button button-primary button-large" href="'.$cta_button_link.'">'.$cta_button_text.'</a>
146
+ </div>';
147
+ } elseif($cta_button_link == 'disabled') {
148
+ $output .= '
149
+ <div class="cnb-promobox-action-right">
150
+ <button class="button button-primary button-large" disabled>'.$cta_button_text.'</a>
151
+ </div>';
152
+ }
153
+ $output .= '
154
+ <div class="clear"></div>
155
+ </div>
156
+ ';
157
+ }
158
+ $output .= '
159
+ </div>
160
+ </div>
161
+ </div>
162
+ ';
163
+ echo $output;
164
+ return null;
165
+ }
166
+
167
+ /**
168
+ * Returns the url for the Upgrade to cloud page
169
+ *
170
+ * @return string admin page url
171
+ */
172
+ function cnb_legacy_upgrade_page() {
173
+ $url = admin_url('admin.php');
174
+ $new_link = add_query_arg( 'page', 'call-now-button-upgrade', $url );
175
+ return esc_url_raw($new_link);
176
+ }
177
+
178
+ /**
179
+ * The equivalent of the JS function `set_cnb_wordpress_upgrade_link`
180
+ *
181
+ * @return string URL of the upgrade URL (path parameters are already escaped)
182
+ */
183
+ function get_cnb_wordpress_upgrade_link() {
184
+ $email = esc_attr(get_bloginfo('admin_email'));
185
+ $action = esc_url( admin_url('admin.php') );
186
+
187
+ return 'https://www.callnowbutton.com/wordpress'
188
+ . '?e=' . $email
189
+ . '&a=' . $action
190
+ . '&utm_source=wp-plugin&utm_medium=referral&utm_campaign=beta_tester&utm_term=sign-up-for-api';
191
+ }
src/admin/partials/admin-header.php CHANGED
@@ -1,5 +1,6 @@
1
  <?php
2
  require_once dirname( __FILE__ ) . '/../../utils/notices.php';
 
3
  require_once dirname( __FILE__ ) . '/admin-functions.php';
4
 
5
  function cnb_admin_header_no_args() {
@@ -13,7 +14,7 @@ function cnb_admin_header_no_args() {
13
  }
14
 
15
  function cnb_admin_header_args( $cnb_options, $cnb_settings, $cnb_cloud_notifications = array(), $cnb_changelog = array() ) {
16
- echo '<div class="wrap">'; // This is closed in cnb_admin_footer
17
 
18
  echo '<!--## NOTIFICATION BARS ## -->';
19
  $cnb_cloud_notifications = array_merge($cnb_cloud_notifications, cnb_get_cloud_notices());
@@ -51,6 +52,7 @@ function cnb_admin_header_args( $cnb_options, $cnb_settings, $cnb_cloud_notifica
51
  if ( $cnb_settings['updated'][0] ) {
52
  cnb_upgrade_notice($cnb_settings['updated'][1], $cnb_changelog);
53
  }
 
54
  }
55
 
56
  function cnb_admin_header() {
1
  <?php
2
  require_once dirname( __FILE__ ) . '/../../utils/notices.php';
3
+ require_once dirname( __FILE__ ) . '/../../utils/utils.php';
4
  require_once dirname( __FILE__ ) . '/admin-functions.php';
5
 
6
  function cnb_admin_header_no_args() {
14
  }
15
 
16
  function cnb_admin_header_args( $cnb_options, $cnb_settings, $cnb_cloud_notifications = array(), $cnb_changelog = array() ) {
17
+ echo '<div class="wrap call-now-button">'; // This is closed in cnb_admin_footer
18
 
19
  echo '<!--## NOTIFICATION BARS ## -->';
20
  $cnb_cloud_notifications = array_merge($cnb_cloud_notifications, cnb_get_cloud_notices());
52
  if ( $cnb_settings['updated'][0] ) {
53
  cnb_upgrade_notice($cnb_settings['updated'][1], $cnb_changelog);
54
  }
55
+ cnb_show_advanced();
56
  }
57
 
58
  function cnb_admin_header() {
src/admin/partials/domain-upgrade/overview.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function cnb_get_plan($plans, $name) {
3
+ foreach ($plans as $plan) {
4
+ if ($plan->nickname === $name) {
5
+ return $plan;
6
+ }
7
+ }
8
+ return null;
9
+ }
10
+
11
+ function getProfileEditModal($additional_classes=null, $link_text='Verify your information', $modal_header=null, $data_title='') {
12
+ if (!$modal_header) {$modal_header=$link_text;}
13
+ $url = admin_url('admin.php');
14
+ $full_url = add_query_arg(
15
+ array(
16
+ 'TB_inline' => 'true',
17
+ 'inlineId' => 'cnb_admin_page_domain_upgrade_profile',
18
+ 'height' => '800'),
19
+ $url );
20
+ printf(
21
+ '<a href="%1$s" title="%2$s" class="thickbox open-profile-details-modal %4$s" id="cnb-button-overview-modal-add-new" onclick="cnb_btn=\'%5$s\'">%3$s</a>',
22
+ $full_url,
23
+ __(esc_html($modal_header)),
24
+ __(esc_html($link_text)),
25
+ esc_attr($additional_classes),
26
+ __(esc_attr($data_title))
27
+ );
28
+ }
29
+ function cnb_domain_upgrade_overview($domain, $user) {
30
+ // Render upgrade form
31
+ $plans = CnbAppRemotePayment::cnb_remote_get_plans();
32
+
33
+ $active_currency = null;
34
+ if ($user && !is_wp_error($user) && isset($user->stripeDetails) && !empty($user->stripeDetails->currency)) {
35
+ $active_currency = $user->stripeDetails->currency;
36
+ }
37
+
38
+ $profile_set = false;
39
+ if ($user && !is_wp_error($user) && isset($user->address) && !empty($user->address->country)) {
40
+ $profile_set = true;
41
+ }
42
+ ?>
43
+ <script>
44
+ <?php if (!$profile_set) { ?>
45
+ // Unless a profile hasn't been set yet, in which case, ensure we ask customers for that first
46
+ jQuery(function() {
47
+ jQuery('.button-upgrade').hide();
48
+ jQuery('.open-profile-details-modal').on('click', function() {
49
+ jQuery('.open-profile-details-modal').hide();
50
+ jQuery('.button-upgrade').show();
51
+ });
52
+ });
53
+ <?php } else { ?>
54
+ // Hide the "Next" buttons, we already have a profile
55
+ jQuery(function() {
56
+ jQuery('.open-profile-details-modal').hide();
57
+ });
58
+ <?php } ?>
59
+
60
+ <?php if ($active_currency) { ?>
61
+ // We already know the currency, so a "select currency" tab menu makes no sense
62
+ jQuery(function() {
63
+ jQuery('.nav-tab-wrapper').hide();
64
+ });
65
+ <?php } ?>
66
+ </script>
67
+ <p>Your domain <strong><?php esc_html_e($domain->name) ?></strong> is currently on the <code><?php esc_html_e($domain->type) ?></code> cloud plan.</p>
68
+
69
+ <form id="wp_domain_upgrade" method="post">
70
+ <input type="hidden" name="cnb_domain_id" id="cnb_domain_id" value="<?php esc_attr_e($domain->id) ?>">
71
+
72
+ <h2>Select a plan to remove the "Powered by Call Now Button" message from your buttons</h2>
73
+
74
+ <h2 class="nav-tab-wrapper">
75
+ <a href="#" data-cnb-currency="eur" class="cnb-currency-select cnb-currency-eur nav-tab<?php if($active_currency !== 'usd') {?> nav-tab-active<?php }?>">Euro (&euro;)</a>
76
+ <a href="#" data-cnb-currency="usd" class="cnb-currency-select cnb-currency-usd nav-tab<?php if($active_currency === 'usd') {?> nav-tab-active<?php }?>">US Dollar ($)</a>
77
+ </h2>
78
+ <div class="cnb-message notice"><p class="cnb-error-message"></p></div>
79
+ <div class="cnb-price-plans">
80
+ <div class="currency-box currency-box-eur cnb-flexbox<?php if($active_currency !== 'usd') {?> currency-box-active<?php }?>">
81
+ <?php $plan = cnb_get_plan($plans, 'powered-by-eur-yearly'); ?>
82
+ <div class="pricebox">
83
+ <h3 class="yearly">Yearly Plan</h3>
84
+ <div class="benefit">All branding removed</div>
85
+ <div class="plan-amount"><span class="currency">€</span><span class="euros">1</span><span class="cents">.67</span><span class="timeframe">/month</span></div>
86
+ <div class="billingprice">
87
+ Billed at €19.99 annually
88
+ </div>
89
+ <?php getProfileEditModal('button button-primary', 'Next', 'Verify your information', 'powered-by-eur-yearly'); ?>
90
+ <a class="button button-primary button-upgrade powered-by-eur-yearly" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
91
+ </div>
92
+
93
+ <?php $plan = cnb_get_plan($plans, 'powered-by-eur-monthly'); ?>
94
+ <div class="pricebox">
95
+ <h3 class="">Monthly Plan</h3>
96
+ <div class="benefit">All branding removed</div>
97
+ <div class="plan-amount"><span class="currency">€</span><span class="euros">4</span><span class="cents">.99</span><span class="timeframe">/month</span></div>
98
+ <div class="billingprice">
99
+ Billed at €4.99 monthly
100
+ </div>
101
+ <?php getProfileEditModal('button button-secondary', 'Next', 'Verify your information', 'powered-by-eur-monthly'); ?>
102
+ <a class="button button-secondary button-upgrade powered-by-eur-monthly" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
103
+ </div>
104
+ </div>
105
+ <div class="currency-box currency-box-usd cnb-flexbox<?php if($active_currency === 'usd') {?> currency-box-active<?php }?>">
106
+ <?php $plan = cnb_get_plan($plans, 'powered-by-usd-yearly'); ?>
107
+ <div class="pricebox">
108
+ <h3 class="yearly">Yearly Plan</h3>
109
+ <div class="benefit">All branding removed</div>
110
+ <div class="plan-amount"><span class="currency">$</span><span class="euros">1</span><span class="cents">.99</span><span class="timeframe">/month</span></div>
111
+ <div class="billingprice">
112
+ Billed at $23.88 annually
113
+ </div>
114
+ <?php getProfileEditModal('button button-primary', 'Next', 'Verify your information', 'powered-by-usd-yearly'); ?>
115
+ <a class="button button-primary button-upgrade powered-by-usd-yearly" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
116
+ </div>
117
+ <?php $plan = cnb_get_plan($plans, 'powered-by-usd-monthly'); ?>
118
+ <div class="pricebox">
119
+ <h3 class="">Monthly Plan</h3>
120
+ <div class="benefit">All branding removed</div>
121
+ <div class="plan-amount"><span class="currency">$</span><span class="euros">5</span><span class="cents">.99</span><span class="timeframe">/month</span></div>
122
+ <div class="billingprice">
123
+ Billed at $5.99 monthly
124
+ </div>
125
+ <?php getProfileEditModal('button button-secondary', 'Next', 'Verify your information', 'powered-by-usd-monthly'); ?>
126
+ <a class="button button-secondary button-upgrade powered-by-usd-monthly" href="#" onclick="cnb_get_checkout('<?php _e($plan->id) ?>')">Upgrade</a>
127
+ </div>
128
+ </div>
129
+ </div>
130
+ </form>
131
+
132
+ <p class="cnb-center">All <u>cloud</u> plans (free and paid) contain the following features:</p>
133
+ <div class="cnb-center" style="margin-bottom:50px;">
134
+ <div><b>&check;</b> Phone, Email, Location, WhatsApp, Links</div>
135
+ <div><b>&check;</b> Unlimited buttons</div>
136
+ <div><b>&check;</b> Multibutton</div>
137
+ <div><b>&check;</b> Buttonbar (full width with multiple actions)</div>
138
+ <div><b>&check;</b> Advanced page targeting options</div>
139
+ <div><b>&check;</b> Scheduling</div>
140
+ </div>
141
+ <?php }
src/admin/partials/domain-upgrade/upgraded.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function cnb_upgrade_create_settings_url() {
4
+ $url = admin_url('admin.php');
5
+ $tab_link =
6
+ add_query_arg(
7
+ array(
8
+ 'page' => 'call-now-button-settings'),
9
+ $url );
10
+ return esc_url( $tab_link );
11
+ }
12
+
13
+ function cnb_domain_upgrade_upgraded($domain, $notice=null) {
14
+ $portal_url = CnbAppRemote::cnb_remote_create_billing_portal();
15
+
16
+ echo '<p>Your domain <strong>' . esc_html($domain->name) .'</strong> is currently on the <code>'. esc_html($domain->type) .'</code> cloud plan.</p>';
17
+
18
+ // Render notice if JUST upgraded and show general information about domain (instead of upgrade form)
19
+ if ($notice) {
20
+ CnbAdminNotices::get_instance()->renderNotice( $notice );
21
+ // Big "Yay!"
22
+ echo '<div style="width:200px; height:auto"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 561 309"><path d="M107.373,301.9a109.773,109.773,0,0,0,19.32-5.52,155.59,155.59,0,0,0,36.6-20.16,121,121,0,0,0,30.12-31.44q18.477-.241,34.68-0.96t25.08-4.32q9.837-4.083,14.04-10.44t4.2-11.4a10.559,10.559,0,0,0-.12-1.68,10.242,10.242,0,0,0-.36-1.44q-1.2-3.841-2.16-3.84-0.72,0-.72,2.16v1.44q0,6.959-3.96,10.2a92.727,92.727,0,0,1-11.88,7.8q-6.723,3.837-21.96,5.04t-33,1.2a290.972,290.972,0,0,0,12.84-27.48q6.356-15.48,12-32.4t10.2-33.36q4.555-16.435,7.68-30.36,2.16-9.837,2.16-14.64t-1.32-6.72a3.863,3.863,0,0,0-3.24-1.92q-2.88,0-6,2.88t-3.6,5.04q-2.16,7.443-6.24,18.48t-9.84,23.64q-5.76,12.6-12.96,24.96a184.347,184.347,0,0,1-15.48,22.68,84.992,84.992,0,0,1-17.16,16.56q-11.284,7.92-21.36,7.92a14.461,14.461,0,0,1-10.32-3.84q-4.085-3.836-4.08-12.24,0-1.917.24-4.32a48.082,48.082,0,0,1,.72-4.8,149.376,149.376,0,0,1,8.16-24.96q5.76-13.916,13.56-28.8t15.96-28.56a174.627,174.627,0,0,0,14.16-30.12,87.036,87.036,0,0,0,5.52-29.16,46.691,46.691,0,0,0-5.28-22.2q-5.283-9.956-18-15.48a41.469,41.469,0,0,0-11.52-3.72,77.4,77.4,0,0,0-13.2-1.08q-16.083,0-34.32,6.12a162.671,162.671,0,0,0-35.88,17.4,176.481,176.481,0,0,0-32.28,26.52A129.268,129.268,0,0,0,14.853,88.3a108.621,108.621,0,0,0-6.96,18.6,70.9,70.9,0,0,0-2.4,18.36q0,15.363,6.48,26.64a46.526,46.526,0,0,0,16.92,17.4,43.619,43.619,0,0,0,22.44,6.12,45.766,45.766,0,0,0,17.76-3.6,82.446,82.446,0,0,0,27.12-17.64,88.512,88.512,0,0,0,17.4-23.52q6.12-12.357,6.12-22.44,0-8.64-4.56-14.16t-14.4-5.52a51.739,51.739,0,0,0-11.76,1.68,6.733,6.733,0,0,0-3.12,1.32q-1.44,1.08-1.44,1.56,0,0.962,2.16.96h1.2a6.994,6.994,0,0,0,1.68-.24,29.9,29.9,0,0,1,6.24-.72q7.92,0,11.4,4.44t3.48,11.4a46.527,46.527,0,0,1-3.12,15.6,78.488,78.488,0,0,1-8.76,17.04,83.89,83.89,0,0,1-12.96,15.12,44.622,44.622,0,0,1-15.72,9.6,46.932,46.932,0,0,1-15.36,2.64,36.88,36.88,0,0,1-17.52-4.32,33.31,33.31,0,0,1-13.2-12.84q-5.04-8.516-5.04-21.48a73.287,73.287,0,0,1,2.04-16.32,119.309,119.309,0,0,1,6.36-19.2,125.152,125.152,0,0,1,19.68-31.44,165.561,165.561,0,0,1,28.92-27,156.037,156.037,0,0,1,33.24-18.84q17.037-6.958,32.4-6.96,14.4,0,24.96,6.72a16.293,16.293,0,0,1,6.6,8.28,34.892,34.892,0,0,1,2.04,12.36,85.436,85.436,0,0,1-3.12,21.12,162.259,162.259,0,0,1-8.88,24.96,215.654,215.654,0,0,1-13.44,25.44q-6.48,10.8-14.04,24.36a280.918,280.918,0,0,0-13.44,27.48,112.986,112.986,0,0,0-7.8,25.92q-0.243,1.683-.36,3.36c-0.083,1.122-.12,2.16-0.12,3.12q0,13.923,7.92,20.4a28.988,28.988,0,0,0,18.96,6.48q14.877,0,28.8-9.36a95.478,95.478,0,0,0,20.64-19.32,189.687,189.687,0,0,0,16.56-24.12,232.159,232.159,0,0,0,11.52-22.32q-6.48,24-14.88,47.04t-17.76,46.32a523.566,523.566,0,0,0-54.48,2.76,175.855,175.855,0,0,0-49.92,12.6q-15.362,6.239-22.2,13.92t-6.84,14.16q0,8.877,10.44,15.12t27.24,6.24A97.719,97.719,0,0,0,107.373,301.9Zm-34.08-8.16q-7.324-3.122-7.32-8.4,0-4.083,4.68-9.36t15.48-11.28a130.694,130.694,0,0,1,46.56-16.2,334.727,334.727,0,0,1,49.44-3.72,101.744,101.744,0,0,1-27,28.92,137.241,137.241,0,0,1-32.28,17.4,95.658,95.658,0,0,1-16.08,4.32,87.429,87.429,0,0,1-15.12,1.44Q80.611,296.863,73.293,293.743ZM429.57,163.9q-6.245,12.483-11.16,21a75.586,75.586,0,0,1-10.8,14.64,60.436,60.436,0,0,1-14.28,10.8,156.273,156.273,0,0,1-21.36,9.48q-5.76,10.317-13.08,21.48a148.749,148.749,0,0,1-16.56,20.88,83.473,83.473,0,0,1-20.4,15.84,50.308,50.308,0,0,1-24.6,6.12q-12.477,0-17.76-4.92a15.412,15.412,0,0,1-5.28-11.64,18.313,18.313,0,0,1,.96-6.24q0.962-2.643,2.88-6.72a35.934,35.934,0,0,1,9.36-12,55.137,55.137,0,0,1,12.96-8.16,142.837,142.837,0,0,1,28.44-9.36q15.957-3.6,30.6-7.92a124.05,124.05,0,0,0,8.4-18.12q3.836-10.2,6.96-19.92t5.04-15.96q-2.88,5.283-7.32,12.84a145.514,145.514,0,0,1-9.96,14.76,62.714,62.714,0,0,1-11.88,12,21.791,21.791,0,0,1-13.32,4.8,21.187,21.187,0,0,1-6.36-1.2,14.088,14.088,0,0,1-6.48-4.44q-2.763-3.24-2.76-9.72a26.341,26.341,0,0,1,3-12.12c1.191-2.336,2.327-4.617,3.434-6.869-0.6,1.142-1.224,2.308-1.872,3.509a169.966,169.966,0,0,1-8.88,14.64,65.146,65.146,0,0,1-9.96,11.76q-5.163,4.68-10.44,5.16a12.548,12.548,0,0,1-6-1.2,13.526,13.526,0,0,1-5.88-5.28q-2.52-3.836-2.52-10.8a55.888,55.888,0,0,1,2.16-13.92q-2.88,4.563-7.44,11.16a74.782,74.782,0,0,1-9.84,11.64,34.073,34.073,0,0,1-8.64,6.24,17.655,17.655,0,0,1-7.44,1.92q-6.243,0-10.08-5.64t-3.84-14.76q0-9.6,4.8-21.84t15.6-25.44a53.97,53.97,0,0,1,16.92-13.56,42.337,42.337,0,0,1,19.56-5.16,31.164,31.164,0,0,1,10.56,1.8,22.469,22.469,0,0,1,8.88,5.88,5.3,5.3,0,0,1,1.68,3.84,2.954,2.954,0,0,1-1.2,2.4,3.412,3.412,0,0,1-3.12.48q-2.643-8.4-11.28-8.4a21.446,21.446,0,0,0-9.36,2.64q-8.162,4.32-16.92,14.16a144,144,0,0,0-15.24,20.4,59.659,59.659,0,0,0-3,5.52q-2.041,4.084-3.96,9.12a47.329,47.329,0,0,0-2.64,9.84,14.3,14.3,0,0,0-.24,2.04v1.8q0,7.92,6,7.92,7.2,0,16.32-10.56a138.065,138.065,0,0,0,11.28-16.08q5.04-8.4,10.32-18a109.441,109.441,0,0,1,6.72-10.8,10.3,10.3,0,0,1,8.88-4.32,20.007,20.007,0,0,1,5.28.72,12.723,12.723,0,0,0,5.52.24,42.9,42.9,0,0,0-5.16,7.2q-3.24,5.283-6.84,12t-6.48,13.68a82,82,0,0,0-4.08,12q-0.242,1.44-.6,4.08a32.118,32.118,0,0,0-.36,3.84q0,6.723,3.84,6.72t8.28-4.56a71.612,71.612,0,0,0,8.76-11.28q4.32-6.716,7.92-13.56t5.76-11.16a4.008,4.008,0,0,1,1.5-2.013c0.487-.979.953-1.979,1.373-3.027q3.6-7.436,7.2-14.28t6.24-12.12q2.637-5.276,9.12-5.28h14.88q-1.683,1.44-4.2,3.24a17.671,17.671,0,0,0-4.68,5.4q-6.48,11.043-11.28,21.24t-10.32,21.72a57.607,57.607,0,0,0-3.84,10.08,31.653,31.653,0,0,0-1.2,7.92q0,7.92,5.28,7.92,5.76,0,13.92-9.36a162.607,162.607,0,0,0,13.56-18.84q6.84-10.917,13.2-22.56t11.16-21.48q2.637-5.276,9.36-5.28h13.2a31.662,31.662,0,0,0-10.68,12.48q-3.725,7.684-8.28,19.68-5.04,13.2-9.48,27.24t-9.96,28.2a108.823,108.823,0,0,0,17.88-8.16,49.041,49.041,0,0,0,16.92-15.84,164.176,164.176,0,0,0,9.48-15.72q3.96-7.56,5.64-10.92c0.637-1.6,1.518-2.4,2.64-2.4s1.68,0.72,1.68,2.16A5.964,5.964,0,0,1,429.57,163.9ZM329.13,231.7a165.51,165.51,0,0,0-24.36,8.28,42.165,42.165,0,0,0-18.12,13.68q-6.6,8.877-6.6,15.84a9.6,9.6,0,0,0,2.76,7.08q2.762,2.757,8.76,2.76,7.92,0,16.32-4.8a89.765,89.765,0,0,0,16.32-12.12,195.3,195.3,0,0,0,14.52-14.88q6.6-7.56,10.68-13.32a43.594,43.594,0,0,0,2.64-4.32q1.44-2.643,2.88-5.04Q343.167,227.98,329.13,231.7Zm139.916-60.36q5.159-7.677,12.36-18.24t15.36-22.44q8.157-11.88,16.08-23.76t14.52-21.84q6.6-9.956,10.8-16.56t4.68-8.28l-0.48-1.2-1.2-.72h-7.68a34.313,34.313,0,0,0-7.2.72,7.142,7.142,0,0,0-5.04,4.08l-61.44,116.88-0.24,1.44,2.4,0.48Q463.885,179.023,469.046,171.343Zm-11.04,36.24a11.089,11.089,0,0,0,3.72-8.16,7.76,7.76,0,0,0-2.4-5.88,8.7,8.7,0,0,0-6.24-2.28,12.445,12.445,0,0,0-7.44,2.64,9.635,9.635,0,0,0-4.08,6.96,10.481,10.481,0,0,0,1.56,7.2q2.037,3.117,6.6,3.12A11.656,11.656,0,0,0,458.006,207.583Z"/></svg></div>';
23
+ echo '<h1><strong>'.esc_html($domain->name).'</strong> has been successfully upgraded!</h1><h3>All branding has been removed from your buttons and you\'ll enjoy:</h3>
24
+ <div><div><b>&check;</b> Phone, Email, Location, WhatsApp, Links</div><div><b>&check;</b> Unlimited buttons</div><div><b>&check;</b> Multibutton</div><div><b>&check;</b> Buttonbar (full width with multiple actions)</div><div><b>&check;</b> Advanced page targeting options</div><div><b>&check;</b> Scheduling</div></div>';
25
+ } ?>
26
+
27
+ <p>
28
+ <?php if (!empty($domain->expires)) { ?>
29
+ Your subscription will
30
+ <?php echo $domain->renew == 1 ? ' renew automatically ' : ' expire '; ?>
31
+ on <?php echo date('F d, Y', strtotime(esc_html($domain->expires))); ?>.
32
+ <?php } ?>
33
+ You can change this on the <a href="<?php esc_html_e(cnb_upgrade_create_settings_url()) ?>">settings page</a>.</p>
34
+ <p>You can access and download your invoice via <a href="<?php esc_html_e($portal_url->url); ?>">the invoice dashboard</a>. For any questions, please head over to our <a href="https://callnowbutton.com/support/">help center</a>.</p>
35
+ <?php } ?>
src/admin/partials/domain-upgrade/upgrading.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function cnb_domain_upgrade_upgrading($domain) {
4
+ $busy_notice = new CnbNotice(
5
+ 'warning',
6
+ '<p>We are processing the upgrade for <strong>'.esc_html($domain->name).'</strong>, please hold on.</p>
7
+ <p>This page will refresh in 2 seconds...</p>');
8
+ CnbAdminNotices::get_instance()->renderNotice( $busy_notice );
9
+ echo '<script>setTimeout(window.location.reload.bind(window.location), 2000);</script>';
10
+ }
src/admin/settings-profile.php ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function cnb_add_header_profile_edit() {
3
+ echo 'Profile';
4
+ }
5
+
6
+ // List from https://gist.github.com/jylopez/7a3eb87e94981a579303a73cf72a5086
7
+ // Based on https://stripe.com/global
8
+ // Updated list with all countries minus EU santioned countries + Russia for difficult VAT requirements
9
+ // https://sanctionsmap.eu/#/main
10
+ function cnb_stripe_get_countries() {
11
+ return array(
12
+ array( "country" => 'Afghanistan', "code" => 'AF'),
13
+ array( "country" => 'Åland Islands', "code" => 'AX'),
14
+ array( "country" => 'Albania', "code" => 'AL'),
15
+ array( "country" => 'Algeria', "code" => 'DZ'),
16
+ array( "country" => 'American Samoa', "code" => 'AS'),
17
+ array( "country" => 'Andorra', "code" => 'AD'),
18
+ array( "country" => 'Angola', "code" => 'AO'),
19
+ array( "country" => 'Anguilla', "code" => 'AI'),
20
+ array( "country" => 'Antarctica', "code" => 'AQ'),
21
+ array( "country" => 'Antigua and Barbuda', "code" => 'AG'),
22
+ array( "country" => 'Argentina', "code" => 'AR'),
23
+ array( "country" => 'Armenia', "code" => 'AM'),
24
+ array( "country" => 'Aruba', "code" => 'AW'),
25
+ array( "country" => 'Australia', "code" => 'AU'),
26
+ array( "country" => 'Austria', "code" => 'AT'),
27
+ array( "country" => 'Azerbaijan', "code" => 'AZ'),
28
+ array( "country" => 'Bahamas', "code" => 'BS'),
29
+ array( "country" => 'Bahrain', "code" => 'BH'),
30
+ array( "country" => 'Bangladesh', "code" => 'BD'),
31
+ array( "country" => 'Barbados', "code" => 'BB'),
32
+ array( "country" => 'Belarus', "code" => 'BY'),
33
+ array( "country" => 'Belgium', "code" => 'BE'),
34
+ array( "country" => 'Belize', "code" => 'BZ'),
35
+ array( "country" => 'Benin', "code" => 'BJ'),
36
+ array( "country" => 'Bermuda', "code" => 'BM'),
37
+ array( "country" => 'Bhutan', "code" => 'BT'),
38
+ array( "country" => 'Bolivia', "code" => 'BO'),
39
+ array( "country" => 'Bonaire, Sint Eustatius and Saba', "code" => 'BQ'),
40
+ array( "country" => 'Bosnia and Herzegovina', "code" => 'BA'),
41
+ array( "country" => 'Botswana', "code" => 'BW'),
42
+ array( "country" => 'Bouvet Island', "code" => 'BV'),
43
+ array( "country" => 'Brazil', "code" => 'BR'),
44
+ array( "country" => 'British Indian Ocean Territory', "code" => 'IO'),
45
+ array( "country" => 'Brunei Darussalam', "code" => 'BN'),
46
+ array( "country" => 'Bulgaria', "code" => 'BG'),
47
+ array( "country" => 'Burkina Faso', "code" => 'BF'),
48
+ array( "country" => 'Burundi', "code" => 'BI'),
49
+ array( "country" => 'Cabo Verde', "code" => 'CV'),
50
+ array( "country" => 'Cambodia', "code" => 'KH'),
51
+ array( "country" => 'Cameroon', "code" => 'CM'),
52
+ array( "country" => 'Canada', "code" => 'CA'),
53
+ array( "country" => 'Cayman Islands', "code" => 'KY'),
54
+ array( "country" => 'Central African Republic', "code" => 'CF'),
55
+ array( "country" => 'Chad', "code" => 'TD'),
56
+ array( "country" => 'Chile', "code" => 'CL'),
57
+ array( "country" => 'China', "code" => 'CN'),
58
+ array( "country" => 'Christmas Island', "code" => 'CX'),
59
+ array( "country" => 'Cocos (Keeling) Islands', "code" => 'CC'),
60
+ array( "country" => 'Colombia', "code" => 'CO'),
61
+ array( "country" => 'Comoros', "code" => 'KM'),
62
+ array( "country" => 'Congo', "code" => 'CG'),
63
+ array( "country" => 'Cook Islands', "code" => 'CK'),
64
+ array( "country" => 'Costa Rica', "code" => 'CR'),
65
+ array( "country" => 'Côte d\'Ivoire', "code" => 'CI'),
66
+ array( "country" => 'Croatia', "code" => 'HR'),
67
+ array( "country" => 'Cuba', "code" => 'CU'),
68
+ array( "country" => 'Curaçao', "code" => 'CW'),
69
+ array( "country" => 'Cyprus', "code" => 'CY'),
70
+ array( "country" => 'Czechia', "code" => 'CZ'),
71
+ array( "country" => 'Denmark', "code" => 'DK'),
72
+ array( "country" => 'Djibouti', "code" => 'DJ'),
73
+ array( "country" => 'Dominica', "code" => 'DM'),
74
+ array( "country" => 'Dominican Republic', "code" => 'DO'),
75
+ array( "country" => 'Ecuador', "code" => 'EC'),
76
+ array( "country" => 'Egypt', "code" => 'EG'),
77
+ array( "country" => 'El Salvador', "code" => 'SV'),
78
+ array( "country" => 'Equatorial Guinea', "code" => 'GQ'),
79
+ array( "country" => 'Eritrea', "code" => 'ER'),
80
+ array( "country" => 'Estonia', "code" => 'EE'),
81
+ array( "country" => 'Eswatini', "code" => 'SZ'),
82
+ array( "country" => 'Ethiopia', "code" => 'ET'),
83
+ array( "country" => 'Falkland Islands (Malvinas)', "code" => 'FK'),
84
+ array( "country" => 'Faroe Islands', "code" => 'FO'),
85
+ array( "country" => 'Fiji', "code" => 'FJ'),
86
+ array( "country" => 'Finland', "code" => 'FI'),
87
+ array( "country" => 'France', "code" => 'FR'),
88
+ array( "country" => 'French Guiana', "code" => 'GF'),
89
+ array( "country" => 'French Polynesia', "code" => 'PF'),
90
+ array( "country" => 'French Southern Territories', "code" => 'TF'),
91
+ array( "country" => 'Gabon', "code" => 'GA'),
92
+ array( "country" => 'Gambia', "code" => 'GM'),
93
+ array( "country" => 'Georgia', "code" => 'GE'),
94
+ array( "country" => 'Germany', "code" => 'DE'),
95
+ array( "country" => 'Ghana', "code" => 'GH'),
96
+ array( "country" => 'Gibraltar', "code" => 'GI'),
97
+ array( "country" => 'Greece', "code" => 'GR'),
98
+ array( "country" => 'Greenland', "code" => 'GL'),
99
+ array( "country" => 'Grenada', "code" => 'GD'),
100
+ array( "country" => 'Guadeloupe', "code" => 'GP'),
101
+ array( "country" => 'Guam', "code" => 'GU'),
102
+ array( "country" => 'Guatemala', "code" => 'GT'),
103
+ array( "country" => 'Guernsey', "code" => 'GG'),
104
+ array( "country" => 'Guinea-Bissau', "code" => 'GW'),
105
+ array( "country" => 'Guyana', "code" => 'GY'),
106
+ array( "country" => 'Haiti', "code" => 'HT'),
107
+ array( "country" => 'Heard Island and McDonald Islands', "code" => 'HM'),
108
+ array( "country" => 'Holy See', "code" => 'VA'),
109
+ array( "country" => 'Honduras', "code" => 'HN'),
110
+ array( "country" => 'Hong Kong', "code" => 'HK'),
111
+ array( "country" => 'Hungary', "code" => 'HU'),
112
+ array( "country" => 'Iceland', "code" => 'IS'),
113
+ array( "country" => 'India', "code" => 'IN'),
114
+ array( "country" => 'Indonesia', "code" => 'ID'),
115
+ array( "country" => 'Iraq', "code" => 'IQ'),
116
+ array( "country" => 'Ireland', "code" => 'IE'),
117
+ array( "country" => 'Isle of Man', "code" => 'IM'),
118
+ array( "country" => 'Israel', "code" => 'IL'),
119
+ array( "country" => 'Italy', "code" => 'IT'),
120
+ array( "country" => 'Jamaica', "code" => 'JM'),
121
+ array( "country" => 'Japan', "code" => 'JP'),
122
+ array( "country" => 'Jersey', "code" => 'JE'),
123
+ array( "country" => 'Jordan', "code" => 'JO'),
124
+ array( "country" => 'Kazakhstan', "code" => 'KZ'),
125
+ array( "country" => 'Kenya', "code" => 'KE'),
126
+ array( "country" => 'Kiribati', "code" => 'KI'),
127
+ array( "country" => 'Korea, Republic of', "code" => 'KR'),
128
+ array( "country" => 'Kuwait', "code" => 'KW'),
129
+ array( "country" => 'Kyrgyzstan', "code" => 'KG'),
130
+ array( "country" => 'Lao', "code" => 'LA'),
131
+ array( "country" => 'Latvia', "code" => 'LV'),
132
+ array( "country" => 'Lebanon', "code" => 'LB'),
133
+ array( "country" => 'Lesotho', "code" => 'LS'),
134
+ array( "country" => 'Liberia', "code" => 'LR'),
135
+ array( "country" => 'Liechtenstein', "code" => 'LI'),
136
+ array( "country" => 'Lithuania', "code" => 'LT'),
137
+ array( "country" => 'Luxembourg', "code" => 'LU'),
138
+ array( "country" => 'Macao', "code" => 'MO'),
139
+ array( "country" => 'Madagascar', "code" => 'MG'),
140
+ array( "country" => 'Malawi', "code" => 'MW'),
141
+ array( "country" => 'Malaysia', "code" => 'MY'),
142
+ array( "country" => 'Maldives', "code" => 'MV'),
143
+ array( "country" => 'Malta', "code" => 'MT'),
144
+ array( "country" => 'Marshall Islands', "code" => 'MH'),
145
+ array( "country" => 'Martinique', "code" => 'MQ'),
146
+ array( "country" => 'Mauritania', "code" => 'MR'),
147
+ array( "country" => 'Mauritius', "code" => 'MU'),
148
+ array( "country" => 'Mayotte', "code" => 'YT'),
149
+ array( "country" => 'Mexico', "code" => 'MX'),
150
+ array( "country" => 'Micronesia', "code" => 'FM'),
151
+ array( "country" => 'Moldova', "code" => 'MD'),
152
+ array( "country" => 'Monaco', "code" => 'MC'),
153
+ array( "country" => 'Mongolia', "code" => 'MN'),
154
+ array( "country" => 'Montenegro', "code" => 'ME'),
155
+ array( "country" => 'Montserrat', "code" => 'MS'),
156
+ array( "country" => 'Morocco', "code" => 'MA'),
157
+ array( "country" => 'Mozambique', "code" => 'MZ'),
158
+ array( "country" => 'Namibia', "code" => 'NA'),
159
+ array( "country" => 'Nauru', "code" => 'NR'),
160
+ array( "country" => 'Nepal', "code" => 'NP'),
161
+ array( "country" => 'Netherlands', "code" => 'NL'),
162
+ array( "country" => 'New Caledonia', "code" => 'NC'),
163
+ array( "country" => 'New Zealand', "code" => 'NZ'),
164
+ array( "country" => 'Nicaragua', "code" => 'NI'),
165
+ array( "country" => 'Niger', "code" => 'NE'),
166
+ array( "country" => 'Nigeria', "code" => 'NG'),
167
+ array( "country" => 'Niue', "code" => 'NU'),
168
+ array( "country" => 'Norfolk Island', "code" => 'NF'),
169
+ array( "country" => 'North Macedonia', "code" => 'MK'),
170
+ array( "country" => 'Northern Mariana Islands', "code" => 'MP'),
171
+ array( "country" => 'Norway', "code" => 'NO'),
172
+ array( "country" => 'Oman', "code" => 'OM'),
173
+ array( "country" => 'Pakistan', "code" => 'PK'),
174
+ array( "country" => 'Palau', "code" => 'PW'),
175
+ array( "country" => 'Palestine', "code" => 'PS'),
176
+ array( "country" => 'Panama', "code" => 'PA'),
177
+ array( "country" => 'Papua New Guinea', "code" => 'PG'),
178
+ array( "country" => 'Paraguay', "code" => 'PY'),
179
+ array( "country" => 'Peru', "code" => 'PE'),
180
+ array( "country" => 'Philippines', "code" => 'PH'),
181
+ array( "country" => 'Pitcairn', "code" => 'PN'),
182
+ array( "country" => 'Poland', "code" => 'PL'),
183
+ array( "country" => 'Portugal', "code" => 'PT'),
184
+ array( "country" => 'Puerto Rico', "code" => 'PR'),
185
+ array( "country" => 'Qatar', "code" => 'QA'),
186
+ array( "country" => 'Réunion', "code" => 'RE'),
187
+ array( "country" => 'Romania', "code" => 'RO'),
188
+ array( "country" => 'Rwanda', "code" => 'RW'),
189
+ array( "country" => 'Saint Barthélemy', "code" => 'BL'),
190
+ array( "country" => 'Saint Helena, Ascension and Tristan da Cunha', "code" => 'SH'),
191
+ array( "country" => 'Saint Kitts and Nevis', "code" => 'KN'),
192
+ array( "country" => 'Saint Lucia', "code" => 'LC'),
193
+ array( "country" => 'Saint Martin (French part)', "code" => 'MF'),
194
+ array( "country" => 'Saint Pierre and Miquelon', "code" => 'PM'),
195
+ array( "country" => 'Saint Vincent and the Grenadines', "code" => 'VC'),
196
+ array( "country" => 'Samoa', "code" => 'WS'),
197
+ array( "country" => 'San Marino', "code" => 'SM'),
198
+ array( "country" => 'Sao Tome and Principe', "code" => 'ST'),
199
+ array( "country" => 'Saudi Arabia', "code" => 'SA'),
200
+ array( "country" => 'Senegal', "code" => 'SN'),
201
+ array( "country" => 'Serbia', "code" => 'RS'),
202
+ array( "country" => 'Seychelles', "code" => 'SC'),
203
+ array( "country" => 'Sierra Leone', "code" => 'SL'),
204
+ array( "country" => 'Singapore', "code" => 'SG'),
205
+ array( "country" => 'Sint Maarten (Dutch part)', "code" => 'SX'),
206
+ array( "country" => 'Slovakia', "code" => 'SK'),
207
+ array( "country" => 'Slovenia', "code" => 'SI'),
208
+ array( "country" => 'Solomon Islands', "code" => 'SB'),
209
+ array( "country" => 'Somalia', "code" => 'SO'),
210
+ array( "country" => 'South Africa', "code" => 'ZA'),
211
+ array( "country" => 'South Georgia + South Sandwich Isl.', "code" => 'GS'),
212
+ array( "country" => 'Spain', "code" => 'ES'),
213
+ array( "country" => 'Sri Lanka', "code" => 'LK'),
214
+ array( "country" => 'Suriname', "code" => 'SR'),
215
+ array( "country" => 'Svalbard and Jan Mayen', "code" => 'SJ'),
216
+ array( "country" => 'Sweden', "code" => 'SE'),
217
+ array( "country" => 'Switzerland', "code" => 'CH'),
218
+ array( "country" => 'Syrian Arab Republic', "code" => 'SY'),
219
+ array( "country" => 'Taiwan, Province of China', "code" => 'TW'),
220
+ array( "country" => 'Tajikistan', "code" => 'TJ'),
221
+ array( "country" => 'Tanzania, United Republic of', "code" => 'TZ'),
222
+ array( "country" => 'Thailand', "code" => 'TH'),
223
+ array( "country" => 'Timor-Leste', "code" => 'TL'),
224
+ array( "country" => 'Togo', "code" => 'TG'),
225
+ array( "country" => 'Tokelau', "code" => 'TK'),
226
+ array( "country" => 'Tonga', "code" => 'TO'),
227
+ array( "country" => 'Trinidad and Tobago', "code" => 'TT'),
228
+ array( "country" => 'Tunisia', "code" => 'TN'),
229
+ array( "country" => 'Turkey', "code" => 'TR'),
230
+ array( "country" => 'Turkmenistan', "code" => 'TM'),
231
+ array( "country" => 'Turks and Caicos Islands', "code" => 'TC'),
232
+ array( "country" => 'Tuvalu', "code" => 'TV'),
233
+ array( "country" => 'Uganda', "code" => 'UG'),
234
+ array( "country" => 'Ukraine', "code" => 'UA'),
235
+ array( "country" => 'United Arab Emirates', "code" => 'AE'),
236
+ array( "country" => 'United Kingdom', "code" => 'GB'),
237
+ array( "country" => 'United States Minor Outlying Islands', "code" => 'UM'),
238
+ array( "country" => 'United States of America', "code" => 'US'),
239
+ array( "country" => 'Uruguay', "code" => 'UY'),
240
+ array( "country" => 'Uzbekistan', "code" => 'UZ'),
241
+ array( "country" => 'Vanuatu', "code" => 'VU'),
242
+ array( "country" => 'Venezuela (Bolivarian Republic of)', "code" => 'VE'),
243
+ array( "country" => 'Viet Nam', "code" => 'VN'),
244
+ array( "country" => 'Virgin Islands (British)', "code" => 'VG'),
245
+ array( "country" => 'Virgin Islands (U.S.)', "code" => 'VI'),
246
+ array( "country" => 'Wallis and Futuna', "code" => 'WF'),
247
+ array( "country" => 'Western Sahara', "code" => 'EH'),
248
+ array( "country" => 'Yemen', "code" => 'YE'),
249
+ array( "country" => 'Zambia', "code" => 'ZM')
250
+ );
251
+ }
252
+
253
+ function cnb_admin_profile_edit_process_real($nonce, $profile) {
254
+ if( $nonce && wp_verify_nonce( $nonce, 'cnb-profile-edit') ) {
255
+ // If VAT is disabled, ensure the VAT number itself is blanked as well
256
+ if ( $profile['euvatbusiness'] == 0 ) {
257
+ $profile['taxIds'][0]['value'] = '';
258
+ }
259
+ unset( $profile['euvatbusiness'] );
260
+
261
+ return CnbAppRemote::cnb_remote_update_user_info( $profile );
262
+ }
263
+ return null;
264
+ }
265
+
266
+ function cnb_admin_profile_edit_process() {
267
+ global $cnb_slug_base;
268
+ $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
269
+ $profile = filter_input(
270
+ INPUT_POST,
271
+ 'user',
272
+ FILTER_SANITIZE_STRING,
273
+ FILTER_REQUIRE_ARRAY | FILTER_FLAG_NO_ENCODE_QUOTES);
274
+ $result = cnb_admin_profile_edit_process_real($nonce, $profile);
275
+ if($result) {
276
+ // Create notification
277
+ $notification = array();
278
+ $notification[] = new CnbNotice('success', '<p>Your profile has been updated.</p>');
279
+ $transient_id = 'cnb-' . wp_generate_uuid4();
280
+ set_transient( $transient_id, $notification, HOUR_IN_SECONDS );
281
+
282
+ // Redirect
283
+ // Create link
284
+ $url = admin_url( 'admin.php' );
285
+ $redirect_link =
286
+ add_query_arg(
287
+ array(
288
+ 'page' => 'call-now-button-profile',
289
+ 'tid' => $transient_id
290
+ ),
291
+ $url );
292
+ $redirect_url = esc_url_raw( $redirect_link );
293
+ wp_safe_redirect( $redirect_url );
294
+ } else {
295
+ wp_die( __( 'Invalid nonce specified', CNB_NAME), __( 'Error', CNB_NAME), array(
296
+ 'response' => 403,
297
+ 'back_link' => 'admin.php?page=' . $cnb_slug_base . '-profile',
298
+ ) );
299
+ }
300
+
301
+ }
302
+
303
+ /**
304
+ * @param false $modal
305
+ *
306
+ * @return CNB_User|WP_Error
307
+ */
308
+ function cnb_admin_page_profile_edit_render_form($modal = false) {
309
+ $cnb_user = CnbAppRemote::cnb_remote_get_user_info();
310
+ if (is_wp_error($cnb_user)) {
311
+ return $cnb_user;
312
+ }
313
+
314
+ $cnb_user_stripe_verified = isset($cnb_user->taxIds[0]->verification->status) && $cnb_user->taxIds[0]->verification->status === 'verified';
315
+ $cnb_user_stripe_verification_pending = isset($cnb_user->taxIds[0]->verification->status) && $cnb_user->taxIds[0]->verification->status === 'pending';
316
+ ?>
317
+ <form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" class="cnb-container cnb-settings-profile">
318
+ <input type="hidden" name="page" value="call-now-button" />
319
+ <input type="hidden" name="action" value="cnb_profile_edit" />
320
+ <?php wp_nonce_field('cnb-profile-edit') ?>
321
+ <table class="form-table nav-tab-only">
322
+ <tbody>
323
+ <?php if(!$modal) { ?>
324
+ <tr>
325
+ <th colspan="2"><h2>Account owner</h2></th>
326
+ </tr>
327
+ <tr class="cnb_advanced_view">
328
+ <th scope="row"><label for="user_id">ID</label></th>
329
+ <td>
330
+ <code><?php esc_html_e( $cnb_user->id ) ?></code>
331
+ </td>
332
+ </tr>
333
+ <?php } ?>
334
+ <tr>
335
+ <th scope="row"><label for="user_email">Email</label></th>
336
+ <td>
337
+ <input type="text" id="user_email" name="user[email]" value="<?php esc_html_e( $cnb_user->email ) ?>"
338
+ disabled class="regular-text ltr">
339
+ <p class="description">Contact support to change your account email address.</p>
340
+ </td>
341
+ </tr>
342
+
343
+ <tr>
344
+ <th scope="row"><label for="user[name]">Full name<span class="cnb_required">*</span></label></th>
345
+ <td>
346
+ <input type="text" id="user[name]" name="user[name]" value="<?php esc_html_e( $cnb_user->name ) ?>" required="required"
347
+ class="regular-text ltr">
348
+ </td>
349
+ </tr>
350
+
351
+ <tr>
352
+ <th scope="row"><label for="user[companyName]">Company name<span class="cnb_required cnb_vat_companies_show" style="display:none">*</span></label></th>
353
+ <td>
354
+ <input type="text" id="user[companyName]" name="user[companyName]" value="<?php esc_html_e( $cnb_user->companyName ) ?>"
355
+ class="regular-text ltr cnb_vat_companies_required">
356
+ </td>
357
+ </tr>
358
+
359
+ <tr class="cnb_vat_companies_show" style="display:none">
360
+ <th scope="row"><label for="user[address][line1]">Address<span class="cnb_required">*</span></label></th>
361
+ <td>
362
+ <input type="text" id="user[address][line1]" name="user[address][line1]" value="<?php esc_html_e( isset($cnb_user->address) ? $cnb_user->address->line1: '' ) ?>"
363
+ class="regular-text ltr cnb_vat_companies_required cnb_eu_values_only">
364
+ </td>
365
+ </tr>
366
+ <tr class="cnb_vat_companies_show" style="display:none">
367
+ <th scope="row"><label for="user[address][line2]">Building, apartment, etc.</label></th>
368
+ <td>
369
+ <input type="text" id="user[address][line2]" name="user[address][line2]" value="<?php esc_html_e( isset($cnb_user->address) ? $cnb_user->address->line2 : '') ?>"
370
+ class="regular-text ltr cnb_eu_values_only">
371
+ </td>
372
+ </tr>
373
+
374
+ <tr class="cnb_vat_companies_show cnb_us_show" style="display:none">
375
+ <th scope="row"><label for="user[address][postalCode]"><span class="cnb_ie_only" style="display:none">Eircode/</span>Zip/Postal code<span class="cnb_required cnb_us_show cnb_vat_companies_show" style="display:none">*</span></label></th>
376
+ <td>
377
+ <input type="text" id="user[address][postalCode]" name="user[address][postalCode]"
378
+ value="<?php esc_html_e( isset($cnb_user->address) ? $cnb_user->address->postalCode : '' ) ?>"
379
+ class="regular-text ltr cnb_us_required cnb_vat_companies_required cnb_useu_values_only">
380
+ </td>
381
+ </tr>
382
+
383
+ <tr>
384
+ <th scope="row"><label for="user[address][city]">City<span class="cnb_required">*</span></label></th>
385
+ <td>
386
+ <input type="text" id="user[address][city]" name="user[address][city]" value="<?php esc_html_e( isset($cnb_user->address) ? $cnb_user->address->city : '' ) ?>"
387
+ required="required" class="regular-text ltr">
388
+ </td>
389
+ </tr>
390
+
391
+ <tr class="cnb_us_show" style="display:none">
392
+ <th scope="row"><label for="user[address][state]">State<span class="cnb_required">*</span></label></th>
393
+ <td>
394
+ <input type="text" id="user[address][state]" name="user[address][state]" value="<?php esc_html_e( isset($cnb_user->address) ? $cnb_user->address->state : '' ) ?>"
395
+ class="regular-text ltr cnb_us_required cnb_us_values_only">
396
+ </td>
397
+ </tr>
398
+
399
+ <tr>
400
+ <th scope="row"><label for="cnb_profile_country">Country<span class="cnb_required">*</span></label></th>
401
+ <td>
402
+ <label>
403
+ <select id="cnb_profile_country" class="select-menu" name="user[address][country]"
404
+ required="required">
405
+ <option value=""></option>
406
+ <?php
407
+ foreach ( cnb_stripe_get_countries() as $country ) {
408
+ $selected = '';
409
+ if (isset($cnb_user->address)) {
410
+ $selected = $country['code'] === $cnb_user->address->country ? ' selected="selected"' : '';
411
+ }
412
+ echo '<option value="' . $country['code'] . '"' . $selected . '>' . $country['country'] . '</option>' . "\n";
413
+ }
414
+ ?>
415
+ </select>
416
+ </label>
417
+ </td>
418
+ </tr>
419
+
420
+ <tr class="cnb_show_vat_toggle" style="display:none">
421
+ <th scope="row"><label for="cnb-euvatbusiness">VAT registered business?</label></th>
422
+ <td>
423
+ <input type="hidden" name="user[euvatbusiness]" value="0">
424
+ <input id="cnb-euvatbusiness" type="checkbox" name="user[euvatbusiness]" value="1"
425
+ <?php if(!empty($cnb_user->taxIds[0]->value)) { ?>checked="checked"<?php } ?>
426
+ class="regular-text ltr cnb_eu_values_only">
427
+ <label for="cnb-euvatbusiness">Yes</label>
428
+ </td>
429
+ </tr>
430
+
431
+ <tr class="cnb_vat_companies_show" style="display:none">
432
+ <th scope="row"><label for="cnb_profile_vat">VAT number<span class="cnb_required">*</span></label>
433
+ <a href="https://callnowbutton.com/support/vat/" target="_blank" class="cnb-nounderscore">
434
+ <span class="dashicons dashicons-editor-help"></span>
435
+ </a>
436
+ </th>
437
+ <td>
438
+ <input id="cnb_profile_vat" type="text" name="user[taxIds][0][value]"
439
+ value="<?php esc_html_e( isset($cnb_user->taxIds[0]) ? $cnb_user->taxIds[0]->value : '' ) ?>"
440
+ class="regular-text ltr cnb_vat_companies_required cnb_eu_values_only">
441
+ <input id="cnb_user_taxids_type" type="hidden" name="user[taxIds][0][type]" value="eu_vat"
442
+ class="regular-text ltr cnb_vat_companies_required cnb_eu_values_only">
443
+ <p class="description">Required for EU based companies outside the Netherlands that are registered for
444
+ VAT.</p>
445
+ <?php
446
+ if ($cnb_user_stripe_verified) {
447
+ echo '<p class="description"><span class="dashicons dashicons-saved"></span><em>Your VAT number is verified.</em></p>';
448
+ } else if ($cnb_user_stripe_verification_pending) {
449
+ echo '<p class="description"><span class="dashicons dashicons-info"></span><em>Your VAT number is being verified.</em></p>';
450
+ }
451
+ ?>
452
+ </td>
453
+ </tr>
454
+
455
+ <tr><th></th><td><?php submit_button() ?></td></tr>
456
+ </tbody>
457
+ </table>
458
+ </form>
459
+ <?php
460
+ return $cnb_user;
461
+ }
462
+
463
+ function cnb_admin_page_profile_edit_render() {
464
+ add_action('cnb_header_name', 'cnb_add_header_profile_edit');
465
+ do_action('cnb_header');
466
+ cnb_admin_page_profile_edit_render_form();
467
+ do_action('cnb_footer');
468
+ }
src/admin/settings.php CHANGED
@@ -46,12 +46,6 @@ function cnb_settings_disallow_active_without_phone_number($input) {
46
  */
47
  function cnb_settings_options_validate($input) {
48
  $original_settings = get_option('cnb');
49
- // When beta mode is disabled, disable the cloud as well
50
- if (array_key_exists('cloud_beta_enabled', $input) && $input['cloud_beta_enabled'] == 0) {
51
- $input['cloud_enabled'] = 0;
52
- $input['status'] = 'enabled';
53
- delete_option('cnb_cloud_migration_done');
54
- }
55
 
56
  // Since "active" and "cloud_enabled" have been merged into "status", we have to deal with that
57
  if (array_key_exists('status', $input)) {
@@ -100,7 +94,7 @@ function cnb_settings_options_validate($input) {
100
  $updated_options = array_merge($original_settings, $input);
101
 
102
  // If the cloud is enabled, this is a fail-safe to ensure the user ID is set, even if it isn't
103
- // explicitly set by the user YET. (since the whole "cnb[cloud_use_id] input field doesn't exist yet...
104
  if (isset($updated_options['cloud_enabled']) && $updated_options['cloud_enabled'] == 1) {
105
  $cloud_id = CnbAdminCloud::cnb_set_default_option_for_cloud( $updated_options );
106
  // Normally, this returns null, since there is a cnb[cloud_use_id].
@@ -108,6 +102,14 @@ function cnb_settings_options_validate($input) {
108
  $updated_options['cloud_use_id'] = $cloud_id;
109
  }
110
  }
 
 
 
 
 
 
 
 
111
 
112
  // Check for legacy button
113
  $check = cnb_settings_disallow_active_without_phone_number($updated_options);
@@ -133,45 +135,6 @@ function cnb_settings_options_validate($input) {
133
  return $updated_options;
134
  }
135
 
136
- /**
137
- * Only true if beta is in the URL or beta mode is enabled via the options
138
- * @return bool
139
- */
140
- function cnb_is_beta_user_via_url() {
141
- return filter_input( INPUT_GET, 'beta', FILTER_SANITIZE_STRING ) !== null;
142
- }
143
-
144
- /**
145
- * @param $cnb_options array Regular 'cnb' options
146
- *
147
- * @return bool
148
- */
149
- function cnb_is_beta_user_via_options($cnb_options) {
150
- return is_array($cnb_options) && array_key_exists('cloud_beta_enabled', $cnb_options) && $cnb_options['cloud_beta_enabled'] == 1;
151
- }
152
-
153
- /**
154
- * @param $cnb_options array Regular 'cnb' options
155
- *
156
- * @return bool
157
- */
158
- function cnb_is_beta_user_via_url_only($cnb_options) {
159
- $beta_url = cnb_is_beta_user_via_url();
160
- $beta_options = cnb_is_beta_user_via_options($cnb_options);
161
- return $beta_url && !$beta_options;
162
- }
163
- /**
164
- * Only true if beta is in the URL or beta mode is enabled via the options
165
- * @param $cnb_options array Regular 'cnb' options
166
- * @return bool
167
- */
168
- function cnb_is_beta_user($cnb_options) {
169
- // $beta_url = cnb_is_beta_user_via_url();
170
- // $beta_options = cnb_is_beta_user_via_options($cnb_options);
171
- // return $beta_url || $beta_options;
172
- return cnb_is_beta_user_via_options($cnb_options);
173
- }
174
-
175
  function cnb_admin_settings_create_cloud_domain($cnb_user) {
176
  $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
177
  if( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $nonce, 'cnb_create_cloud_domain') ) {
@@ -222,20 +185,30 @@ function cnb_admin_setting_migrate() {
222
  }
223
 
224
  function cnb_admin_settings_page() {
225
- global $cnb_options;
226
 
227
  add_action('cnb_header_name', 'cnb_add_header_settings');
228
 
229
  // Fix for https://github.com/callnowbutton/wp-plugin/issues/263
230
  $cnb_options['cloud_enabled'] = isset($cnb_options['cloud_enabled']) ? $cnb_options['cloud_enabled'] : 0;
231
 
232
- $beta = cnb_is_beta_user($cnb_options);
233
- $beta_tmp = cnb_is_beta_user_via_url_only($cnb_options);
234
- if ($beta_tmp) {
235
- cnb_activate_beta_render_notice();
 
 
 
 
 
 
236
  }
237
 
238
- if ($beta && $cnb_options['cloud_enabled']) {
 
 
 
 
239
  $cnbAppRemote = new CnbAppRemote();
240
  $cnb_user = CnbAppRemote::cnb_remote_get_user_info();
241
 
@@ -246,65 +219,51 @@ function cnb_admin_settings_page() {
246
  $cnb_clean_site_url = $cnbAppRemote->cnb_clean_site_url();
247
  CnbDomain::setSaneDefault($cnb_cloud_domain);
248
  }
249
-
250
- // Set "cloud_use_id" to the user if "cloud_use_id" has not been set yet
251
- if ( ! array_key_exists( 'cloud_use_id', $cnb_options ) ) {
252
- $cnb_options['cloud_use_id'] = 0;
253
- if ( ! ( $cnb_user instanceof WP_Error ) ) {
254
- $cnb_options['cloud_use_id'] = $cnb_user->id;
255
- }
256
- }
257
- }
258
-
259
- // If beta is not enabled, there are actually no "advanced" tab, so we reset to "basic_options"
260
- $active_advanced_tab = cnb_is_active_tab('advanced_options');
261
- if (!$beta && !empty($active_advanced_tab)) {
262
- $_GET['tab'] = 'basic_options';
263
  }
264
 
265
  do_action('cnb_header');
266
- ?>
267
-
268
- <?php
269
  $show_advanced_view_only = array_key_exists('advanced_view', $cnb_options) && $cnb_options['advanced_view'] === 1;
270
- if ($show_advanced_view_only) {
271
- echo '<script type="text/javascript">show_advanced_view_only_set=1</script>';
272
- }
273
  ?>
 
 
 
274
 
275
  <h2 class="nav-tab-wrapper">
276
  <a href="<?php echo cnb_settings_create_tab_url('basic_options') ?>"
277
  class="nav-tab <?php echo cnb_is_active_tab('basic_options') ?>">General</a>
278
- <?php if ($cnb_options['status'] === 'cloud') { ?>
279
  <a href="<?php echo cnb_settings_create_tab_url('account_options') ?>"
280
  class="nav-tab <?php echo cnb_is_active_tab('account_options') ?>">Account</a>
281
- <?php } ?>
282
- <?php if ($beta) { ?>
283
  <a href="<?php echo cnb_settings_create_tab_url('advanced_options') ?>"
284
  class="nav-tab <?php echo cnb_is_active_tab('advanced_options') ?>">Advanced</a>
285
- <?php } ?>
286
  </h2>
287
  <form method="post" action="<?php echo esc_url( admin_url('options.php') ); ?>" class="cnb-container">
288
  <?php settings_fields('cnb_options'); ?>
289
  <table class="form-table <?php echo cnb_is_active_tab('basic_options'); ?>">
290
- <?php if ($beta) { ?>
291
  <tr><th colspan="2"></th></tr>
292
  <tr>
293
- <th scope="row">Account type</th>
 
 
294
  <td>
295
  <div class="cnb-radio-item">
296
  <input type="radio" name="cnb[cloud_enabled]" id="cnb_cloud_disabled" value="0" <?php checked('0', $cnb_options['cloud_enabled']); ?>>
297
  <label for="cnb_cloud_disabled">Normal</label>
298
- <p class="description">One call button for your website.</p>
299
  </div>
300
  <div class="cnb-radio-item">
301
  <input type="radio" name="cnb[cloud_enabled]" id="cnb_cloud_enabled" value="1" <?php checked('1', $cnb_options['cloud_enabled']); ?>>
302
- <label for="cnb_cloud_enabled">Cloud</label>
303
- <p class="description">Unlimited buttons for your website for calls, emails, WhatsApp, URLs and locations. Also provides a button scheduler and better page targeting.</p>
 
 
 
 
 
304
  </div>
305
  </td>
306
  </tr>
307
- <?php } ?>
308
  <?php if ($cnb_options['status'] !== 'cloud') { ?>
309
  <tr>
310
  <th colspan="2"><h2>Tracking</h2></th>
@@ -339,7 +298,7 @@ function cnb_admin_settings_page() {
339
  cnb_admin_page_domain_edit_render_form_button_display($cnb_cloud_domain);
340
  } ?>
341
  </table>
342
- <?php if ($beta && $cnb_options['status'] === 'cloud') { ?>
343
  <table class="form-table <?php echo cnb_is_active_tab('account_options'); ?>">
344
  <tr><th colspan="2"></th></tr>
345
  <tr>
@@ -348,7 +307,7 @@ function cnb_admin_settings_page() {
348
  <?php if ($cnb_user instanceof WP_Error || $show_advanced_view_only) { ?>
349
  <label><input type="text" class="regular-text" name="cnb[api_key]" id="cnb_api_key"
350
  placeholder="e.g. b52c3f83-38dc-4493-bc90-642da5be7e39"/></label>
351
- <?php if ($cnb_user instanceof WP_Error) { ?><p class="description">Get you key at <a href="<?php echo CNB_WEBSITE?>"><?php echo CNB_WEBSITE?></a></p><?php } ?>
352
  <?php } ?>
353
  <?php if (isset($cnb_options['api_key']) && !is_wp_error($cnb_user)) { ?><p class="description"><span class="dashicons dashicons-saved"></span>Your key is set correctly.</p><?php }?>
354
  </td>
@@ -370,19 +329,7 @@ function cnb_admin_settings_page() {
370
  <?php } ?>
371
  </table>
372
  <?php } ?>
373
- <?php if ($beta) { ?>
374
  <table class="form-table <?php echo cnb_is_active_tab('advanced_options'); ?>">
375
- <tr><th colspan="2"></th></tr>
376
- <tr>
377
- <th>Beta mode</th>
378
- <td><label>
379
- <input type="hidden" name="cnb[cloud_beta_enabled]" value="0" />
380
- <input id="beta" type="checkbox" name="cnb[cloud_beta_enabled]" value="1" <?php checked('1', $beta); ?> />
381
- <label title="Enabled" for="beta">Enabled</label>
382
- </label>
383
- <p class="description">You can stop being a beta user and return to the original button at any time</p>
384
- </td>
385
- </tr>
386
  <?php if(isset($cnb_cloud_domain) && !($cnb_cloud_domain instanceof WP_Error) && $cnb_options['status'] === 'cloud') {
387
  ?>
388
  <tr>
@@ -395,27 +342,31 @@ function cnb_admin_settings_page() {
395
  <th colspan="2"><h2>For power users</h2></th>
396
  </tr>
397
  <tr class="when-cloud-enabled cnb_advanced_view">
398
- <th>Advanced view</th>
399
  <td>
400
  <input type="hidden" name="cnb[advanced_view]" value="0" />
401
- <input id="cnb-advanced-view" type="checkbox" name="cnb[advanced_view]" value="1" <?php checked('1', $cnb_options['advanced_view']); ?> />
402
- <label for="cnb-advanced-view">Enable</label>
 
 
403
  <p class="description">For power users only.</p>
404
  </td>
405
  </tr>
406
  <?php if ($cnb_options['status'] === 'cloud') { ?>
407
  <tr class="cnb_advanced_view">
408
- <th>Show traces</th>
409
  <td>
410
  <input type="hidden" name="cnb[footer_show_traces]" value="0" />
411
- <input id="cnb-show-traces" type="checkbox" name="cnb[footer_show_traces]" value="1" <?php checked('1', $cnb_options['footer_show_traces']); ?> />
412
- <label for="cnb-show-traces">Enable</label>
 
 
413
  <p class="description">Display API calls and timings in the footer.</p>
414
  </td>
415
  </tr>
416
  <?php if (!($cnb_user instanceof WP_Error) && isset($cnb_cloud_domain) && $cnb_options['status'] === 'cloud') { ?>
417
  <tr class="when-cloud-enabled cnb_advanced_view">
418
- <th scope="row">Domain</th>
419
  <td>
420
  <div>
421
  <p>Your domain: <strong><?php esc_html_e($cnb_clean_site_url) ?></strong></p>
@@ -425,7 +376,8 @@ function cnb_admin_settings_page() {
425
  <?php } else { ?>
426
  <p class="description">Your domain <strong><?php esc_html_e($cnb_cloud_domain->name) ?></strong> is connected with ID <code><?php esc_html_e($cnb_cloud_domain->id) ?></code></p>
427
  <?php }?>
428
- <label><select name="cnb[cloud_use_id]">
 
429
 
430
  <optgroup label="Account-wide">
431
  <option
@@ -447,23 +399,26 @@ function cnb_admin_settings_page() {
447
  </optgroup>
448
  </select></label>
449
  <p class="description">The current value is <code><?php esc_html_e($cnb_options['cloud_use_id']) ?></code></p>
 
450
  </div>
451
  </td>
452
  </tr>
453
  <?php } ?>
454
  <tr class="when-cloud-enabled cnb_advanced_view">
455
- <th>Show all buttons</th>
456
  <td>
457
  <input type="hidden" name="cnb[show_all_buttons_for_domain]" value="0" />
458
- <input id="cnb-all-domains" type="checkbox" name="cnb[show_all_buttons_for_domain]" value="1" <?php checked('1', $cnb_options['show_all_buttons_for_domain']); ?> />
459
- <label for="cnb-all-domains">Enable</label>
 
 
460
  <p class="description">When checked, the "All Buttons" overview shows all buttons for this account, not just for the current domain.</p>
461
  </td>
462
  </tr>
463
  <tr class="when-cloud-enabled cnb_advanced_view">
464
- <th>API endpoint</th>
465
  <td><label>
466
- <input type="text" name="cnb[api_base]" class="regular-text"
467
  value="<?php echo CnbAppRemote::cnb_get_api_base() ?>" />
468
  </label>
469
  <p class="description">The API endpoint to use to communicate with the CallNowButton Cloud service.<br />
@@ -472,20 +427,61 @@ function cnb_admin_settings_page() {
472
  </td>
473
  </tr>
474
  <tr class="cnb_advanced_view">
475
- <th>API caching</th>
476
  <td>
477
  <input type="hidden" name="cnb[api_caching]" value="0" />
478
- <input id="cnb-api-caching" type="checkbox" name="cnb[api_caching]" value="1" <?php checked('1', $cnb_options['api_caching']); ?> />
479
- <label for="cnb-api-caching">Enable</label>
480
- <p class="description">Cache API requests (using Wordpress transients)</p>
 
 
481
  </td>
482
  </tr>
483
- <?php } // end of beta check ?>
484
  </table>
485
- <?php } ?>
486
  <input type="hidden" name="cnb[version]" value="<?php echo CNB_VERSION; ?>"/>
487
- <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>"/></p>
488
  </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
 
490
  <?php do_action('cnb_footer'); ?>
491
  <?php }
46
  */
47
  function cnb_settings_options_validate($input) {
48
  $original_settings = get_option('cnb');
 
 
 
 
 
 
49
 
50
  // Since "active" and "cloud_enabled" have been merged into "status", we have to deal with that
51
  if (array_key_exists('status', $input)) {
94
  $updated_options = array_merge($original_settings, $input);
95
 
96
  // If the cloud is enabled, this is a fail-safe to ensure the user ID is set, even if it isn't
97
+ // explicitly set by the user YET. Since the whole "cnb[cloud_use_id]" input field doesn't exist yet...
98
  if (isset($updated_options['cloud_enabled']) && $updated_options['cloud_enabled'] == 1) {
99
  $cloud_id = CnbAdminCloud::cnb_set_default_option_for_cloud( $updated_options );
100
  // Normally, this returns null, since there is a cnb[cloud_use_id].
102
  $updated_options['cloud_use_id'] = $cloud_id;
103
  }
104
  }
105
+ if (!empty($original_settings['api_key']) && !empty($input['api_key']) && $original_settings['api_key'] !== $input['api_key']) {
106
+ unset($updated_options['cloud_use_id']);
107
+ $cloud_id = CnbAdminCloud::cnb_set_default_option_for_cloud( $updated_options );
108
+ // Normally, this returns null, since there is a cnb[cloud_use_id].
109
+ if ($cloud_id != null) {
110
+ $updated_options['cloud_use_id'] = $cloud_id;
111
+ }
112
+ }
113
 
114
  // Check for legacy button
115
  $check = cnb_settings_disallow_active_without_phone_number($updated_options);
135
  return $updated_options;
136
  }
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  function cnb_admin_settings_create_cloud_domain($cnb_user) {
139
  $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
140
  if( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $nonce, 'cnb_create_cloud_domain') ) {
185
  }
186
 
187
  function cnb_admin_settings_page() {
188
+ global $cnb_options, $use_cloud;
189
 
190
  add_action('cnb_header_name', 'cnb_add_header_settings');
191
 
192
  // Fix for https://github.com/callnowbutton/wp-plugin/issues/263
193
  $cnb_options['cloud_enabled'] = isset($cnb_options['cloud_enabled']) ? $cnb_options['cloud_enabled'] : 0;
194
 
195
+ // Parse special header
196
+ $api_key = filter_input(INPUT_GET, 'api_key', FILTER_SANITIZE_STRING);
197
+ if (empty($cnb_options['api_key']) && $api_key) {
198
+ $options = array();
199
+ // This also enabled the cloud
200
+ $options['cloud_enabled'] = 1;
201
+ $options['api_key'] = $api_key;
202
+ update_option('cnb', $options);
203
+ $reload_url = cnb_settings_create_tab_url('basic_options');
204
+ echo '<script>window.location.href = "'.$reload_url.'";</script>';
205
  }
206
 
207
+ $cnb_cloud_domain = null;
208
+ $cnb_cloud_domains = array();
209
+ $cnb_clean_site_url = null;
210
+ $cnb_user = null;
211
+ if ($cnb_options['cloud_enabled']) {
212
  $cnbAppRemote = new CnbAppRemote();
213
  $cnb_user = CnbAppRemote::cnb_remote_get_user_info();
214
 
219
  $cnb_clean_site_url = $cnbAppRemote->cnb_clean_site_url();
220
  CnbDomain::setSaneDefault($cnb_cloud_domain);
221
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  }
223
 
224
  do_action('cnb_header');
 
 
 
225
  $show_advanced_view_only = array_key_exists('advanced_view', $cnb_options) && $cnb_options['advanced_view'] === 1;
 
 
 
226
  ?>
227
+ <div class="cnb-two-column-section">
228
+ <div class="cnb-body-column">
229
+ <div class="cnb-body-content">
230
 
231
  <h2 class="nav-tab-wrapper">
232
  <a href="<?php echo cnb_settings_create_tab_url('basic_options') ?>"
233
  class="nav-tab <?php echo cnb_is_active_tab('basic_options') ?>">General</a>
234
+ <?php if ($use_cloud) { ?>
235
  <a href="<?php echo cnb_settings_create_tab_url('account_options') ?>"
236
  class="nav-tab <?php echo cnb_is_active_tab('account_options') ?>">Account</a>
 
 
237
  <a href="<?php echo cnb_settings_create_tab_url('advanced_options') ?>"
238
  class="nav-tab <?php echo cnb_is_active_tab('advanced_options') ?>">Advanced</a>
239
+ <?php } ?>
240
  </h2>
241
  <form method="post" action="<?php echo esc_url( admin_url('options.php') ); ?>" class="cnb-container">
242
  <?php settings_fields('cnb_options'); ?>
243
  <table class="form-table <?php echo cnb_is_active_tab('basic_options'); ?>">
 
244
  <tr><th colspan="2"></th></tr>
245
  <tr>
246
+ <th scope="row">Plugin type<a href="<?php echo cnb_legacy_upgrade_page(); ?>" class="cnb-nounderscore">
247
+ <span class="dashicons dashicons-editor-help"></span>
248
+ </a></th>
249
  <td>
250
  <div class="cnb-radio-item">
251
  <input type="radio" name="cnb[cloud_enabled]" id="cnb_cloud_disabled" value="0" <?php checked('0', $cnb_options['cloud_enabled']); ?>>
252
  <label for="cnb_cloud_disabled">Normal</label>
253
+
254
  </div>
255
  <div class="cnb-radio-item">
256
  <input type="radio" name="cnb[cloud_enabled]" id="cnb_cloud_enabled" value="1" <?php checked('1', $cnb_options['cloud_enabled']); ?>>
257
+ <label for="cnb_cloud_enabled">Premium</label>
258
+ <?php if ($cnb_options['cloud_enabled'] == 0) { ?>
259
+ <p class="description">Paid and free options. <a href="<?php echo cnb_legacy_upgrade_page(); ?>">Learn more</a></p>
260
+ <?php } ?>
261
+ <?php if ($cnb_options['cloud_enabled'] == 1 && isset($cnb_cloud_domain) && !is_wp_error($cnb_cloud_domain) && $cnb_cloud_domain->type !== 'PRO') { ?>
262
+ <p class="description">Paid and free options. <a href="<?php echo get_cnb_domain_upgrade($cnb_cloud_domain); ?>">Learn more</a></p>
263
+ <?php } ?>
264
  </div>
265
  </td>
266
  </tr>
 
267
  <?php if ($cnb_options['status'] !== 'cloud') { ?>
268
  <tr>
269
  <th colspan="2"><h2>Tracking</h2></th>
298
  cnb_admin_page_domain_edit_render_form_button_display($cnb_cloud_domain);
299
  } ?>
300
  </table>
301
+ <?php if ($cnb_options['status'] === 'cloud') { ?>
302
  <table class="form-table <?php echo cnb_is_active_tab('account_options'); ?>">
303
  <tr><th colspan="2"></th></tr>
304
  <tr>
307
  <?php if ($cnb_user instanceof WP_Error || $show_advanced_view_only) { ?>
308
  <label><input type="text" class="regular-text" name="cnb[api_key]" id="cnb_api_key"
309
  placeholder="e.g. b52c3f83-38dc-4493-bc90-642da5be7e39"/></label>
310
+ <?php if ($cnb_user instanceof WP_Error) { ?><p class="description">Get your API key at <a href="<?php echo CNB_WEBSITE?>"><?php echo CNB_WEBSITE?></a></p><?php } ?>
311
  <?php } ?>
312
  <?php if (isset($cnb_options['api_key']) && !is_wp_error($cnb_user)) { ?><p class="description"><span class="dashicons dashicons-saved"></span>Your key is set correctly.</p><?php }?>
313
  </td>
329
  <?php } ?>
330
  </table>
331
  <?php } ?>
 
332
  <table class="form-table <?php echo cnb_is_active_tab('advanced_options'); ?>">
 
 
 
 
 
 
 
 
 
 
 
333
  <?php if(isset($cnb_cloud_domain) && !($cnb_cloud_domain instanceof WP_Error) && $cnb_options['status'] === 'cloud') {
334
  ?>
335
  <tr>
342
  <th colspan="2"><h2>For power users</h2></th>
343
  </tr>
344
  <tr class="when-cloud-enabled cnb_advanced_view">
345
+ <th><label for="cnb-advanced-view">Advanced view</label></th>
346
  <td>
347
  <input type="hidden" name="cnb[advanced_view]" value="0" />
348
+ <input id="cnb-advanced-view" class="cnb_toggle_checkbox" type="checkbox" name="cnb[advanced_view]" value="1" <?php checked('1', $cnb_options['advanced_view']); ?> />
349
+ <label for="cnb-advanced-view" class="cnb_toggle_label">Toggle</label>
350
+ <span data-cnb_toggle_state_label="cnb-advanced-view" class="cnb_toggle_state cnb_toggle_false">Disabled</span>
351
+ <span data-cnb_toggle_state_label="cnb-advanced-view" class="cnb_toggle_state cnb_toggle_true">Enabled</span>
352
  <p class="description">For power users only.</p>
353
  </td>
354
  </tr>
355
  <?php if ($cnb_options['status'] === 'cloud') { ?>
356
  <tr class="cnb_advanced_view">
357
+ <th><label for="cnb-show-traces">Show traces</label></th>
358
  <td>
359
  <input type="hidden" name="cnb[footer_show_traces]" value="0" />
360
+ <input id="cnb-show-traces" class="cnb_toggle_checkbox" type="checkbox" name="cnb[footer_show_traces]" value="1" <?php checked('1', $cnb_options['footer_show_traces']); ?> />
361
+ <label for="cnb-show-traces" class="cnb_toggle_label">Toggle</label>
362
+ <span data-cnb_toggle_state_label="cnb-show-traces" class="cnb_toggle_state cnb_toggle_false">Disabled</span>
363
+ <span data-cnb_toggle_state_label="cnb-show-traces" class="cnb_toggle_state cnb_toggle_true">Enabled</span>
364
  <p class="description">Display API calls and timings in the footer.</p>
365
  </td>
366
  </tr>
367
  <?php if (!($cnb_user instanceof WP_Error) && isset($cnb_cloud_domain) && $cnb_options['status'] === 'cloud') { ?>
368
  <tr class="when-cloud-enabled cnb_advanced_view">
369
+ <th scope="row"><label for="cnb[cloud_use_id]">Domain</label></th>
370
  <td>
371
  <div>
372
  <p>Your domain: <strong><?php esc_html_e($cnb_clean_site_url) ?></strong></p>
376
  <?php } else { ?>
377
  <p class="description">Your domain <strong><?php esc_html_e($cnb_cloud_domain->name) ?></strong> is connected with ID <code><?php esc_html_e($cnb_cloud_domain->id) ?></code></p>
378
  <?php }?>
379
+ <?php if (isset($cnb_options['cloud_use_id'])) { ?>
380
+ <label><select name="cnb[cloud_use_id]" id="cnb[cloud_use_id]">
381
 
382
  <optgroup label="Account-wide">
383
  <option
399
  </optgroup>
400
  </select></label>
401
  <p class="description">The current value is <code><?php esc_html_e($cnb_options['cloud_use_id']) ?></code></p>
402
+ <?php } ?>
403
  </div>
404
  </td>
405
  </tr>
406
  <?php } ?>
407
  <tr class="when-cloud-enabled cnb_advanced_view">
408
+ <th><label for="cnb-all-domains">Show all buttons</label></th>
409
  <td>
410
  <input type="hidden" name="cnb[show_all_buttons_for_domain]" value="0" />
411
+ <input id="cnb-all-domains" class="cnb_toggle_checkbox" type="checkbox" name="cnb[show_all_buttons_for_domain]" value="1" <?php checked('1', $cnb_options['show_all_buttons_for_domain']); ?> />
412
+ <label for="cnb-all-domains" class="cnb_toggle_label">Toggle</label>
413
+ <span data-cnb_toggle_state_label="cnb-all-domains" class="cnb_toggle_state cnb_toggle_false">Disabled</span>
414
+ <span data-cnb_toggle_state_label="cnb-all-domains" class="cnb_toggle_state cnb_toggle_true">Enabled</span>
415
  <p class="description">When checked, the "All Buttons" overview shows all buttons for this account, not just for the current domain.</p>
416
  </td>
417
  </tr>
418
  <tr class="when-cloud-enabled cnb_advanced_view">
419
+ <th><label for="cnb[api_base]">API endpoint</label></th>
420
  <td><label>
421
+ <input type="text" id="cnb[api_base]" name="cnb[api_base]" class="regular-text"
422
  value="<?php echo CnbAppRemote::cnb_get_api_base() ?>" />
423
  </label>
424
  <p class="description">The API endpoint to use to communicate with the CallNowButton Cloud service.<br />
427
  </td>
428
  </tr>
429
  <tr class="cnb_advanced_view">
430
+ <th><label for="cnb-api-caching">API caching</label></th>
431
  <td>
432
  <input type="hidden" name="cnb[api_caching]" value="0" />
433
+ <input id="cnb-api-caching" class="cnb_toggle_checkbox" type="checkbox" name="cnb[api_caching]" value="1" <?php checked('1', $cnb_options['api_caching']); ?> />
434
+ <label for="cnb-api-caching" class="cnb_toggle_label">Toggle</label>
435
+ <span data-cnb_toggle_state_label="cnb-api-caching" class="cnb_toggle_state cnb_toggle_false">Disabled</span>
436
+ <span data-cnb_toggle_state_label="cnb-api-caching" class="cnb_toggle_state cnb_toggle_true">Enabled</span>
437
+ <p class="description">Cache API requests (using WordPress transients)</p>
438
  </td>
439
  </tr>
440
+ <?php } // end of cloud check ?>
441
  </table>
 
442
  <input type="hidden" name="cnb[version]" value="<?php echo CNB_VERSION; ?>"/>
443
+ <?php submit_button(); ?>
444
  </form>
445
+ </div>
446
+ </div>
447
+ <div class="cnb-postbox-container cnb-side-column">
448
+ <?php if(!$use_cloud) {
449
+ cnb_promobox(
450
+ 'blue',
451
+ 'More buttons!',
452
+ 'Switch to Premium to enable lots of buttons. Coupled with advanced page selection options you can get really creative.</p>
453
+ <p>If you need more phone numbers on a single page, then the Multibutton&trade; and the Buttonbar&trade; give you exactly what you need.</p>',
454
+ 'cloud',
455
+ '<strong>Give it a try!</strong>',
456
+ 'Enable Premium',
457
+ get_cnb_wordpress_upgrade_link()
458
+ );
459
+ cnb_promobox(
460
+ 'grey',
461
+ 'Go Premium for free',
462
+ 'Premium comes in 2 versions: <em>Free</em> and <em>Paid</em>.</p>
463
+ <p>Both plans give you access to <strong>all features</strong>.</p>
464
+ <p>The only difference is that the Free version shows <em>Powered by Call Now Button</em> next to your buttons.</p>',
465
+ 'info-outline',
466
+ '',
467
+ 'Learn more',
468
+ cnb_legacy_upgrade_page()
469
+ );
470
+ } ?>
471
+ <?php if($use_cloud && isset($cnb_cloud_domain) && !is_wp_error($cnb_cloud_domain) && $cnb_cloud_domain->type !== 'PRO') {
472
+ cnb_promobox(
473
+ 'blue',
474
+ 'Introduction offer',
475
+ '<p>Remove the <em>powered by</em> branding from your buttons!</p>
476
+ <p>Benefit from our introductory offer and enjoy unlimited access to all features without our branding.</p>',
477
+ 'flag',
478
+ '<strong>&euro;2.49/$2.99 per month</strong>',
479
+ 'Upgrade',
480
+ get_cnb_domain_upgrade($cnb_cloud_domain)
481
+ );
482
+ } ?>
483
+ </div>
484
+ </div>
485
 
486
  <?php do_action('cnb_footer'); ?>
487
  <?php }
src/autoload.php CHANGED
@@ -12,10 +12,21 @@ spl_autoload_register(
12
  'cnb_button_list_table' => '/admin/button-overview.php',
13
  'cnb_condition_list_table' => '/admin/condition-overview.php',
14
  'cnb_domain_list_table' => '/admin/domain-overview.php',
 
 
15
  'cnbadmincloud' => '/admin/api/CnbAdminCloud.php',
 
16
  'cnbappremote' => '/admin/api/CnbAppRemote.php',
 
17
  'cnbappremotepayment' => '/admin/api/CnbAppRemotePayment.php',
 
 
 
 
 
18
  'cnbget' => '/admin/api/CnbAppRemote.php',
 
 
19
  'remotetrace' => '/admin/api/RemoteTrace.php',
20
  'remotetracer' => '/admin/api/RemoteTracer.php'
21
  );
12
  'cnb_button_list_table' => '/admin/button-overview.php',
13
  'cnb_condition_list_table' => '/admin/condition-overview.php',
14
  'cnb_domain_list_table' => '/admin/domain-overview.php',
15
+ 'cnbaction' => '/admin/models/CnbAction.class.php',
16
+ 'cnbactionproperties' => '/admin/models/CnbAction.class.php',
17
  'cnbadmincloud' => '/admin/api/CnbAdminCloud.php',
18
+ 'cnbadminnotices' => '/utils/CnbAdminNotices.class.php',
19
  'cnbappremote' => '/admin/api/CnbAppRemote.php',
20
+ 'cnbappremotehelper' => '/admin/api/CnbAppRemote.php',
21
  'cnbappremotepayment' => '/admin/api/CnbAppRemotePayment.php',
22
+ 'cnbbutton' => '/admin/models/CnbButton.class.php',
23
+ 'cnbbuttonoptions' => '/admin/models/CnbButton.class.php',
24
+ 'cnbcondition' => '/admin/models/CnbCondition.class.php',
25
+ 'cnbdomain' => '/admin/models/CnbDomain.class.php',
26
+ 'cnbdomainproperties' => '/admin/models/CnbDomain.class.php',
27
  'cnbget' => '/admin/api/CnbAppRemote.php',
28
+ 'cnbnotice' => '/utils/CnbAdminNotices.class.php',
29
+ 'cnbnotices' => '/utils/CnbAdminNotices.class.php',
30
  'remotetrace' => '/admin/api/RemoteTrace.php',
31
  'remotetracer' => '/admin/api/RemoteTracer.php'
32
  );
src/call-now-button.php CHANGED
@@ -22,6 +22,8 @@ $cnb_options['api_caching'] = isset($cnb_options['api_caching']) && $cnb_options
22
 
23
  $plugin_title = apply_filters('cnb_plugin_title', CNB_NAME);
24
  $cnb_cloud_hosting = isset($cnb_options['cloud_enabled']) && $cnb_options['cloud_enabled'] == 1;
 
 
25
 
26
  // Used by settings
27
  $cnb_options['status'] = $cnb_cloud_hosting ? 'cloud' : ($cnb_options['active'] ? 'enabled' : 'disabled');
@@ -31,6 +33,7 @@ $cnb_options['status'] = $cnb_cloud_hosting ? 'cloud' : ($cnb_options['active']
31
  */
32
  function cnb_admin_styling() {
33
  wp_enqueue_style('cnb_styling');
 
34
  }
35
 
36
  function cnb_admin_button_overview() {
@@ -68,6 +71,16 @@ function cnb_admin_page_legacy_edit() {
68
  cnb_admin_page_legacy_edit_render();
69
  }
70
 
 
 
 
 
 
 
 
 
 
 
71
  /**
72
  * Adds the plugin to the options menu
73
  */
@@ -76,7 +89,8 @@ function cnb_register_admin_pages() {
76
 
77
  $menu_page_function = $cnb_cloud_hosting ? 'cnb_admin_button_overview' : 'cnb_admin_page_legacy_edit';
78
 
79
- $menu_page_title = $cnb_cloud_hosting ? 'Buttons' : 'Call Now Button';
 
80
  $menu_page_position = $cnb_cloud_hosting ? 30 : 66;
81
 
82
  // Oldest WordPress only has "smartphone", no "phone" (this is added in a later version)
@@ -116,6 +130,11 @@ function cnb_register_admin_pages() {
116
  // Apikey overview
117
  $apikey_overview = add_submenu_page($cnb_slug_base, $plugin_title, 'API Keys', 'manage_options', $cnb_slug_base . '-apikeys', 'cnb_admin_page_apikey_overview');
118
  add_action('admin_print_styles-' . $apikey_overview, 'cnb_admin_styling');
 
 
 
 
 
119
  } else {
120
  // Fake out Action overview
121
  if (isset($_GET['page']) && $_GET['page'] === 'call-now-button-actions' && $_GET['action']) {
@@ -132,6 +151,9 @@ function cnb_register_admin_pages() {
132
  // Legacy edit
133
  $legacy_edit = add_submenu_page( $cnb_slug_base, $plugin_title, 'My button', 'manage_options', $cnb_slug_base, 'cnb_admin_page_legacy_edit' );
134
  add_action( 'admin_print_styles-' . $legacy_edit, 'cnb_admin_styling' );
 
 
 
135
  }
136
 
137
  // Settings pages
@@ -327,6 +349,16 @@ function cnb_admin_create_apikey() {
327
 
328
  add_action( 'admin_post_cnb_create_apikey', 'cnb_admin_create_apikey' );
329
 
 
 
 
 
 
 
 
 
 
 
330
  /**
331
  * Called when the Settings page is migrating from Legacy to the cloud
332
  */
@@ -350,9 +382,9 @@ $adminNotices = CnbAdminNotices::get_instance();
350
  // Render the Frontend
351
  if (!is_admin() && isButtonActive($cnb_options)) {
352
  $cnb_has_text = ($cnb_options['text'] == '') ? false : true;
353
- $cnb_is_classic = isset($cnb_options['classic']) && $cnb_options['classic'] == 1 && !$cnb_has_text;
354
 
355
- $renderer = $cnb_cloud_hosting ? 'cloud' : ($cnb_is_classic ? 'classic' : 'modern');
356
 
357
  require_once dirname( __FILE__ ) . "/renderers/$renderer/wp_head.php";
358
  require_once dirname( __FILE__ ) . "/renderers/$renderer/wp_foot.php";
22
 
23
  $plugin_title = apply_filters('cnb_plugin_title', CNB_NAME);
24
  $cnb_cloud_hosting = isset($cnb_options['cloud_enabled']) && $cnb_options['cloud_enabled'] == 1;
25
+ $cloud_use_id = isset($cnb_options['cloud_use_id']) && !empty($cnb_options['cloud_use_id']) ? $cnb_options['cloud_use_id'] : 0;
26
+ $use_cloud = $cnb_cloud_hosting && $cloud_use_id !== 0;
27
 
28
  // Used by settings
29
  $cnb_options['status'] = $cnb_cloud_hosting ? 'cloud' : ($cnb_options['active'] ? 'enabled' : 'disabled');
33
  */
34
  function cnb_admin_styling() {
35
  wp_enqueue_style('cnb_styling');
36
+ wp_enqueue_style('wp-components');
37
  }
38
 
39
  function cnb_admin_button_overview() {
71
  cnb_admin_page_legacy_edit_render();
72
  }
73
 
74
+ function cnb_admin_page_legacy_upgrade() {
75
+ require_once dirname( __FILE__ ) . '/admin/legacy-upgrade.php';
76
+ cnb_admin_page_legacy_upgrade_render();
77
+ }
78
+
79
+ function cnb_admin_page_profile_edit() {
80
+ require_once dirname( __FILE__ ) . '/admin/settings-profile.php';
81
+ cnb_admin_page_profile_edit_render();
82
+ }
83
+
84
  /**
85
  * Adds the plugin to the options menu
86
  */
89
 
90
  $menu_page_function = $cnb_cloud_hosting ? 'cnb_admin_button_overview' : 'cnb_admin_page_legacy_edit';
91
 
92
+ // $menu_page_title = $cnb_cloud_hosting ? 'Buttons' : 'Call Now Button';
93
+ $menu_page_title = 'Call Now Button';
94
  $menu_page_position = $cnb_cloud_hosting ? 30 : 66;
95
 
96
  // Oldest WordPress only has "smartphone", no "phone" (this is added in a later version)
130
  // Apikey overview
131
  $apikey_overview = add_submenu_page($cnb_slug_base, $plugin_title, 'API Keys', 'manage_options', $cnb_slug_base . '-apikeys', 'cnb_admin_page_apikey_overview');
132
  add_action('admin_print_styles-' . $apikey_overview, 'cnb_admin_styling');
133
+
134
+ // Profile edit
135
+ $profile = add_submenu_page($cnb_slug_base, $plugin_title, 'Profile', 'manage_options', $cnb_slug_base . '-profile', 'cnb_admin_page_profile_edit');
136
+ add_action('admin_print_styles-' . $profile, 'cnb_admin_styling');
137
+
138
  } else {
139
  // Fake out Action overview
140
  if (isset($_GET['page']) && $_GET['page'] === 'call-now-button-actions' && $_GET['action']) {
151
  // Legacy edit
152
  $legacy_edit = add_submenu_page( $cnb_slug_base, $plugin_title, 'My button', 'manage_options', $cnb_slug_base, 'cnb_admin_page_legacy_edit' );
153
  add_action( 'admin_print_styles-' . $legacy_edit, 'cnb_admin_styling' );
154
+
155
+ $legacy_upgrade = add_submenu_page( $cnb_slug_base, $plugin_title, 'Unlock features', 'manage_options', $cnb_slug_base .'-upgrade', 'cnb_admin_page_legacy_upgrade' );
156
+ add_action( 'admin_print_styles-' . $legacy_upgrade, 'cnb_admin_styling' );
157
  }
158
 
159
  // Settings pages
349
 
350
  add_action( 'admin_post_cnb_create_apikey', 'cnb_admin_create_apikey' );
351
 
352
+ /**
353
+ * Called when an API key is created via POST
354
+ */
355
+ function cnb_admin_profile_edit() {
356
+ require_once dirname( __FILE__ ) . '/admin/settings-profile.php';
357
+ cnb_admin_profile_edit_process();
358
+ }
359
+
360
+ add_action( 'admin_post_cnb_profile_edit', 'cnb_admin_profile_edit' );
361
+
362
  /**
363
  * Called when the Settings page is migrating from Legacy to the cloud
364
  */
382
  // Render the Frontend
383
  if (!is_admin() && isButtonActive($cnb_options)) {
384
  $cnb_has_text = ($cnb_options['text'] == '') ? false : true;
385
+ $cnb_is_classic = $cnb_options['classic'] == 1 && !$cnb_has_text;
386
 
387
+ $renderer = $use_cloud ? 'cloud' : ($cnb_is_classic ? 'classic' : 'modern');
388
 
389
  require_once dirname( __FILE__ ) . "/renderers/$renderer/wp_head.php";
390
  require_once dirname( __FILE__ ) . "/renderers/$renderer/wp_foot.php";
src/utils/CnbAdminNotices.class.php CHANGED
@@ -14,6 +14,9 @@ class CnbNotice {
14
  $this->dismiss_option = $dismiss_option;
15
  }
16
 
 
 
 
17
  public $type;
18
  public $message;
19
  public $dismissable;
14
  $this->dismiss_option = $dismiss_option;
15
  }
16
 
17
+ /**
18
+ * @var string|null info, success, warning, error
19
+ */
20
  public $type;
21
  public $message;
22
  public $dismissable;
src/utils/notices.php CHANGED
@@ -26,14 +26,17 @@ function cnb_upgrade_notice($cnb_old_version, $cnb_changelog) {
26
  }
27
 
28
  function cnb_settings_get_account_missing_notice() {
29
- $message = '<h3 class="title">Activate cloud version</h3>
30
- <p>To activate the cloud version of the Call Now Button, you\'ll need an account at
31
- <a href="https://app.callnowbutton.com?utm_source=wp-plugin&utm_medium=referral&utm_campaign=beta_tester&utm_term=sign-up-for-api">https://app.callnowbutton.com</a>, get a unique API key and add it to the field below.</p>
32
- <p>Let\'s go:</p>
 
 
 
33
  <ol>
34
- <li>Create your account on <a href="https://app.callnowbutton.com?utm_source=wp-plugin&utm_medium=referral&utm_campaign=beta_tester&utm_term=sign-up-for-api">https://app.callnowbutton.com</a></li>
35
  <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>
36
- <li>Copy the API key, paste it into the field below and click <strong>Save API key</strong>.</li>
37
  </ol>';
38
  $message .= cnb_settings_api_key_input();
39
 
@@ -42,20 +45,14 @@ function cnb_settings_get_account_missing_notice() {
42
  }
43
 
44
  function cnb_settings_api_key_invalid_notice() {
45
- $message = '<h3 class="title">API key is incorrect</h3>
46
- <p>Your API key seems to be invalid. This might have a few reasons:
47
  <ol>
48
- <li>You didn\'t copy the entire API key (it is case-sensative and should be in the form of a UUID).</li>
49
- <li>
50
- You have deleted your API key (check <a href="https://app.callnowbutton.com/app/profile">your profile</a>).
51
- <ol>
52
- <li>Go to your profile page and click <strong>Create new API key</strong>.</li>
53
- <li>Copy the API key into the "API key" field below</li>
54
- <li>Click "Save API key"</li>
55
- </ol>
56
- </li>
57
- <li>As unlikely as it is, our service might be experiencing issues (check <a href="https://status.callnowbutton.com">our status page</a>).</li>
58
- </ol>';
59
  $message .= cnb_settings_api_key_input();
60
 
61
  $adminNotices = CnbAdminNotices::get_instance();
@@ -66,7 +63,7 @@ function cnb_generic_error_notice($user) {
66
  $message = '<h3 class="title">Something went wrong!</h3>
67
  <p>Something has gone wrong and we do not know why...</p>
68
  <p>As unlikely as it is, our service might be experiencing issues (check <a href="https://status.callnowbutton.com">our status page</a>).</p>
69
- <p>If you think you found a bug, please report it at our <a href="https://wordpress.org/support/plugin/call-now-button/">support forum</a>.';
70
  $message .= CnbAdminCloud::cnb_admin_get_error_message_details($user);
71
 
72
  $adminNotices = CnbAdminNotices::get_instance();
@@ -74,7 +71,9 @@ function cnb_generic_error_notice($user) {
74
  }
75
 
76
  function cnb_settings_api_key_input() {
77
- global $cnb_options;
 
 
78
 
79
  $message = '<form method="post" action="' . esc_url( admin_url('options.php') ) . '" class="cnb-container">';
80
  ob_start();
@@ -85,9 +84,11 @@ function cnb_settings_api_key_input() {
85
  <tr class="when-cloud-enabled">
86
  <th scope="row">API key</th>
87
  <td>
 
 
88
  <input type="text" class="regular-text" name="cnb[api_key]"
89
  placeholder="e.g. b52c3f83-38dc-4493-bc90-642da5be7e39"/>
90
- <input type="submit" class="button-primary" value="' . __('Save API key') . '"/>
91
  </td>
92
  </table>
93
  </form>';
@@ -96,14 +97,13 @@ function cnb_settings_api_key_input() {
96
 
97
  function cnb_settings_get_domain_missing_notice($domain) {
98
  $message = '<h3 class="title">Domain not found yet</h3>
99
- <p>You have enabled Cloud Hosting and are logged in,
100
- but we need to create the domain remotely.</p>
101
  <p>
102
  <form action="' . esc_url( admin_url('admin-post.php') ) . '" method="post">
103
  <input type="hidden" name="page" value="call-now-button-settings" />
104
  <input type="hidden" name="action" value="cnb_create_cloud_domain" />
105
  <input type="hidden" name="_wpnonce" value="' . wp_create_nonce('cnb_create_cloud_domain') .'" />
106
- <input type="submit" value="Create domain" class="button button-secondary" />
107
  </form>
108
  </p>';
109
  $message .= CnbAdminCloud::cnb_admin_get_error_message_details( $domain );
@@ -114,14 +114,14 @@ function cnb_settings_get_domain_missing_notice($domain) {
114
 
115
  function cnb_settings_get_button_missing_notice() {
116
  $message = '<h3 class="title">Creating your first button</h3>
117
- <p>You have enabled Cloud Hosting and have your domain setup,
118
- so now it\'s time to create your first button.</p>
119
- <p>To make it easy, we can migrate your existing button to the Cloud.</p>
120
  <p><form action="'. esc_url( admin_url('admin-post.php') ) .'" method="post">
121
  <input type="hidden" name="page" value="call-now-button-settings" />
122
  <input type="hidden" name="action" value="cnb_migrate_legacy_button" />
123
  <input type="hidden" name="_wpnonce" value="'. wp_create_nonce('cnb_migrate_legacy_button') .'" />
124
- <input type="submit" value="Migrate button" class="button button-secondary" />
125
  </form></p>';
126
 
127
  $notice = new CnbNotice('warning', $message);
@@ -150,7 +150,7 @@ function cnb_api_key_invalid_notice($error) {
150
  $redirect_url = esc_url( $redirect_link );
151
 
152
  $message = '<h3 class="title">API Key invalid</h3>
153
- <p>You have enabled Cloud Hosting, but you need a valid API key from CallNowButtom</p>
154
  <p>Go to <a href="'.$redirect_url.'">Settings</a> for instructions.</p>';
155
  $message .= CnbAdminCloud::cnb_admin_get_error_message_details( $error );
156
 
@@ -200,23 +200,3 @@ function cnb_caching_plugin_warning_notice($caching_plugin_name) {
200
  $adminNotices = CnbAdminNotices::get_instance();
201
  $adminNotices->error($message);
202
  }
203
-
204
- function cnb_activate_beta_render_notice() {
205
- $message = '<form method="post" action="' . esc_url( admin_url('options.php') ) . '" class="cnb-container">';
206
- ob_start();
207
- settings_fields('cnb_options');
208
- $message .= ob_get_clean();
209
- $message .= '<input type="hidden" name="page" value="call-now-button-settings" />
210
- <table>
211
- <tr>
212
- <th scope="row"</th>
213
- <td>
214
- <input type="hidden" name="cnb[cloud_beta_enabled]" value="1" />
215
- <input type="submit" class="button-primary" value="' . __('Activate beta mode') . '"/> For testing new unreleased functionality.
216
- </td>
217
- </table>
218
- </form>';
219
- $adminNotices = CnbAdminNotices::get_instance();
220
- $adminNotices->renderWarning($message);
221
-
222
- }
26
  }
27
 
28
  function cnb_settings_get_account_missing_notice() {
29
+ $message = '<h3 class="title">Activating Premium</h3>
30
+ <p>To activate Call Now Button Premium, you\'ll need an account at
31
+ <a href="https://app.callnowbutton.com?utm_source=wp-plugin&utm_medium=referral&utm_campaign=beta_tester&utm_term=sign-up-for-api">https://app.callnowbutton.com</a>, generate a unique key and paste that into the field below. There\'s 2 ways to do this:</p>
32
+ <h4>Option 1: The fast track</h4>
33
+ <a class="button button-primary" id="cnb-go-create-account" href="">Take the fast track</a>
34
+ <p>In the fast track we\'ve tried to automate as much as possible of the process and make this as easy as possible.</p>
35
+ <h4>Option 2: The manual process</h4>
36
  <ol>
37
+ <li>Create your account at <a href="https://app.callnowbutton.com?utm_source=wp-plugin&utm_medium=referral&utm_campaign=beta_tester&utm_term=sign-up-for-api">https://app.callnowbutton.com</a></li>
38
  <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>
39
+ <li>Copy the API key that appears, paste it into the field below and click <strong>Save API key</strong>.</li>
40
  </ol>';
41
  $message .= cnb_settings_api_key_input();
42
 
45
  }
46
 
47
  function cnb_settings_api_key_invalid_notice() {
48
+ $message = '<h3 class="title">Ooops, that API key doesn\'t seem right</h3>
49
+ <p>The saved API key is invalid. Let\'s give it another try:</p>
50
  <ol>
51
+ <li>Head over to the profile panel on <a href="https://app.callnowbutton.com/app/profile" target="_blank">app.callnowbutton.com</a>.</li>
52
+ <li>Click <strong>Create new API key</strong>, enter a unique name (can be anything. I always enter my website domain here) and click <strong>Generate new API key</strong>.</li>
53
+ <li>Copy the API key, paste it into the field below and click <strong>Save key</strong>.</li>
54
+ </ol>
55
+ <p>If it\'s still not working, we might be experiencing server issues. Please wait a few minutes and try again. You can check our <a target="_blank" href="https://status.callnowbutton.com">status page</a> to be sure.</p>';
 
 
 
 
 
 
56
  $message .= cnb_settings_api_key_input();
57
 
58
  $adminNotices = CnbAdminNotices::get_instance();
63
  $message = '<h3 class="title">Something went wrong!</h3>
64
  <p>Something has gone wrong and we do not know why...</p>
65
  <p>As unlikely as it is, our service might be experiencing issues (check <a href="https://status.callnowbutton.com">our status page</a>).</p>
66
+ <p>If you think you\'ve found a bug, please report it at our <a href="https://callnowbutton.com/support/" target="_blank">Help Center</a>.';
67
  $message .= CnbAdminCloud::cnb_admin_get_error_message_details($user);
68
 
69
  $adminNotices = CnbAdminNotices::get_instance();
71
  }
72
 
73
  function cnb_settings_api_key_input() {
74
+ // Create URL
75
+ $url = admin_url('admin.php');
76
+ $settings_url = esc_url( $url );
77
 
78
  $message = '<form method="post" action="' . esc_url( admin_url('options.php') ) . '" class="cnb-container">';
79
  ob_start();
84
  <tr class="when-cloud-enabled">
85
  <th scope="row">API key</th>
86
  <td>
87
+ <input type="hidden" id="admin_email" value="'. esc_attr(get_bloginfo('admin_email')) .'">
88
+ <input type="hidden" id="admin_url" value="'. esc_attr($settings_url) .'">
89
  <input type="text" class="regular-text" name="cnb[api_key]"
90
  placeholder="e.g. b52c3f83-38dc-4493-bc90-642da5be7e39"/>
91
+ '. get_submit_button(__('Save API key'), 'primary', 'submit', false).'
92
  </td>
93
  </table>
94
  </form>';
97
 
98
  function cnb_settings_get_domain_missing_notice($domain) {
99
  $message = '<h3 class="title">Domain not found yet</h3>
100
+ <p>You have enabled Call Now Button Premium and you are logged in. Now we need to create this domain remotely.</p>
 
101
  <p>
102
  <form action="' . esc_url( admin_url('admin-post.php') ) . '" method="post">
103
  <input type="hidden" name="page" value="call-now-button-settings" />
104
  <input type="hidden" name="action" value="cnb_create_cloud_domain" />
105
  <input type="hidden" name="_wpnonce" value="' . wp_create_nonce('cnb_create_cloud_domain') .'" />
106
+ '. get_submit_button(__('Create domain'), 'secondary', 'submit', false).'
107
  </form>
108
  </p>';
109
  $message .= CnbAdminCloud::cnb_admin_get_error_message_details( $domain );
114
 
115
  function cnb_settings_get_button_missing_notice() {
116
  $message = '<h3 class="title">Creating your first button</h3>
117
+ <p>You have enabled Call Now Button Premium and your domain have been set up.
118
+ Now it\'s time to create your first button.</p>
119
+ <p>To make it easy, we can migrate your existing button to your account.</p>
120
  <p><form action="'. esc_url( admin_url('admin-post.php') ) .'" method="post">
121
  <input type="hidden" name="page" value="call-now-button-settings" />
122
  <input type="hidden" name="action" value="cnb_migrate_legacy_button" />
123
  <input type="hidden" name="_wpnonce" value="'. wp_create_nonce('cnb_migrate_legacy_button') .'" />
124
+ '. get_submit_button(__('Migrate button'), 'secondary', 'submit', false).'
125
  </form></p>';
126
 
127
  $notice = new CnbNotice('warning', $message);
150
  $redirect_url = esc_url( $redirect_link );
151
 
152
  $message = '<h3 class="title">API Key invalid</h3>
153
+ <p>You have enabled Call Now Button Premium, but you still need a valid API key.</p>
154
  <p>Go to <a href="'.$redirect_url.'">Settings</a> for instructions.</p>';
155
  $message .= CnbAdminCloud::cnb_admin_get_error_message_details( $error );
156
 
200
  $adminNotices = CnbAdminNotices::get_instance();
201
  $adminNotices->error($message);
202
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/utils/utils.php CHANGED
@@ -302,7 +302,9 @@ function cnb_get_cloud_notices() {
302
  } else if ( $cnb_cloud_buttons !== null ) {
303
  $cnb_cloud_buttons_this_domain = array_filter( $cnb_cloud_buttons, function ( $button ) use ( $cnb_cloud_domain ) {
304
  // Fix for https://github.com/callnowbutton/wp-plugin/issues/295
305
- if (is_wp_error($cnb_cloud_domain)) return false;
 
 
306
  return $button->domain === $cnb_cloud_domain->id;
307
  } );
308
  }
@@ -455,3 +457,26 @@ function cnb_wporg_recursive_sanitize_text_field( $array ) {
455
  function cnb_check_ajax_referer($action, $query_arg=false, $die=false) {
456
  return check_ajax_referer($action, $query_arg, $die);
457
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  } else if ( $cnb_cloud_buttons !== null ) {
303
  $cnb_cloud_buttons_this_domain = array_filter( $cnb_cloud_buttons, function ( $button ) use ( $cnb_cloud_domain ) {
304
  // Fix for https://github.com/callnowbutton/wp-plugin/issues/295
305
+ if (is_wp_error($cnb_cloud_domain)) {
306
+ return false;
307
+ }
308
  return $button->domain === $cnb_cloud_domain->id;
309
  } );
310
  }
457
  function cnb_check_ajax_referer($action, $query_arg=false, $die=false) {
458
  return check_ajax_referer($action, $query_arg, $die);
459
  }
460
+
461
+ function cnb_show_advanced() {
462
+ global $cnb_options;
463
+ $show_advanced_view_only = array_key_exists( 'advanced_view', $cnb_options ) && $cnb_options['advanced_view'] === 1;
464
+ if ( $show_advanced_view_only ) {
465
+ echo '<script type="text/javascript">show_advanced_view_only_set=1</script>';
466
+ }
467
+ }
468
+
469
+ function get_cnb_domain_upgrade($cnb_cloud_domain) {
470
+ if ($cnb_cloud_domain !== null && !($cnb_cloud_domain instanceof WP_Error)) {
471
+ $url = admin_url('admin.php');
472
+ $upgrade_link =
473
+ add_query_arg(array(
474
+ 'page' => 'call-now-button-domains',
475
+ 'action' => 'upgrade',
476
+ 'id' => $cnb_cloud_domain->id
477
+ ),
478
+ $url);
479
+ return esc_url($upgrade_link);
480
+ }
481
+ return null;
482
+ }