Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress - Version 1.1.13

Version Description

Download this release

Release Info

Developer sandesh055
Plugin Icon Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress
Version 1.1.13
Comparing to
See all releases

Code changes from version 1.1.12 to 1.1.13

Files changed (66) hide show
  1. admin/assets/css/global-admin-rtl.css +1 -1
  2. admin/assets/css/global-admin.css +1 -1
  3. admin/assets/js/admin-menu-settings.js +0 -305
  4. assets/css/checkout-template-divi-rtl.css +39 -0
  5. assets/css/checkout-template-divi.css +39 -0
  6. assets/css/checkout-template-rtl.css +13 -1
  7. assets/css/checkout-template.css +13 -1
  8. assets/js/checkout-template.js +3 -1
  9. cartflows.php +1 -1
  10. changelog.txt +7 -0
  11. classes/batch-process/class-cartflows-batch-process.php +270 -270
  12. classes/batch-process/class-cartflows-importer-beaver-builder-batch.php +63 -63
  13. classes/batch-process/class-cartflows-importer-beaver-builder.php +229 -229
  14. classes/batch-process/class-cartflows-importer-divi-batch.php +63 -63
  15. classes/batch-process/class-cartflows-importer-divi.php +217 -217
  16. classes/batch-process/class-cartflows-importer-elementor-batch.php +66 -66
  17. classes/batch-process/class-cartflows-importer-elementor.php +69 -69
  18. classes/class-cartflows-admin-fields.php +198 -198
  19. classes/class-cartflows-admin.php +445 -437
  20. classes/class-cartflows-api.php +381 -381
  21. classes/class-cartflows-bb-compatibility.php +76 -76
  22. classes/class-cartflows-cloning.php +436 -436
  23. classes/class-cartflows-compatibility.php +400 -400
  24. classes/class-cartflows-default-meta.php +926 -926
  25. classes/class-cartflows-divi-compatibility.php +55 -55
  26. classes/class-cartflows-flow-frontend.php +199 -199
  27. classes/class-cartflows-frontend.php +439 -439
  28. classes/class-cartflows-functions.php +388 -388
  29. classes/class-cartflows-helper.php +464 -464
  30. classes/class-cartflows-importer-core.php +272 -272
  31. classes/class-cartflows-importer.php +1569 -1569
  32. classes/class-cartflows-loader.php +1 -1
  33. classes/class-cartflows-logger.php +101 -101
  34. classes/class-cartflows-meta-fields.php +1482 -1482
  35. classes/class-cartflows-meta.php +75 -75
  36. classes/class-cartflows-thrive-compatibility.php +77 -77
  37. classes/class-cartflows-update.php +77 -77
  38. classes/class-cartflows-utils.php +344 -344
  39. classes/class-cartflows-wizard.php +447 -447
  40. includes/admin/cartflows-general.php +151 -143
  41. includes/exporter.php +23 -23
  42. includes/importer.php +26 -26
  43. languages/cartflows.pot +133 -101
  44. modules/checkout/classes/class-cartflows-checkout-meta.php +772 -765
  45. modules/checkout/templates/embed/checkout-template-simple.php +33 -33
  46. modules/flow/class-cartflows-flow.php +48 -48
  47. modules/flow/classes/class-cartflows-flow-meta.php +743 -743
  48. modules/flow/classes/class-cartflows-flow-post-type.php +281 -281
  49. modules/flow/classes/class-cartflows-step-post-type.php +486 -470
  50. modules/flow/templates/template-canvas.php +49 -49
  51. modules/flow/templates/template-default.php +54 -54
  52. modules/flow/view/meta-flow-steps.php +200 -200
  53. modules/landing/classes/class-cartflows-landing-meta.php +236 -236
  54. modules/thankyou/classes/class-cartflows-thankyou-meta.php +371 -371
  55. readme.txt +9 -2
  56. woocommerce/template/cart/cart-shipping.php +79 -79
  57. woocommerce/template/checkout/form-billing.php +80 -80
  58. woocommerce/template/checkout/form-checkout.php +64 -64
  59. woocommerce/template/checkout/form-coupon.php +42 -42
  60. woocommerce/template/checkout/form-login.php +36 -36
  61. woocommerce/template/checkout/payment.php +61 -0
  62. woocommerce/template/checkout/review-order.php +113 -113
  63. woocommerce/template/checkout/thankyou.php +87 -87
  64. woocommerce/template/notices/error.php +35 -35
  65. woocommerce/template/notices/notice.php +34 -34
  66. woocommerce/template/notices/success.php +34 -34
admin/assets/css/global-admin-rtl.css CHANGED
@@ -734,7 +734,7 @@ input[type="text"].error:focus{
734
  border-left: none;
735
  border-top: none;
736
  border-bottom: none;
737
- min-height: 190px;
738
  overflow: hidden;
739
  padding: 10px 0px;
740
  }
734
  border-left: none;
735
  border-top: none;
736
  border-bottom: none;
737
+ min-height: 227px;
738
  overflow: hidden;
739
  padding: 10px 0px;
740
  }
admin/assets/css/global-admin.css CHANGED
@@ -734,7 +734,7 @@ input[type="text"].error:focus{
734
  border-right: none;
735
  border-top: none;
736
  border-bottom: none;
737
- min-height: 190px;
738
  overflow: hidden;
739
  padding: 10px 0px;
740
  }
734
  border-right: none;
735
  border-top: none;
736
  border-bottom: none;
737
+ min-height: 227px;
738
  overflow: hidden;
739
  padding: 10px 0px;
740
  }
admin/assets/js/admin-menu-settings.js CHANGED
@@ -1,308 +1,3 @@
1
  ( function( $ ) {
2
 
3
- /**
4
- * AJAX Request Queue
5
- *
6
- * - add()
7
- * - remove()
8
- * - run()
9
- * - stop()
10
- *
11
- * @since 1.0.0
12
- */
13
- var UaelAjaxQueue = (function() {
14
-
15
- var requests = [];
16
-
17
- return {
18
-
19
- /**
20
- * Add AJAX request
21
- *
22
- * @since 1.0.0
23
- */
24
- add: function(opt) {
25
- requests.push(opt);
26
- },
27
-
28
- /**
29
- * Remove AJAX request
30
- *
31
- * @since 1.0.0
32
- */
33
- remove: function(opt) {
34
- if( jQuery.inArray(opt, requests) > -1 )
35
- requests.splice($.inArray(opt, requests), 1);
36
- },
37
-
38
- /**
39
- * Run / Process AJAX request
40
- *
41
- * @since 1.0.0
42
- */
43
- run: function() {
44
- var self = this,
45
- oriSuc;
46
-
47
- if( requests.length ) {
48
- oriSuc = requests[0].complete;
49
-
50
- requests[0].complete = function() {
51
- if( typeof(oriSuc) === 'function' ) oriSuc();
52
- requests.shift();
53
- self.run.apply(self, []);
54
- };
55
-
56
- jQuery.ajax(requests[0]);
57
-
58
- } else {
59
-
60
- self.tid = setTimeout(function() {
61
- self.run.apply(self, []);
62
- }, 1000);
63
- }
64
- },
65
-
66
- /**
67
- * Stop AJAX request
68
- *
69
- * @since 1.0.0
70
- */
71
- stop: function() {
72
-
73
- requests = [];
74
- clearTimeout(this.tid);
75
- }
76
- };
77
-
78
- }());
79
-
80
- UaelAdmin = {
81
-
82
- init: function() {
83
- /**
84
- * Run / Process AJAX request
85
- */
86
- UaelAjaxQueue.run();
87
- this._knowledgebase();
88
- this._support();
89
-
90
- $( document ).delegate( ".uael-activate-widget", "click", UaelAdmin._activate_widget );
91
- $( document ).delegate( ".uael-deactivate-widget", "click", UaelAdmin._deactivate_widget );
92
-
93
- $( document ).delegate( ".uael-activate-all", "click", UaelAdmin._bulk_activate_widgets );
94
- $( document ).delegate( ".uael-deactivate-all", "click", UaelAdmin._bulk_deactivate_widgets );
95
-
96
- $( document ).delegate( "#uael-gen-enable-beta-update", "click", UaelAdmin._allow_beta_updates );
97
-
98
- /* White Label */
99
- $( document ).delegate( "#uael-wl-enable-knowledgebase", "change", UaelAdmin._knowledgebase );
100
- $( document ).delegate( "#uael-wl-enable-support", "change", UaelAdmin._support );
101
- },
102
-
103
- /**
104
- * Activate All Widgets.
105
- */
106
- _bulk_activate_widgets: function( e ) {
107
- var button = $( this );
108
-
109
- var data = {
110
- action: 'uael_bulk_activate_widgets',
111
- nonce: uael.ajax_nonce,
112
- };
113
-
114
- if ( button.hasClass( 'updating-message' ) ) {
115
- return;
116
- }
117
-
118
- $( button ).addClass('updating-message');
119
-
120
- UaelAjaxQueue.add({
121
- url: ajaxurl,
122
- type: 'POST',
123
- data: data,
124
- success: function(data){
125
-
126
- // Bulk add or remove classes to all modules.
127
- $('.uael-widget-list').children( "li" ).addClass( 'activate' ).removeClass( 'deactivate' );
128
- $('.uael-widget-list').children( "li" ).find('.uael-activate-widget')
129
- .addClass('uael-deactivate-widget')
130
- .text(uael.deactivate)
131
- .removeClass('uael-activate-widget');
132
- $( button ).removeClass('updating-message');
133
- }
134
- });
135
- e.preventDefault();
136
- },
137
-
138
- /**
139
- * Deactivate All Widgets.
140
- */
141
- _bulk_deactivate_widgets: function( e ) {
142
- var button = $( this );
143
-
144
- var data = {
145
- action: 'uael_bulk_deactivate_widgets',
146
- nonce: uael.ajax_nonce,
147
- };
148
-
149
- if ( button.hasClass( 'updating-message' ) ) {
150
- return;
151
- }
152
- $( button ).addClass('updating-message');
153
-
154
- UaelAjaxQueue.add({
155
- url: ajaxurl,
156
- type: 'POST',
157
- data: data,
158
- success: function(data){
159
- // Bulk add or remove classes to all modules.
160
- $('.uael-widget-list').children( "li" ).addClass( 'deactivate' ).removeClass( 'activate' );
161
- $('.uael-widget-list').children( "li" ).find('.uael-deactivate-widget')
162
- .addClass('uael-activate-widget')
163
- .text(uael.activate)
164
- .removeClass('uael-deactivate-widget');
165
- $( button ).removeClass('updating-message');
166
- }
167
- });
168
- e.preventDefault();
169
- },
170
-
171
- /**
172
- * Activate Module.
173
- */
174
- _activate_widget: function( e ) {
175
- var button = $( this ),
176
- id = button.parents('li').attr('id');
177
-
178
- var data = {
179
- module_id : id,
180
- action: 'uael_activate_widget',
181
- nonce: uael.ajax_nonce,
182
- };
183
-
184
- if ( button.hasClass( 'updating-message' ) ) {
185
- return;
186
- }
187
-
188
- $( button ).addClass('updating-message');
189
-
190
- UaelAjaxQueue.add({
191
- url: ajaxurl,
192
- type: 'POST',
193
- data: data,
194
- success: function(data){
195
-
196
- // Add active class.
197
- $( '#' + id ).addClass('activate').removeClass( 'deactivate' );
198
- // Change button classes & text.
199
- $( '#' + id ).find('.uael-activate-widget')
200
- .addClass('uael-deactivate-widget')
201
- .text(uael.deactivate)
202
- .removeClass('uael-activate-widget')
203
- .removeClass('updating-message');
204
- }
205
- });
206
-
207
- e.preventDefault();
208
- },
209
-
210
- /**
211
- * Deactivate Module.
212
- */
213
- _deactivate_widget: function( e ) {
214
- var button = $( this ),
215
- id = button.parents('li').attr('id');
216
- var data = {
217
- module_id: id,
218
- action: 'uael_deactivate_widget',
219
- nonce: uael.ajax_nonce,
220
- };
221
-
222
- if ( button.hasClass( 'updating-message' ) ) {
223
- return;
224
- }
225
-
226
- $( button ).addClass('updating-message');
227
-
228
- UaelAjaxQueue.add({
229
- url: ajaxurl,
230
- type: 'POST',
231
- data: data,
232
- success: function(data){
233
-
234
- // Remove active class.
235
- $( '#' + id ).addClass( 'deactivate' ).removeClass('activate');
236
-
237
- // Change button classes & text.
238
- $( '#' + id ).find('.uael-deactivate-widget')
239
- .addClass('uael-activate-widget')
240
- .text(uael.activate)
241
- .removeClass('uael-deactivate-widget')
242
- .removeClass('updating-message');
243
- }
244
- })
245
- e.preventDefault();
246
- },
247
-
248
- /**
249
- * Allow Beta Updates.
250
- */
251
- _allow_beta_updates: function( e ) {
252
-
253
- var $this = $(this);
254
- var allow_beta = $this.attr('data-value');
255
-
256
- if ( 'disable' === allow_beta ) {
257
- allow_beta = 'enable';
258
- }else{
259
- allow_beta = 'disable';
260
- }
261
-
262
- $this.addClass('loading');
263
-
264
- var data = {
265
- allow_beta: allow_beta,
266
- action: 'uael_allow_beta_updates',
267
- nonce: uael.ajax_nonce,
268
- };
269
-
270
- UaelAjaxQueue.add({
271
- url: ajaxurl,
272
- type: 'POST',
273
- data: data,
274
- success: function(data){
275
-
276
- window.location.href += '&message=saved';
277
- }
278
- })
279
- },
280
-
281
- /**
282
- * Knowledge Base.
283
- */
284
- _knowledgebase: function() {
285
- if ( $('#uael-wl-enable-knowledgebase').is(':checked') ) {
286
- $('p.uael-knowledgebase-url').show();
287
- }else{
288
- $('p.uael-knowledgebase-url').hide();
289
- }
290
- },
291
- /**
292
- * Support.
293
- */
294
- _support: function() {
295
- if ( $('#uael-wl-enable-support').is(':checked') ) {
296
- $('p.uael-support-url').show();
297
- }else{
298
- $('p.uael-support-url').hide();
299
- }
300
- }
301
- }
302
-
303
- $( document ).ready(function() {
304
- UaelAdmin.init();
305
- });
306
-
307
-
308
  } )( jQuery );
1
  ( function( $ ) {
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  } )( jQuery );
assets/css/checkout-template-divi-rtl.css CHANGED
@@ -235,6 +235,45 @@
235
  width: 100%;
236
  }
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  @media only screen and (max-width: 768px) {
239
  .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout .col2-set{
240
  display: block;
235
  width: 100%;
236
  }
237
 
238
+ /**
239
+ * *************************************
240
+ * Two Step Divi Compatibility css Start
241
+ * *************************************
242
+ */
243
+
244
+
245
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set,
246
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .wcf-order-wrap,
247
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .wcf-product-option-wrap{
248
+ display: block;
249
+ width: 100%;
250
+ float: none;
251
+ padding-left: 0;
252
+ padding: 0px;
253
+ -webkit-border-radius: 0px;
254
+ border-radius: 0px;
255
+ margin-bottom: 20px;
256
+ }
257
+
258
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set .woocommerce-billing-fields .woocommerce-billing-fields__field-wrapper,
259
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set .woocommerce-shipping-fields .woocommerce-shipping-fields__field-wrapper,
260
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set .woocommerce-additional-fields .woocommerce-additional-fields__field-wrapper{
261
+ margin: 0px;
262
+ }
263
+
264
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-additional-fields > h3,
265
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-billing-fields > h3,
266
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step #order_review_heading,
267
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout #order_review_heading{
268
+ display: none !important;
269
+ }
270
+
271
+ /**
272
+ * *************************************
273
+ * Two Step Divi Compatibility css End
274
+ * *************************************
275
+ */
276
+
277
  @media only screen and (max-width: 768px) {
278
  .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout .col2-set{
279
  display: block;
assets/css/checkout-template-divi.css CHANGED
@@ -235,6 +235,45 @@
235
  width: 100%;
236
  }
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  @media only screen and (max-width: 768px) {
239
  .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout .col2-set{
240
  display: block;
235
  width: 100%;
236
  }
237
 
238
+ /**
239
+ * *************************************
240
+ * Two Step Divi Compatibility css Start
241
+ * *************************************
242
+ */
243
+
244
+
245
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set,
246
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .wcf-order-wrap,
247
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .wcf-product-option-wrap{
248
+ display: block;
249
+ width: 100%;
250
+ float: none;
251
+ padding-right: 0;
252
+ padding: 0px;
253
+ -webkit-border-radius: 0px;
254
+ border-radius: 0px;
255
+ margin-bottom: 20px;
256
+ }
257
+
258
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set .woocommerce-billing-fields .woocommerce-billing-fields__field-wrapper,
259
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set .woocommerce-shipping-fields .woocommerce-shipping-fields__field-wrapper,
260
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout .col2-set .woocommerce-additional-fields .woocommerce-additional-fields__field-wrapper{
261
+ margin: 0px;
262
+ }
263
+
264
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-additional-fields > h3,
265
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-billing-fields > h3,
266
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step #order_review_heading,
267
+ .et_pb_module #wcf-embed-checkout-form.wcf-embed-checkout-form-two-step .woocommerce-checkout #order_review_heading{
268
+ display: none !important;
269
+ }
270
+
271
+ /**
272
+ * *************************************
273
+ * Two Step Divi Compatibility css End
274
+ * *************************************
275
+ */
276
+
277
  @media only screen and (max-width: 768px) {
278
  .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout .col2-set{
279
  display: block;
assets/css/checkout-template-rtl.css CHANGED
@@ -100,6 +100,11 @@
100
  * Common Classes
101
  * **************
102
  */
 
 
 
 
 
103
  .mt20{
104
  margin-top: 20px !important;
105
  }
@@ -118,6 +123,7 @@
118
  border-color: #69bf29;
119
  }
120
 
 
121
  .wcf-embed-checkout-form .woocommerce form .form-row input.input-text.field-required{
122
  border-color: #e2401c;
123
  }
@@ -364,6 +370,7 @@
364
  border-radius: 3px;
365
  -webkit-box-shadow: none;
366
  box-shadow: none;
 
367
  }
368
 
369
  .wcf-embed-checkout-form #order_review{
@@ -558,6 +565,7 @@
558
  display: block;
559
  margin-bottom: 1.1em;
560
  padding: 3px 7px;
 
561
  }
562
 
563
  .wcf-embed-checkout-form table.shop_table {
@@ -668,8 +676,10 @@
668
  .wcf-embed-checkout-form #payment .woocommerce-privacy-policy-text p{
669
  font-family: inherit;
670
  font-weight:inherit;
671
- color: #444;
 
672
  margin-top: 0;
 
673
  }
674
 
675
  .wcf-embed-checkout-form #payment .wc_payment_methods .payment_box p{
@@ -682,6 +692,8 @@
682
  }
683
 
684
  .wcf-embed-checkout-form .woocommerce .woocommerce-info,
 
 
685
  .wcf-embed-checkout-form .woocommerce .woocommerce-notices-wrapper .woocommerce-message,
686
  .wcf-embed-checkout-form .woocommerce .woocommerce-NoticeGroup .woocommerce-message{
687
  padding: 1em 2.0em 0.4em 2em;
100
  * Common Classes
101
  * **************
102
  */
103
+
104
+ .wcf-embed-checkout-form .woocommerce .blockUI.blockOverlay {
105
+ font-size: 15px;
106
+ }
107
+
108
  .mt20{
109
  margin-top: 20px !important;
110
  }
123
  border-color: #69bf29;
124
  }
125
 
126
+ .wcf-embed-checkout-form .select2-container--default.field-required .select2-selection--single,
127
  .wcf-embed-checkout-form .woocommerce form .form-row input.input-text.field-required{
128
  border-color: #e2401c;
129
  }
370
  border-radius: 3px;
371
  -webkit-box-shadow: none;
372
  box-shadow: none;
373
+ height: auto;
374
  }
375
 
376
  .wcf-embed-checkout-form #order_review{
565
  display: block;
566
  margin-bottom: 1.1em;
567
  padding: 3px 7px;
568
+ position: relative;
569
  }
570
 
571
  .wcf-embed-checkout-form table.shop_table {
676
  .wcf-embed-checkout-form #payment .woocommerce-privacy-policy-text p{
677
  font-family: inherit;
678
  font-weight:inherit;
679
+ font-size: 11px;
680
+ color: #777;
681
  margin-top: 0;
682
+ text-align: justify;
683
  }
684
 
685
  .wcf-embed-checkout-form #payment .wc_payment_methods .payment_box p{
692
  }
693
 
694
  .wcf-embed-checkout-form .woocommerce .woocommerce-info,
695
+ .wcf-embed-checkout-form .woocommerce .woocommerce-error,
696
+ .wcf-embed-checkout-form .woocommerce .woocommerce-message,
697
  .wcf-embed-checkout-form .woocommerce .woocommerce-notices-wrapper .woocommerce-message,
698
  .wcf-embed-checkout-form .woocommerce .woocommerce-NoticeGroup .woocommerce-message{
699
  padding: 1em 2.0em 0.4em 2em;
assets/css/checkout-template.css CHANGED
@@ -100,6 +100,11 @@
100
  * Common Classes
101
  * **************
102
  */
 
 
 
 
 
103
  .mt20{
104
  margin-top: 20px !important;
105
  }
@@ -118,6 +123,7 @@
118
  border-color: #69bf29;
119
  }
120
 
 
121
  .wcf-embed-checkout-form .woocommerce form .form-row input.input-text.field-required{
122
  border-color: #e2401c;
123
  }
@@ -364,6 +370,7 @@
364
  border-radius: 3px;
365
  -webkit-box-shadow: none;
366
  box-shadow: none;
 
367
  }
368
 
369
  .wcf-embed-checkout-form #order_review{
@@ -558,6 +565,7 @@
558
  display: block;
559
  margin-bottom: 1.1em;
560
  padding: 3px 7px;
 
561
  }
562
 
563
  .wcf-embed-checkout-form table.shop_table {
@@ -668,8 +676,10 @@
668
  .wcf-embed-checkout-form #payment .woocommerce-privacy-policy-text p{
669
  font-family: inherit;
670
  font-weight:inherit;
671
- color: #444;
 
672
  margin-top: 0;
 
673
  }
674
 
675
  .wcf-embed-checkout-form #payment .wc_payment_methods .payment_box p{
@@ -682,6 +692,8 @@
682
  }
683
 
684
  .wcf-embed-checkout-form .woocommerce .woocommerce-info,
 
 
685
  .wcf-embed-checkout-form .woocommerce .woocommerce-notices-wrapper .woocommerce-message,
686
  .wcf-embed-checkout-form .woocommerce .woocommerce-NoticeGroup .woocommerce-message{
687
  padding: 1em 2em 0.4em 2.0em;
100
  * Common Classes
101
  * **************
102
  */
103
+
104
+ .wcf-embed-checkout-form .woocommerce .blockUI.blockOverlay {
105
+ font-size: 15px;
106
+ }
107
+
108
  .mt20{
109
  margin-top: 20px !important;
110
  }
123
  border-color: #69bf29;
124
  }
125
 
126
+ .wcf-embed-checkout-form .select2-container--default.field-required .select2-selection--single,
127
  .wcf-embed-checkout-form .woocommerce form .form-row input.input-text.field-required{
128
  border-color: #e2401c;
129
  }
370
  border-radius: 3px;
371
  -webkit-box-shadow: none;
372
  box-shadow: none;
373
+ height: auto;
374
  }
375
 
376
  .wcf-embed-checkout-form #order_review{
565
  display: block;
566
  margin-bottom: 1.1em;
567
  padding: 3px 7px;
568
+ position: relative;
569
  }
570
 
571
  .wcf-embed-checkout-form table.shop_table {
676
  .wcf-embed-checkout-form #payment .woocommerce-privacy-policy-text p{
677
  font-family: inherit;
678
  font-weight:inherit;
679
+ font-size: 11px;
680
+ color: #777;
681
  margin-top: 0;
682
+ text-align: justify;
683
  }
684
 
685
  .wcf-embed-checkout-form #payment .wc_payment_methods .payment_box p{
692
  }
693
 
694
  .wcf-embed-checkout-form .woocommerce .woocommerce-info,
695
+ .wcf-embed-checkout-form .woocommerce .woocommerce-error,
696
+ .wcf-embed-checkout-form .woocommerce .woocommerce-message,
697
  .wcf-embed-checkout-form .woocommerce .woocommerce-notices-wrapper .woocommerce-message,
698
  .wcf-embed-checkout-form .woocommerce .woocommerce-NoticeGroup .woocommerce-message{
699
  padding: 1em 2em 0.4em 2.0em;
assets/js/checkout-template.js CHANGED
@@ -61,7 +61,9 @@
61
  if( field_id != 'billing_company' && field_id != 'billing_address_2' && field_id != 'shipping_company' && field_id != 'shipping_address_2'){
62
  $this.addClass('field-required');
63
  }
64
- }
 
 
65
  });
66
  }
67
 
61
  if( field_id != 'billing_company' && field_id != 'billing_address_2' && field_id != 'shipping_company' && field_id != 'shipping_address_2'){
62
  $this.addClass('field-required');
63
  }
64
+ }else{
65
+ $this.removeClass('field-required');
66
+ }
67
  });
68
  }
69
 
cartflows.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: CartFlows
4
  * Plugin URI: https://cartflows.com/
5
  * Description: Create beautiful checkout pages & sales flows for WooCommerce.
6
- * Version: 1.1.12
7
  * Author: CartFlows Inc
8
  * Author URI: https://cartflows.com/
9
  * Text Domain: cartflows
3
  * Plugin Name: CartFlows
4
  * Plugin URI: https://cartflows.com/
5
  * Description: Create beautiful checkout pages & sales flows for WooCommerce.
6
+ * Version: 1.1.13
7
  * Author: CartFlows Inc
8
  * Author URI: https://cartflows.com/
9
  * Text Domain: cartflows
changelog.txt CHANGED
@@ -1,3 +1,10 @@
 
 
 
 
 
 
 
1
  Version 1.1.12 - Friday, 22nd March 2019
2
  - New: Added ability to set checkout page as a home page.
3
  - Fix: Thrive Architect CSS conflict.
1
+ Version 1.1.13 - Tuesday, 9th April 2019
2
+ - Improvement: Added compatibility for a Two-Step checkout style of CartFlows Pro.
3
+ - Fix: CSS conflict with the Divi theme.
4
+ - Fix: Checkout field validation issue.
5
+ - Fix: Conflict with the Norebro theme.
6
+ - Fix: Redirection issue while paying through a Swish payment gateway.
7
+
8
  Version 1.1.12 - Friday, 22nd March 2019
9
  - New: Added ability to set checkout page as a home page.
10
  - Fix: Thrive Architect CSS conflict.
classes/batch-process/class-cartflows-batch-process.php CHANGED
@@ -1,270 +1,270 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Batch_Process' ) ) :
10
-
11
- /**
12
- * CartFlows_Batch_Process
13
- *
14
- * @since 1.0.0
15
- */
16
- class CartFlows_Batch_Process {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.0
22
- * @var object Class object.
23
- * @access private
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Elementor Batch Instance
29
- *
30
- * @since 1.1.1 Updated instance name with elementor specific.
31
- *
32
- * @since 1.0.0
33
- * @var object Class object.
34
- * @access public
35
- */
36
- public static $batch_instance_elementor;
37
-
38
- /**
39
- * Beaver Builder Batch Instance
40
- *
41
- * @since 1.1.1
42
- * @var object Class object.
43
- * @access public
44
- */
45
- public static $batch_instance_bb;
46
-
47
- /**
48
- * Divi Batch Instance
49
- *
50
- * @since 1.1.1
51
- * @var object Class object.
52
- * @access public
53
- */
54
- public static $batch_instance_divi;
55
-
56
- /**
57
- * Initiator
58
- *
59
- * @since 1.0.0
60
- * @return object initialized object of class.
61
- */
62
- public static function get_instance() {
63
- if ( ! isset( self::$instance ) ) {
64
- self::$instance = new self;
65
- }
66
- return self::$instance;
67
- }
68
-
69
- /**
70
- * Constructor
71
- *
72
- * @since 1.0.0
73
- */
74
- public function __construct() {
75
-
76
- // Not BB or Elementor then avoid importer.
77
- // if ( ! class_exists( '\Elementor\Plugin' ) && ! class_exists( 'FLBuilder' ) ) {
78
- // return;
79
- // }
80
- // Core Helpers - Image.
81
- require_once ABSPATH . 'wp-admin/includes/image.php';
82
-
83
- // Core Helpers - Batch Processing.
84
- require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-cartflows-importer-image.php';
85
- require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php';
86
- require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php';
87
-
88
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
89
-
90
- // Elementor.
91
- if ( ( 'elementor' === $default_page_builder ) && class_exists( '\Elementor\Plugin' ) ) {
92
- // Add "elementor" in import [queue].
93
- // @todo Remove required `allow_url_fopen` support.
94
- if ( ini_get( 'allow_url_fopen' ) ) {
95
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
96
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor-batch.php';
97
- self::$batch_instance_elementor = new Cartflows_Importer_Elementor_Batch();
98
- }
99
- }
100
-
101
- // Beaver Builder.
102
- if ( ( 'beaver-builder' === $default_page_builder ) && class_exists( 'FLBuilder' ) ) {
103
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder.php';
104
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder-batch.php';
105
- self::$batch_instance_bb = new Cartflows_Importer_Beaver_Builder_Batch();
106
- }
107
-
108
- // Divi.
109
- if ( ( 'divi' === $default_page_builder ) && ( class_exists( 'ET_Builder_Plugin' ) || Cartflows_Compatibility::get_instance()->is_divi_enabled() ) ) {
110
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi.php';
111
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi-batch.php';
112
- self::$batch_instance_divi = new Cartflows_Importer_Divi_Batch();
113
- }
114
-
115
- // Start image importing after site import complete.
116
- add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) );
117
- add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) );
118
- add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
119
- add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
120
- }
121
-
122
- /**
123
- * Added .svg files as supported format in the uploader.
124
- *
125
- * @since 1.1.4
126
- *
127
- * @param array $mimes Already supported mime types.
128
- */
129
- public function custom_upload_mimes( $mimes ) {
130
-
131
- // Allow SVG files.
132
- $mimes['svg'] = 'image/svg+xml';
133
- $mimes['svgz'] = 'image/svg+xml';
134
-
135
- // Allow XML files.
136
- $mimes['xml'] = 'text/xml';
137
-
138
- return $mimes;
139
- }
140
-
141
- /**
142
- * Add SVG image support
143
- *
144
- * @since 1.1.4
145
- *
146
- * @param array $response Attachment response.
147
- * @param object $attachment Attachment object.
148
- * @param array $meta Attachment meta data.
149
- */
150
- function add_svg_image_support( $response, $attachment, $meta ) {
151
- if ( ! function_exists( 'simplexml_load_file' ) ) {
152
- return $response;
153
- }
154
-
155
- if ( ! empty( $response['sizes'] ) ) {
156
- return $response;
157
- }
158
-
159
- if ( 'image/svg+xml' !== $response['mime'] ) {
160
- return $response;
161
- }
162
-
163
- $svg_path = get_attached_file( $attachment->ID );
164
-
165
- $dimensions = self::get_svg_dimensions( $svg_path );
166
-
167
- $response['sizes'] = array(
168
- 'full' => array(
169
- 'url' => $response['url'],
170
- 'width' => $dimensions->width,
171
- 'height' => $dimensions->height,
172
- 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
173
- ),
174
- );
175
-
176
- return $response;
177
- }
178
-
179
- /**
180
- * Get SVG Dimensions
181
- *
182
- * @since 1.1.4.
183
- *
184
- * @param string $svg SVG file path.
185
- * @return array Return SVG file height & width for valid SVG file.
186
- */
187
- public static function get_svg_dimensions( $svg ) {
188
-
189
- $svg = simplexml_load_file( $svg );
190
-
191
- if ( false === $svg ) {
192
- $width = '0';
193
- $height = '0';
194
- } else {
195
- $attributes = $svg->attributes();
196
- $width = (string) $attributes->width;
197
- $height = (string) $attributes->height;
198
- }
199
-
200
- return (object) array(
201
- 'width' => $width,
202
- 'height' => $height,
203
- );
204
- }
205
-
206
- /**
207
- * Batch Process Complete.
208
- *
209
- * @return void
210
- */
211
- public function complete_batch_import() {
212
- wcf()->logger->import_log( '(✓) BATCH Process Complete!' );
213
- }
214
-
215
- /**
216
- * Start Image Import
217
- *
218
- * @param integer $post_id Post Id.
219
- *
220
- * @return void
221
- */
222
- public function start_batch_process( $post_id = '' ) {
223
-
224
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
225
-
226
- wcf()->logger->import_log( '(✓) BATCH Started!' );
227
- wcf()->logger->import_log( '(✓) Step ID ' . $post_id );
228
-
229
- // Add "elementor" in import [queue].
230
- if ( 'beaver-builder' === $default_page_builder && self::$batch_instance_bb ) {
231
-
232
- // Add to queue.
233
- self::$batch_instance_bb->push_to_queue( $post_id );
234
-
235
- // Dispatch Queue.
236
- self::$batch_instance_bb->save()->dispatch();
237
-
238
- wcf()->logger->import_log( '(✓) Dispatch "Beaver Builder" Request..' );
239
-
240
- } elseif ( 'elementor' === $default_page_builder && self::$batch_instance_elementor ) {
241
-
242
- // Add to queue.
243
- self::$batch_instance_elementor->push_to_queue( $post_id );
244
-
245
- // Dispatch Queue.
246
- self::$batch_instance_elementor->save()->dispatch();
247
-
248
- wcf()->logger->import_log( '(✓) Dispatch "Elementor" Request..' );
249
- } elseif ( 'divi' === $default_page_builder && self::$batch_instance_divi ) {
250
-
251
- // Add to queue.
252
- self::$batch_instance_divi->push_to_queue( $post_id );
253
-
254
- // Dispatch Queue.
255
- self::$batch_instance_divi->save()->dispatch();
256
-
257
- wcf()->logger->import_log( '(✓) Dispatch "Divi" Request..' );
258
- } else {
259
- wcf()->logger->import_log( '(✕) Could not import image due to allow_url_fopen() is disabled!' );
260
- }
261
- }
262
-
263
- }
264
-
265
- /**
266
- * Kicking this off by calling 'get_instance()' method
267
- */
268
- CartFlows_Batch_Process::get_instance();
269
-
270
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Batch_Process' ) ) :
10
+
11
+ /**
12
+ * CartFlows_Batch_Process
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class CartFlows_Batch_Process {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.0
22
+ * @var object Class object.
23
+ * @access private
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Elementor Batch Instance
29
+ *
30
+ * @since 1.1.1 Updated instance name with elementor specific.
31
+ *
32
+ * @since 1.0.0
33
+ * @var object Class object.
34
+ * @access public
35
+ */
36
+ public static $batch_instance_elementor;
37
+
38
+ /**
39
+ * Beaver Builder Batch Instance
40
+ *
41
+ * @since 1.1.1
42
+ * @var object Class object.
43
+ * @access public
44
+ */
45
+ public static $batch_instance_bb;
46
+
47
+ /**
48
+ * Divi Batch Instance
49
+ *
50
+ * @since 1.1.1
51
+ * @var object Class object.
52
+ * @access public
53
+ */
54
+ public static $batch_instance_divi;
55
+
56
+ /**
57
+ * Initiator
58
+ *
59
+ * @since 1.0.0
60
+ * @return object initialized object of class.
61
+ */
62
+ public static function get_instance() {
63
+ if ( ! isset( self::$instance ) ) {
64
+ self::$instance = new self;
65
+ }
66
+ return self::$instance;
67
+ }
68
+
69
+ /**
70
+ * Constructor
71
+ *
72
+ * @since 1.0.0
73
+ */
74
+ public function __construct() {
75
+
76
+ // Not BB or Elementor then avoid importer.
77
+ // if ( ! class_exists( '\Elementor\Plugin' ) && ! class_exists( 'FLBuilder' ) ) {
78
+ // return;
79
+ // }
80
+ // Core Helpers - Image.
81
+ require_once ABSPATH . 'wp-admin/includes/image.php';
82
+
83
+ // Core Helpers - Batch Processing.
84
+ require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-cartflows-importer-image.php';
85
+ require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php';
86
+ require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php';
87
+
88
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
89
+
90
+ // Elementor.
91
+ if ( ( 'elementor' === $default_page_builder ) && class_exists( '\Elementor\Plugin' ) ) {
92
+ // Add "elementor" in import [queue].
93
+ // @todo Remove required `allow_url_fopen` support.
94
+ if ( ini_get( 'allow_url_fopen' ) ) {
95
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
96
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor-batch.php';
97
+ self::$batch_instance_elementor = new Cartflows_Importer_Elementor_Batch();
98
+ }
99
+ }
100
+
101
+ // Beaver Builder.
102
+ if ( ( 'beaver-builder' === $default_page_builder ) && class_exists( 'FLBuilder' ) ) {
103
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder.php';
104
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder-batch.php';
105
+ self::$batch_instance_bb = new Cartflows_Importer_Beaver_Builder_Batch();
106
+ }
107
+
108
+ // Divi.
109
+ if ( ( 'divi' === $default_page_builder ) && ( class_exists( 'ET_Builder_Plugin' ) || Cartflows_Compatibility::get_instance()->is_divi_enabled() ) ) {
110
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi.php';
111
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi-batch.php';
112
+ self::$batch_instance_divi = new Cartflows_Importer_Divi_Batch();
113
+ }
114
+
115
+ // Start image importing after site import complete.
116
+ add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) );
117
+ add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) );
118
+ add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
119
+ add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
120
+ }
121
+
122
+ /**
123
+ * Added .svg files as supported format in the uploader.
124
+ *
125
+ * @since 1.1.4
126
+ *
127
+ * @param array $mimes Already supported mime types.
128
+ */
129
+ public function custom_upload_mimes( $mimes ) {
130
+
131
+ // Allow SVG files.
132
+ $mimes['svg'] = 'image/svg+xml';
133
+ $mimes['svgz'] = 'image/svg+xml';
134
+
135
+ // Allow XML files.
136
+ $mimes['xml'] = 'text/xml';
137
+
138
+ return $mimes;
139
+ }
140
+
141
+ /**
142
+ * Add SVG image support
143
+ *
144
+ * @since 1.1.4
145
+ *
146
+ * @param array $response Attachment response.
147
+ * @param object $attachment Attachment object.
148
+ * @param array $meta Attachment meta data.
149
+ */
150
+ function add_svg_image_support( $response, $attachment, $meta ) {
151
+ if ( ! function_exists( 'simplexml_load_file' ) ) {
152
+ return $response;
153
+ }
154
+
155
+ if ( ! empty( $response['sizes'] ) ) {
156
+ return $response;
157
+ }
158
+
159
+ if ( 'image/svg+xml' !== $response['mime'] ) {
160
+ return $response;
161
+ }
162
+
163
+ $svg_path = get_attached_file( $attachment->ID );
164
+
165
+ $dimensions = self::get_svg_dimensions( $svg_path );
166
+
167
+ $response['sizes'] = array(
168
+ 'full' => array(
169
+ 'url' => $response['url'],
170
+ 'width' => $dimensions->width,
171
+ 'height' => $dimensions->height,
172
+ 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
173
+ ),
174
+ );
175
+
176
+ return $response;
177
+ }
178
+
179
+ /**
180
+ * Get SVG Dimensions
181
+ *
182
+ * @since 1.1.4.
183
+ *
184
+ * @param string $svg SVG file path.
185
+ * @return array Return SVG file height & width for valid SVG file.
186
+ */
187
+ public static function get_svg_dimensions( $svg ) {
188
+
189
+ $svg = simplexml_load_file( $svg );
190
+
191
+ if ( false === $svg ) {
192
+ $width = '0';
193
+ $height = '0';
194
+ } else {
195
+ $attributes = $svg->attributes();
196
+ $width = (string) $attributes->width;
197
+ $height = (string) $attributes->height;
198
+ }
199
+
200
+ return (object) array(
201
+ 'width' => $width,
202
+ 'height' => $height,
203
+ );
204
+ }
205
+
206
+ /**
207
+ * Batch Process Complete.
208
+ *
209
+ * @return void
210
+ */
211
+ public function complete_batch_import() {
212
+ wcf()->logger->import_log( '(✓) BATCH Process Complete!' );
213
+ }
214
+
215
+ /**
216
+ * Start Image Import
217
+ *
218
+ * @param integer $post_id Post Id.
219
+ *
220
+ * @return void
221
+ */
222
+ public function start_batch_process( $post_id = '' ) {
223
+
224
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
225
+
226
+ wcf()->logger->import_log( '(✓) BATCH Started!' );
227
+ wcf()->logger->import_log( '(✓) Step ID ' . $post_id );
228
+
229
+ // Add "elementor" in import [queue].
230
+ if ( 'beaver-builder' === $default_page_builder && self::$batch_instance_bb ) {
231
+
232
+ // Add to queue.
233
+ self::$batch_instance_bb->push_to_queue( $post_id );
234
+
235
+ // Dispatch Queue.
236
+ self::$batch_instance_bb->save()->dispatch();
237
+
238
+ wcf()->logger->import_log( '(✓) Dispatch "Beaver Builder" Request..' );
239
+
240
+ } elseif ( 'elementor' === $default_page_builder && self::$batch_instance_elementor ) {
241
+
242
+ // Add to queue.
243
+ self::$batch_instance_elementor->push_to_queue( $post_id );
244
+
245
+ // Dispatch Queue.
246
+ self::$batch_instance_elementor->save()->dispatch();
247
+
248
+ wcf()->logger->import_log( '(✓) Dispatch "Elementor" Request..' );
249
+ } elseif ( 'divi' === $default_page_builder && self::$batch_instance_divi ) {
250
+
251
+ // Add to queue.
252
+ self::$batch_instance_divi->push_to_queue( $post_id );
253
+
254
+ // Dispatch Queue.
255
+ self::$batch_instance_divi->save()->dispatch();
256
+
257
+ wcf()->logger->import_log( '(✓) Dispatch "Divi" Request..' );
258
+ } else {
259
+ wcf()->logger->import_log( '(✕) Could not import image due to allow_url_fopen() is disabled!' );
260
+ }
261
+ }
262
+
263
+ }
264
+
265
+ /**
266
+ * Kicking this off by calling 'get_instance()' method
267
+ */
268
+ CartFlows_Batch_Process::get_instance();
269
+
270
+ endif;
classes/batch-process/class-cartflows-importer-beaver-builder-batch.php CHANGED
@@ -1,63 +1,63 @@
1
- <?php
2
- /**
3
- * Beaver Builder Batch Process
4
- *
5
- * @package CartFlows
6
- * @since 1.1.1
7
- */
8
-
9
- if ( ! class_exists( 'Cartflows_Importer_Beaver_Builder_Batch' ) && class_exists( 'WP_Background_Process' ) ) :
10
-
11
- /**
12
- * Image Background Process
13
- *
14
- * @since 1.1.1
15
- */
16
- class Cartflows_Importer_Beaver_Builder_Batch extends WP_Background_Process {
17
-
18
- /**
19
- * Image Process
20
- *
21
- * @var string
22
- */
23
- protected $action = 'cartflows_beaver_builder_image_process';
24
-
25
- /**
26
- * Task
27
- *
28
- * Override this method to perform any actions required on each
29
- * queue item. Return the modified item for further processing
30
- * in the next pass through. Or, return false to remove the
31
- * item from the queue.
32
- *
33
- * @since 1.1.1
34
- *
35
- * @param integer $post_id Post Id.
36
- * @return mixed
37
- */
38
- protected function task( $post_id ) {
39
-
40
- CartFlows_Importer_Beaver_Builder::get_instance()->import_single_post( $post_id );
41
-
42
- return false;
43
- }
44
-
45
- /**
46
- * Complete
47
- *
48
- * Override if applicable, but ensure that the below actions are
49
- * performed, or, call parent::complete().
50
- *
51
- * @since 1.1.1
52
- */
53
- protected function complete() {
54
-
55
- parent::complete();
56
-
57
- do_action( 'cartflows_import_complete' );
58
-
59
- }
60
-
61
- }
62
-
63
- endif;
1
+ <?php
2
+ /**
3
+ * Beaver Builder Batch Process
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! class_exists( 'Cartflows_Importer_Beaver_Builder_Batch' ) && class_exists( 'WP_Background_Process' ) ) :
10
+
11
+ /**
12
+ * Image Background Process
13
+ *
14
+ * @since 1.1.1
15
+ */
16
+ class Cartflows_Importer_Beaver_Builder_Batch extends WP_Background_Process {
17
+
18
+ /**
19
+ * Image Process
20
+ *
21
+ * @var string
22
+ */
23
+ protected $action = 'cartflows_beaver_builder_image_process';
24
+
25
+ /**
26
+ * Task
27
+ *
28
+ * Override this method to perform any actions required on each
29
+ * queue item. Return the modified item for further processing
30
+ * in the next pass through. Or, return false to remove the
31
+ * item from the queue.
32
+ *
33
+ * @since 1.1.1
34
+ *
35
+ * @param integer $post_id Post Id.
36
+ * @return mixed
37
+ */
38
+ protected function task( $post_id ) {
39
+
40
+ CartFlows_Importer_Beaver_Builder::get_instance()->import_single_post( $post_id );
41
+
42
+ return false;
43
+ }
44
+
45
+ /**
46
+ * Complete
47
+ *
48
+ * Override if applicable, but ensure that the below actions are
49
+ * performed, or, call parent::complete().
50
+ *
51
+ * @since 1.1.1
52
+ */
53
+ protected function complete() {
54
+
55
+ parent::complete();
56
+
57
+ do_action( 'cartflows_import_complete' );
58
+
59
+ }
60
+
61
+ }
62
+
63
+ endif;
classes/batch-process/class-cartflows-importer-beaver-builder.php CHANGED
@@ -1,229 +1,229 @@
1
- <?php
2
- /**
3
- * Beaver Builder Importer
4
- *
5
- * @package CartFlows
6
- * @since 1.1.1
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Importer_Beaver_Builder' ) ) :
10
-
11
- /**
12
- * CartFlows Import Beaver Builder
13
- *
14
- * @since 1.1.1
15
- */
16
- class CartFlows_Importer_Beaver_Builder {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.1
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.1.1
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.1.1
45
- */
46
- public function __construct() {
47
- }
48
-
49
- /**
50
- * Update post meta.
51
- *
52
- * @param integer $post_id Post ID.
53
- * @return void
54
- */
55
- public function import_single_post( $post_id = 0 ) {
56
-
57
- $data = get_post_meta( $post_id, '_fl_builder_data', true );
58
- if ( ! empty( $data ) ) {
59
-
60
- $data = $this->get_import_data( $data );
61
-
62
- // Update page builder data.
63
- update_post_meta( $post_id, '_fl_builder_data', $data );
64
- update_post_meta( $post_id, '_fl_builder_draft', $data );
65
-
66
- // Clear all cache.
67
- FLBuilderModel::delete_asset_cache_for_all_posts();
68
- } else {
69
- wcf()->logger->import_log( '(✕) Not have "Beaver Builder" Data. Post meta _fl_builder_data is empty!' );
70
- }
71
- }
72
-
73
- /**
74
- * Update post meta.
75
- *
76
- * @param array $data Page builder data.
77
- * @return mixed
78
- */
79
- public function get_import_data( $data ) {
80
-
81
- if ( empty( $data ) ) {
82
- return array();
83
- }
84
-
85
- foreach ( $data as $key => $el ) {
86
-
87
- // Import 'row' images.
88
- if ( 'row' === $el->type ) {
89
- $data[ $key ]->settings = self::import_row_images( $el->settings );
90
- }
91
-
92
- // Import 'module' images.
93
- if ( 'module' === $el->type ) {
94
- $data[ $key ]->settings = self::import_module_images( $el->settings );
95
- }
96
-
97
- // Import 'column' images.
98
- if ( 'column' === $el->type ) {
99
- $data[ $key ]->settings = self::import_column_images( $el->settings );
100
- }
101
- }
102
-
103
- return $data;
104
- }
105
-
106
- /**
107
- * Import Module Images.
108
- *
109
- * @param object $settings Module settings object.
110
- * @return object
111
- */
112
- public static function import_module_images( $settings ) {
113
-
114
- /**
115
- * 1) Set photos.
116
- */
117
- $settings = self::import_photo( $settings );
118
-
119
- /**
120
- * 2) Set `$settings->data` for Only type 'image-icon'
121
- *
122
- * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
123
- */
124
- if (
125
- isset( $settings->data ) &&
126
- isset( $settings->photo ) && ! empty( $settings->photo ) &&
127
- 'image-icon' === $settings->type
128
- ) {
129
- $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
130
- }
131
-
132
- /**
133
- * 3) Set `list item` module images
134
- */
135
- if ( isset( $settings->add_list_item ) ) {
136
- foreach ( $settings->add_list_item as $key => $value ) {
137
- $settings->add_list_item[ $key ] = self::import_photo( $value );
138
- }
139
- }
140
-
141
- return $settings;
142
- }
143
-
144
- /**
145
- * Import Column Images.
146
- *
147
- * @param object $settings Column settings object.
148
- * @return object
149
- */
150
- public static function import_column_images( $settings ) {
151
-
152
- // 1) Set BG Images.
153
- $settings = self::import_bg_image( $settings );
154
-
155
- return $settings;
156
- }
157
-
158
- /**
159
- * Import Row Images.
160
- *
161
- * @param object $settings Row settings object.
162
- * @return object
163
- */
164
- public static function import_row_images( $settings ) {
165
-
166
- // 1) Set BG Images.
167
- $settings = self::import_bg_image( $settings );
168
-
169
- return $settings;
170
- }
171
-
172
- /**
173
- * Helper: Import BG Images.
174
- *
175
- * @param object $settings Row settings object.
176
- * @return object
177
- */
178
- public static function import_bg_image( $settings ) {
179
-
180
- if (
181
- ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
182
- ) {
183
- $image = array(
184
- 'url' => $settings->bg_image_src,
185
- 'id' => $settings->bg_image,
186
- );
187
-
188
- $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
189
-
190
- $settings->bg_image_src = $downloaded_image['url'];
191
- $settings->bg_image = $downloaded_image['id'];
192
- }
193
-
194
- return $settings;
195
- }
196
-
197
- /**
198
- * Helper: Import Photo.
199
- *
200
- * @param object $settings Row settings object.
201
- * @return object
202
- */
203
- public static function import_photo( $settings ) {
204
-
205
- if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
206
-
207
- $image = array(
208
- 'url' => $settings->photo_src,
209
- 'id' => $settings->photo,
210
- );
211
-
212
- $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
213
-
214
- $settings->photo_src = $downloaded_image['url'];
215
- $settings->photo = $downloaded_image['id'];
216
- }
217
-
218
- return $settings;
219
- }
220
-
221
-
222
- }
223
-
224
- /**
225
- * Initialize class object with 'get_instance()' method
226
- */
227
- CartFlows_Importer_Beaver_Builder::get_instance();
228
-
229
- endif;
1
+ <?php
2
+ /**
3
+ * Beaver Builder Importer
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Importer_Beaver_Builder' ) ) :
10
+
11
+ /**
12
+ * CartFlows Import Beaver Builder
13
+ *
14
+ * @since 1.1.1
15
+ */
16
+ class CartFlows_Importer_Beaver_Builder {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.1
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.1.1
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.1.1
45
+ */
46
+ public function __construct() {
47
+ }
48
+
49
+ /**
50
+ * Update post meta.
51
+ *
52
+ * @param integer $post_id Post ID.
53
+ * @return void
54
+ */
55
+ public function import_single_post( $post_id = 0 ) {
56
+
57
+ $data = get_post_meta( $post_id, '_fl_builder_data', true );
58
+ if ( ! empty( $data ) ) {
59
+
60
+ $data = $this->get_import_data( $data );
61
+
62
+ // Update page builder data.
63
+ update_post_meta( $post_id, '_fl_builder_data', $data );
64
+ update_post_meta( $post_id, '_fl_builder_draft', $data );
65
+
66
+ // Clear all cache.
67
+ FLBuilderModel::delete_asset_cache_for_all_posts();
68
+ } else {
69
+ wcf()->logger->import_log( '(✕) Not have "Beaver Builder" Data. Post meta _fl_builder_data is empty!' );
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Update post meta.
75
+ *
76
+ * @param array $data Page builder data.
77
+ * @return mixed
78
+ */
79
+ public function get_import_data( $data ) {
80
+
81
+ if ( empty( $data ) ) {
82
+ return array();
83
+ }
84
+
85
+ foreach ( $data as $key => $el ) {
86
+
87
+ // Import 'row' images.
88
+ if ( 'row' === $el->type ) {
89
+ $data[ $key ]->settings = self::import_row_images( $el->settings );
90
+ }
91
+
92
+ // Import 'module' images.
93
+ if ( 'module' === $el->type ) {
94
+ $data[ $key ]->settings = self::import_module_images( $el->settings );
95
+ }
96
+
97
+ // Import 'column' images.
98
+ if ( 'column' === $el->type ) {
99
+ $data[ $key ]->settings = self::import_column_images( $el->settings );
100
+ }
101
+ }
102
+
103
+ return $data;
104
+ }
105
+
106
+ /**
107
+ * Import Module Images.
108
+ *
109
+ * @param object $settings Module settings object.
110
+ * @return object
111
+ */
112
+ public static function import_module_images( $settings ) {
113
+
114
+ /**
115
+ * 1) Set photos.
116
+ */
117
+ $settings = self::import_photo( $settings );
118
+
119
+ /**
120
+ * 2) Set `$settings->data` for Only type 'image-icon'
121
+ *
122
+ * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
123
+ */
124
+ if (
125
+ isset( $settings->data ) &&
126
+ isset( $settings->photo ) && ! empty( $settings->photo ) &&
127
+ 'image-icon' === $settings->type
128
+ ) {
129
+ $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
130
+ }
131
+
132
+ /**
133
+ * 3) Set `list item` module images
134
+ */
135
+ if ( isset( $settings->add_list_item ) ) {
136
+ foreach ( $settings->add_list_item as $key => $value ) {
137
+ $settings->add_list_item[ $key ] = self::import_photo( $value );
138
+ }
139
+ }
140
+
141
+ return $settings;
142
+ }
143
+
144
+ /**
145
+ * Import Column Images.
146
+ *
147
+ * @param object $settings Column settings object.
148
+ * @return object
149
+ */
150
+ public static function import_column_images( $settings ) {
151
+
152
+ // 1) Set BG Images.
153
+ $settings = self::import_bg_image( $settings );
154
+
155
+ return $settings;
156
+ }
157
+
158
+ /**
159
+ * Import Row Images.
160
+ *
161
+ * @param object $settings Row settings object.
162
+ * @return object
163
+ */
164
+ public static function import_row_images( $settings ) {
165
+
166
+ // 1) Set BG Images.
167
+ $settings = self::import_bg_image( $settings );
168
+
169
+ return $settings;
170
+ }
171
+
172
+ /**
173
+ * Helper: Import BG Images.
174
+ *
175
+ * @param object $settings Row settings object.
176
+ * @return object
177
+ */
178
+ public static function import_bg_image( $settings ) {
179
+
180
+ if (
181
+ ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
182
+ ) {
183
+ $image = array(
184
+ 'url' => $settings->bg_image_src,
185
+ 'id' => $settings->bg_image,
186
+ );
187
+
188
+ $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
189
+
190
+ $settings->bg_image_src = $downloaded_image['url'];
191
+ $settings->bg_image = $downloaded_image['id'];
192
+ }
193
+
194
+ return $settings;
195
+ }
196
+
197
+ /**
198
+ * Helper: Import Photo.
199
+ *
200
+ * @param object $settings Row settings object.
201
+ * @return object
202
+ */
203
+ public static function import_photo( $settings ) {
204
+
205
+ if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
206
+
207
+ $image = array(
208
+ 'url' => $settings->photo_src,
209
+ 'id' => $settings->photo,
210
+ );
211
+
212
+ $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
213
+
214
+ $settings->photo_src = $downloaded_image['url'];
215
+ $settings->photo = $downloaded_image['id'];
216
+ }
217
+
218
+ return $settings;
219
+ }
220
+
221
+
222
+ }
223
+
224
+ /**
225
+ * Initialize class object with 'get_instance()' method
226
+ */
227
+ CartFlows_Importer_Beaver_Builder::get_instance();
228
+
229
+ endif;
classes/batch-process/class-cartflows-importer-divi-batch.php CHANGED
@@ -1,63 +1,63 @@
1
- <?php
2
- /**
3
- * Divi Batch Process
4
- *
5
- * @package CartFlows
6
- * @since 1.1.1
7
- */
8
-
9
- if ( ! class_exists( 'Cartflows_Importer_Divi_Batch' ) && class_exists( 'WP_Background_Process' ) ) :
10
-
11
- /**
12
- * Image Background Process
13
- *
14
- * @since 1.1.1
15
- */
16
- class Cartflows_Importer_Divi_Batch extends WP_Background_Process {
17
-
18
- /**
19
- * Image Process
20
- *
21
- * @var string
22
- */
23
- protected $action = 'cartflows_divi_image_process';
24
-
25
- /**
26
- * Task
27
- *
28
- * Override this method to perform any actions required on each
29
- * queue item. Return the modified item for further processing
30
- * in the next pass through. Or, return false to remove the
31
- * item from the queue.
32
- *
33
- * @since 1.1.1
34
- *
35
- * @param integer $post_id Post Id.
36
- * @return mixed
37
- */
38
- protected function task( $post_id ) {
39
-
40
- CartFlows_Importer_Divi::get_instance()->import_single_post( $post_id );
41
-
42
- return false;
43
- }
44
-
45
- /**
46
- * Complete
47
- *
48
- * Override if applicable, but ensure that the below actions are
49
- * performed, or, call parent::complete().
50
- *
51
- * @since 1.1.1
52
- */
53
- protected function complete() {
54
-
55
- parent::complete();
56
-
57
- do_action( 'cartflows_import_complete' );
58
-
59
- }
60
-
61
- }
62
-
63
- endif;
1
+ <?php
2
+ /**
3
+ * Divi Batch Process
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! class_exists( 'Cartflows_Importer_Divi_Batch' ) && class_exists( 'WP_Background_Process' ) ) :
10
+
11
+ /**
12
+ * Image Background Process
13
+ *
14
+ * @since 1.1.1
15
+ */
16
+ class Cartflows_Importer_Divi_Batch extends WP_Background_Process {
17
+
18
+ /**
19
+ * Image Process
20
+ *
21
+ * @var string
22
+ */
23
+ protected $action = 'cartflows_divi_image_process';
24
+
25
+ /**
26
+ * Task
27
+ *
28
+ * Override this method to perform any actions required on each
29
+ * queue item. Return the modified item for further processing
30
+ * in the next pass through. Or, return false to remove the
31
+ * item from the queue.
32
+ *
33
+ * @since 1.1.1
34
+ *
35
+ * @param integer $post_id Post Id.
36
+ * @return mixed
37
+ */
38
+ protected function task( $post_id ) {
39
+
40
+ CartFlows_Importer_Divi::get_instance()->import_single_post( $post_id );
41
+
42
+ return false;
43
+ }
44
+
45
+ /**
46
+ * Complete
47
+ *
48
+ * Override if applicable, but ensure that the below actions are
49
+ * performed, or, call parent::complete().
50
+ *
51
+ * @since 1.1.1
52
+ */
53
+ protected function complete() {
54
+
55
+ parent::complete();
56
+
57
+ do_action( 'cartflows_import_complete' );
58
+
59
+ }
60
+
61
+ }
62
+
63
+ endif;
classes/batch-process/class-cartflows-importer-divi.php CHANGED
@@ -1,217 +1,217 @@
1
- <?php
2
- /**
3
- * Divi Importer
4
- *
5
- * @package CartFlows
6
- * @since 1.1.1
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Importer_Divi' ) ) :
10
-
11
- /**
12
- * CartFlows Import Divi
13
- *
14
- * @since 1.1.1
15
- */
16
- class CartFlows_Importer_Divi {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.1
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.1.1
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.1.1
45
- */
46
- public function __construct() {
47
- add_action( 'admin_head', array( $this, 're_process_data_flow' ) );
48
- add_action( 'admin_head', array( $this, 're_process_data_step' ) );
49
- }
50
-
51
- /**
52
- * Rest Data.
53
- *
54
- * @param integer $post_id Post ID.
55
- * @return void
56
- */
57
- function reset_data( $post_id ) {
58
-
59
- $content = get_post_meta( $post_id, 'divi_content_processed', true );
60
-
61
- if ( ! empty( $content ) ) {
62
-
63
- $content = CartFlows_Importer::get_instance()->get_content( $content );
64
-
65
- // Update post content.
66
- wp_update_post(
67
- array(
68
- 'ID' => $post_id,
69
- 'post_content' => $content,
70
- )
71
- );
72
- }
73
- }
74
-
75
- /**
76
- * Re process data.
77
- */
78
- function re_process_data_flow() {
79
- wcf()->logger->import_log( ' Without batch started.. ' );
80
-
81
- if ( CARTFLOWS_FLOW_POST_TYPE !== get_post_type() ) {
82
- return;
83
- }
84
-
85
- global $pagenow;
86
-
87
- if ( 'post.php' !== $pagenow ) {
88
- return;
89
- }
90
-
91
- // Is Highlight step then return!
92
- // Because, It process only for the first flow import.
93
- if ( isset( $_GET['highlight-step-id'] ) ) {
94
- return;
95
- }
96
-
97
- $post_id = get_the_ID();
98
-
99
- /* If Imported Flow */
100
- if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_flow', true ) ) {
101
- return;
102
- }
103
-
104
- // wcf()->logger->import_log( ' Reprocessing Divi Data.. ' . $post_id );.
105
- $flow_processed = get_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
106
-
107
- if ( ! $flow_processed ) {
108
-
109
- $steps = get_post_meta( $post_id, 'wcf-steps', true );
110
- $steps_count = count( $steps );
111
- $steps_remaing = $steps_count;
112
-
113
- foreach ( $steps as $key => $step ) {
114
-
115
- $step_processed = get_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
116
-
117
- if ( ! $step_processed ) {
118
-
119
- $content = get_post_meta( $step['id'], 'divi_content_processed', true );
120
- // It means that batch is not complete yet.
121
- if ( ! empty( $content ) ) {
122
- $this->reset_data( $step['id'] );
123
-
124
- wcf()->logger->import_log( ' Processing without batch.. ' . $step['id'] );
125
-
126
- // Step processed!
127
- update_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
128
-
129
- $steps_remaing--;
130
- }
131
- }
132
- }
133
-
134
- // All step data processed.
135
- if ( 0 === $steps_remaing ) {
136
- wcf()->logger->import_log( ' ----------- FLOW COMPLETE ----------------- ' . $post_id );
137
- update_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
138
- }
139
- } else {
140
- wcf()->logger->import_log( ' Already processed.. ' );
141
- }
142
-
143
- wcf()->logger->import_log( ' Without batch end.. ' );
144
-
145
- }
146
-
147
- /**
148
- * Re process data for step.
149
- */
150
- function re_process_data_step() {
151
-
152
- wcf()->logger->import_log( ' Without batch started.. ' );
153
-
154
- if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type() ) {
155
- return;
156
- }
157
-
158
- $post_id = get_the_ID();
159
-
160
- /* If Imported Step */
161
- if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_step', true ) ) {
162
- return;
163
- }
164
-
165
- $step_processed = get_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
166
-
167
- if ( ! $step_processed ) {
168
-
169
- $content = get_post_meta( $post_id, 'divi_content_processed', true );
170
- // It means that batch is not complete yet.
171
- if ( ! empty( $content ) ) {
172
- $this->reset_data( $post_id );
173
-
174
- wcf()->logger->import_log( ' Processing without batch.. ' . $post_id );
175
-
176
- // Step processed!
177
- update_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
178
- }
179
- }
180
- }
181
-
182
- /**
183
- * Update post meta.
184
- *
185
- * @param integer $post_id Post ID.
186
- * @return void
187
- */
188
- public function import_single_post( $post_id = 0 ) {
189
-
190
- // Download and replace images.
191
- $content = get_post_meta( $post_id, 'divi_content', true );
192
-
193
- if ( empty( $content ) ) {
194
- wcf()->logger->import_log( '(✕) Not have "Divi" Data. Post content is empty!' );
195
- } else {
196
-
197
- wcf()->logger->import_log( '(✓) Processing Request..' );
198
-
199
- // Update hotlink images.
200
- $content = CartFlows_Importer::get_instance()->get_content( $content );
201
-
202
- // Save processed data.
203
- update_post_meta( $post_id, 'divi_content_processed', $content );
204
-
205
- // Delete temporary meta key.
206
- wcf()->logger->import_log( '(✓) Process Complete' );
207
- }
208
- }
209
-
210
- }
211
-
212
- /**
213
- * Initialize class object with 'get_instance()' method
214
- */
215
- CartFlows_Importer_Divi::get_instance();
216
-
217
- endif;
1
+ <?php
2
+ /**
3
+ * Divi Importer
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Importer_Divi' ) ) :
10
+
11
+ /**
12
+ * CartFlows Import Divi
13
+ *
14
+ * @since 1.1.1
15
+ */
16
+ class CartFlows_Importer_Divi {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.1
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.1.1
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.1.1
45
+ */
46
+ public function __construct() {
47
+ add_action( 'admin_head', array( $this, 're_process_data_flow' ) );
48
+ add_action( 'admin_head', array( $this, 're_process_data_step' ) );
49
+ }
50
+
51
+ /**
52
+ * Rest Data.
53
+ *
54
+ * @param integer $post_id Post ID.
55
+ * @return void
56
+ */
57
+ function reset_data( $post_id ) {
58
+
59
+ $content = get_post_meta( $post_id, 'divi_content_processed', true );
60
+
61
+ if ( ! empty( $content ) ) {
62
+
63
+ $content = CartFlows_Importer::get_instance()->get_content( $content );
64
+
65
+ // Update post content.
66
+ wp_update_post(
67
+ array(
68
+ 'ID' => $post_id,
69
+ 'post_content' => $content,
70
+ )
71
+ );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Re process data.
77
+ */
78
+ function re_process_data_flow() {
79
+ wcf()->logger->import_log( ' Without batch started.. ' );
80
+
81
+ if ( CARTFLOWS_FLOW_POST_TYPE !== get_post_type() ) {
82
+ return;
83
+ }
84
+
85
+ global $pagenow;
86
+
87
+ if ( 'post.php' !== $pagenow ) {
88
+ return;
89
+ }
90
+
91
+ // Is Highlight step then return!
92
+ // Because, It process only for the first flow import.
93
+ if ( isset( $_GET['highlight-step-id'] ) ) {
94
+ return;
95
+ }
96
+
97
+ $post_id = get_the_ID();
98
+
99
+ /* If Imported Flow */
100
+ if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_flow', true ) ) {
101
+ return;
102
+ }
103
+
104
+ // wcf()->logger->import_log( ' Reprocessing Divi Data.. ' . $post_id );.
105
+ $flow_processed = get_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
106
+
107
+ if ( ! $flow_processed ) {
108
+
109
+ $steps = get_post_meta( $post_id, 'wcf-steps', true );
110
+ $steps_count = count( $steps );
111
+ $steps_remaing = $steps_count;
112
+
113
+ foreach ( $steps as $key => $step ) {
114
+
115
+ $step_processed = get_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
116
+
117
+ if ( ! $step_processed ) {
118
+
119
+ $content = get_post_meta( $step['id'], 'divi_content_processed', true );
120
+ // It means that batch is not complete yet.
121
+ if ( ! empty( $content ) ) {
122
+ $this->reset_data( $step['id'] );
123
+
124
+ wcf()->logger->import_log( ' Processing without batch.. ' . $step['id'] );
125
+
126
+ // Step processed!
127
+ update_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
128
+
129
+ $steps_remaing--;
130
+ }
131
+ }
132
+ }
133
+
134
+ // All step data processed.
135
+ if ( 0 === $steps_remaing ) {
136
+ wcf()->logger->import_log( ' ----------- FLOW COMPLETE ----------------- ' . $post_id );
137
+ update_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
138
+ }
139
+ } else {
140
+ wcf()->logger->import_log( ' Already processed.. ' );
141
+ }
142
+
143
+ wcf()->logger->import_log( ' Without batch end.. ' );
144
+
145
+ }
146
+
147
+ /**
148
+ * Re process data for step.
149
+ */
150
+ function re_process_data_step() {
151
+
152
+ wcf()->logger->import_log( ' Without batch started.. ' );
153
+
154
+ if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type() ) {
155
+ return;
156
+ }
157
+
158
+ $post_id = get_the_ID();
159
+
160
+ /* If Imported Step */
161
+ if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_step', true ) ) {
162
+ return;
163
+ }
164
+
165
+ $step_processed = get_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
166
+
167
+ if ( ! $step_processed ) {
168
+
169
+ $content = get_post_meta( $post_id, 'divi_content_processed', true );
170
+ // It means that batch is not complete yet.
171
+ if ( ! empty( $content ) ) {
172
+ $this->reset_data( $post_id );
173
+
174
+ wcf()->logger->import_log( ' Processing without batch.. ' . $post_id );
175
+
176
+ // Step processed!
177
+ update_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Update post meta.
184
+ *
185
+ * @param integer $post_id Post ID.
186
+ * @return void
187
+ */
188
+ public function import_single_post( $post_id = 0 ) {
189
+
190
+ // Download and replace images.
191
+ $content = get_post_meta( $post_id, 'divi_content', true );
192
+
193
+ if ( empty( $content ) ) {
194
+ wcf()->logger->import_log( '(✕) Not have "Divi" Data. Post content is empty!' );
195
+ } else {
196
+
197
+ wcf()->logger->import_log( '(✓) Processing Request..' );
198
+
199
+ // Update hotlink images.
200
+ $content = CartFlows_Importer::get_instance()->get_content( $content );
201
+
202
+ // Save processed data.
203
+ update_post_meta( $post_id, 'divi_content_processed', $content );
204
+
205
+ // Delete temporary meta key.
206
+ wcf()->logger->import_log( '(✓) Process Complete' );
207
+ }
208
+ }
209
+
210
+ }
211
+
212
+ /**
213
+ * Initialize class object with 'get_instance()' method
214
+ */
215
+ CartFlows_Importer_Divi::get_instance();
216
+
217
+ endif;
classes/batch-process/class-cartflows-importer-elementor-batch.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
- /**
3
- * Elementor Batch Process
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'Cartflows_Importer_Elementor_Batch' ) && class_exists( 'WP_Background_Process' ) ) :
10
-
11
- /**
12
- * Image Background Process
13
- *
14
- * @since 1.1.1 Updated class name with Elementor specific.
15
- *
16
- * @since 1.0.0
17
- */
18
- class Cartflows_Importer_Elementor_Batch extends WP_Background_Process {
19
-
20
- /**
21
- * Image Process
22
- *
23
- * @var string
24
- */
25
- protected $action = 'cartflows_elementor_image_process';
26
-
27
- /**
28
- * Task
29
- *
30
- * Override this method to perform any actions required on each
31
- * queue item. Return the modified item for further processing
32
- * in the next pass through. Or, return false to remove the
33
- * item from the queue.
34
- *
35
- * @since 1.0.0
36
- *
37
- * @param integer $post_id Post Id.
38
- * @return mixed
39
- */
40
- protected function task( $post_id ) {
41
-
42
- $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
43
- $obj->import_single_template( $post_id );
44
-
45
- return false;
46
- }
47
-
48
- /**
49
- * Complete
50
- *
51
- * Override if applicable, but ensure that the below actions are
52
- * performed, or, call parent::complete().
53
- *
54
- * @since 1.0.0
55
- */
56
- protected function complete() {
57
-
58
- parent::complete();
59
-
60
- do_action( 'cartflows_import_complete' );
61
-
62
- }
63
-
64
- }
65
-
66
- endif;
1
+ <?php
2
+ /**
3
+ * Elementor Batch Process
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'Cartflows_Importer_Elementor_Batch' ) && class_exists( 'WP_Background_Process' ) ) :
10
+
11
+ /**
12
+ * Image Background Process
13
+ *
14
+ * @since 1.1.1 Updated class name with Elementor specific.
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ class Cartflows_Importer_Elementor_Batch extends WP_Background_Process {
19
+
20
+ /**
21
+ * Image Process
22
+ *
23
+ * @var string
24
+ */
25
+ protected $action = 'cartflows_elementor_image_process';
26
+
27
+ /**
28
+ * Task
29
+ *
30
+ * Override this method to perform any actions required on each
31
+ * queue item. Return the modified item for further processing
32
+ * in the next pass through. Or, return false to remove the
33
+ * item from the queue.
34
+ *
35
+ * @since 1.0.0
36
+ *
37
+ * @param integer $post_id Post Id.
38
+ * @return mixed
39
+ */
40
+ protected function task( $post_id ) {
41
+
42
+ $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
43
+ $obj->import_single_template( $post_id );
44
+
45
+ return false;
46
+ }
47
+
48
+ /**
49
+ * Complete
50
+ *
51
+ * Override if applicable, but ensure that the below actions are
52
+ * performed, or, call parent::complete().
53
+ *
54
+ * @since 1.0.0
55
+ */
56
+ protected function complete() {
57
+
58
+ parent::complete();
59
+
60
+ do_action( 'cartflows_import_complete' );
61
+
62
+ }
63
+
64
+ }
65
+
66
+ endif;
classes/batch-process/class-cartflows-importer-elementor.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- /**
3
- * Elementor Importer
4
- *
5
- * @package CARTFLOWS
6
- */
7
-
8
- namespace Elementor\TemplateLibrary;
9
-
10
- use Elementor\Core\Base\Document;
11
- use Elementor\DB;
12
- use Elementor\Core\Settings\Page\Manager as PageSettingsManager;
13
- use Elementor\Core\Settings\Manager as SettingsManager;
14
- use Elementor\Core\Settings\Page\Model;
15
- use Elementor\Editor;
16
- use Elementor\Plugin;
17
- use Elementor\Settings;
18
- use Elementor\Utils;
19
-
20
- if ( ! defined( 'ABSPATH' ) ) {
21
- exit; // Exit if accessed directly.
22
- }
23
-
24
- /**
25
- * Elementor template library local source.
26
- *
27
- * Elementor template library local source handler class is responsible for
28
- * handling local Elementor templates saved by the user locally on his site.
29
- *
30
- * @since 1.0.0
31
- */
32
- class CartFlows_Importer_Elementor extends Source_Local {
33
-
34
- /**
35
- * Import single template
36
- *
37
- * @param int $post_id post ID.
38
- */
39
- public function import_single_template( $post_id ) {
40
-
41
- $rest_content = get_post_meta( $post_id, '_elementor_data', true );
42
-
43
- if ( empty( $rest_content ) ) {
44
- $data = __( 'Invalid content.', 'cartflows' );
45
- wcf()->logger->import_log( '(✕) ' . $data );
46
- }
47
-
48
- $rest_content = add_magic_quotes( $rest_content );
49
- $content = json_decode( $rest_content, true );
50
-
51
- if ( ! is_array( $content ) ) {
52
- $data = __( 'Invalid content. Expected an array.', 'cartflows' );
53
- wcf()->logger->import_log( '(✕) ' . $data );
54
- wcf()->logger->import_log( $content );
55
- } else {
56
-
57
- wcf()->logger->import_log( '(✓) Processing Request..' );
58
-
59
- // Import the data.
60
- $content = $this->process_export_import_content( $content, 'on_import' );
61
-
62
- // Update content.
63
- update_metadata( 'post', $post_id, '_elementor_data', $content );
64
-
65
- wcf()->logger->import_log( '(✓) Process Complete' );
66
- }
67
-
68
- }
69
- }
1
+ <?php
2
+ /**
3
+ * Elementor Importer
4
+ *
5
+ * @package CARTFLOWS
6
+ */
7
+
8
+ namespace Elementor\TemplateLibrary;
9
+
10
+ use Elementor\Core\Base\Document;
11
+ use Elementor\DB;
12
+ use Elementor\Core\Settings\Page\Manager as PageSettingsManager;
13
+ use Elementor\Core\Settings\Manager as SettingsManager;
14
+ use Elementor\Core\Settings\Page\Model;
15
+ use Elementor\Editor;
16
+ use Elementor\Plugin;
17
+ use Elementor\Settings;
18
+ use Elementor\Utils;
19
+
20
+ if ( ! defined( 'ABSPATH' ) ) {
21
+ exit; // Exit if accessed directly.
22
+ }
23
+
24
+ /**
25
+ * Elementor template library local source.
26
+ *
27
+ * Elementor template library local source handler class is responsible for
28
+ * handling local Elementor templates saved by the user locally on his site.
29
+ *
30
+ * @since 1.0.0
31
+ */
32
+ class CartFlows_Importer_Elementor extends Source_Local {
33
+
34
+ /**
35
+ * Import single template
36
+ *
37
+ * @param int $post_id post ID.
38
+ */
39
+ public function import_single_template( $post_id ) {
40
+
41
+ $rest_content = get_post_meta( $post_id, '_elementor_data', true );
42
+
43
+ if ( empty( $rest_content ) ) {
44
+ $data = __( 'Invalid content.', 'cartflows' );
45
+ wcf()->logger->import_log( '(✕) ' . $data );
46
+ }
47
+
48
+ $rest_content = add_magic_quotes( $rest_content );
49
+ $content = json_decode( $rest_content, true );
50
+
51
+ if ( ! is_array( $content ) ) {
52
+ $data = __( 'Invalid content. Expected an array.', 'cartflows' );
53
+ wcf()->logger->import_log( '(✕) ' . $data );
54
+ wcf()->logger->import_log( $content );
55
+ } else {
56
+
57
+ wcf()->logger->import_log( '(✓) Processing Request..' );
58
+
59
+ // Import the data.
60
+ $content = $this->process_export_import_content( $content, 'on_import' );
61
+
62
+ // Update content.
63
+ update_metadata( 'post', $post_id, '_elementor_data', $content );
64
+
65
+ wcf()->logger->import_log( '(✓) Process Complete' );
66
+ }
67
+
68
+ }
69
+ }
classes/class-cartflows-admin-fields.php CHANGED
@@ -1,198 +1,198 @@
1
- <?php
2
- /**
3
- * CARTFLOWS Admin Fields.
4
- *
5
- * @package CARTFLOWS
6
- */
7
-
8
- /**
9
- * Class Cartflows_Admin_Fields.
10
- */
11
- class Cartflows_Admin_Fields {
12
-
13
- /**
14
- * Text Field
15
- *
16
- * @param array $args Args.
17
- * @return string
18
- */
19
- static public function text_field( $args ) {
20
-
21
- $id = $args['id'];
22
- $name = $args['name'];
23
- $title = $args['title'];
24
- $value = $args['value'];
25
-
26
- $output = '<div class="form-field" id="form-field-' . $id . '">';
27
- $output .= '<label for="' . $id . '">' . $title . '</label>';
28
- $output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_attr( $value ) . '">';
29
- $output .= '</div>';
30
-
31
- return $output;
32
- }
33
-
34
- /**
35
- * URL Field
36
- *
37
- * @param array $args Args.
38
- * @return string
39
- */
40
- static public function url_field( $args ) {
41
-
42
- $id = $args['id'];
43
- $name = $args['name'];
44
- $title = $args['title'];
45
- $value = $args['value'];
46
-
47
- $output = '<div class="form-field">';
48
- $output .= '<label for="' . $id . '">' . $title . '</label>';
49
- $output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_url( $value ) . '">';
50
- $output .= '</div>';
51
-
52
- return $output;
53
- }
54
-
55
- /**
56
- * Checkbox Field
57
- *
58
- * @param array $args Args.
59
- * @return string
60
- */
61
- static public function checkobox_field( $args ) {
62
-
63
- $id = $args['id'];
64
- $name = $args['name'];
65
- $title = $args['title'];
66
- $value = $args['value'];
67
-
68
- $output = '<div class="form-field" id="form-field-' . $id . '">';
69
- $output .= '<label for="' . $id . '">';
70
- $output .= '<input type="hidden" id="wcf_hid_' . $id . '" name="' . $name . '" value="disable">';
71
- $output .= '<input type="checkbox" id="wcf_' . $id . '" name="' . $name . '" value="enable" ' . checked( $value, 'enable', false ) . '>';
72
- $output .= $title;
73
- $output .= '</label>';
74
- $output .= '</div>';
75
-
76
- return $output;
77
- }
78
-
79
- /**
80
- * Select Field
81
- *
82
- * @since 1.1.4
83
- *
84
- * @param array $args Args.
85
- * @return string
86
- */
87
- static public function select_field( $args ) {
88
-
89
- $id = $args['id'];
90
- $name = $args['name'];
91
- $title = $args['title'];
92
- $description = $args['description'];
93
- $value = $args['value'];
94
- $options = $args['options'];
95
-
96
- $output = '<div class="form-field" id="form-field-' . $id . '">';
97
-
98
- $output .= '<div class="form-field-label">';
99
- $output .= $title;
100
- $output .= '</div>';
101
-
102
- $output .= '<div class="form-field-data">';
103
- $output .= '<select id="wcf_' . $id . '" name="' . $name . '">';
104
- foreach ( $options as $option_value => $option_title ) {
105
- $output .= '<option value="' . $option_value . '" ' . selected( $value, $option_value, false ) . '>' . $option_title . '</option>';
106
- }
107
- $output .= '</select>';
108
- $output .= '</div>';
109
-
110
- $output .= '<div class="form-field-desc">';
111
- $output .= '<p>';
112
- $output .= $description;
113
- $output .= '</p>';
114
- $output .= '</div>';
115
- $output .= '</div>';
116
-
117
- return $output;
118
- }
119
-
120
- /**
121
- * Checkout Selection Field
122
- *
123
- * @param array $args Args.
124
- * @return string
125
- */
126
- static public function flow_checkout_selection_field( $args ) {
127
-
128
- $id = $args['id'];
129
- $name = $args['name'];
130
- $title = $args['title'];
131
- $value = $args['value'];
132
-
133
- $checkout_steps = get_posts(
134
- array(
135
- 'posts_per_page' => -1,
136
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
137
- 'post_status' => 'publish',
138
- 'orderby' => 'ID',
139
- 'order' => 'ASC',
140
- 'tax_query' => array(
141
- array(
142
- 'taxonomy' => CARTFLOWS_TAXONOMY_STEP_TYPE,
143
- 'field' => 'slug',
144
- 'terms' => 'checkout',
145
- ),
146
- ),
147
- )
148
- );
149
-
150
- $output = '<div class="form-field" id="form-field-' . $id . '">';
151
-
152
- $output .= '<div class="form-field-label">';
153
- $output .= '<label for="' . $id . '">';
154
- $output .= $title;
155
- $output .= '</label>';
156
- $output .= '</div>';
157
-
158
- $output .= '<div class="form-field-data">';
159
- $output .= '<select id="wcf_' . $id . '" name="' . $name . '">';
160
-
161
- if ( ! empty( $checkout_steps ) ) {
162
- $output .= '<option value="">' . __( 'Select', 'cartflows' ) . '</option>';
163
- } else {
164
-
165
- $output .= '<option value="">' . __( 'No Checkout Steps', 'cartflows' ) . '</option>';
166
- }
167
-
168
- foreach ( $checkout_steps as $index => $step_data ) {
169
-
170
- $output .= '<option value="' . $step_data->ID . '" ' . selected( $value, $step_data->ID, false ) . '>' . $step_data->post_title . ' (#' . $step_data->ID . ') </option>';
171
- }
172
-
173
- $output .= '</select>';
174
- $output .= '</div>';
175
-
176
- if ( '' !== $value ) {
177
- $output .= '<div class="form-field-actions">';
178
- $output .= '<a href="' . get_edit_post_link( $value ) . '" target="_blank" class="" title="Edit">';
179
- $output .= '<span class="dashicons dashicons-edit"></span>';
180
- $output .= '<span class="">Edit</span>';
181
- $output .= '</a>';
182
- $output .= '<a href="' . get_permalink( $value ) . '" target="_blank" class="" title="View">';
183
- $output .= '<span class="dashicons dashicons-visibility"></span>';
184
- $output .= '<span class="">View</span>';
185
- $output .= '</a>';
186
- $output .= '</div>';
187
- }
188
-
189
- $output .= '<div class="form-field-desc">';
190
- /* translators: %s: link */
191
- $output .= '<p>' . sprintf( __( 'Be sure not to add any product in above selected Global Checkout step. Please read information about how to set up Global Checkout %1$shere%2$s.', 'cartflows' ), '<a href="https://cartflows.com/docs/global-checkout/" target="_blank">', '</a>' ) . '</p>';
192
- $output .= '</div>';
193
-
194
- $output .= '</div>';
195
-
196
- return $output;
197
- }
198
- }
1
+ <?php
2
+ /**
3
+ * CARTFLOWS Admin Fields.
4
+ *
5
+ * @package CARTFLOWS
6
+ */
7
+
8
+ /**
9
+ * Class Cartflows_Admin_Fields.
10
+ */
11
+ class Cartflows_Admin_Fields {
12
+
13
+ /**
14
+ * Text Field
15
+ *
16
+ * @param array $args Args.
17
+ * @return string
18
+ */
19
+ static public function text_field( $args ) {
20
+
21
+ $id = $args['id'];
22
+ $name = $args['name'];
23
+ $title = $args['title'];
24
+ $value = $args['value'];
25
+
26
+ $output = '<div class="form-field" id="form-field-' . $id . '">';
27
+ $output .= '<label for="' . $id . '">' . $title . '</label>';
28
+ $output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_attr( $value ) . '">';
29
+ $output .= '</div>';
30
+
31
+ return $output;
32
+ }
33
+
34
+ /**
35
+ * URL Field
36
+ *
37
+ * @param array $args Args.
38
+ * @return string
39
+ */
40
+ static public function url_field( $args ) {
41
+
42
+ $id = $args['id'];
43
+ $name = $args['name'];
44
+ $title = $args['title'];
45
+ $value = $args['value'];
46
+
47
+ $output = '<div class="form-field">';
48
+ $output .= '<label for="' . $id . '">' . $title . '</label>';
49
+ $output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_url( $value ) . '">';
50
+ $output .= '</div>';
51
+
52
+ return $output;
53
+ }
54
+
55
+ /**
56
+ * Checkbox Field
57
+ *
58
+ * @param array $args Args.
59
+ * @return string
60
+ */
61
+ static public function checkobox_field( $args ) {
62
+
63
+ $id = $args['id'];
64
+ $name = $args['name'];
65
+ $title = $args['title'];
66
+ $value = $args['value'];
67
+
68
+ $output = '<div class="form-field" id="form-field-' . $id . '">';
69
+ $output .= '<label for="' . $id . '">';
70
+ $output .= '<input type="hidden" id="wcf_hid_' . $id . '" name="' . $name . '" value="disable">';
71
+ $output .= '<input type="checkbox" id="wcf_' . $id . '" name="' . $name . '" value="enable" ' . checked( $value, 'enable', false ) . '>';
72
+ $output .= $title;
73
+ $output .= '</label>';
74
+ $output .= '</div>';
75
+
76
+ return $output;
77
+ }
78
+
79
+ /**
80
+ * Select Field
81
+ *
82
+ * @since 1.1.4
83
+ *
84
+ * @param array $args Args.
85
+ * @return string
86
+ */
87
+ static public function select_field( $args ) {
88
+
89
+ $id = $args['id'];
90
+ $name = $args['name'];
91
+ $title = $args['title'];
92
+ $description = $args['description'];
93
+ $value = $args['value'];
94
+ $options = $args['options'];
95
+
96
+ $output = '<div class="form-field" id="form-field-' . $id . '">';
97
+
98
+ $output .= '<div class="form-field-label">';
99
+ $output .= $title;
100
+ $output .= '</div>';
101
+
102
+ $output .= '<div class="form-field-data">';
103
+ $output .= '<select id="wcf_' . $id . '" name="' . $name . '">';
104
+ foreach ( $options as $option_value => $option_title ) {
105
+ $output .= '<option value="' . $option_value . '" ' . selected( $value, $option_value, false ) . '>' . $option_title . '</option>';
106
+ }
107
+ $output .= '</select>';
108
+ $output .= '</div>';
109
+
110
+ $output .= '<div class="form-field-desc">';
111
+ $output .= '<p>';
112
+ $output .= $description;
113
+ $output .= '</p>';
114
+ $output .= '</div>';
115
+ $output .= '</div>';
116
+
117
+ return $output;
118
+ }
119
+
120
+ /**
121
+ * Checkout Selection Field
122
+ *
123
+ * @param array $args Args.
124
+ * @return string
125
+ */
126
+ static public function flow_checkout_selection_field( $args ) {
127
+
128
+ $id = $args['id'];
129
+ $name = $args['name'];
130
+ $title = $args['title'];
131
+ $value = $args['value'];
132
+
133
+ $checkout_steps = get_posts(
134
+ array(
135
+ 'posts_per_page' => -1,
136
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
137
+ 'post_status' => 'publish',
138
+ 'orderby' => 'ID',
139
+ 'order' => 'ASC',
140
+ 'tax_query' => array(
141
+ array(
142
+ 'taxonomy' => CARTFLOWS_TAXONOMY_STEP_TYPE,
143
+ 'field' => 'slug',
144
+ 'terms' => 'checkout',
145
+ ),
146
+ ),
147
+ )
148
+ );
149
+
150
+ $output = '<div class="form-field" id="form-field-' . $id . '">';
151
+
152
+ $output .= '<div class="form-field-label">';
153
+ $output .= '<label for="' . $id . '">';
154
+ $output .= $title;
155
+ $output .= '</label>';
156
+ $output .= '</div>';
157
+
158
+ $output .= '<div class="form-field-data">';
159
+ $output .= '<select id="wcf_' . $id . '" name="' . $name . '">';
160
+
161
+ if ( ! empty( $checkout_steps ) ) {
162
+ $output .= '<option value="">' . __( 'Select', 'cartflows' ) . '</option>';
163
+ } else {
164
+
165
+ $output .= '<option value="">' . __( 'No Checkout Steps', 'cartflows' ) . '</option>';
166
+ }
167
+
168
+ foreach ( $checkout_steps as $index => $step_data ) {
169
+
170
+ $output .= '<option value="' . $step_data->ID . '" ' . selected( $value, $step_data->ID, false ) . '>' . $step_data->post_title . ' (#' . $step_data->ID . ') </option>';
171
+ }
172
+
173
+ $output .= '</select>';
174
+ $output .= '</div>';
175
+
176
+ if ( '' !== $value ) {
177
+ $output .= '<div class="form-field-actions">';
178
+ $output .= '<a href="' . get_edit_post_link( $value ) . '" target="_blank" class="" title="Edit">';
179
+ $output .= '<span class="dashicons dashicons-edit"></span>';
180
+ $output .= '<span class="">Edit</span>';
181
+ $output .= '</a>';
182
+ $output .= '<a href="' . get_permalink( $value ) . '" target="_blank" class="" title="View">';
183
+ $output .= '<span class="dashicons dashicons-visibility"></span>';
184
+ $output .= '<span class="">View</span>';
185
+ $output .= '</a>';
186
+ $output .= '</div>';
187
+ }
188
+
189
+ $output .= '<div class="form-field-desc">';
190
+ /* translators: %s: link */
191
+ $output .= '<p>' . sprintf( __( 'Be sure not to add any product in above selected Global Checkout step. Please read information about how to set up Global Checkout %1$shere%2$s.', 'cartflows' ), '<a href="https://cartflows.com/docs/global-checkout/" target="_blank">', '</a>' ) . '</p>';
192
+ $output .= '</div>';
193
+
194
+ $output .= '</div>';
195
+
196
+ return $output;
197
+ }
198
+ }
classes/class-cartflows-admin.php CHANGED
@@ -1,437 +1,445 @@
1
- <?php
2
- /**
3
- * CartFlows Admin.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Class Cartflows_Admin.
10
- */
11
- class Cartflows_Admin {
12
-
13
- /**
14
- * Calls on initialization
15
- *
16
- * @since 1.0.0
17
- */
18
- public static function init() {
19
-
20
- self::initialise_plugin();
21
- self::init_hooks();
22
- }
23
-
24
- /**
25
- * Init Hooks.
26
- *
27
- * @since 1.0.0
28
- * @return void
29
- */
30
- static public function init_hooks() {
31
-
32
- if ( ! is_admin() ) {
33
- return;
34
- }
35
-
36
- include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin-fields.php';
37
-
38
- // Add CARTFLOWS menu option to admin.
39
- add_action( 'network_admin_menu', __CLASS__ . '::menu' );
40
- add_action( 'admin_menu', __CLASS__ . '::menu' );
41
- add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
42
-
43
- add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
44
-
45
- // Enqueue admin scripts.
46
- if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS == $_REQUEST['page'] ) {
47
-
48
- add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
49
-
50
- self::save_settings();
51
- }
52
-
53
- /* Global Addmin Script */
54
- add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
55
-
56
- add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
57
-
58
- /* Add lite version class to body */
59
- add_action( 'admin_body_class', __CLASS__ . '::add_admin_body_class' );
60
- }
61
-
62
- /**
63
- * Initialises the Plugin Name.
64
- *
65
- * @since 1.0.0
66
- * @return void
67
- */
68
- static public function initialise_plugin() {
69
-
70
- $name = 'Cartflows';
71
- $short_name = 'Cflows';
72
-
73
- define( 'CARTFLOWS_PLUGIN_NAME', $name );
74
- define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
75
- }
76
-
77
- /**
78
- * Renders the admin settings menu.
79
- *
80
- * @since 1.0.0
81
- * @return void
82
- */
83
- static public function menu() {
84
-
85
- if ( ! current_user_can( 'manage_options' ) ) {
86
- return;
87
- }
88
-
89
- add_menu_page(
90
- 'CartFlows',
91
- 'CartFlows',
92
- 'manage_options',
93
- CARTFLOWS_SLUG,
94
- __CLASS__ . '::render',
95
- 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),
96
- 39.7
97
- );
98
-
99
- }
100
-
101
- /**
102
- * Add submenu to admin menu.
103
- *
104
- * @since 1.0.0
105
- */
106
- static function submenu() {
107
-
108
- $parent_slug = CARTFLOWS_SLUG;
109
- $page_title = __( 'Settings', 'cartflows' );
110
- $menu_title = __( 'Settings', 'cartflows' );
111
- $capability = 'manage_options';
112
- $menu_slug = 'cartflows_settings';
113
- $callback = __CLASS__ . '::render';
114
-
115
- add_submenu_page(
116
- $parent_slug,
117
- $page_title,
118
- $menu_title,
119
- $capability,
120
- $menu_slug,
121
- $callback
122
- );
123
- }
124
-
125
- /**
126
- * Renders the admin settings.
127
- *
128
- * @since 1.0.0
129
- * @return void
130
- */
131
- static public function render() {
132
- $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
133
- $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
134
- $action = str_replace( '_', '-', $action );
135
-
136
- // Enable header icon filter below.
137
- $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
138
-
139
- include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
140
- }
141
-
142
- /**
143
- * Renders the admin settings content.
144
- *
145
- * @since 1.0.0
146
- * @return void
147
- */
148
- static public function render_content() {
149
-
150
- $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
151
- $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
152
- $action = str_replace( '_', '-', $action );
153
- $action = 'general';
154
-
155
- $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
156
-
157
- include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
158
- }
159
-
160
- /**
161
- * Save Global Setting options.
162
- *
163
- * @since 1.0.0
164
- */
165
- static public function save_common_settings() {
166
-
167
- if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-common-settings-nonce'], 'cartflows-common-settings' ) ) {
168
-
169
- $url = $_SERVER['REQUEST_URI'];
170
- $input_settings = array();
171
- $new_settings = array();
172
-
173
- if ( isset( $_POST['_cartflows_common'] ) ) {
174
-
175
- $input_settings = $_POST['_cartflows_common'];
176
-
177
- // Loop through the input and sanitize each of the values.
178
- foreach ( $input_settings as $key => $val ) {
179
-
180
- if ( is_array( $val ) ) {
181
- foreach ( $val as $k => $v ) {
182
- $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
183
- }
184
- } else {
185
- $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
186
- }
187
- }
188
- }
189
-
190
- Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true );
191
-
192
- $query = array(
193
- 'message' => 'saved',
194
- );
195
-
196
- $redirect_to = add_query_arg( $query, $url );
197
-
198
- wp_redirect( $redirect_to );
199
- exit;
200
- } // End if statement.
201
- }
202
-
203
- /**
204
- * Check is cartflows admin.
205
- *
206
- * @since 1.0.0
207
- * @return boolean
208
- */
209
- static public function is_global_admin() {
210
-
211
- $current_screen = get_current_screen();
212
-
213
- if (
214
- is_object( $current_screen ) &&
215
- isset( $current_screen->post_type ) &&
216
- ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
217
- CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
218
- )
219
- ) {
220
- return true;
221
- }
222
- return false;
223
- }
224
-
225
- /**
226
- * Check is flow admin.
227
- *
228
- * @since 1.0.0
229
- * @return boolean
230
- */
231
- static public function is_flow_edit_admin() {
232
-
233
- $current_screen = get_current_screen();
234
-
235
- if (
236
- is_object( $current_screen ) &&
237
- isset( $current_screen->post_type ) &&
238
- ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
239
- isset( $current_screen->base ) &&
240
- ( 'post' === $current_screen->base )
241
- ) {
242
- return true;
243
- }
244
- return false;
245
- }
246
-
247
- /**
248
- * Global Admin Scripts.
249
- *
250
- * @since 1.0.0
251
- */
252
- static public function global_admin_scripts() {
253
-
254
- $localize = array(
255
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
256
- 'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
257
- );
258
-
259
- wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
260
-
261
- if ( self::is_global_admin() ) {
262
-
263
- // Styles.
264
- wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
265
- wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
266
-
267
- wp_enqueue_script(
268
- 'wcf-global-admin',
269
- CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
270
- array( 'jquery' ),
271
- CARTFLOWS_VER,
272
- true
273
- );
274
-
275
- do_action( 'cartflows_global_admin_scripts' );
276
- }
277
- }
278
-
279
- /**
280
- * Global Admin Data.
281
- *
282
- * @since 1.0.0
283
- */
284
- static public function global_admin_data() {
285
-
286
- $current_screen = get_current_screen();
287
-
288
- if ( ! $current_screen ) {
289
- return;
290
- }
291
-
292
- if ( 'edit-' . CARTFLOWS_FLOW_POST_TYPE != $current_screen->id ) {
293
- return;
294
- }
295
-
296
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
297
- ?>
298
-
299
- <div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
300
- <div class="wcf-templates-popup-content">
301
- <div class="spinner"></div>
302
- <div class="wcf-templates-wrap wcf-templates-wrap-flows">
303
-
304
- <div id="wcf-remote-flow-actions" class="wcf-template-header">
305
- <div class="wcf-template-logo-wrap">
306
- <span class="wcf-cartflows-logo-img">
307
- <span class="cartflows-logo-icon"></span>
308
- </span>
309
- <span class="wcf-cartflows-title"><?php _e( 'Flows Library', 'cartflows' ); ?></span>
310
- </div>
311
- <div class="wcf-tab-wrapper">
312
- <?php if ( 'other' !== $default_page_builder ) { ?>
313
- <div id="wcf-get-started-steps">
314
- <ul class="filter-links ">
315
- <li>
316
- <a href="#" class="current" data-slug="ready-templates" data-title="<?php _e( 'Ready Templates', 'cartflows' ); ?>"><?php _e( 'Ready Templates', 'cartflows' ); ?></a>
317
- </li>
318
- <li>
319
- <a href="#" data-slug="canvas" data-title="<?php _e( 'Create Your Own', 'cartflows' ); ?>"><?php _e( 'Create Your Own', 'cartflows' ); ?></a>
320
- </li>
321
- </ul>
322
- </div>
323
- <?php } ?>
324
- </div>
325
- <div class="wcf-popup-close-wrap">
326
- <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
327
- </div>
328
- </div>
329
- <!-- <div class="wcf-search-form">
330
- <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
331
- <input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
332
- </div> -->
333
-
334
- <div id="wcf-remote-content">
335
- <?php if ( 'other' !== $default_page_builder ) { ?>
336
- <div id="wcf-ready-templates">
337
- <div id="wcf-remote-filters">
338
- <div id="wcf-page-builders"></div>
339
- <div id="wcf-categories"></div>
340
- </div>
341
- <div class="wcf-page-builder-notice"></div>
342
- <div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
343
- <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
344
- </div>
345
- <?php } ?>
346
- <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
347
- <div class="inner">
348
- <a href="#" class="button button-hero button-primary cartflows-flow-import-blank"><?php _e( 'Design Your Flow', 'cartflows' ); ?></a>
349
- <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php _e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
350
- </div>
351
- </div>
352
- </div>
353
- </div>
354
- </div>
355
- </div>
356
-
357
- <?php
358
- }
359
-
360
- /**
361
- * Enqueues the needed CSS/JS for the builder's admin settings page.
362
- *
363
- * @since 1.0.0
364
- */
365
- static public function styles_scripts() {
366
-
367
- // Styles.
368
- wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
369
- wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
370
-
371
- // Script.
372
- wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
373
-
374
- $localize = array(
375
- 'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
376
- );
377
-
378
- wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
379
- }
380
-
381
- /**
382
- * Save All admin settings here
383
- */
384
- static public function save_settings() {
385
-
386
- // Only admins can save settings.
387
- if ( ! current_user_can( 'manage_options' ) ) {
388
- return;
389
- }
390
-
391
- self::save_common_settings();
392
-
393
- // Let extensions hook into saving.
394
- do_action( 'cartflows_admin_settings_save' );
395
- }
396
-
397
- /**
398
- * Get and return page URL
399
- *
400
- * @param string $menu_slug Menu name.
401
- * @since 1.0.0
402
- * @return string page url
403
- */
404
- static public function get_page_url( $menu_slug ) {
405
-
406
- $parent_page = self::$default_menu_position;
407
-
408
- if ( strpos( $parent_page, '?' ) !== false ) {
409
- $query_var = '&page=' . self::$plugin_slug;
410
- } else {
411
- $query_var = '?page=' . self::$plugin_slug;
412
- }
413
-
414
- $parent_page_url = admin_url( $parent_page . $query_var );
415
-
416
- $url = $parent_page_url . '&action=' . $menu_slug;
417
-
418
- return esc_url( $url );
419
- }
420
-
421
- /**
422
- * Admin body classes.
423
- *
424
- * Body classes to be added to <body> tag in admin page
425
- *
426
- * @param String $classes body classes returned from the filter.
427
- * @return String body classes to be added to <body> tag in admin page
428
- */
429
- static public function add_admin_body_class( $classes ) {
430
-
431
- $classes .= ' cartflows-' . CARTFLOWS_VER;
432
-
433
- return $classes;
434
- }
435
- }
436
-
437
- Cartflows_Admin::init();
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * CartFlows Admin.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Class Cartflows_Admin.
10
+ */
11
+ class Cartflows_Admin {
12
+
13
+ /**
14
+ * Calls on initialization
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ public static function init() {
19
+
20
+ self::initialise_plugin();
21
+ self::init_hooks();
22
+ }
23
+
24
+ /**
25
+ * Init Hooks.
26
+ *
27
+ * @since 1.0.0
28
+ * @return void
29
+ */
30
+ static public function init_hooks() {
31
+
32
+ if ( ! is_admin() ) {
33
+ return;
34
+ }
35
+
36
+ include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin-fields.php';
37
+
38
+ // Add CARTFLOWS menu option to admin.
39
+ add_action( 'network_admin_menu', __CLASS__ . '::menu' );
40
+ add_action( 'admin_menu', __CLASS__ . '::menu' );
41
+ add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
42
+
43
+ add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
44
+
45
+ add_action( 'init', __CLASS__ . '::settings_admin_scripts' );
46
+
47
+ /* Global Addmin Script */
48
+ add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
49
+
50
+ add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
51
+
52
+ /* Add lite version class to body */
53
+ add_action( 'admin_body_class', __CLASS__ . '::add_admin_body_class' );
54
+ }
55
+
56
+
57
+ /**
58
+ * Initialize after Cartflows pro get loaded.
59
+ */
60
+ static public function settings_admin_scripts() {
61
+ // Enqueue admin scripts.
62
+ if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS == $_REQUEST['page'] ) {
63
+ add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
64
+
65
+ self::save_settings();
66
+ }
67
+ }
68
+ /**
69
+ * Initialises the Plugin Name.
70
+ *
71
+ * @since 1.0.0
72
+ * @return void
73
+ */
74
+ static public function initialise_plugin() {
75
+
76
+ $name = 'Cartflows';
77
+ $short_name = 'Cflows';
78
+
79
+ define( 'CARTFLOWS_PLUGIN_NAME', $name );
80
+ define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
81
+ }
82
+
83
+ /**
84
+ * Renders the admin settings menu.
85
+ *
86
+ * @since 1.0.0
87
+ * @return void
88
+ */
89
+ static public function menu() {
90
+
91
+ if ( ! current_user_can( 'manage_options' ) ) {
92
+ return;
93
+ }
94
+
95
+ add_menu_page(
96
+ 'CartFlows',
97
+ 'CartFlows',
98
+ 'manage_options',
99
+ CARTFLOWS_SLUG,
100
+ __CLASS__ . '::render',
101
+ 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),
102
+ 39.7
103
+ );
104
+
105
+ }
106
+
107
+ /**
108
+ * Add submenu to admin menu.
109
+ *
110
+ * @since 1.0.0
111
+ */
112
+ static function submenu() {
113
+
114
+ $parent_slug = CARTFLOWS_SLUG;
115
+ $page_title = __( 'Settings', 'cartflows' );
116
+ $menu_title = __( 'Settings', 'cartflows' );
117
+ $capability = 'manage_options';
118
+ $menu_slug = 'cartflows_settings';
119
+ $callback = __CLASS__ . '::render';
120
+
121
+ add_submenu_page(
122
+ $parent_slug,
123
+ $page_title,
124
+ $menu_title,
125
+ $capability,
126
+ $menu_slug,
127
+ $callback
128
+ );
129
+ }
130
+
131
+ /**
132
+ * Renders the admin settings.
133
+ *
134
+ * @since 1.0.0
135
+ * @return void
136
+ */
137
+ static public function render() {
138
+ $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
139
+ $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
140
+ $action = str_replace( '_', '-', $action );
141
+
142
+ // Enable header icon filter below.
143
+ $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
144
+
145
+ include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
146
+ }
147
+
148
+ /**
149
+ * Renders the admin settings content.
150
+ *
151
+ * @since 1.0.0
152
+ * @return void
153
+ */
154
+ static public function render_content() {
155
+
156
+ $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
157
+ $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
158
+ $action = str_replace( '_', '-', $action );
159
+ $action = 'general';
160
+
161
+ $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
162
+
163
+ include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
164
+ }
165
+
166
+ /**
167
+ * Save Global Setting options.
168
+ *
169
+ * @since 1.0.0
170
+ */
171
+ static public function save_common_settings() {
172
+
173
+ if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-common-settings-nonce'], 'cartflows-common-settings' ) ) {
174
+
175
+ $url = $_SERVER['REQUEST_URI'];
176
+ $input_settings = array();
177
+ $new_settings = array();
178
+
179
+ if ( isset( $_POST['_cartflows_common'] ) ) {
180
+
181
+ $input_settings = $_POST['_cartflows_common'];
182
+
183
+ // Loop through the input and sanitize each of the values.
184
+ foreach ( $input_settings as $key => $val ) {
185
+
186
+ if ( is_array( $val ) ) {
187
+ foreach ( $val as $k => $v ) {
188
+ $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
189
+ }
190
+ } else {
191
+ $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
192
+ }
193
+ }
194
+ }
195
+
196
+ Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true );
197
+
198
+ $query = array(
199
+ 'message' => 'saved',
200
+ );
201
+
202
+ $redirect_to = add_query_arg( $query, $url );
203
+
204
+ wp_redirect( $redirect_to );
205
+ exit;
206
+ } // End if statement.
207
+ }
208
+
209
+ /**
210
+ * Check is cartflows admin.
211
+ *
212
+ * @since 1.0.0
213
+ * @return boolean
214
+ */
215
+ static public function is_global_admin() {
216
+
217
+ $current_screen = get_current_screen();
218
+
219
+ if (
220
+ is_object( $current_screen ) &&
221
+ isset( $current_screen->post_type ) &&
222
+ ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
223
+ CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
224
+ )
225
+ ) {
226
+ return true;
227
+ }
228
+ return false;
229
+ }
230
+
231
+ /**
232
+ * Check is flow admin.
233
+ *
234
+ * @since 1.0.0
235
+ * @return boolean
236
+ */
237
+ static public function is_flow_edit_admin() {
238
+
239
+ $current_screen = get_current_screen();
240
+
241
+ if (
242
+ is_object( $current_screen ) &&
243
+ isset( $current_screen->post_type ) &&
244
+ ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
245
+ isset( $current_screen->base ) &&
246
+ ( 'post' === $current_screen->base )
247
+ ) {
248
+ return true;
249
+ }
250
+ return false;
251
+ }
252
+
253
+ /**
254
+ * Global Admin Scripts.
255
+ *
256
+ * @since 1.0.0
257
+ */
258
+ static public function global_admin_scripts() {
259
+
260
+ $localize = array(
261
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
262
+ 'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
263
+ );
264
+
265
+ wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
266
+
267
+ if ( self::is_global_admin() ) {
268
+
269
+ // Styles.
270
+ wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
271
+ wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
272
+
273
+ wp_enqueue_script(
274
+ 'wcf-global-admin',
275
+ CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
276
+ array( 'jquery' ),
277
+ CARTFLOWS_VER,
278
+ true
279
+ );
280
+
281
+ do_action( 'cartflows_global_admin_scripts' );
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Global Admin Data.
287
+ *
288
+ * @since 1.0.0
289
+ */
290
+ static public function global_admin_data() {
291
+
292
+ $current_screen = get_current_screen();
293
+
294
+ if ( ! $current_screen ) {
295
+ return;
296
+ }
297
+
298
+ if ( 'edit-' . CARTFLOWS_FLOW_POST_TYPE != $current_screen->id ) {
299
+ return;
300
+ }
301
+
302
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
303
+ ?>
304
+
305
+ <div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
306
+ <div class="wcf-templates-popup-content">
307
+ <div class="spinner"></div>
308
+ <div class="wcf-templates-wrap wcf-templates-wrap-flows">
309
+
310
+ <div id="wcf-remote-flow-actions" class="wcf-template-header">
311
+ <div class="wcf-template-logo-wrap">
312
+ <span class="wcf-cartflows-logo-img">
313
+ <span class="cartflows-logo-icon"></span>
314
+ </span>
315
+ <span class="wcf-cartflows-title"><?php _e( 'Flows Library', 'cartflows' ); ?></span>
316
+ </div>
317
+ <div class="wcf-tab-wrapper">
318
+ <?php if ( 'other' !== $default_page_builder ) { ?>
319
+ <div id="wcf-get-started-steps">
320
+ <ul class="filter-links ">
321
+ <li>
322
+ <a href="#" class="current" data-slug="ready-templates" data-title="<?php _e( 'Ready Templates', 'cartflows' ); ?>"><?php _e( 'Ready Templates', 'cartflows' ); ?></a>
323
+ </li>
324
+ <li>
325
+ <a href="#" data-slug="canvas" data-title="<?php _e( 'Create Your Own', 'cartflows' ); ?>"><?php _e( 'Create Your Own', 'cartflows' ); ?></a>
326
+ </li>
327
+ </ul>
328
+ </div>
329
+ <?php } ?>
330
+ </div>
331
+ <div class="wcf-popup-close-wrap">
332
+ <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
333
+ </div>
334
+ </div>
335
+ <!-- <div class="wcf-search-form">
336
+ <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
337
+ <input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
338
+ </div> -->
339
+
340
+ <div id="wcf-remote-content">
341
+ <?php if ( 'other' !== $default_page_builder ) { ?>
342
+ <div id="wcf-ready-templates">
343
+ <div id="wcf-remote-filters">
344
+ <div id="wcf-page-builders"></div>
345
+ <div id="wcf-categories"></div>
346
+ </div>
347
+ <div class="wcf-page-builder-notice"></div>
348
+ <div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
349
+ <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
350
+ </div>
351
+ <?php } ?>
352
+ <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
353
+ <div class="inner">
354
+ <a href="#" class="button button-hero button-primary cartflows-flow-import-blank"><?php _e( 'Design Your Flow', 'cartflows' ); ?></a>
355
+ <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php _e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
356
+ </div>
357
+ </div>
358
+ </div>
359
+ </div>
360
+ </div>
361
+ </div>
362
+
363
+ <?php
364
+ }
365
+
366
+ /**
367
+ * Enqueues the needed CSS/JS for the builder's admin settings page.
368
+ *
369
+ * @since 1.0.0
370
+ */
371
+ static public function styles_scripts() {
372
+
373
+ // Styles.
374
+ wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
375
+ wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
376
+
377
+ // Script.
378
+ wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
379
+
380
+ $localize = array(
381
+ 'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
382
+ );
383
+
384
+ wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
385
+
386
+ do_action( 'cartflows_admin_settings_after_enqueue_scripts' );
387
+ }
388
+
389
+ /**
390
+ * Save All admin settings here
391
+ */
392
+ static public function save_settings() {
393
+
394
+ // Only admins can save settings.
395
+ if ( ! current_user_can( 'manage_options' ) ) {
396
+ return;
397
+ }
398
+
399
+ self::save_common_settings();
400
+
401
+ // Let extensions hook into saving.
402
+ do_action( 'cartflows_admin_settings_save' );
403
+ }
404
+
405
+ /**
406
+ * Get and return page URL
407
+ *
408
+ * @param string $menu_slug Menu name.
409
+ * @since 1.0.0
410
+ * @return string page url
411
+ */
412
+ static public function get_page_url( $menu_slug ) {
413
+
414
+ $parent_page = self::$default_menu_position;
415
+
416
+ if ( strpos( $parent_page, '?' ) !== false ) {
417
+ $query_var = '&page=' . self::$plugin_slug;
418
+ } else {
419
+ $query_var = '?page=' . self::$plugin_slug;
420
+ }
421
+
422
+ $parent_page_url = admin_url( $parent_page . $query_var );
423
+
424
+ $url = $parent_page_url . '&action=' . $menu_slug;
425
+
426
+ return esc_url( $url );
427
+ }
428
+
429
+ /**
430
+ * Admin body classes.
431
+ *
432
+ * Body classes to be added to <body> tag in admin page
433
+ *
434
+ * @param String $classes body classes returned from the filter.
435
+ * @return String body classes to be added to <body> tag in admin page
436
+ */
437
+ static public function add_admin_body_class( $classes ) {
438
+
439
+ $classes .= ' cartflows-' . CARTFLOWS_VER;
440
+
441
+ return $classes;
442
+ }
443
+ }
444
+
445
+ Cartflows_Admin::init();
classes/class-cartflows-api.php CHANGED
@@ -1,381 +1,381 @@
1
- <?php
2
- /**
3
- * CartFlows API
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_API' ) ) :
10
-
11
- /**
12
- * CartFlows API
13
- *
14
- * @since 1.0.0
15
- */
16
- class CartFlows_API {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @access private
22
- * @var object Class object.
23
- * @since 1.0.0
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.0
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @since 1.0.0
44
- */
45
- public function __construct() {
46
- }
47
-
48
- /**
49
- * Get site URL.
50
- *
51
- * @since 1.0.0
52
- *
53
- * @return string Site URL.
54
- */
55
- public static function get_site_url() {
56
- return apply_filters( 'cartflows_templates_url', CARTFLOWS_TEMPLATES_URL );
57
- }
58
-
59
- /**
60
- * Get Client Site Templates Rest API URL.
61
- *
62
- * @since 1.0.0
63
- *
64
- * @return string API site URL.
65
- */
66
- public static function get_step_endpoint_url() {
67
- return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_STEP_POST_TYPE . '/';
68
- }
69
-
70
- /**
71
- * Get Client Site Category Rest API URL.
72
- *
73
- * @since 1.0.0
74
- *
75
- * @return string API site URL.
76
- */
77
- public static function get_category_endpoint_url() {
78
- return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER . '/';
79
- }
80
-
81
- /**
82
- * Get API request URL.
83
- *
84
- * @since 1.0.0
85
- *
86
- * @param string $api_base base of api request.
87
- * @return string API site URL.
88
- */
89
- public static function get_request_api_url( $api_base = '' ) {
90
- return self::get_site_url() . 'wp-json/' . CARTFLOWS_STEP_POST_TYPE . '/v1/' . $api_base;
91
- }
92
-
93
- /**
94
- * License Args.
95
- *
96
- * @return array License arguments.
97
- */
98
- public static function get_licence_args() {
99
- return apply_filters( 'cartflows_licence_args', array() );
100
- }
101
-
102
- /**
103
- * Get single demo.
104
- *
105
- * @since 1.0.0
106
- *
107
- * @param string $site_id Template ID of the site.
108
- * @return array Template data.
109
- */
110
- public static function get_template( $site_id ) {
111
- // @codingStandardsIgnoreStart
112
- $request_params = array(
113
- 'licence_args' => self::get_licence_args(),
114
- '_fields' => 'id,slug,status,type,link,title,featured_media,template,cartflows_step_page_builder,cartflows_step_type,cartflows_step_flow,featured_image_url,licence_status,flow_type,step_type,page_builder,divi_content,post_meta',
115
- );
116
- // @codingStandardsIgnoreEnd
117
-
118
- $url = add_query_arg( $request_params, self::get_step_endpoint_url() . $site_id );
119
-
120
- $api_args = array(
121
- 'timeout' => 15,
122
- );
123
-
124
- $response = self::remote_get( $url, $api_args );
125
-
126
- if ( $response['success'] ) {
127
- $template = $response['data'];
128
- return array(
129
- 'title' => ( isset( $template['title']->rendered ) ) ? $template['title']->rendered : '',
130
- 'post_meta' => ( isset( $template['post_meta'] ) ) ? $template['post_meta'] : '',
131
- 'data' => $template,
132
- 'divi_content' => isset( $response['data']['divi_content'] ) ? $response['data']['divi_content'] : '',
133
- 'message' => $response['message'], // __( 'Your API Key is not valid. Please add valid API Key.', 'cartflows' ),
134
- 'success' => $response['success'],
135
- );
136
- }
137
-
138
- return array(
139
- 'title' => '',
140
- 'post_meta' => array(),
141
- 'message' => $response['message'],
142
- 'data' => $response['data'],
143
- 'divi_content' => '',
144
- 'success' => $response['success'],
145
- );
146
- }
147
-
148
- /**
149
- * Get Cloud Templates
150
- *
151
- * @since 1.0.0
152
- *
153
- * @param array $args For selecting the demos (Search terms, pagination etc).
154
- * @return array CartFlows list.
155
- */
156
- public static function get_templates( $args = array() ) {
157
-
158
- $request_params = wp_parse_args(
159
- $args,
160
- array(
161
- 'page' => '1',
162
- 'per_page' => '15',
163
- )
164
- );
165
-
166
- $url = add_query_arg( $request_params, self::get_step_endpoint_url() );
167
-
168
- $api_args = array(
169
- 'timeout' => 15,
170
- );
171
-
172
- $response = self::remote_get( $url, $api_args );
173
-
174
- if ( $response['success'] ) {
175
- $templates_data = $response['data'];
176
- $templates = array();
177
- foreach ( $templates_data as $key => $template ) {
178
-
179
- if ( ! isset( $template->id ) ) {
180
- continue;
181
- }
182
-
183
- $templates[ $key ]['id'] = isset( $template->id ) ? esc_attr( $template->id ) : '';
184
- $templates[ $key ]['slug'] = isset( $template->slug ) ? esc_attr( $template->slug ) : '';
185
- $templates[ $key ]['link'] = isset( $template->link ) ? esc_url( $template->link ) : '';
186
- $templates[ $key ]['date'] = isset( $template->date ) ? esc_attr( $template->date ) : '';
187
- $templates[ $key ]['title'] = isset( $template->title->rendered ) ? esc_attr( $template->title->rendered ) : '';
188
- $templates[ $key ]['featured_image_url'] = isset( $template->featured_image_url ) ? esc_url( $template->featured_image_url ) : '';
189
- $templates[ $key ]['content'] = isset( $template->content->rendered ) ? $template->content->rendered : '';
190
- $templates[ $key ]['divi_content'] = isset( $template->divi_content ) ? $template->divi_content : '';
191
- $templates[ $key ]['post_meta'] = isset( $template->post_meta ) ? $template->post_meta : '';
192
- }
193
-
194
- return array(
195
- 'templates' => $templates,
196
- 'templates_count' => $response['count'],
197
- 'data' => $response,
198
- );
199
- }
200
-
201
- return array(
202
- 'templates' => array(),
203
- 'templates_count' => 0,
204
- 'data' => $response,
205
- );
206
-
207
- }
208
-
209
- /**
210
- * Get categories.
211
- *
212
- * @since 1.0.0
213
- * @param array $args Arguments.
214
- * @return array Category data.
215
- */
216
- public static function get_categories( $args = array() ) {
217
-
218
- $request_params = apply_filters(
219
- 'cartflows_categories_api_params',
220
- wp_parse_args(
221
- $args,
222
- array(
223
- 'page' => '1',
224
- 'per_page' => '15',
225
- )
226
- )
227
- );
228
-
229
- $url = add_query_arg( $request_params, self::get_category_endpoint_url() );
230
-
231
- $api_args = apply_filters(
232
- 'cartflows_api_args',
233
- array(
234
- 'timeout' => 15,
235
- )
236
- );
237
-
238
- $response = self::remote_get( $url, $api_args );
239
-
240
- if ( $response['success'] ) {
241
- $categories_data = $response['data'];
242
- $categories = array();
243
-
244
- foreach ( $categories_data as $key => $category ) {
245
- if ( isset( $category->count ) && ! empty( $category->count ) ) {
246
- $categories[] = array(
247
- 'id' => isset( $category->id ) ? absint( $category->id ) : 0,
248
- 'count' => isset( $category->count ) ? absint( $category->count ) : 0,
249
- 'description' => isset( $category->description ) ? $category->description : '',
250
- 'link' => isset( $category->link ) ? esc_url( $category->link ) : '',
251
- 'name' => isset( $category->name ) ? $category->name : '',
252
- 'slug' => isset( $category->slug ) ? sanitize_text_field( $category->slug ) : '',
253
- 'taxonomy' => isset( $category->taxonomy ) ? $category->taxonomy : '',
254
- 'parent' => isset( $category->parent ) ? $category->parent : '',
255
- );
256
- }
257
- }
258
-
259
- return array(
260
- 'categories' => $categories,
261
- 'categories_count' => $response['count'],
262
- 'data' => $response,
263
- );
264
- }
265
-
266
- return array(
267
- 'categories' => array(),
268
- 'categories_count' => 0,
269
- 'data' => $response,
270
- );
271
- }
272
-
273
- /**
274
- * Remote GET API Request
275
- *
276
- * @since 1.0.0
277
- *
278
- * @param string $url Target server API URL.
279
- * @param array $args Array of arguments for the API request.
280
- * @return mixed Return the API request result.
281
- */
282
- public static function remote_get( $url = '', $args = array() ) {
283
- $request = wp_remote_get( $url, $args );
284
- return self::request( $request );
285
- }
286
-
287
- /**
288
- * Remote POST API Request
289
- *
290
- * @since 1.0.0
291
- *
292
- * @param string $url Target server API URL.
293
- * @param array $args Array of arguments for the API request.
294
- * @return mixed Return the API request result.
295
- */
296
- public static function remote_post( $url = '', $args = array() ) {
297
- $request = wp_remote_post( $url, $args );
298
-
299
- return self::request( $request );
300
- }
301
-
302
- /**
303
- * Site API Request
304
- *
305
- * @since 1.0.0
306
- *
307
- * @param boolean $api_base Target server API URL.
308
- * @param array $args Array of arguments for the API request.
309
- * @return mixed Return the API request result.
310
- */
311
- public static function site_request( $api_base = '', $args = array() ) {
312
-
313
- $api_url = self::get_request_api_url( $api_base );
314
-
315
- return self::remote_post( $api_url, $args );
316
- }
317
-
318
- /**
319
- * API Request
320
- *
321
- * Handle the API request and return the result.
322
- *
323
- * @since 1.0.0
324
- *
325
- * @param array $request Array of arguments for the API request.
326
- * @return mixed Return the API request result.
327
- */
328
- public static function request( $request ) {
329
-
330
- // Is WP Error?
331
- if ( is_wp_error( $request ) ) {
332
- return array(
333
- 'success' => false,
334
- 'message' => $request->get_error_message(),
335
- 'data' => $request,
336
- 'count' => 0,
337
- );
338
- }
339
-
340
- // Invalid response code.
341
- if ( wp_remote_retrieve_response_code( $request ) != 200 ) {
342
- return array(
343
- 'success' => false,
344
- 'message' => $request['response'],
345
- 'data' => $request,
346
- 'count' => 0,
347
- );
348
- }
349
-
350
- // Get body data.
351
- $body = wp_remote_retrieve_body( $request );
352
-
353
- // Is WP Error?
354
- if ( is_wp_error( $body ) ) {
355
- return array(
356
- 'success' => false,
357
- 'message' => $body->get_error_message(),
358
- 'data' => $request,
359
- 'count' => 0,
360
- );
361
- }
362
-
363
- // Decode body content.
364
- $body_decoded = json_decode( $body );
365
-
366
- return array(
367
- 'success' => true,
368
- 'message' => __( 'Request successfully processed!', 'cartflows' ),
369
- 'data' => (array) $body_decoded,
370
- 'count' => wp_remote_retrieve_header( $request, 'x-wp-total' ),
371
- );
372
- }
373
-
374
- }
375
-
376
- /**
377
- * Initialize class object with 'get_instance()' method
378
- */
379
- CartFlows_API::get_instance();
380
-
381
- endif;
1
+ <?php
2
+ /**
3
+ * CartFlows API
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_API' ) ) :
10
+
11
+ /**
12
+ * CartFlows API
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class CartFlows_API {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @access private
22
+ * @var object Class object.
23
+ * @since 1.0.0
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.0
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ public function __construct() {
46
+ }
47
+
48
+ /**
49
+ * Get site URL.
50
+ *
51
+ * @since 1.0.0
52
+ *
53
+ * @return string Site URL.
54
+ */
55
+ public static function get_site_url() {
56
+ return apply_filters( 'cartflows_templates_url', CARTFLOWS_TEMPLATES_URL );
57
+ }
58
+
59
+ /**
60
+ * Get Client Site Templates Rest API URL.
61
+ *
62
+ * @since 1.0.0
63
+ *
64
+ * @return string API site URL.
65
+ */
66
+ public static function get_step_endpoint_url() {
67
+ return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_STEP_POST_TYPE . '/';
68
+ }
69
+
70
+ /**
71
+ * Get Client Site Category Rest API URL.
72
+ *
73
+ * @since 1.0.0
74
+ *
75
+ * @return string API site URL.
76
+ */
77
+ public static function get_category_endpoint_url() {
78
+ return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER . '/';
79
+ }
80
+
81
+ /**
82
+ * Get API request URL.
83
+ *
84
+ * @since 1.0.0
85
+ *
86
+ * @param string $api_base base of api request.
87
+ * @return string API site URL.
88
+ */
89
+ public static function get_request_api_url( $api_base = '' ) {
90
+ return self::get_site_url() . 'wp-json/' . CARTFLOWS_STEP_POST_TYPE . '/v1/' . $api_base;
91
+ }
92
+
93
+ /**
94
+ * License Args.
95
+ *
96
+ * @return array License arguments.
97
+ */
98
+ public static function get_licence_args() {
99
+ return apply_filters( 'cartflows_licence_args', array() );
100
+ }
101
+
102
+ /**
103
+ * Get single demo.
104
+ *
105
+ * @since 1.0.0
106
+ *
107
+ * @param string $site_id Template ID of the site.
108
+ * @return array Template data.
109
+ */
110
+ public static function get_template( $site_id ) {
111
+ // @codingStandardsIgnoreStart
112
+ $request_params = array(
113
+ 'licence_args' => self::get_licence_args(),
114
+ '_fields' => 'id,slug,status,type,link,title,featured_media,template,cartflows_step_page_builder,cartflows_step_type,cartflows_step_flow,featured_image_url,licence_status,flow_type,step_type,page_builder,divi_content,post_meta',
115
+ );
116
+ // @codingStandardsIgnoreEnd
117
+
118
+ $url = add_query_arg( $request_params, self::get_step_endpoint_url() . $site_id );
119
+
120
+ $api_args = array(
121
+ 'timeout' => 15,
122
+ );
123
+
124
+ $response = self::remote_get( $url, $api_args );
125
+
126
+ if ( $response['success'] ) {
127
+ $template = $response['data'];
128
+ return array(
129
+ 'title' => ( isset( $template['title']->rendered ) ) ? $template['title']->rendered : '',
130
+ 'post_meta' => ( isset( $template['post_meta'] ) ) ? $template['post_meta'] : '',
131
+ 'data' => $template,
132
+ 'divi_content' => isset( $response['data']['divi_content'] ) ? $response['data']['divi_content'] : '',
133
+ 'message' => $response['message'], // __( 'Your API Key is not valid. Please add valid API Key.', 'cartflows' ),
134
+ 'success' => $response['success'],
135
+ );
136
+ }
137
+
138
+ return array(
139
+ 'title' => '',
140
+ 'post_meta' => array(),
141
+ 'message' => $response['message'],
142
+ 'data' => $response['data'],
143
+ 'divi_content' => '',
144
+ 'success' => $response['success'],
145
+ );
146
+ }
147
+
148
+ /**
149
+ * Get Cloud Templates
150
+ *
151
+ * @since 1.0.0
152
+ *
153
+ * @param array $args For selecting the demos (Search terms, pagination etc).
154
+ * @return array CartFlows list.
155
+ */
156
+ public static function get_templates( $args = array() ) {
157
+
158
+ $request_params = wp_parse_args(
159
+ $args,
160
+ array(
161
+ 'page' => '1',
162
+ 'per_page' => '15',
163
+ )
164
+ );
165
+
166
+ $url = add_query_arg( $request_params, self::get_step_endpoint_url() );
167
+
168
+ $api_args = array(
169
+ 'timeout' => 15,
170
+ );
171
+
172
+ $response = self::remote_get( $url, $api_args );
173
+
174
+ if ( $response['success'] ) {
175
+ $templates_data = $response['data'];
176
+ $templates = array();
177
+ foreach ( $templates_data as $key => $template ) {
178
+
179
+ if ( ! isset( $template->id ) ) {
180
+ continue;
181
+ }
182
+
183
+ $templates[ $key ]['id'] = isset( $template->id ) ? esc_attr( $template->id ) : '';
184
+ $templates[ $key ]['slug'] = isset( $template->slug ) ? esc_attr( $template->slug ) : '';
185
+ $templates[ $key ]['link'] = isset( $template->link ) ? esc_url( $template->link ) : '';
186
+ $templates[ $key ]['date'] = isset( $template->date ) ? esc_attr( $template->date ) : '';
187
+ $templates[ $key ]['title'] = isset( $template->title->rendered ) ? esc_attr( $template->title->rendered ) : '';
188
+ $templates[ $key ]['featured_image_url'] = isset( $template->featured_image_url ) ? esc_url( $template->featured_image_url ) : '';
189
+ $templates[ $key ]['content'] = isset( $template->content->rendered ) ? $template->content->rendered : '';
190
+ $templates[ $key ]['divi_content'] = isset( $template->divi_content ) ? $template->divi_content : '';
191
+ $templates[ $key ]['post_meta'] = isset( $template->post_meta ) ? $template->post_meta : '';
192
+ }
193
+
194
+ return array(
195
+ 'templates' => $templates,
196
+ 'templates_count' => $response['count'],
197
+ 'data' => $response,
198
+ );
199
+ }
200
+
201
+ return array(
202
+ 'templates' => array(),
203
+ 'templates_count' => 0,
204
+ 'data' => $response,
205
+ );
206
+
207
+ }
208
+
209
+ /**
210
+ * Get categories.
211
+ *
212
+ * @since 1.0.0
213
+ * @param array $args Arguments.
214
+ * @return array Category data.
215
+ */
216
+ public static function get_categories( $args = array() ) {
217
+
218
+ $request_params = apply_filters(
219
+ 'cartflows_categories_api_params',
220
+ wp_parse_args(
221
+ $args,
222
+ array(
223
+ 'page' => '1',
224
+ 'per_page' => '15',
225
+ )
226
+ )
227
+ );
228
+
229
+ $url = add_query_arg( $request_params, self::get_category_endpoint_url() );
230
+
231
+ $api_args = apply_filters(
232
+ 'cartflows_api_args',
233
+ array(
234
+ 'timeout' => 15,
235
+ )
236
+ );
237
+
238
+ $response = self::remote_get( $url, $api_args );
239
+
240
+ if ( $response['success'] ) {
241
+ $categories_data = $response['data'];
242
+ $categories = array();
243
+
244
+ foreach ( $categories_data as $key => $category ) {
245
+ if ( isset( $category->count ) && ! empty( $category->count ) ) {
246
+ $categories[] = array(
247
+ 'id' => isset( $category->id ) ? absint( $category->id ) : 0,
248
+ 'count' => isset( $category->count ) ? absint( $category->count ) : 0,
249
+ 'description' => isset( $category->description ) ? $category->description : '',
250
+ 'link' => isset( $category->link ) ? esc_url( $category->link ) : '',
251
+ 'name' => isset( $category->name ) ? $category->name : '',
252
+ 'slug' => isset( $category->slug ) ? sanitize_text_field( $category->slug ) : '',
253
+ 'taxonomy' => isset( $category->taxonomy ) ? $category->taxonomy : '',
254
+ 'parent' => isset( $category->parent ) ? $category->parent : '',
255
+ );
256
+ }
257
+ }
258
+
259
+ return array(
260
+ 'categories' => $categories,
261
+ 'categories_count' => $response['count'],
262
+ 'data' => $response,
263
+ );
264
+ }
265
+
266
+ return array(
267
+ 'categories' => array(),
268
+ 'categories_count' => 0,
269
+ 'data' => $response,
270
+ );
271
+ }
272
+
273
+ /**
274
+ * Remote GET API Request
275
+ *
276
+ * @since 1.0.0
277
+ *
278
+ * @param string $url Target server API URL.
279
+ * @param array $args Array of arguments for the API request.
280
+ * @return mixed Return the API request result.
281
+ */
282
+ public static function remote_get( $url = '', $args = array() ) {
283
+ $request = wp_remote_get( $url, $args );
284
+ return self::request( $request );
285
+ }
286
+
287
+ /**
288
+ * Remote POST API Request
289
+ *
290
+ * @since 1.0.0
291
+ *
292
+ * @param string $url Target server API URL.
293
+ * @param array $args Array of arguments for the API request.
294
+ * @return mixed Return the API request result.
295
+ */
296
+ public static function remote_post( $url = '', $args = array() ) {
297
+ $request = wp_remote_post( $url, $args );
298
+
299
+ return self::request( $request );
300
+ }
301
+
302
+ /**
303
+ * Site API Request
304
+ *
305
+ * @since 1.0.0
306
+ *
307
+ * @param boolean $api_base Target server API URL.
308
+ * @param array $args Array of arguments for the API request.
309
+ * @return mixed Return the API request result.
310
+ */
311
+ public static function site_request( $api_base = '', $args = array() ) {
312
+
313
+ $api_url = self::get_request_api_url( $api_base );
314
+
315
+ return self::remote_post( $api_url, $args );
316
+ }
317
+
318
+ /**
319
+ * API Request
320
+ *
321
+ * Handle the API request and return the result.
322
+ *
323
+ * @since 1.0.0
324
+ *
325
+ * @param array $request Array of arguments for the API request.
326
+ * @return mixed Return the API request result.
327
+ */
328
+ public static function request( $request ) {
329
+
330
+ // Is WP Error?
331
+ if ( is_wp_error( $request ) ) {
332
+ return array(
333
+ 'success' => false,
334
+ 'message' => $request->get_error_message(),
335
+ 'data' => $request,
336
+ 'count' => 0,
337
+ );
338
+ }
339
+
340
+ // Invalid response code.
341
+ if ( wp_remote_retrieve_response_code( $request ) != 200 ) {
342
+ return array(
343
+ 'success' => false,
344
+ 'message' => $request['response'],
345
+ 'data' => $request,
346
+ 'count' => 0,
347
+ );
348
+ }
349
+
350
+ // Get body data.
351
+ $body = wp_remote_retrieve_body( $request );
352
+
353
+ // Is WP Error?
354
+ if ( is_wp_error( $body ) ) {
355
+ return array(
356
+ 'success' => false,
357
+ 'message' => $body->get_error_message(),
358
+ 'data' => $request,
359
+ 'count' => 0,
360
+ );
361
+ }
362
+
363
+ // Decode body content.
364
+ $body_decoded = json_decode( $body );
365
+
366
+ return array(
367
+ 'success' => true,
368
+ 'message' => __( 'Request successfully processed!', 'cartflows' ),
369
+ 'data' => (array) $body_decoded,
370
+ 'count' => wp_remote_retrieve_header( $request, 'x-wp-total' ),
371
+ );
372
+ }
373
+
374
+ }
375
+
376
+ /**
377
+ * Initialize class object with 'get_instance()' method
378
+ */
379
+ CartFlows_API::get_instance();
380
+
381
+ endif;
classes/class-cartflows-bb-compatibility.php CHANGED
@@ -1,76 +1,76 @@
1
- <?php
2
- /**
3
- * Beaver Builder page builder compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- if ( ! class_exists( 'Cartflows_BB_Compatibility' ) ) :
9
-
10
- /**
11
- * Class for Beaver Builder page builder compatibility
12
- */
13
- class Cartflows_BB_Compatibility {
14
-
15
- /**
16
- * Member Variable
17
- *
18
- * @var instance
19
- */
20
- private static $instance;
21
-
22
- /**
23
- * Initiator
24
- *
25
- * @since 1.1.4
26
- */
27
- public static function get_instance() {
28
- if ( ! isset( self::$instance ) ) {
29
- self::$instance = new self;
30
- }
31
- return self::$instance;
32
- }
33
-
34
- /**
35
- * Constructor
36
- *
37
- * @since 1.1.4
38
- */
39
- public function __construct() {
40
- add_filter( 'fl_builder_post_types', array( $this, 'post_types' ) );
41
- add_action( 'admin_init', array( $this, 'disable_rediraction' ), 99 );
42
- }
43
-
44
- /**
45
- * Disable Beaver Builder Redirection after plugin install.
46
- *
47
- * @since 1.1.4
48
- *
49
- * @return void
50
- */
51
- function disable_rediraction() {
52
- delete_transient( '_fl_builder_activation_admin_notice' );
53
- }
54
-
55
- /**
56
- * Add beaver builder support for step post type.
57
- *
58
- * @since 1.1.4
59
- *
60
- * @param array $post_types container Post types.
61
- * @return array
62
- */
63
- public function post_types( $post_types ) {
64
-
65
- $post_types[] = 'cartflows_step';
66
-
67
- return $post_types;
68
- }
69
- }
70
-
71
- /**
72
- * Kicking this off by calling 'get_instance()' method
73
- */
74
- Cartflows_BB_Compatibility::get_instance();
75
-
76
- endif;
1
+ <?php
2
+ /**
3
+ * Beaver Builder page builder compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ if ( ! class_exists( 'Cartflows_BB_Compatibility' ) ) :
9
+
10
+ /**
11
+ * Class for Beaver Builder page builder compatibility
12
+ */
13
+ class Cartflows_BB_Compatibility {
14
+
15
+ /**
16
+ * Member Variable
17
+ *
18
+ * @var instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Initiator
24
+ *
25
+ * @since 1.1.4
26
+ */
27
+ public static function get_instance() {
28
+ if ( ! isset( self::$instance ) ) {
29
+ self::$instance = new self;
30
+ }
31
+ return self::$instance;
32
+ }
33
+
34
+ /**
35
+ * Constructor
36
+ *
37
+ * @since 1.1.4
38
+ */
39
+ public function __construct() {
40
+ add_filter( 'fl_builder_post_types', array( $this, 'post_types' ) );
41
+ add_action( 'admin_init', array( $this, 'disable_rediraction' ), 99 );
42
+ }
43
+
44
+ /**
45
+ * Disable Beaver Builder Redirection after plugin install.
46
+ *
47
+ * @since 1.1.4
48
+ *
49
+ * @return void
50
+ */
51
+ function disable_rediraction() {
52
+ delete_transient( '_fl_builder_activation_admin_notice' );
53
+ }
54
+
55
+ /**
56
+ * Add beaver builder support for step post type.
57
+ *
58
+ * @since 1.1.4
59
+ *
60
+ * @param array $post_types container Post types.
61
+ * @return array
62
+ */
63
+ public function post_types( $post_types ) {
64
+
65
+ $post_types[] = 'cartflows_step';
66
+
67
+ return $post_types;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Kicking this off by calling 'get_instance()' method
73
+ */
74
+ Cartflows_BB_Compatibility::get_instance();
75
+
76
+ endif;
classes/class-cartflows-cloning.php CHANGED
@@ -1,436 +1,436 @@
1
- <?php
2
- /**
3
- * Cloning.
4
- *
5
- * @package cartflows-pro
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Cloning {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Initiator
25
- */
26
- public static function get_instance() {
27
- if ( ! isset( self::$instance ) ) {
28
- self::$instance = new self;
29
- }
30
- return self::$instance;
31
- }
32
-
33
- /**
34
- * Constructor
35
- */
36
- public function __construct() {
37
-
38
- add_filter( 'post_row_actions', array( $this, 'clone_link' ), 99, 2 );
39
- add_action( 'admin_action_cartflows_clone_flow', array( $this, 'clone_flow' ) );
40
- add_action( 'admin_action_cartflows_clone_step', array( $this, 'clone_step' ) );
41
- }
42
-
43
- /**
44
- * Clone flow with steps and its meta.
45
- */
46
- function clone_flow() {
47
-
48
- global $wpdb;
49
-
50
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_flow' == $_REQUEST['action'] ) ) ) {
51
- wp_die( 'No post to duplicate has been supplied!' );
52
- }
53
-
54
- /*
55
- * Nonce verification
56
- */
57
- if ( ! isset( $_GET['flow_clone_nonce'] ) || ! wp_verify_nonce( $_GET['flow_clone_nonce'], basename( __FILE__ ) ) ) {
58
- return;
59
- }
60
-
61
- /**
62
- * Get the original post id
63
- */
64
- $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
65
-
66
- /**
67
- * And all the original post data then
68
- */
69
- $post = get_post( $post_id );
70
-
71
- /**
72
- * Assign current user to be the new post author
73
- */
74
- $current_user = wp_get_current_user();
75
- $new_post_author = $current_user->ID;
76
-
77
- /**
78
- * If post data exists, create the post duplicate
79
- */
80
- if ( isset( $post ) && null !== $post ) {
81
-
82
- /**
83
- * New post data array
84
- */
85
-
86
- $args = array(
87
- 'comment_status' => $post->comment_status,
88
- 'ping_status' => $post->ping_status,
89
- 'post_author' => $new_post_author,
90
- 'post_content' => $post->post_content,
91
- 'post_excerpt' => $post->post_excerpt,
92
- 'post_name' => $post->post_name,
93
- 'post_parent' => $post->post_parent,
94
- 'post_password' => $post->post_password,
95
- 'post_status' => $post->post_status,
96
- 'post_title' => $post->post_title . ' Clone',
97
- 'post_type' => $post->post_type,
98
- 'to_ping' => $post->to_ping,
99
- 'menu_order' => $post->menu_order,
100
- );
101
-
102
- /**
103
- * Insert the post
104
- */
105
- $new_flow_id = wp_insert_post( $args );
106
-
107
- /**
108
- * Get all current post terms ad set them to the new post
109
- */
110
- // returns array of taxonomy names for post type, ex array("category", "post_tag");.
111
- $taxonomies = get_object_taxonomies( $post->post_type );
112
-
113
- foreach ( $taxonomies as $taxonomy ) {
114
-
115
- $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
116
-
117
- wp_set_object_terms( $new_flow_id, $post_terms, $taxonomy, false );
118
- }
119
-
120
- /**
121
- * Duplicate all post meta just in two SQL queries
122
- */
123
- // @codingStandardsIgnoreStart
124
- $post_meta_infos = $wpdb->get_results(
125
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
126
- );
127
- // @codingStandardsIgnoreEnd
128
-
129
- if ( ! empty( $post_meta_infos ) ) {
130
-
131
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
132
-
133
- foreach ( $post_meta_infos as $meta_info ) {
134
-
135
- $meta_key = $meta_info->meta_key;
136
-
137
- if ( '_wp_old_slug' === $meta_key ) {
138
- continue;
139
- }
140
-
141
- $meta_value = addslashes( $meta_info->meta_value );
142
-
143
- $sql_query_sel[] = "SELECT $new_flow_id, '$meta_key', '$meta_value'";
144
- }
145
-
146
- $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
147
-
148
- // @codingStandardsIgnoreStart
149
- $wpdb->query( $sql_query );
150
- // @codingStandardsIgnoreEnd
151
- }
152
-
153
- /* Steps Cloning */
154
- $flow_steps = get_post_meta( $post_id, 'wcf-steps', true );
155
- $new_flow_steps = array();
156
-
157
- if ( is_array( $flow_steps ) && ! empty( $flow_steps ) ) {
158
-
159
- foreach ( $flow_steps as $index => $step_data ) {
160
-
161
- $step_id = $step_data['id'];
162
- $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
163
-
164
- $step_object = get_post( $step_id );
165
-
166
- /**
167
- * New step post data array
168
- */
169
- $step_args = array(
170
- 'comment_status' => $step_object->comment_status,
171
- 'ping_status' => $step_object->ping_status,
172
- 'post_author' => $new_post_author,
173
- 'post_content' => $step_object->post_content,
174
- 'post_excerpt' => $step_object->post_excerpt,
175
- 'post_name' => $step_object->post_name,
176
- 'post_parent' => $step_object->post_parent,
177
- 'post_password' => $step_object->post_password,
178
- 'post_status' => $step_object->post_status,
179
- 'post_title' => $step_object->post_title,
180
- 'post_type' => $step_object->post_type,
181
- 'to_ping' => $step_object->to_ping,
182
- 'menu_order' => $step_object->menu_order,
183
- );
184
-
185
- /**
186
- * Insert the post
187
- */
188
- $new_step_id = wp_insert_post( $step_args );
189
-
190
- /**
191
- * Duplicate all step meta
192
- */
193
- // @codingStandardsIgnoreStart
194
- $post_meta_infos = $wpdb->get_results(
195
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$step_id"
196
- );
197
- // @codingStandardsIgnoreEnd
198
-
199
- if ( ! empty( $post_meta_infos ) ) {
200
-
201
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
202
-
203
- foreach ( $post_meta_infos as $meta_info ) {
204
-
205
- $meta_key = $meta_info->meta_key;
206
-
207
- if ( '_wp_old_slug' === $meta_key ) {
208
- continue;
209
- }
210
-
211
- $meta_value = addslashes( $meta_info->meta_value );
212
-
213
- $sql_query_sel[] = "SELECT $new_step_id, '$meta_key', '$meta_value'";
214
- }
215
-
216
- $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
217
-
218
- // @codingStandardsIgnoreStart
219
- $wpdb->query( $sql_query );
220
- // @codingStandardsIgnoreEnd
221
- }
222
-
223
- // insert post meta.
224
- update_post_meta( $new_step_id, 'wcf-flow-id', $new_flow_id );
225
- update_post_meta( $new_step_id, 'wcf-step-type', $step_type );
226
-
227
- wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
228
- wp_set_object_terms( $new_step_id, 'flow-' . $new_flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
229
-
230
- /* Add New Flow Steps */
231
- $new_flow_steps[] = array(
232
- 'id' => $new_step_id,
233
- 'title' => $step_object->post_title,
234
- 'type' => $step_type,
235
- );
236
- }
237
- }
238
-
239
- /* Update New Flow Step Post Meta */
240
- update_post_meta( $new_flow_id, 'wcf-steps', $new_flow_steps );
241
-
242
- /* Clear Page Builder Cache */
243
- $this->clear_cache();
244
-
245
- /**
246
- * Redirect to the new flow edit screen
247
- */
248
- wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_flow_id ) );
249
- exit;
250
- } else {
251
- wp_die( 'Post creation failed, could not find original post: ' . $post_id );
252
- }
253
- }
254
-
255
- /**
256
- * Clone step with its meta.
257
- */
258
- function clone_step() {
259
-
260
- global $wpdb;
261
-
262
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_step' === $_REQUEST['action'] ) ) ) {
263
- wp_die( 'No post to duplicate has been supplied!' );
264
- }
265
-
266
- /*
267
- * Nonce verification
268
- */
269
- if ( ! isset( $_GET['step_clone_nonce'] ) || ! wp_verify_nonce( $_GET['step_clone_nonce'], 'step_clone' ) ) {
270
- return;
271
- }
272
-
273
- /**
274
- * Get the original post id
275
- */
276
- $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
277
-
278
- /**
279
- * And all the original post data then
280
- */
281
- $post = get_post( $post_id );
282
-
283
- /**
284
- * Assign current user to be the new post author
285
- */
286
- $current_user = wp_get_current_user();
287
- $new_post_author = $current_user->ID;
288
-
289
- /**
290
- * If post data exists, create the post duplicate
291
- */
292
- if ( isset( $post ) && null !== $post ) {
293
-
294
- /**
295
- * New post data array
296
- */
297
- $args = array(
298
- 'comment_status' => $post->comment_status,
299
- 'ping_status' => $post->ping_status,
300
- 'post_author' => $new_post_author,
301
- 'post_content' => $post->post_content,
302
- 'post_excerpt' => $post->post_excerpt,
303
- 'post_name' => $post->post_name,
304
- 'post_parent' => $post->post_parent,
305
- 'post_password' => $post->post_password,
306
- 'post_status' => $post->post_status,
307
- 'post_title' => $post->post_title . ' Clone',
308
- 'post_type' => $post->post_type,
309
- 'to_ping' => $post->to_ping,
310
- 'menu_order' => $post->menu_order,
311
- );
312
-
313
- /**
314
- * Insert the post
315
- */
316
- $new_step_id = wp_insert_post( $args );
317
-
318
- /**
319
- * Get all current post terms ad set them to the new post
320
- */
321
- // returns array of taxonomy names for post type, ex array("category", "post_tag");.
322
- $taxonomies = get_object_taxonomies( $post->post_type );
323
-
324
- foreach ( $taxonomies as $taxonomy ) {
325
-
326
- $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
327
-
328
- wp_set_object_terms( $new_step_id, $post_terms, $taxonomy, false );
329
- }
330
-
331
- /**
332
- * Duplicate all post meta just in two SQL queries
333
- */
334
- // @codingStandardsIgnoreStart
335
- $post_meta_infos = $wpdb->get_results(
336
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
337
- );
338
- // @codingStandardsIgnoreEnd
339
-
340
- if ( ! empty( $post_meta_infos ) ) {
341
-
342
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
343
-
344
- foreach ( $post_meta_infos as $meta_info ) {
345
-
346
- $meta_key = $meta_info->meta_key;
347
-
348
- if ( '_wp_old_slug' === $meta_key ) {
349
- continue;
350
- }
351
-
352
- $meta_value = addslashes( $meta_info->meta_value );
353
-
354
- $sql_query_sel[] = "SELECT $new_step_id, '$meta_key', '$meta_value'";
355
- }
356
-
357
- $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
358
-
359
- // @codingStandardsIgnoreStart
360
- $wpdb->query( $sql_query );
361
- // @codingStandardsIgnoreEnd
362
- }
363
-
364
- $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
365
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
366
- $step_type = get_post_meta( $post_id, 'wcf-step-type', true );
367
-
368
- if ( ! is_array( $flow_steps ) ) {
369
- $flow_steps = array();
370
- }
371
-
372
- $flow_steps[] = array(
373
- 'id' => $new_step_id,
374
- 'title' => $post->post_title,
375
- 'type' => $step_type,
376
- );
377
-
378
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
379
-
380
- /* Clear Page Builder Cache */
381
- $this->clear_cache();
382
-
383
- /**
384
- * Redirect to the new flow edit screen
385
- */
386
- $redirect_url = add_query_arg( 'highlight-step-id', $new_step_id, get_edit_post_link( $flow_id, 'default' ) );
387
-
388
- wp_redirect( $redirect_url );
389
- exit;
390
- } else {
391
- wp_die( 'Post creation failed, could not find original post: ' . $post_id );
392
- }
393
- }
394
-
395
- /**
396
- * Add the clone link to action list for flows row actions
397
- *
398
- * @param array $actions Actions array.
399
- * @param object $post Post object.
400
- *
401
- * @return array
402
- */
403
- function clone_link( $actions, $post ) {
404
-
405
- if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
406
-
407
- if ( isset( $actions['duplicate'] ) ) { // Duplicate page plugin remove.
408
- unset( $actions['duplicate'] );
409
- }
410
- if ( isset( $actions['edit_as_new_draft'] ) ) { // Duplicate post plugin remove.
411
- unset( $actions['edit_as_new_draft'] );
412
- }
413
-
414
- $actions['clone'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_clone_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_clone_nonce' ) . '" title="' . __( 'Clone this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Clone', 'cartflows' ) . '</a>';
415
- }
416
-
417
- return $actions;
418
- }
419
-
420
- /**
421
- * Clear Page Builder Cache
422
- */
423
- function clear_cache() {
424
-
425
- // Clear 'Elementor' file cache.
426
- if ( class_exists( '\Elementor\Plugin' ) ) {
427
- Elementor\Plugin::$instance->files_manager->clear_cache();
428
- }
429
- }
430
-
431
- }
432
-
433
- /**
434
- * Kicking this off by calling 'get_instance()' method
435
- */
436
- Cartflows_Cloning::get_instance();
1
+ <?php
2
+ /**
3
+ * Cloning.
4
+ *
5
+ * @package cartflows-pro
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Cloning {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Initiator
25
+ */
26
+ public static function get_instance() {
27
+ if ( ! isset( self::$instance ) ) {
28
+ self::$instance = new self;
29
+ }
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Constructor
35
+ */
36
+ public function __construct() {
37
+
38
+ add_filter( 'post_row_actions', array( $this, 'clone_link' ), 99, 2 );
39
+ add_action( 'admin_action_cartflows_clone_flow', array( $this, 'clone_flow' ) );
40
+ add_action( 'admin_action_cartflows_clone_step', array( $this, 'clone_step' ) );
41
+ }
42
+
43
+ /**
44
+ * Clone flow with steps and its meta.
45
+ */
46
+ function clone_flow() {
47
+
48
+ global $wpdb;
49
+
50
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_flow' == $_REQUEST['action'] ) ) ) {
51
+ wp_die( 'No post to duplicate has been supplied!' );
52
+ }
53
+
54
+ /*
55
+ * Nonce verification
56
+ */
57
+ if ( ! isset( $_GET['flow_clone_nonce'] ) || ! wp_verify_nonce( $_GET['flow_clone_nonce'], basename( __FILE__ ) ) ) {
58
+ return;
59
+ }
60
+
61
+ /**
62
+ * Get the original post id
63
+ */
64
+ $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
65
+
66
+ /**
67
+ * And all the original post data then
68
+ */
69
+ $post = get_post( $post_id );
70
+
71
+ /**
72
+ * Assign current user to be the new post author
73
+ */
74
+ $current_user = wp_get_current_user();
75
+ $new_post_author = $current_user->ID;
76
+
77
+ /**
78
+ * If post data exists, create the post duplicate
79
+ */
80
+ if ( isset( $post ) && null !== $post ) {
81
+
82
+ /**
83
+ * New post data array
84
+ */
85
+
86
+ $args = array(
87
+ 'comment_status' => $post->comment_status,
88
+ 'ping_status' => $post->ping_status,
89
+ 'post_author' => $new_post_author,
90
+ 'post_content' => $post->post_content,
91
+ 'post_excerpt' => $post->post_excerpt,
92
+ 'post_name' => $post->post_name,
93
+ 'post_parent' => $post->post_parent,
94
+ 'post_password' => $post->post_password,
95
+ 'post_status' => $post->post_status,
96
+ 'post_title' => $post->post_title . ' Clone',
97
+ 'post_type' => $post->post_type,
98
+ 'to_ping' => $post->to_ping,
99
+ 'menu_order' => $post->menu_order,
100
+ );
101
+
102
+ /**
103
+ * Insert the post
104
+ */
105
+ $new_flow_id = wp_insert_post( $args );
106
+
107
+ /**
108
+ * Get all current post terms ad set them to the new post
109
+ */
110
+ // returns array of taxonomy names for post type, ex array("category", "post_tag");.
111
+ $taxonomies = get_object_taxonomies( $post->post_type );
112
+
113
+ foreach ( $taxonomies as $taxonomy ) {
114
+
115
+ $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
116
+
117
+ wp_set_object_terms( $new_flow_id, $post_terms, $taxonomy, false );
118
+ }
119
+
120
+ /**
121
+ * Duplicate all post meta just in two SQL queries
122
+ */
123
+ // @codingStandardsIgnoreStart
124
+ $post_meta_infos = $wpdb->get_results(
125
+ "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
126
+ );
127
+ // @codingStandardsIgnoreEnd
128
+
129
+ if ( ! empty( $post_meta_infos ) ) {
130
+
131
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
132
+
133
+ foreach ( $post_meta_infos as $meta_info ) {
134
+
135
+ $meta_key = $meta_info->meta_key;
136
+
137
+ if ( '_wp_old_slug' === $meta_key ) {
138
+ continue;
139
+ }
140
+
141
+ $meta_value = addslashes( $meta_info->meta_value );
142
+
143
+ $sql_query_sel[] = "SELECT $new_flow_id, '$meta_key', '$meta_value'";
144
+ }
145
+
146
+ $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
147
+
148
+ // @codingStandardsIgnoreStart
149
+ $wpdb->query( $sql_query );
150
+ // @codingStandardsIgnoreEnd
151
+ }
152
+
153
+ /* Steps Cloning */
154
+ $flow_steps = get_post_meta( $post_id, 'wcf-steps', true );
155
+ $new_flow_steps = array();
156
+
157
+ if ( is_array( $flow_steps ) && ! empty( $flow_steps ) ) {
158
+
159
+ foreach ( $flow_steps as $index => $step_data ) {
160
+
161
+ $step_id = $step_data['id'];
162
+ $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
163
+
164
+ $step_object = get_post( $step_id );
165
+
166
+ /**
167
+ * New step post data array
168
+ */
169
+ $step_args = array(
170
+ 'comment_status' => $step_object->comment_status,
171
+ 'ping_status' => $step_object->ping_status,
172
+ 'post_author' => $new_post_author,
173
+ 'post_content' => $step_object->post_content,
174
+ 'post_excerpt' => $step_object->post_excerpt,
175
+ 'post_name' => $step_object->post_name,
176
+ 'post_parent' => $step_object->post_parent,
177
+ 'post_password' => $step_object->post_password,
178
+ 'post_status' => $step_object->post_status,
179
+ 'post_title' => $step_object->post_title,
180
+ 'post_type' => $step_object->post_type,
181
+ 'to_ping' => $step_object->to_ping,
182
+ 'menu_order' => $step_object->menu_order,
183
+ );
184
+
185
+ /**
186
+ * Insert the post
187
+ */
188
+ $new_step_id = wp_insert_post( $step_args );
189
+
190
+ /**
191
+ * Duplicate all step meta
192
+ */
193
+ // @codingStandardsIgnoreStart
194
+ $post_meta_infos = $wpdb->get_results(
195
+ "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$step_id"
196
+ );
197
+ // @codingStandardsIgnoreEnd
198
+
199
+ if ( ! empty( $post_meta_infos ) ) {
200
+
201
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
202
+
203
+ foreach ( $post_meta_infos as $meta_info ) {
204
+
205
+ $meta_key = $meta_info->meta_key;
206
+
207
+ if ( '_wp_old_slug' === $meta_key ) {
208
+ continue;
209
+ }
210
+
211
+ $meta_value = addslashes( $meta_info->meta_value );
212
+
213
+ $sql_query_sel[] = "SELECT $new_step_id, '$meta_key', '$meta_value'";
214
+ }
215
+
216
+ $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
217
+
218
+ // @codingStandardsIgnoreStart
219
+ $wpdb->query( $sql_query );
220
+ // @codingStandardsIgnoreEnd
221
+ }
222
+
223
+ // insert post meta.
224
+ update_post_meta( $new_step_id, 'wcf-flow-id', $new_flow_id );
225
+ update_post_meta( $new_step_id, 'wcf-step-type', $step_type );
226
+
227
+ wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
228
+ wp_set_object_terms( $new_step_id, 'flow-' . $new_flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
229
+
230
+ /* Add New Flow Steps */
231
+ $new_flow_steps[] = array(
232
+ 'id' => $new_step_id,
233
+ 'title' => $step_object->post_title,
234
+ 'type' => $step_type,
235
+ );
236
+ }
237
+ }
238
+
239
+ /* Update New Flow Step Post Meta */
240
+ update_post_meta( $new_flow_id, 'wcf-steps', $new_flow_steps );
241
+
242
+ /* Clear Page Builder Cache */
243
+ $this->clear_cache();
244
+
245
+ /**
246
+ * Redirect to the new flow edit screen
247
+ */
248
+ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_flow_id ) );
249
+ exit;
250
+ } else {
251
+ wp_die( 'Post creation failed, could not find original post: ' . $post_id );
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Clone step with its meta.
257
+ */
258
+ function clone_step() {
259
+
260
+ global $wpdb;
261
+
262
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_step' === $_REQUEST['action'] ) ) ) {
263
+ wp_die( 'No post to duplicate has been supplied!' );
264
+ }
265
+
266
+ /*
267
+ * Nonce verification
268
+ */
269
+ if ( ! isset( $_GET['step_clone_nonce'] ) || ! wp_verify_nonce( $_GET['step_clone_nonce'], 'step_clone' ) ) {
270
+ return;
271
+ }
272
+
273
+ /**
274
+ * Get the original post id
275
+ */
276
+ $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
277
+
278
+ /**
279
+ * And all the original post data then
280
+ */
281
+ $post = get_post( $post_id );
282
+
283
+ /**
284
+ * Assign current user to be the new post author
285
+ */
286
+ $current_user = wp_get_current_user();
287
+ $new_post_author = $current_user->ID;
288
+
289
+ /**
290
+ * If post data exists, create the post duplicate
291
+ */
292
+ if ( isset( $post ) && null !== $post ) {
293
+
294
+ /**
295
+ * New post data array
296
+ */
297
+ $args = array(
298
+ 'comment_status' => $post->comment_status,
299
+ 'ping_status' => $post->ping_status,
300
+ 'post_author' => $new_post_author,
301
+ 'post_content' => $post->post_content,
302
+ 'post_excerpt' => $post->post_excerpt,
303
+ 'post_name' => $post->post_name,
304
+ 'post_parent' => $post->post_parent,
305
+ 'post_password' => $post->post_password,
306
+ 'post_status' => $post->post_status,
307
+ 'post_title' => $post->post_title . ' Clone',
308
+ 'post_type' => $post->post_type,
309
+ 'to_ping' => $post->to_ping,
310
+ 'menu_order' => $post->menu_order,
311
+ );
312
+
313
+ /**
314
+ * Insert the post
315
+ */
316
+ $new_step_id = wp_insert_post( $args );
317
+
318
+ /**
319
+ * Get all current post terms ad set them to the new post
320
+ */
321
+ // returns array of taxonomy names for post type, ex array("category", "post_tag");.
322
+ $taxonomies = get_object_taxonomies( $post->post_type );
323
+
324
+ foreach ( $taxonomies as $taxonomy ) {
325
+
326
+ $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
327
+
328
+ wp_set_object_terms( $new_step_id, $post_terms, $taxonomy, false );
329
+ }
330
+
331
+ /**
332
+ * Duplicate all post meta just in two SQL queries
333
+ */
334
+ // @codingStandardsIgnoreStart
335
+ $post_meta_infos = $wpdb->get_results(
336
+ "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
337
+ );
338
+ // @codingStandardsIgnoreEnd
339
+
340
+ if ( ! empty( $post_meta_infos ) ) {
341
+
342
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
343
+
344
+ foreach ( $post_meta_infos as $meta_info ) {
345
+
346
+ $meta_key = $meta_info->meta_key;
347
+
348
+ if ( '_wp_old_slug' === $meta_key ) {
349
+ continue;
350
+ }
351
+
352
+ $meta_value = addslashes( $meta_info->meta_value );
353
+
354
+ $sql_query_sel[] = "SELECT $new_step_id, '$meta_key', '$meta_value'";
355
+ }
356
+
357
+ $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
358
+
359
+ // @codingStandardsIgnoreStart
360
+ $wpdb->query( $sql_query );
361
+ // @codingStandardsIgnoreEnd
362
+ }
363
+
364
+ $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
365
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
366
+ $step_type = get_post_meta( $post_id, 'wcf-step-type', true );
367
+
368
+ if ( ! is_array( $flow_steps ) ) {
369
+ $flow_steps = array();
370
+ }
371
+
372
+ $flow_steps[] = array(
373
+ 'id' => $new_step_id,
374
+ 'title' => $post->post_title,
375
+ 'type' => $step_type,
376
+ );
377
+
378
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
379
+
380
+ /* Clear Page Builder Cache */
381
+ $this->clear_cache();
382
+
383
+ /**
384
+ * Redirect to the new flow edit screen
385
+ */
386
+ $redirect_url = add_query_arg( 'highlight-step-id', $new_step_id, get_edit_post_link( $flow_id, 'default' ) );
387
+
388
+ wp_redirect( $redirect_url );
389
+ exit;
390
+ } else {
391
+ wp_die( 'Post creation failed, could not find original post: ' . $post_id );
392
+ }
393
+ }
394
+
395
+ /**
396
+ * Add the clone link to action list for flows row actions
397
+ *
398
+ * @param array $actions Actions array.
399
+ * @param object $post Post object.
400
+ *
401
+ * @return array
402
+ */
403
+ function clone_link( $actions, $post ) {
404
+
405
+ if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
406
+
407
+ if ( isset( $actions['duplicate'] ) ) { // Duplicate page plugin remove.
408
+ unset( $actions['duplicate'] );
409
+ }
410
+ if ( isset( $actions['edit_as_new_draft'] ) ) { // Duplicate post plugin remove.
411
+ unset( $actions['edit_as_new_draft'] );
412
+ }
413
+
414
+ $actions['clone'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_clone_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_clone_nonce' ) . '" title="' . __( 'Clone this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Clone', 'cartflows' ) . '</a>';
415
+ }
416
+
417
+ return $actions;
418
+ }
419
+
420
+ /**
421
+ * Clear Page Builder Cache
422
+ */
423
+ function clear_cache() {
424
+
425
+ // Clear 'Elementor' file cache.
426
+ if ( class_exists( '\Elementor\Plugin' ) ) {
427
+ Elementor\Plugin::$instance->files_manager->clear_cache();
428
+ }
429
+ }
430
+
431
+ }
432
+
433
+ /**
434
+ * Kicking this off by calling 'get_instance()' method
435
+ */
436
+ Cartflows_Cloning::get_instance();
classes/class-cartflows-compatibility.php CHANGED
@@ -1,400 +1,400 @@
1
- <?php
2
- /**
3
- * Page builder compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- if ( ! class_exists( 'Cartflows_Compatibility' ) ) {
9
-
10
- /**
11
- * Class for page builder compatibility
12
- */
13
- class Cartflows_Compatibility {
14
-
15
- /**
16
- * Member Variable
17
- *
18
- * @var object instance
19
- */
20
- private static $instance;
21
-
22
- /**
23
- * Initiator
24
- */
25
- public static function get_instance() {
26
- if ( ! isset( self::$instance ) ) {
27
- self::$instance = new self;
28
- }
29
- return self::$instance;
30
- }
31
-
32
- /**
33
- * Constructor
34
- */
35
- public function __construct() {
36
-
37
- $this->load_files();
38
-
39
- // Override post meta.
40
- add_action( 'wp', array( $this, 'override_meta' ), 0 );
41
-
42
- add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
43
- }
44
-
45
- /**
46
- * Load page builder compatibility files
47
- */
48
- public function load_files() {
49
- if ( class_exists( '\Elementor\Plugin' ) ) {
50
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-elementor-compatibility.php';
51
- }
52
-
53
- if ( $this->is_divi_enabled() ) {
54
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-divi-compatibility.php';
55
- }
56
-
57
- if ( $this->is_bb_enabled() ) {
58
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-bb-compatibility.php';
59
- }
60
-
61
- if ( class_exists( 'TCB_Post' ) ) {
62
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
63
- }
64
- }
65
-
66
- /**
67
- * Check if it is beaver builder enabled.
68
- *
69
- * @since 1.1.4
70
- */
71
- public function is_bb_enabled() {
72
-
73
- if ( class_exists( 'FLBuilderModel' ) ) {
74
- return true;
75
- }
76
-
77
- return false;
78
- }
79
-
80
- /**
81
- * Check if elementor preview mode is on.
82
- */
83
- public function is_elementor_preview_mode() {
84
-
85
- if ( class_exists( '\Elementor\Plugin' ) ) {
86
-
87
- if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
88
- return true;
89
- }
90
- }
91
-
92
- return false;
93
- }
94
-
95
- /**
96
- * Get Current Theme.
97
- */
98
- public function get_current_theme() {
99
-
100
- $theme_name = '';
101
- $theme = wp_get_theme();
102
-
103
- if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
104
- $theme_name = $theme->parent_theme;
105
- } else {
106
- $theme_name = $theme->name;
107
- }
108
-
109
- return $theme_name;
110
- }
111
-
112
- /**
113
- * Check if it is beaver builder preview mode
114
- */
115
- public function is_bb_preview_mode() {
116
-
117
- if ( class_exists( 'FLBuilderModel' ) ) {
118
- if ( FLBuilderModel::is_builder_active() ) {
119
- return true;
120
- } else {
121
- return false;
122
- }
123
- }
124
-
125
- return false;
126
- }
127
-
128
- /**
129
- * Check for page builder preview mode.
130
- */
131
- public function is_page_builder_preview() {
132
-
133
- if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_preview() ) {
134
- return true;
135
- }
136
-
137
- return false;
138
- }
139
-
140
- /**
141
- * Check if divi builder enabled for post id.
142
- */
143
- public function is_divi_builder_preview() {
144
-
145
- if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) {
146
- return true;
147
- }
148
-
149
- return false;
150
- }
151
-
152
- /**
153
- * Check if divi builder enabled for post id.
154
- *
155
- * @param int $post_id post id.
156
- */
157
- public function is_divi_builder_enabled( $post_id ) {
158
-
159
- if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
160
- return true;
161
- }
162
-
163
- return false;
164
- }
165
-
166
- /**
167
- * Check if compatibility theme enabled.
168
- */
169
- function is_compatibility_theme_enabled() {
170
-
171
- $theme = wp_get_theme();
172
-
173
- $is_compatibility = false;
174
-
175
- if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
176
-
177
- $is_compatibility = true;
178
- }
179
-
180
- return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
181
- }
182
-
183
- /**
184
- * Check if divi builder enabled for post id.
185
- *
186
- * @param object $theme theme data.
187
- * @return boolean
188
- */
189
- function is_divi_enabled( $theme = false ) {
190
-
191
- if ( ! $theme ) {
192
- $theme = wp_get_theme();
193
- }
194
-
195
- if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
196
- return true;
197
- }
198
-
199
- return false;
200
- }
201
-
202
- /**
203
- * Check if Divi theme is install status.
204
- *
205
- * @return boolean
206
- */
207
- function is_divi_theme_installed() {
208
- foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
209
- if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
210
- return true;
211
- }
212
- }
213
- return false;
214
- }
215
-
216
- /**
217
- * Check if Flatsome enabled for post id.
218
- *
219
- * @param object $theme theme data.
220
- * @return boolean
221
- */
222
- function is_flatsome_enabled( $theme = false ) {
223
-
224
- if ( ! $theme ) {
225
- $theme = wp_get_theme();
226
- }
227
-
228
- if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
229
- return true;
230
- }
231
-
232
- return false;
233
- }
234
-
235
- /**
236
- * Check if The7 enabled for post id.
237
- *
238
- * @param object $theme theme data.
239
- * @return boolean
240
- */
241
- function is_the_seven_enabled( $theme = false ) {
242
-
243
- if ( ! $theme ) {
244
- $theme = wp_get_theme();
245
- }
246
-
247
- if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
248
- return true;
249
- }
250
-
251
- return false;
252
- }
253
-
254
- /**
255
- * Check if OceanWp enabled for post id.
256
- *
257
- * @param object $theme theme data.
258
- * @return boolean
259
- */
260
- function is_oceanwp_enabled( $theme = false ) {
261
-
262
- if ( ! $theme ) {
263
- $theme = wp_get_theme();
264
- }
265
-
266
- if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
267
- return true;
268
- }
269
-
270
- return false;
271
- }
272
-
273
- /**
274
- * Check for thrive architect edit page.
275
- *
276
- * @param int $post_id post id.
277
- */
278
- public function is_thrive_edit_page( $post_id ) {
279
-
280
- if ( true === $this->is_thrive_builder_page( $post_id ) ) {
281
- return true;
282
- } else {
283
- return false;
284
- }
285
- }
286
-
287
- /**
288
- * Check if the page being rendered is the main ID on the editor page.
289
- *
290
- * @since 1.0.0
291
- * @param String $post_id Post ID which is to be rendered.
292
- * @return boolean True if current if is being rendered is not being edited.
293
- */
294
- private function is_thrive_builder_page( $post_id ) {
295
- $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
296
- $post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
297
-
298
- return ( true == $tve && $post_id !== $post );
299
- }
300
-
301
- /**
302
- * Overwrite meta for page
303
- */
304
- public function override_meta() {
305
-
306
- // don't override meta for `elementor_library` post type.
307
- if ( 'elementor_library' == get_post_type() ) {
308
- return;
309
- }
310
-
311
- if ( ! is_singular() ) {
312
- return;
313
- }
314
-
315
- global $post;
316
- $post_id = $post->ID;
317
- $post_type = get_post_type();
318
-
319
- if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
320
- || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
321
- || $this->is_divi_builder_enabled( $post_id ) ) ) {
322
-
323
- if ( '' == $post->post_content ) {
324
-
325
- $this->overwrite_template( $post_id );
326
- }
327
- }
328
- }
329
-
330
- /**
331
- * Assign cartflow canvas template to page.
332
- *
333
- * @param int $post_id post ID.
334
- */
335
- public function overwrite_template( $post_id ) {
336
-
337
- $template = 'cartflows-canvas';
338
- $key = '_wp_page_template';
339
-
340
- $record_exists = get_post_meta( $post_id, $key, true );
341
-
342
- if ( 'cartflows-canvas' == $record_exists ) {
343
- return;
344
- }
345
-
346
- // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
347
- if ( class_exists( '\Elementor\Plugin' ) ) {
348
-
349
- global $wpdb;
350
-
351
- if ( '' == $record_exists || ! $record_exists ) {
352
-
353
- $wpdb->insert(
354
- $wpdb->prefix . 'postmeta',
355
- array(
356
- 'post_id' => $post_id,
357
- 'meta_key' => $key,
358
- 'meta_value' => $template, // ... and so on
359
- )
360
- );
361
- } else {
362
-
363
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
364
- }
365
- } else {
366
-
367
- update_post_meta( $post_id, $key, $template );
368
- }
369
- }
370
-
371
- /**
372
- * Load font awesome style from oceanwp on checkout page.
373
- */
374
- public function load_fontawesome() {
375
-
376
- $theme = get_template();
377
-
378
- if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
379
-
380
- $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
381
-
382
- if ( $load_fa ) {
383
-
384
- wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
385
- }
386
-
387
- $custom_css = '
388
- #oceanwp-cart-sidebar-wrap,
389
- #owp-qv-wrap{
390
- display: none;
391
- }';
392
-
393
- wp_add_inline_style( 'wcf-frontend-global', $custom_css );
394
- }
395
- }
396
- }
397
- }
398
-
399
- Cartflows_Compatibility::get_instance();
400
-
1
+ <?php
2
+ /**
3
+ * Page builder compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ if ( ! class_exists( 'Cartflows_Compatibility' ) ) {
9
+
10
+ /**
11
+ * Class for page builder compatibility
12
+ */
13
+ class Cartflows_Compatibility {
14
+
15
+ /**
16
+ * Member Variable
17
+ *
18
+ * @var object instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Initiator
24
+ */
25
+ public static function get_instance() {
26
+ if ( ! isset( self::$instance ) ) {
27
+ self::$instance = new self;
28
+ }
29
+ return self::$instance;
30
+ }
31
+
32
+ /**
33
+ * Constructor
34
+ */
35
+ public function __construct() {
36
+
37
+ $this->load_files();
38
+
39
+ // Override post meta.
40
+ add_action( 'wp', array( $this, 'override_meta' ), 0 );
41
+
42
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
43
+ }
44
+
45
+ /**
46
+ * Load page builder compatibility files
47
+ */
48
+ public function load_files() {
49
+ if ( class_exists( '\Elementor\Plugin' ) ) {
50
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-elementor-compatibility.php';
51
+ }
52
+
53
+ if ( $this->is_divi_enabled() ) {
54
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-divi-compatibility.php';
55
+ }
56
+
57
+ if ( $this->is_bb_enabled() ) {
58
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-bb-compatibility.php';
59
+ }
60
+
61
+ if ( class_exists( 'TCB_Post' ) ) {
62
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Check if it is beaver builder enabled.
68
+ *
69
+ * @since 1.1.4
70
+ */
71
+ public function is_bb_enabled() {
72
+
73
+ if ( class_exists( 'FLBuilderModel' ) ) {
74
+ return true;
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Check if elementor preview mode is on.
82
+ */
83
+ public function is_elementor_preview_mode() {
84
+
85
+ if ( class_exists( '\Elementor\Plugin' ) ) {
86
+
87
+ if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
88
+ return true;
89
+ }
90
+ }
91
+
92
+ return false;
93
+ }
94
+
95
+ /**
96
+ * Get Current Theme.
97
+ */
98
+ public function get_current_theme() {
99
+
100
+ $theme_name = '';
101
+ $theme = wp_get_theme();
102
+
103
+ if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
104
+ $theme_name = $theme->parent_theme;
105
+ } else {
106
+ $theme_name = $theme->name;
107
+ }
108
+
109
+ return $theme_name;
110
+ }
111
+
112
+ /**
113
+ * Check if it is beaver builder preview mode
114
+ */
115
+ public function is_bb_preview_mode() {
116
+
117
+ if ( class_exists( 'FLBuilderModel' ) ) {
118
+ if ( FLBuilderModel::is_builder_active() ) {
119
+ return true;
120
+ } else {
121
+ return false;
122
+ }
123
+ }
124
+
125
+ return false;
126
+ }
127
+
128
+ /**
129
+ * Check for page builder preview mode.
130
+ */
131
+ public function is_page_builder_preview() {
132
+
133
+ if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_preview() ) {
134
+ return true;
135
+ }
136
+
137
+ return false;
138
+ }
139
+
140
+ /**
141
+ * Check if divi builder enabled for post id.
142
+ */
143
+ public function is_divi_builder_preview() {
144
+
145
+ if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) {
146
+ return true;
147
+ }
148
+
149
+ return false;
150
+ }
151
+
152
+ /**
153
+ * Check if divi builder enabled for post id.
154
+ *
155
+ * @param int $post_id post id.
156
+ */
157
+ public function is_divi_builder_enabled( $post_id ) {
158
+
159
+ if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
160
+ return true;
161
+ }
162
+
163
+ return false;
164
+ }
165
+
166
+ /**
167
+ * Check if compatibility theme enabled.
168
+ */
169
+ function is_compatibility_theme_enabled() {
170
+
171
+ $theme = wp_get_theme();
172
+
173
+ $is_compatibility = false;
174
+
175
+ if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
176
+
177
+ $is_compatibility = true;
178
+ }
179
+
180
+ return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
181
+ }
182
+
183
+ /**
184
+ * Check if divi builder enabled for post id.
185
+ *
186
+ * @param object $theme theme data.
187
+ * @return boolean
188
+ */
189
+ function is_divi_enabled( $theme = false ) {
190
+
191
+ if ( ! $theme ) {
192
+ $theme = wp_get_theme();
193
+ }
194
+
195
+ if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
196
+ return true;
197
+ }
198
+
199
+ return false;
200
+ }
201
+
202
+ /**
203
+ * Check if Divi theme is install status.
204
+ *
205
+ * @return boolean
206
+ */
207
+ function is_divi_theme_installed() {
208
+ foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
209
+ if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
210
+ return true;
211
+ }
212
+ }
213
+ return false;
214
+ }
215
+
216
+ /**
217
+ * Check if Flatsome enabled for post id.
218
+ *
219
+ * @param object $theme theme data.
220
+ * @return boolean
221
+ */
222
+ function is_flatsome_enabled( $theme = false ) {
223
+
224
+ if ( ! $theme ) {
225
+ $theme = wp_get_theme();
226
+ }
227
+
228
+ if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
229
+ return true;
230
+ }
231
+
232
+ return false;
233
+ }
234
+
235
+ /**
236
+ * Check if The7 enabled for post id.
237
+ *
238
+ * @param object $theme theme data.
239
+ * @return boolean
240
+ */
241
+ function is_the_seven_enabled( $theme = false ) {
242
+
243
+ if ( ! $theme ) {
244
+ $theme = wp_get_theme();
245
+ }
246
+
247
+ if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
248
+ return true;
249
+ }
250
+
251
+ return false;
252
+ }
253
+
254
+ /**
255
+ * Check if OceanWp enabled for post id.
256
+ *
257
+ * @param object $theme theme data.
258
+ * @return boolean
259
+ */
260
+ function is_oceanwp_enabled( $theme = false ) {
261
+
262
+ if ( ! $theme ) {
263
+ $theme = wp_get_theme();
264
+ }
265
+
266
+ if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
267
+ return true;
268
+ }
269
+
270
+ return false;
271
+ }
272
+
273
+ /**
274
+ * Check for thrive architect edit page.
275
+ *
276
+ * @param int $post_id post id.
277
+ */
278
+ public function is_thrive_edit_page( $post_id ) {
279
+
280
+ if ( true === $this->is_thrive_builder_page( $post_id ) ) {
281
+ return true;
282
+ } else {
283
+ return false;
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Check if the page being rendered is the main ID on the editor page.
289
+ *
290
+ * @since 1.0.0
291
+ * @param String $post_id Post ID which is to be rendered.
292
+ * @return boolean True if current if is being rendered is not being edited.
293
+ */
294
+ private function is_thrive_builder_page( $post_id ) {
295
+ $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
296
+ $post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
297
+
298
+ return ( true == $tve && $post_id !== $post );
299
+ }
300
+
301
+ /**
302
+ * Overwrite meta for page
303
+ */
304
+ public function override_meta() {
305
+
306
+ // don't override meta for `elementor_library` post type.
307
+ if ( 'elementor_library' == get_post_type() ) {
308
+ return;
309
+ }
310
+
311
+ if ( ! is_singular() ) {
312
+ return;
313
+ }
314
+
315
+ global $post;
316
+ $post_id = $post->ID;
317
+ $post_type = get_post_type();
318
+
319
+ if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
320
+ || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
321
+ || $this->is_divi_builder_enabled( $post_id ) ) ) {
322
+
323
+ if ( '' == $post->post_content ) {
324
+
325
+ $this->overwrite_template( $post_id );
326
+ }
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Assign cartflow canvas template to page.
332
+ *
333
+ * @param int $post_id post ID.
334
+ */
335
+ public function overwrite_template( $post_id ) {
336
+
337
+ $template = 'cartflows-canvas';
338
+ $key = '_wp_page_template';
339
+
340
+ $record_exists = get_post_meta( $post_id, $key, true );
341
+
342
+ if ( 'cartflows-canvas' == $record_exists ) {
343
+ return;
344
+ }
345
+
346
+ // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
347
+ if ( class_exists( '\Elementor\Plugin' ) ) {
348
+
349
+ global $wpdb;
350
+
351
+ if ( '' == $record_exists || ! $record_exists ) {
352
+
353
+ $wpdb->insert(
354
+ $wpdb->prefix . 'postmeta',
355
+ array(
356
+ 'post_id' => $post_id,
357
+ 'meta_key' => $key,
358
+ 'meta_value' => $template, // ... and so on
359
+ )
360
+ );
361
+ } else {
362
+
363
+ $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
364
+ }
365
+ } else {
366
+
367
+ update_post_meta( $post_id, $key, $template );
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Load font awesome style from oceanwp on checkout page.
373
+ */
374
+ public function load_fontawesome() {
375
+
376
+ $theme = get_template();
377
+
378
+ if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
379
+
380
+ $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
381
+
382
+ if ( $load_fa ) {
383
+
384
+ wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
385
+ }
386
+
387
+ $custom_css = '
388
+ #oceanwp-cart-sidebar-wrap,
389
+ #owp-qv-wrap{
390
+ display: none;
391
+ }';
392
+
393
+ wp_add_inline_style( 'wcf-frontend-global', $custom_css );
394
+ }
395
+ }
396
+ }
397
+ }
398
+
399
+ Cartflows_Compatibility::get_instance();
400
+
classes/class-cartflows-default-meta.php CHANGED
@@ -1,926 +1,926 @@
1
- <?php
2
- /**
3
- * Cartflow default options.
4
- *
5
- * @package Cartflows
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Default_Meta {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Member Variable
25
- *
26
- * @var checkout_fields
27
- */
28
- private static $checkout_fields = null;
29
-
30
- /**
31
- * Member Variable
32
- *
33
- * @var checkout_fields
34
- */
35
- private static $thankyou_fields = null;
36
-
37
- /**
38
- * Member Variable
39
- *
40
- * @var flow_fields
41
- */
42
- private static $flow_fields = null;
43
-
44
- /**
45
- * Member Variable
46
- *
47
- * @var landing_fields
48
- */
49
- private static $landing_fields = null;
50
-
51
- /**
52
- * Initiator
53
- */
54
- public static function get_instance() {
55
- if ( ! isset( self::$instance ) ) {
56
- self::$instance = new self;
57
- }
58
- return self::$instance;
59
- }
60
-
61
- /**
62
- * Constructor
63
- */
64
- public function __construct() {
65
-
66
- }
67
-
68
- /**
69
- * Checkout Default fields.
70
- *
71
- * @param int $post_id post id.
72
- * @return array
73
- */
74
- function get_checkout_fields( $post_id ) {
75
-
76
- if ( null === self::$checkout_fields ) {
77
-
78
- self::$checkout_fields = array(
79
- 'wcf-field-google-font-url' => array(
80
- 'default' => '',
81
- 'sanitize' => 'FILTER_DEFAULT',
82
- ),
83
- 'wcf-checkout-products' => array(
84
- 'default' => array(),
85
- 'sanitize' => 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS',
86
- ),
87
- 'wcf-checkout-layout' => array(
88
- 'default' => 'two-column',
89
- 'sanitize' => 'FILTER_DEFAULT',
90
- ),
91
- 'wcf-input-font-family' => array(
92
- 'default' => '',
93
- 'sanitize' => 'FILTER_DEFAULT',
94
- ),
95
- 'wcf-input-font-weight' => array(
96
- 'default' => '',
97
- 'sanitize' => 'FILTER_DEFAULT',
98
- ),
99
- 'wcf-heading-font-family' => array(
100
- 'default' => '',
101
- 'sanitize' => 'FILTER_DEFAULT',
102
- ),
103
- 'wcf-heading-font-weight' => array(
104
- 'default' => '',
105
- 'sanitize' => 'FILTER_DEFAULT',
106
- ),
107
- 'wcf-base-font-family' => array(
108
- 'default' => '',
109
- 'sanitize' => 'FILTER_DEFAULT',
110
- ),
111
- 'wcf-advance-options-fields' => array(
112
- 'default' => '',
113
- 'sanitize' => 'FILTER_DEFAULT',
114
- ),
115
- 'wcf-base-font-weight' => array(
116
- 'default' => '',
117
- 'sanitize' => 'FILTER_DEFAULT',
118
- ),
119
- 'wcf-button-font-family' => array(
120
- 'default' => '',
121
- 'sanitize' => 'FILTER_DEFAULT',
122
- ),
123
- 'wcf-button-font-weight' => array(
124
- 'default' => '',
125
- 'sanitize' => 'FILTER_DEFAULT',
126
- ),
127
- 'wcf-primary-color' => array(
128
- 'default' => '',
129
- 'sanitize' => 'FILTER_DEFAULT',
130
- ),
131
- 'wcf-heading-color' => array(
132
- 'default' => '',
133
- 'sanitize' => 'FILTER_DEFAULT',
134
- ),
135
- 'wcf-section-bg-color' => array(
136
- 'default' => '',
137
- 'sanitize' => 'FILTER_DEFAULT',
138
- ),
139
- 'wcf-hl-bg-color' => array(
140
- 'default' => '',
141
- 'sanitize' => 'FILTER_DEFAULT',
142
- ),
143
- 'wcf-field-tb-padding' => array(
144
- 'default' => '',
145
- 'sanitize' => 'FILTER_DEFAULT',
146
- ),
147
- 'wcf-field-lr-padding' => array(
148
- 'default' => '',
149
- 'sanitize' => 'FILTER_DEFAULT',
150
- ),
151
- 'wcf-fields-skins' => array(
152
- 'default' => '',
153
- 'sanitize' => 'FILTER_DEFAULT',
154
- ),
155
- 'wcf-input-field-size' => array(
156
- 'default' => '33px',
157
- 'sanitize' => 'FILTER_DEFAULT',
158
- ),
159
- 'wcf-field-color' => array(
160
- 'default' => '',
161
- 'sanitize' => 'FILTER_DEFAULT',
162
- ),
163
- 'wcf-field-bg-color' => array(
164
- 'default' => '',
165
- 'sanitize' => 'FILTER_DEFAULT',
166
- ),
167
- 'wcf-field-border-color' => array(
168
- 'default' => '',
169
- 'sanitize' => 'FILTER_DEFAULT',
170
- ),
171
- 'wcf-box-border-color' => array(
172
- 'default' => '',
173
- 'sanitize' => 'FILTER_DEFAULT',
174
- ),
175
- 'wcf-field-label-color' => array(
176
- 'default' => '',
177
- 'sanitize' => 'FILTER_DEFAULT',
178
- ),
179
- 'wcf-submit-tb-padding' => array(
180
- 'default' => '',
181
- 'sanitize' => 'FILTER_DEFAULT',
182
- ),
183
- 'wcf-submit-lr-padding' => array(
184
- 'default' => '',
185
- 'sanitize' => 'FILTER_DEFAULT',
186
- ),
187
- 'wcf-input-button-size' => array(
188
- 'default' => '33px',
189
- 'sanitize' => 'FILTER_DEFAULT',
190
- ),
191
- 'wcf-submit-color' => array(
192
- 'default' => '',
193
- 'sanitize' => 'FILTER_DEFAULT',
194
- ),
195
- 'wcf-submit-hover-color' => array(
196
- 'default' => '',
197
- 'sanitize' => 'FILTER_DEFAULT',
198
- ),
199
- 'wcf-submit-bg-color' => array(
200
- 'default' => '',
201
- 'sanitize' => 'FILTER_DEFAULT',
202
- ),
203
- 'wcf-submit-bg-hover-color' => array(
204
- 'default' => '',
205
- 'sanitize' => 'FILTER_DEFAULT',
206
- ),
207
- 'wcf-submit-border-color' => array(
208
- 'default' => '',
209
- 'sanitize' => 'FILTER_DEFAULT',
210
- ),
211
- 'wcf-submit-border-hover-color' => array(
212
- 'default' => '',
213
- 'sanitize' => 'FILTER_DEFAULT',
214
- ),
215
- 'wcf-active-tab' => array(
216
- 'default' => '',
217
- 'sanitize' => 'FILTER_DEFAULT',
218
- ),
219
- 'wcf-header-logo-image' => array(
220
- 'default' => '',
221
- 'sanitize' => 'FILTER_DEFAULT',
222
- ),
223
- 'wcf-header-logo-width' => array(
224
- 'default' => '',
225
- 'sanitize' => 'FILTER_DEFAULT',
226
- ),
227
- 'wcf-custom-script' => array(
228
- 'default' => '',
229
- 'sanitize' => 'FILTER_DEFAULT',
230
- ),
231
- );
232
-
233
- self::$checkout_fields = apply_filters( 'cartflows_checkout_meta_options', self::$checkout_fields, $post_id );
234
- }
235
-
236
- return self::$checkout_fields;
237
- }
238
-
239
- /**
240
- * Save Checkout Meta fields.
241
- *
242
- * @param int $post_id post id.
243
- * @return void
244
- */
245
- function save_checkout_fields( $post_id ) {
246
-
247
- $post_meta = $this->get_checkout_fields( $post_id );
248
-
249
- $this->save_meta_fields( $post_id, $post_meta );
250
- }
251
-
252
- /**
253
- * Save Landing Meta fields.
254
- *
255
- * @param int $post_id post id.
256
- * @return void
257
- */
258
- function save_landing_fields( $post_id ) {
259
-
260
- $post_meta = $this->get_landing_fields( $post_id );
261
-
262
- $this->save_meta_fields( $post_id, $post_meta );
263
- }
264
-
265
- /**
266
- * Save ThankYou Meta fields.
267
- *
268
- * @param int $post_id post id.
269
- * @return void
270
- */
271
- function save_thankyou_fields( $post_id ) {
272
-
273
- $post_meta = $this->get_thankyou_fields( $post_id );
274
-
275
- $this->save_meta_fields( $post_id, $post_meta );
276
- }
277
-
278
- /**
279
- * Flow Default fields.
280
- *
281
- * @param int $post_id post id.
282
- * @return array
283
- */
284
- function get_flow_fields( $post_id ) {
285
-
286
- if ( null === self::$flow_fields ) {
287
-
288
- self::$flow_fields = array(
289
- 'wcf-steps' => array(
290
- 'default' => array(),
291
- 'sanitize' => 'FILTER_DEFAULT',
292
- ),
293
-
294
- 'wcf-testing' => array(
295
- 'default' => 'yes',
296
- 'sanitize' => 'FILTER_DEFAULT',
297
- ),
298
- );
299
- }
300
-
301
- return apply_filters( 'cartflows_flow_meta_options', self::$flow_fields );
302
- }
303
-
304
- /**
305
- * Save Flow Meta fields.
306
- *
307
- * @param int $post_id post id.
308
- * @return void
309
- */
310
- function save_flow_fields( $post_id ) {
311
-
312
- $post_meta = $this->get_flow_fields( $post_id );
313
-
314
- if ( isset( $post_meta['wcf-steps'] ) ) {
315
- unset( $post_meta['wcf-steps'] );
316
- }
317
-
318
- $this->save_meta_fields( $post_id, $post_meta );
319
- }
320
-
321
- /**
322
- * Save Meta fields - Common Function.
323
- *
324
- * @param int $post_id post id.
325
- * @param array $post_meta options to store.
326
- * @return void
327
- */
328
- function save_meta_fields( $post_id, $post_meta ) {
329
-
330
- if ( ! ( $post_id && is_array( $post_meta ) ) ) {
331
-
332
- return;
333
- }
334
-
335
- foreach ( $post_meta as $key => $data ) {
336
-
337
- $meta_value = false;
338
-
339
- // Sanitize values.
340
- $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
341
-
342
- switch ( $sanitize_filter ) {
343
-
344
- case 'FILTER_SANITIZE_STRING':
345
- $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
346
- break;
347
-
348
- case 'FILTER_SANITIZE_URL':
349
- $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
350
- break;
351
-
352
- case 'FILTER_SANITIZE_NUMBER_INT':
353
- $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
354
- break;
355
-
356
- case 'FILTER_CARTFLOWS_ARRAY':
357
- if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
358
- $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
359
- }
360
- break;
361
-
362
- case 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS':
363
- if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
364
-
365
- $i = 0;
366
- $q = 0;
367
-
368
- foreach ( $_POST[ $key ] as $p_index => $p_data ) {
369
-
370
- foreach ( $p_data as $i_key => $i_value ) {
371
-
372
- if ( is_array( $i_value ) ) {
373
-
374
- foreach ( $i_value as $q_key => $q_value ) {
375
-
376
- $meta_value[ $i ][ $i_key ][ $q ] = array_map( 'sanitize_text_field', $q_value );
377
-
378
- $q++;
379
- }
380
- } else {
381
- $meta_value[ $i ][ $i_key ] = sanitize_text_field( $i_value );
382
- }
383
- }
384
-
385
- $i++;
386
- }
387
- }
388
- break;
389
- case 'FILTER_CARTFLOWS_CHECKOUT_FIELDS':
390
- $count = 10;
391
- $ordered_fields = array();
392
- $billing_fields = array();
393
-
394
- if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
395
- $post_data = $_POST[ $key ];
396
-
397
- if ( 'wcf_field_order_billing' == $key ) {
398
-
399
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
400
-
401
- foreach ( $post_data as $index => $value ) {
402
-
403
- if ( isset( $billing_fields[ $value ] ) ) {
404
- $ordered_fields[ $value ] = $billing_fields[ $value ];
405
- $ordered_fields[ $value ]['priority'] = $count;
406
- $count += 10;
407
- }
408
- }
409
-
410
- $meta_value = $ordered_fields;
411
- }
412
-
413
- if ( 'wcf_field_order_shipping' == $key ) {
414
-
415
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
416
- foreach ( $post_data as $index => $value ) {
417
-
418
- if ( isset( $shipping_fields[ $value ] ) ) {
419
- $ordered_fields[ $value ] = $shipping_fields[ $value ];
420
- $ordered_fields[ $value ]['priority'] = $count;
421
- $count += 10;
422
- }
423
- }
424
- $meta_value = $ordered_fields;
425
- }
426
-
427
- if ( 'wcf_label_text_field_billing' == $key ) {
428
-
429
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
430
-
431
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
432
- echo 'con 1';
433
- $billing_fields = $get_ordered_billing_fields;
434
- } else {
435
- echo 'con 2';
436
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
437
- }
438
-
439
- foreach ( $post_data as $index => $value ) {
440
-
441
- if ( isset( $billing_fields[ $index ] ) ) {
442
- $ordered_fields[ $index ] = $billing_fields[ $index ];
443
- $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
444
- }
445
- }
446
- $key = 'wcf_field_order_billing';
447
- $meta_value = $ordered_fields;
448
- }
449
-
450
- if ( 'wcf_label_text_field_shipping' == $key ) {
451
-
452
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
453
-
454
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
455
- $shipping_fields = $get_ordered_shipping_fields;
456
- } else {
457
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
458
- }
459
-
460
- foreach ( $post_data as $index => $value ) {
461
-
462
- if ( isset( $shipping_fields[ $index ] ) ) {
463
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
464
- $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
465
- }
466
- }
467
- $key = 'wcf_field_order_shipping';
468
- $meta_value = $ordered_fields;
469
- }
470
-
471
- if ( 'wcf_label_placeholder_field_billing' == $key ) {
472
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
473
-
474
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
475
- $billing_fields = $get_ordered_billing_fields;
476
- } else {
477
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
478
- }
479
- foreach ( $post_data as $index => $value ) {
480
-
481
- if ( isset( $billing_fields[ $index ] ) ) {
482
- $ordered_fields[ $index ] = $billing_fields[ $index ];
483
- $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
484
- }
485
- }
486
-
487
- $key = 'wcf_field_order_billing';
488
- $meta_value = $ordered_fields;
489
- }
490
-
491
- if ( 'wcf_label_placeholder_field_shipping' == $key ) {
492
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
493
-
494
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
495
- $shipping_fields = $get_ordered_shipping_fields;
496
- } else {
497
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
498
- }
499
-
500
- foreach ( $post_data as $index => $value ) {
501
-
502
- if ( isset( $shipping_fields[ $index ] ) ) {
503
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
504
- $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
505
- }
506
- }
507
-
508
- $key = 'wcf_field_order_shipping';
509
- $meta_value = $ordered_fields;
510
-
511
- }
512
-
513
- if ( 'wcf_label_default_field_billing' == $key ) {
514
-
515
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
516
-
517
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
518
- $billing_fields = $get_ordered_billing_fields;
519
- } else {
520
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
521
- }
522
-
523
- foreach ( $post_data as $index => $value ) {
524
-
525
- if ( isset( $billing_fields[ $index ] ) ) {
526
- $ordered_fields[ $index ] = $billing_fields[ $index ];
527
- $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
528
- }
529
- }
530
-
531
- $key = 'wcf_field_order_billing';
532
- $meta_value = $ordered_fields;
533
- }
534
-
535
- if ( 'wcf_label_default_field_shipping' == $key ) {
536
-
537
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
538
-
539
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
540
- $shipping_fields = $get_ordered_shipping_fields;
541
- } else {
542
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
543
- }
544
-
545
- foreach ( $post_data as $index => $value ) {
546
-
547
- if ( isset( $shipping_fields[ $index ] ) ) {
548
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
549
- $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
550
- }
551
- }
552
-
553
- $key = 'wcf_field_order_shipping';
554
- $meta_value = $ordered_fields;
555
- }
556
-
557
- if ( 'wcf_is_required_field_billing' == $key ) {
558
-
559
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
560
-
561
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
562
- $billing_fields = $get_ordered_billing_fields;
563
- } else {
564
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
565
- }
566
-
567
- foreach ( $post_data as $index => $value ) {
568
-
569
- if ( isset( $billing_fields[ $index ] ) ) {
570
- $ordered_fields[ $index ] = $billing_fields[ $index ];
571
- if ( 'yes' == $value ) {
572
-
573
- $ordered_fields[ $index ]['required'] = true;
574
- } else {
575
- $ordered_fields[ $index ]['required'] = false;
576
- }
577
- }
578
- }
579
-
580
- $key = 'wcf_field_order_billing';
581
- $meta_value = $ordered_fields;
582
- }
583
-
584
- if ( 'wcf_is_required_field_shipping' == $key ) {
585
-
586
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
587
-
588
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
589
- $shipping_fields = $get_ordered_shipping_fields;
590
- } else {
591
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
592
- }
593
-
594
- foreach ( $post_data as $index => $value ) {
595
-
596
- if ( isset( $shipping_fields[ $index ] ) ) {
597
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
598
-
599
- if ( 'yes' == $value ) {
600
-
601
- $ordered_fields[ $index ]['required'] = true;
602
- } else {
603
- $ordered_fields[ $index ]['required'] = false;
604
- }
605
- }
606
- }
607
-
608
- $key = 'wcf_field_order_shipping';
609
- $meta_value = $ordered_fields;
610
- }
611
-
612
- if ( 'wcf_select_option_field_billing' == $key ) {
613
-
614
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
615
-
616
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
617
- $billing_fields = $get_ordered_billing_fields;
618
- } else {
619
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
620
- }
621
-
622
- foreach ( $post_data as $index => $value ) {
623
-
624
- $options = explode( ',', $value );
625
-
626
- if ( isset( $billing_fields[ $index ] ) ) {
627
- $ordered_fields[ $index ] = $billing_fields[ $index ];
628
-
629
- $ordered_fields[ $index ]['options'] = array();
630
-
631
- foreach ( $options as $key => $option ) {
632
-
633
- $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
634
- }
635
- }
636
- }
637
-
638
- $key = 'wcf_field_order_billing';
639
- $meta_value = $ordered_fields;
640
- }
641
-
642
- if ( 'wcf_select_option_field_shipping' == $key ) {
643
-
644
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
645
-
646
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
647
- $shipping_fields = $get_ordered_shipping_fields;
648
- } else {
649
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
650
- }
651
-
652
- foreach ( $post_data as $index => $value ) {
653
-
654
- $options = explode( ',', $value );
655
-
656
- if ( isset( $shipping_fields[ $index ] ) ) {
657
-
658
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
659
-
660
- $ordered_fields[ $index ]['options'] = array();
661
-
662
- foreach ( $options as $key => $option ) {
663
-
664
- $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
665
- }
666
- }
667
- }
668
-
669
- $key = 'wcf_field_order_shipping';
670
- $meta_value = $ordered_fields;
671
- }
672
- }
673
- break;
674
-
675
- default:
676
- $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
677
- break;
678
- }
679
-
680
- if ( false !== $meta_value ) {
681
- update_post_meta( $post_id, $key, $meta_value );
682
- } else {
683
- delete_post_meta( $post_id, $key );
684
- }
685
- }
686
- }
687
-
688
- /**
689
- * Get checkout meta.
690
- *
691
- * @param int $post_id post id.
692
- * @param string $key options key.
693
- * @param mix $default options default value.
694
- * @return string
695
- */
696
- function get_flow_meta_value( $post_id, $key, $default = false ) {
697
-
698
- $value = $this->get_save_meta( $post_id, $key );
699
-
700
- if ( ! $value ) {
701
-
702
- if ( $default ) {
703
-
704
- $value = $default;
705
- } else {
706
-
707
- $fields = $this->get_flow_fields( $post_id );
708
-
709
- if ( isset( $fields[ $key ]['default'] ) ) {
710
-
711
- $value = $fields[ $key ]['default'];
712
- }
713
- }
714
- }
715
-
716
- return $value;
717
- }
718
-
719
- /**
720
- * Get checkout meta.
721
- *
722
- * @param int $post_id post id.
723
- * @param string $key options key.
724
- * @param mix $default options default value.
725
- * @return string
726
- */
727
- function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) {
728
-
729
- $value = $this->get_save_meta( $post_id, $key );
730
-
731
- if ( ! $value ) {
732
-
733
- if ( $default ) {
734
-
735
- $value = $default;
736
- } else {
737
-
738
- $fields = $this->get_checkout_fields( $post_id );
739
-
740
- if ( isset( $fields[ $key ]['default'] ) ) {
741
-
742
- $value = $fields[ $key ]['default'];
743
- }
744
- }
745
- }
746
-
747
- return $value;
748
- }
749
-
750
- /**
751
- * Get post meta.
752
- *
753
- * @param int $post_id post id.
754
- * @param string $key options key.
755
- * @return string
756
- */
757
- function get_save_meta( $post_id, $key ) {
758
-
759
- $value = get_post_meta( $post_id, $key, true );
760
-
761
- return $value;
762
- }
763
-
764
- /**
765
- * Thank You Default fields.
766
- *
767
- * @param int $post_id post id.
768
- * @return array
769
- */
770
- function get_thankyou_fields( $post_id ) {
771
-
772
- if ( null === self::$thankyou_fields ) {
773
-
774
- self::$thankyou_fields = array(
775
- 'wcf-field-google-font-url' => array(
776
- 'default' => '',
777
- 'sanitize' => 'FILTER_DEFAULT',
778
- ),
779
- 'wcf-active-tab' => array(
780
- 'default' => '',
781
- 'sanitize' => 'FILTER_DEFAULT',
782
- ),
783
- 'wcf-tq-text-color' => array(
784
- 'default' => '',
785
- 'sanitize' => 'FILTER_DEFAULT',
786
- ),
787
- 'wcf-tq-font-family' => array(
788
- 'default' => '',
789
- 'sanitize' => 'FILTER_DEFAULT',
790
- ),
791
- 'wcf-tq-heading-color' => array(
792
- 'default' => '',
793
- 'sanitize' => 'FILTER_DEFAULT',
794
- ),
795
- 'wcf-tq-heading-font-family' => array(
796
- 'default' => '',
797
- 'sanitize' => 'FILTER_DEFAULT',
798
- ),
799
- 'wcf-tq-heading-font-wt' => array(
800
- 'default' => '',
801
- 'sanitize' => 'FILTER_DEFAULT',
802
- ),
803
- 'wcf-tq-container-width' => array(
804
- 'default' => '',
805
- 'sanitize' => 'FILTER_DEFAULT',
806
- ),
807
- 'wcf-tq-section-bg-color' => array(
808
- 'default' => '',
809
- 'sanitize' => 'FILTER_DEFAULT',
810
- ),
811
- 'wcf-tq-advance-options-fields' => array(
812
- 'default' => '',
813
- 'sanitize' => 'FILTER_DEFAULT',
814
- ),
815
- 'wcf-show-overview-section' => array(
816
- 'default' => 'yes',
817
- 'sanitize' => 'FILTER_DEFAULT',
818
- ),
819
- 'wcf-show-details-section' => array(
820
- 'default' => 'yes',
821
- 'sanitize' => 'FILTER_DEFAULT',
822
- ),
823
- 'wcf-show-billing-section' => array(
824
- 'default' => 'yes',
825
- 'sanitize' => 'FILTER_DEFAULT',
826
- ),
827
- 'wcf-show-shipping-section' => array(
828
- 'default' => 'yes',
829
- 'sanitize' => 'FILTER_DEFAULT',
830
- ),
831
- 'wcf-custom-script' => array(
832
- 'default' => '',
833
- 'sanitize' => 'FILTER_DEFAULT',
834
- ),
835
- );
836
-
837
- }
838
-
839
- return apply_filters( 'cartflows_thankyou_meta_options', self::$thankyou_fields, $post_id );
840
- }
841
-
842
- /**
843
- * Get Thank you section meta.
844
- *
845
- * @param int $post_id post id.
846
- * @param string $key options key.
847
- * @param mix $default options default value.
848
- * @return string
849
- */
850
- function get_thankyou_meta_value( $post_id, $key, $default = false ) {
851
-
852
- $value = $this->get_save_meta( $post_id, $key );
853
-
854
- if ( ! $value ) {
855
-
856
- if ( $default ) {
857
-
858
- $value = $default;
859
- } else {
860
-
861
- $fields = $this->get_thankyou_fields( $post_id );
862
-
863
- if ( isset( $fields[ $key ]['default'] ) ) {
864
-
865
- $value = $fields[ $key ]['default'];
866
- }
867
- }
868
- }
869
-
870
- return $value;
871
- }
872
-
873
- /**
874
- * Get Landing section meta.
875
- *
876
- * @param int $post_id post id.
877
- * @param string $key options key.
878
- * @param mix $default options default value.
879
- * @return string
880
- */
881
- function get_landing_meta_value( $post_id, $key, $default = false ) {
882
-
883
- $value = $this->get_save_meta( $post_id, $key );
884
- if ( ! $value ) {
885
-
886
- if ( $default ) {
887
-
888
- $value = $default;
889
- } else {
890
-
891
- $fields = $this->get_landing_fields( $post_id );
892
-
893
- if ( isset( $fields[ $key ]['default'] ) ) {
894
- $value = $fields[ $key ]['default'];
895
- }
896
- }
897
- }
898
-
899
- return $value;
900
- }
901
-
902
- /**
903
- * Thank You Default fields.
904
- *
905
- * @param int $post_id post id.
906
- * @return array
907
- */
908
- function get_landing_fields( $post_id ) {
909
-
910
- if ( null === self::$landing_fields ) {
911
-
912
- self::$landing_fields = array(
913
- 'wcf-custom-script' => array(
914
- 'default' => '',
915
- 'sanitize' => 'FILTER_DEFAULT',
916
- ),
917
- );
918
- }
919
- return apply_filters( 'cartflows_landing_meta_options', self::$landing_fields, $post_id );
920
- }
921
- }
922
-
923
- /**
924
- * Kicking this off by calling 'get_instance()' method
925
- */
926
- Cartflows_Default_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Cartflow default options.
4
+ *
5
+ * @package Cartflows
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Default_Meta {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var checkout_fields
27
+ */
28
+ private static $checkout_fields = null;
29
+
30
+ /**
31
+ * Member Variable
32
+ *
33
+ * @var checkout_fields
34
+ */
35
+ private static $thankyou_fields = null;
36
+
37
+ /**
38
+ * Member Variable
39
+ *
40
+ * @var flow_fields
41
+ */
42
+ private static $flow_fields = null;
43
+
44
+ /**
45
+ * Member Variable
46
+ *
47
+ * @var landing_fields
48
+ */
49
+ private static $landing_fields = null;
50
+
51
+ /**
52
+ * Initiator
53
+ */
54
+ public static function get_instance() {
55
+ if ( ! isset( self::$instance ) ) {
56
+ self::$instance = new self;
57
+ }
58
+ return self::$instance;
59
+ }
60
+
61
+ /**
62
+ * Constructor
63
+ */
64
+ public function __construct() {
65
+
66
+ }
67
+
68
+ /**
69
+ * Checkout Default fields.
70
+ *
71
+ * @param int $post_id post id.
72
+ * @return array
73
+ */
74
+ function get_checkout_fields( $post_id ) {
75
+
76
+ if ( null === self::$checkout_fields ) {
77
+
78
+ self::$checkout_fields = array(
79
+ 'wcf-field-google-font-url' => array(
80
+ 'default' => '',
81
+ 'sanitize' => 'FILTER_DEFAULT',
82
+ ),
83
+ 'wcf-checkout-products' => array(
84
+ 'default' => array(),
85
+ 'sanitize' => 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS',
86
+ ),
87
+ 'wcf-checkout-layout' => array(
88
+ 'default' => 'two-column',
89
+ 'sanitize' => 'FILTER_DEFAULT',
90
+ ),
91
+ 'wcf-input-font-family' => array(
92
+ 'default' => '',
93
+ 'sanitize' => 'FILTER_DEFAULT',
94
+ ),
95
+ 'wcf-input-font-weight' => array(
96
+ 'default' => '',
97
+ 'sanitize' => 'FILTER_DEFAULT',
98
+ ),
99
+ 'wcf-heading-font-family' => array(
100
+ 'default' => '',
101
+ 'sanitize' => 'FILTER_DEFAULT',
102
+ ),
103
+ 'wcf-heading-font-weight' => array(
104
+ 'default' => '',
105
+ 'sanitize' => 'FILTER_DEFAULT',
106
+ ),
107
+ 'wcf-base-font-family' => array(
108
+ 'default' => '',
109
+ 'sanitize' => 'FILTER_DEFAULT',
110
+ ),
111
+ 'wcf-advance-options-fields' => array(
112
+ 'default' => '',
113
+ 'sanitize' => 'FILTER_DEFAULT',
114
+ ),
115
+ 'wcf-base-font-weight' => array(
116
+ 'default' => '',
117
+ 'sanitize' => 'FILTER_DEFAULT',
118
+ ),
119
+ 'wcf-button-font-family' => array(
120
+ 'default' => '',
121
+ 'sanitize' => 'FILTER_DEFAULT',
122
+ ),
123
+ 'wcf-button-font-weight' => array(
124
+ 'default' => '',
125
+ 'sanitize' => 'FILTER_DEFAULT',
126
+ ),
127
+ 'wcf-primary-color' => array(
128
+ 'default' => '',
129
+ 'sanitize' => 'FILTER_DEFAULT',
130
+ ),
131
+ 'wcf-heading-color' => array(
132
+ 'default' => '',
133
+ 'sanitize' => 'FILTER_DEFAULT',
134
+ ),
135
+ 'wcf-section-bg-color' => array(
136
+ 'default' => '',
137
+ 'sanitize' => 'FILTER_DEFAULT',
138
+ ),
139
+ 'wcf-hl-bg-color' => array(
140
+ 'default' => '',
141
+ 'sanitize' => 'FILTER_DEFAULT',
142
+ ),
143
+ 'wcf-field-tb-padding' => array(
144
+ 'default' => '',
145
+ 'sanitize' => 'FILTER_DEFAULT',
146
+ ),
147
+ 'wcf-field-lr-padding' => array(
148
+ 'default' => '',
149
+ 'sanitize' => 'FILTER_DEFAULT',
150
+ ),
151
+ 'wcf-fields-skins' => array(
152
+ 'default' => '',
153
+ 'sanitize' => 'FILTER_DEFAULT',
154
+ ),
155
+ 'wcf-input-field-size' => array(
156
+ 'default' => '33px',
157
+ 'sanitize' => 'FILTER_DEFAULT',
158
+ ),
159
+ 'wcf-field-color' => array(
160
+ 'default' => '',
161
+ 'sanitize' => 'FILTER_DEFAULT',
162
+ ),
163
+ 'wcf-field-bg-color' => array(
164
+ 'default' => '',
165
+ 'sanitize' => 'FILTER_DEFAULT',
166
+ ),
167
+ 'wcf-field-border-color' => array(
168
+ 'default' => '',
169
+ 'sanitize' => 'FILTER_DEFAULT',
170
+ ),
171
+ 'wcf-box-border-color' => array(
172
+ 'default' => '',
173
+ 'sanitize' => 'FILTER_DEFAULT',
174
+ ),
175
+ 'wcf-field-label-color' => array(
176
+ 'default' => '',
177
+ 'sanitize' => 'FILTER_DEFAULT',
178
+ ),
179
+ 'wcf-submit-tb-padding' => array(
180
+ 'default' => '',
181
+ 'sanitize' => 'FILTER_DEFAULT',
182
+ ),
183
+ 'wcf-submit-lr-padding' => array(
184
+ 'default' => '',
185
+ 'sanitize' => 'FILTER_DEFAULT',
186
+ ),
187
+ 'wcf-input-button-size' => array(
188
+ 'default' => '33px',
189
+ 'sanitize' => 'FILTER_DEFAULT',
190
+ ),
191
+ 'wcf-submit-color' => array(
192
+ 'default' => '',
193
+ 'sanitize' => 'FILTER_DEFAULT',
194
+ ),
195
+ 'wcf-submit-hover-color' => array(
196
+ 'default' => '',
197
+ 'sanitize' => 'FILTER_DEFAULT',
198
+ ),
199
+ 'wcf-submit-bg-color' => array(
200
+ 'default' => '',
201
+ 'sanitize' => 'FILTER_DEFAULT',
202
+ ),
203
+ 'wcf-submit-bg-hover-color' => array(
204
+ 'default' => '',
205
+ 'sanitize' => 'FILTER_DEFAULT',
206
+ ),
207
+ 'wcf-submit-border-color' => array(
208
+ 'default' => '',
209
+ 'sanitize' => 'FILTER_DEFAULT',
210
+ ),
211
+ 'wcf-submit-border-hover-color' => array(
212
+ 'default' => '',
213
+ 'sanitize' => 'FILTER_DEFAULT',
214
+ ),
215
+ 'wcf-active-tab' => array(
216
+ 'default' => '',
217
+ 'sanitize' => 'FILTER_DEFAULT',
218
+ ),
219
+ 'wcf-header-logo-image' => array(
220
+ 'default' => '',
221
+ 'sanitize' => 'FILTER_DEFAULT',
222
+ ),
223
+ 'wcf-header-logo-width' => array(
224
+ 'default' => '',
225
+ 'sanitize' => 'FILTER_DEFAULT',
226
+ ),
227
+ 'wcf-custom-script' => array(
228
+ 'default' => '',
229
+ 'sanitize' => 'FILTER_DEFAULT',
230
+ ),
231
+ );
232
+
233
+ self::$checkout_fields = apply_filters( 'cartflows_checkout_meta_options', self::$checkout_fields, $post_id );
234
+ }
235
+
236
+ return self::$checkout_fields;
237
+ }
238
+
239
+ /**
240
+ * Save Checkout Meta fields.
241
+ *
242
+ * @param int $post_id post id.
243
+ * @return void
244
+ */
245
+ function save_checkout_fields( $post_id ) {
246
+
247
+ $post_meta = $this->get_checkout_fields( $post_id );
248
+
249
+ $this->save_meta_fields( $post_id, $post_meta );
250
+ }
251
+
252
+ /**
253
+ * Save Landing Meta fields.
254
+ *
255
+ * @param int $post_id post id.
256
+ * @return void
257
+ */
258
+ function save_landing_fields( $post_id ) {
259
+
260
+ $post_meta = $this->get_landing_fields( $post_id );
261
+
262
+ $this->save_meta_fields( $post_id, $post_meta );
263
+ }
264
+
265
+ /**
266
+ * Save ThankYou Meta fields.
267
+ *
268
+ * @param int $post_id post id.
269
+ * @return void
270
+ */
271
+ function save_thankyou_fields( $post_id ) {
272
+
273
+ $post_meta = $this->get_thankyou_fields( $post_id );
274
+
275
+ $this->save_meta_fields( $post_id, $post_meta );
276
+ }
277
+
278
+ /**
279
+ * Flow Default fields.
280
+ *
281
+ * @param int $post_id post id.
282
+ * @return array
283
+ */
284
+ function get_flow_fields( $post_id ) {
285
+
286
+ if ( null === self::$flow_fields ) {
287
+
288
+ self::$flow_fields = array(
289
+ 'wcf-steps' => array(
290
+ 'default' => array(),
291
+ 'sanitize' => 'FILTER_DEFAULT',
292
+ ),
293
+
294
+ 'wcf-testing' => array(
295
+ 'default' => 'yes',
296
+ 'sanitize' => 'FILTER_DEFAULT',
297
+ ),
298
+ );
299
+ }
300
+
301
+ return apply_filters( 'cartflows_flow_meta_options', self::$flow_fields );
302
+ }
303
+
304
+ /**
305
+ * Save Flow Meta fields.
306
+ *
307
+ * @param int $post_id post id.
308
+ * @return void
309
+ */
310
+ function save_flow_fields( $post_id ) {
311
+
312
+ $post_meta = $this->get_flow_fields( $post_id );
313
+
314
+ if ( isset( $post_meta['wcf-steps'] ) ) {
315
+ unset( $post_meta['wcf-steps'] );
316
+ }
317
+
318
+ $this->save_meta_fields( $post_id, $post_meta );
319
+ }
320
+
321
+ /**
322
+ * Save Meta fields - Common Function.
323
+ *
324
+ * @param int $post_id post id.
325
+ * @param array $post_meta options to store.
326
+ * @return void
327
+ */
328
+ function save_meta_fields( $post_id, $post_meta ) {
329
+
330
+ if ( ! ( $post_id && is_array( $post_meta ) ) ) {
331
+
332
+ return;
333
+ }
334
+
335
+ foreach ( $post_meta as $key => $data ) {
336
+
337
+ $meta_value = false;
338
+
339
+ // Sanitize values.
340
+ $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
341
+
342
+ switch ( $sanitize_filter ) {
343
+
344
+ case 'FILTER_SANITIZE_STRING':
345
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
346
+ break;
347
+
348
+ case 'FILTER_SANITIZE_URL':
349
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
350
+ break;
351
+
352
+ case 'FILTER_SANITIZE_NUMBER_INT':
353
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
354
+ break;
355
+
356
+ case 'FILTER_CARTFLOWS_ARRAY':
357
+ if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
358
+ $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
359
+ }
360
+ break;
361
+
362
+ case 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS':
363
+ if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
364
+
365
+ $i = 0;
366
+ $q = 0;
367
+
368
+ foreach ( $_POST[ $key ] as $p_index => $p_data ) {
369
+
370
+ foreach ( $p_data as $i_key => $i_value ) {
371
+
372
+ if ( is_array( $i_value ) ) {
373
+
374
+ foreach ( $i_value as $q_key => $q_value ) {
375
+
376
+ $meta_value[ $i ][ $i_key ][ $q ] = array_map( 'sanitize_text_field', $q_value );
377
+
378
+ $q++;
379
+ }
380
+ } else {
381
+ $meta_value[ $i ][ $i_key ] = sanitize_text_field( $i_value );
382
+ }
383
+ }
384
+
385
+ $i++;
386
+ }
387
+ }
388
+ break;
389
+ case 'FILTER_CARTFLOWS_CHECKOUT_FIELDS':
390
+ $count = 10;
391
+ $ordered_fields = array();
392
+ $billing_fields = array();
393
+
394
+ if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
395
+ $post_data = $_POST[ $key ];
396
+
397
+ if ( 'wcf_field_order_billing' == $key ) {
398
+
399
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
400
+
401
+ foreach ( $post_data as $index => $value ) {
402
+
403
+ if ( isset( $billing_fields[ $value ] ) ) {
404
+ $ordered_fields[ $value ] = $billing_fields[ $value ];
405
+ $ordered_fields[ $value ]['priority'] = $count;
406
+ $count += 10;
407
+ }
408
+ }
409
+
410
+ $meta_value = $ordered_fields;
411
+ }
412
+
413
+ if ( 'wcf_field_order_shipping' == $key ) {
414
+
415
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
416
+ foreach ( $post_data as $index => $value ) {
417
+
418
+ if ( isset( $shipping_fields[ $value ] ) ) {
419
+ $ordered_fields[ $value ] = $shipping_fields[ $value ];
420
+ $ordered_fields[ $value ]['priority'] = $count;
421
+ $count += 10;
422
+ }
423
+ }
424
+ $meta_value = $ordered_fields;
425
+ }
426
+
427
+ if ( 'wcf_label_text_field_billing' == $key ) {
428
+
429
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
430
+
431
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
432
+ echo 'con 1';
433
+ $billing_fields = $get_ordered_billing_fields;
434
+ } else {
435
+ echo 'con 2';
436
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
437
+ }
438
+
439
+ foreach ( $post_data as $index => $value ) {
440
+
441
+ if ( isset( $billing_fields[ $index ] ) ) {
442
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
443
+ $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
444
+ }
445
+ }
446
+ $key = 'wcf_field_order_billing';
447
+ $meta_value = $ordered_fields;
448
+ }
449
+
450
+ if ( 'wcf_label_text_field_shipping' == $key ) {
451
+
452
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
453
+
454
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
455
+ $shipping_fields = $get_ordered_shipping_fields;
456
+ } else {
457
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
458
+ }
459
+
460
+ foreach ( $post_data as $index => $value ) {
461
+
462
+ if ( isset( $shipping_fields[ $index ] ) ) {
463
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
464
+ $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
465
+ }
466
+ }
467
+ $key = 'wcf_field_order_shipping';
468
+ $meta_value = $ordered_fields;
469
+ }
470
+
471
+ if ( 'wcf_label_placeholder_field_billing' == $key ) {
472
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
473
+
474
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
475
+ $billing_fields = $get_ordered_billing_fields;
476
+ } else {
477
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
478
+ }
479
+ foreach ( $post_data as $index => $value ) {
480
+
481
+ if ( isset( $billing_fields[ $index ] ) ) {
482
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
483
+ $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
484
+ }
485
+ }
486
+
487
+ $key = 'wcf_field_order_billing';
488
+ $meta_value = $ordered_fields;
489
+ }
490
+
491
+ if ( 'wcf_label_placeholder_field_shipping' == $key ) {
492
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
493
+
494
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
495
+ $shipping_fields = $get_ordered_shipping_fields;
496
+ } else {
497
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
498
+ }
499
+
500
+ foreach ( $post_data as $index => $value ) {
501
+
502
+ if ( isset( $shipping_fields[ $index ] ) ) {
503
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
504
+ $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
505
+ }
506
+ }
507
+
508
+ $key = 'wcf_field_order_shipping';
509
+ $meta_value = $ordered_fields;
510
+
511
+ }
512
+
513
+ if ( 'wcf_label_default_field_billing' == $key ) {
514
+
515
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
516
+
517
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
518
+ $billing_fields = $get_ordered_billing_fields;
519
+ } else {
520
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
521
+ }
522
+
523
+ foreach ( $post_data as $index => $value ) {
524
+
525
+ if ( isset( $billing_fields[ $index ] ) ) {
526
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
527
+ $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
528
+ }
529
+ }
530
+
531
+ $key = 'wcf_field_order_billing';
532
+ $meta_value = $ordered_fields;
533
+ }
534
+
535
+ if ( 'wcf_label_default_field_shipping' == $key ) {
536
+
537
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
538
+
539
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
540
+ $shipping_fields = $get_ordered_shipping_fields;
541
+ } else {
542
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
543
+ }
544
+
545
+ foreach ( $post_data as $index => $value ) {
546
+
547
+ if ( isset( $shipping_fields[ $index ] ) ) {
548
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
549
+ $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
550
+ }
551
+ }
552
+
553
+ $key = 'wcf_field_order_shipping';
554
+ $meta_value = $ordered_fields;
555
+ }
556
+
557
+ if ( 'wcf_is_required_field_billing' == $key ) {
558
+
559
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
560
+
561
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
562
+ $billing_fields = $get_ordered_billing_fields;
563
+ } else {
564
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
565
+ }
566
+
567
+ foreach ( $post_data as $index => $value ) {
568
+
569
+ if ( isset( $billing_fields[ $index ] ) ) {
570
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
571
+ if ( 'yes' == $value ) {
572
+
573
+ $ordered_fields[ $index ]['required'] = true;
574
+ } else {
575
+ $ordered_fields[ $index ]['required'] = false;
576
+ }
577
+ }
578
+ }
579
+
580
+ $key = 'wcf_field_order_billing';
581
+ $meta_value = $ordered_fields;
582
+ }
583
+
584
+ if ( 'wcf_is_required_field_shipping' == $key ) {
585
+
586
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
587
+
588
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
589
+ $shipping_fields = $get_ordered_shipping_fields;
590
+ } else {
591
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
592
+ }
593
+
594
+ foreach ( $post_data as $index => $value ) {
595
+
596
+ if ( isset( $shipping_fields[ $index ] ) ) {
597
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
598
+
599
+ if ( 'yes' == $value ) {
600
+
601
+ $ordered_fields[ $index ]['required'] = true;
602
+ } else {
603
+ $ordered_fields[ $index ]['required'] = false;
604
+ }
605
+ }
606
+ }
607
+
608
+ $key = 'wcf_field_order_shipping';
609
+ $meta_value = $ordered_fields;
610
+ }
611
+
612
+ if ( 'wcf_select_option_field_billing' == $key ) {
613
+
614
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
615
+
616
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
617
+ $billing_fields = $get_ordered_billing_fields;
618
+ } else {
619
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
620
+ }
621
+
622
+ foreach ( $post_data as $index => $value ) {
623
+
624
+ $options = explode( ',', $value );
625
+
626
+ if ( isset( $billing_fields[ $index ] ) ) {
627
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
628
+
629
+ $ordered_fields[ $index ]['options'] = array();
630
+
631
+ foreach ( $options as $key => $option ) {
632
+
633
+ $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
634
+ }
635
+ }
636
+ }
637
+
638
+ $key = 'wcf_field_order_billing';
639
+ $meta_value = $ordered_fields;
640
+ }
641
+
642
+ if ( 'wcf_select_option_field_shipping' == $key ) {
643
+
644
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
645
+
646
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
647
+ $shipping_fields = $get_ordered_shipping_fields;
648
+ } else {
649
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
650
+ }
651
+
652
+ foreach ( $post_data as $index => $value ) {
653
+
654
+ $options = explode( ',', $value );
655
+
656
+ if ( isset( $shipping_fields[ $index ] ) ) {
657
+
658
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
659
+
660
+ $ordered_fields[ $index ]['options'] = array();
661
+
662
+ foreach ( $options as $key => $option ) {
663
+
664
+ $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
665
+ }
666
+ }
667
+ }
668
+
669
+ $key = 'wcf_field_order_shipping';
670
+ $meta_value = $ordered_fields;
671
+ }
672
+ }
673
+ break;
674
+
675
+ default:
676
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
677
+ break;
678
+ }
679
+
680
+ if ( false !== $meta_value ) {
681
+ update_post_meta( $post_id, $key, $meta_value );
682
+ } else {
683
+ delete_post_meta( $post_id, $key );
684
+ }
685
+ }
686
+ }
687
+
688
+ /**
689
+ * Get checkout meta.
690
+ *
691
+ * @param int $post_id post id.
692
+ * @param string $key options key.
693
+ * @param mix $default options default value.
694
+ * @return string
695
+ */
696
+ function get_flow_meta_value( $post_id, $key, $default = false ) {
697
+
698
+ $value = $this->get_save_meta( $post_id, $key );
699
+
700
+ if ( ! $value ) {
701
+
702
+ if ( $default ) {
703
+
704
+ $value = $default;
705
+ } else {
706
+
707
+ $fields = $this->get_flow_fields( $post_id );
708
+
709
+ if ( isset( $fields[ $key ]['default'] ) ) {
710
+
711
+ $value = $fields[ $key ]['default'];
712
+ }
713
+ }
714
+ }
715
+
716
+ return $value;
717
+ }
718
+
719
+ /**
720
+ * Get checkout meta.
721
+ *
722
+ * @param int $post_id post id.
723
+ * @param string $key options key.
724
+ * @param mix $default options default value.
725
+ * @return string
726
+ */
727
+ function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) {
728
+
729
+ $value = $this->get_save_meta( $post_id, $key );
730
+
731
+ if ( ! $value ) {
732
+
733
+ if ( false !== $default ) {
734
+
735
+ $value = $default;
736
+ } else {
737
+
738
+ $fields = $this->get_checkout_fields( $post_id );
739
+
740
+ if ( isset( $fields[ $key ]['default'] ) ) {
741
+
742
+ $value = $fields[ $key ]['default'];
743
+ }
744
+ }
745
+ }
746
+
747
+ return $value;
748
+ }
749
+
750
+ /**
751
+ * Get post meta.
752
+ *
753
+ * @param int $post_id post id.
754
+ * @param string $key options key.
755
+ * @return string
756
+ */
757
+ function get_save_meta( $post_id, $key ) {
758
+
759
+ $value = get_post_meta( $post_id, $key, true );
760
+
761
+ return $value;
762
+ }
763
+
764
+ /**
765
+ * Thank You Default fields.
766
+ *
767
+ * @param int $post_id post id.
768
+ * @return array
769
+ */
770
+ function get_thankyou_fields( $post_id ) {
771
+
772
+ if ( null === self::$thankyou_fields ) {
773
+
774
+ self::$thankyou_fields = array(
775
+ 'wcf-field-google-font-url' => array(
776
+ 'default' => '',
777
+ 'sanitize' => 'FILTER_DEFAULT',
778
+ ),
779
+ 'wcf-active-tab' => array(
780
+ 'default' => '',
781
+ 'sanitize' => 'FILTER_DEFAULT',
782
+ ),
783
+ 'wcf-tq-text-color' => array(
784
+ 'default' => '',
785
+ 'sanitize' => 'FILTER_DEFAULT',
786
+ ),
787
+ 'wcf-tq-font-family' => array(
788
+ 'default' => '',
789
+ 'sanitize' => 'FILTER_DEFAULT',
790
+ ),
791
+ 'wcf-tq-heading-color' => array(
792
+ 'default' => '',
793
+ 'sanitize' => 'FILTER_DEFAULT',
794
+ ),
795
+ 'wcf-tq-heading-font-family' => array(
796
+ 'default' => '',
797
+ 'sanitize' => 'FILTER_DEFAULT',
798
+ ),
799
+ 'wcf-tq-heading-font-wt' => array(
800
+ 'default' => '',
801
+ 'sanitize' => 'FILTER_DEFAULT',
802
+ ),
803
+ 'wcf-tq-container-width' => array(
804
+ 'default' => '',
805
+ 'sanitize' => 'FILTER_DEFAULT',
806
+ ),
807
+ 'wcf-tq-section-bg-color' => array(
808
+ 'default' => '',
809
+ 'sanitize' => 'FILTER_DEFAULT',
810
+ ),
811
+ 'wcf-tq-advance-options-fields' => array(
812
+ 'default' => '',
813
+ 'sanitize' => 'FILTER_DEFAULT',
814
+ ),
815
+ 'wcf-show-overview-section' => array(
816
+ 'default' => 'yes',
817
+ 'sanitize' => 'FILTER_DEFAULT',
818
+ ),
819
+ 'wcf-show-details-section' => array(
820
+ 'default' => 'yes',
821
+ 'sanitize' => 'FILTER_DEFAULT',
822
+ ),
823
+ 'wcf-show-billing-section' => array(
824
+ 'default' => 'yes',
825
+ 'sanitize' => 'FILTER_DEFAULT',
826
+ ),
827
+ 'wcf-show-shipping-section' => array(
828
+ 'default' => 'yes',
829
+ 'sanitize' => 'FILTER_DEFAULT',
830
+ ),
831
+ 'wcf-custom-script' => array(
832
+ 'default' => '',
833
+ 'sanitize' => 'FILTER_DEFAULT',
834
+ ),
835
+ );
836
+
837
+ }
838
+
839
+ return apply_filters( 'cartflows_thankyou_meta_options', self::$thankyou_fields, $post_id );
840
+ }
841
+
842
+ /**
843
+ * Get Thank you section meta.
844
+ *
845
+ * @param int $post_id post id.
846
+ * @param string $key options key.
847
+ * @param mix $default options default value.
848
+ * @return string
849
+ */
850
+ function get_thankyou_meta_value( $post_id, $key, $default = false ) {
851
+
852
+ $value = $this->get_save_meta( $post_id, $key );
853
+
854
+ if ( ! $value ) {
855
+
856
+ if ( $default ) {
857
+
858
+ $value = $default;
859
+ } else {
860
+
861
+ $fields = $this->get_thankyou_fields( $post_id );
862
+
863
+ if ( isset( $fields[ $key ]['default'] ) ) {
864
+
865
+ $value = $fields[ $key ]['default'];
866
+ }
867
+ }
868
+ }
869
+
870
+ return $value;
871
+ }
872
+
873
+ /**
874
+ * Get Landing section meta.
875
+ *
876
+ * @param int $post_id post id.
877
+ * @param string $key options key.
878
+ * @param mix $default options default value.
879
+ * @return string
880
+ */
881
+ function get_landing_meta_value( $post_id, $key, $default = false ) {
882
+
883
+ $value = $this->get_save_meta( $post_id, $key );
884
+ if ( ! $value ) {
885
+
886
+ if ( $default ) {
887
+
888
+ $value = $default;
889
+ } else {
890
+
891
+ $fields = $this->get_landing_fields( $post_id );
892
+
893
+ if ( isset( $fields[ $key ]['default'] ) ) {
894
+ $value = $fields[ $key ]['default'];
895
+ }
896
+ }
897
+ }
898
+
899
+ return $value;
900
+ }
901
+
902
+ /**
903
+ * Thank You Default fields.
904
+ *
905
+ * @param int $post_id post id.
906
+ * @return array
907
+ */
908
+ function get_landing_fields( $post_id ) {
909
+
910
+ if ( null === self::$landing_fields ) {
911
+
912
+ self::$landing_fields = array(
913
+ 'wcf-custom-script' => array(
914
+ 'default' => '',
915
+ 'sanitize' => 'FILTER_DEFAULT',
916
+ ),
917
+ );
918
+ }
919
+ return apply_filters( 'cartflows_landing_meta_options', self::$landing_fields, $post_id );
920
+ }
921
+ }
922
+
923
+ /**
924
+ * Kicking this off by calling 'get_instance()' method
925
+ */
926
+ Cartflows_Default_Meta::get_instance();
classes/class-cartflows-divi-compatibility.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
- /**
3
- * Divi page builder compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Class for divi page builder compatibility
10
- */
11
- class Cartflows_Divi_Compatibility {
12
-
13
- /**
14
- * Member Variable
15
- *
16
- * @var instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Initiator
22
- */
23
- public static function get_instance() {
24
- if ( ! isset( self::$instance ) ) {
25
- self::$instance = new self;
26
- }
27
- return self::$instance;
28
- }
29
-
30
- /**
31
- * Constructor
32
- */
33
- public function __construct() {
34
-
35
- add_filter( 'cartflows_container_atts', array( $this, 'add_id_for_cartflows_container' ) );
36
- }
37
-
38
- /**
39
- * Add id attribute to cartflows container which is needed to apply style to divi elements.
40
- *
41
- * @param array $atts container HTML attributes.
42
- * @return array
43
- */
44
- public function add_id_for_cartflows_container( $atts ) {
45
-
46
- $atts['id'] = 'page-container';
47
-
48
- return $atts;
49
- }
50
- }
51
-
52
- /**
53
- * Kicking this off by calling 'get_instance()' method
54
- */
55
- Cartflows_Divi_Compatibility::get_instance();
1
+ <?php
2
+ /**
3
+ * Divi page builder compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Class for divi page builder compatibility
10
+ */
11
+ class Cartflows_Divi_Compatibility {
12
+
13
+ /**
14
+ * Member Variable
15
+ *
16
+ * @var instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Initiator
22
+ */
23
+ public static function get_instance() {
24
+ if ( ! isset( self::$instance ) ) {
25
+ self::$instance = new self;
26
+ }
27
+ return self::$instance;
28
+ }
29
+
30
+ /**
31
+ * Constructor
32
+ */
33
+ public function __construct() {
34
+
35
+ add_filter( 'cartflows_container_atts', array( $this, 'add_id_for_cartflows_container' ) );
36
+ }
37
+
38
+ /**
39
+ * Add id attribute to cartflows container which is needed to apply style to divi elements.
40
+ *
41
+ * @param array $atts container HTML attributes.
42
+ * @return array
43
+ */
44
+ public function add_id_for_cartflows_container( $atts ) {
45
+
46
+ $atts['id'] = 'page-container';
47
+
48
+ return $atts;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Kicking this off by calling 'get_instance()' method
54
+ */
55
+ Cartflows_Divi_Compatibility::get_instance();
classes/class-cartflows-flow-frontend.php CHANGED
@@ -1,199 +1,199 @@
1
- <?php
2
- /**
3
- * Frontend & Markup
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Flow Markup
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Flow_Frontend {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var object instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Initiator
25
- */
26
- public static function get_instance() {
27
- if ( ! isset( self::$instance ) ) {
28
- self::$instance = new self;
29
- }
30
- return self::$instance;
31
- }
32
-
33
- /**
34
- * Constructor
35
- */
36
- public function __construct() {
37
-
38
- /* Analytics */
39
- add_action( 'cartflows_wp_footer', array( $this, 'footer_markup' ) );
40
- }
41
-
42
- /**
43
- * Footer markup
44
- */
45
- function footer_markup() {
46
-
47
- if ( wcf()->utils->is_step_post_type() ) {
48
- // @codingStandardsIgnoreStart
49
- ?>
50
- <?php if( $this->is_flow_testmode() ) { ?>
51
- <div class="wcf-preview-mode">
52
- <span><?php _e( 'Test mode is active — which displays random products for previewing. It can be deactivated from the flow settings in the admin dashboard.', 'cartflows' ); ?></span>
53
- </div>
54
- <?php } ?>
55
- <?php
56
- // @codingStandardsIgnoreEnd
57
- }
58
- }
59
-
60
- /**
61
- * Check if flow test mode is enable.
62
- *
63
- * @since 1.0.0
64
- * @param int $flow_id flow ID.
65
- *
66
- * @return boolean
67
- */
68
- function is_flow_testmode( $flow_id = '' ) {
69
-
70
- if ( ! $flow_id ) {
71
- $flow_id = wcf()->utils->get_flow_id();
72
- }
73
-
74
- $test_mode = wcf()->options->get_flow_meta_value( $flow_id, 'wcf-testing' );
75
-
76
- if ( 'no' === $test_mode ) {
77
- return false;
78
- }
79
-
80
- return true;
81
- }
82
-
83
- /**
84
- * Get steps data.
85
- *
86
- * @since 1.0.0
87
- * @param int $flow_id flow ID.
88
- *
89
- * @return array
90
- */
91
- function get_steps( $flow_id ) {
92
-
93
- $steps = get_post_meta( $flow_id, 'wcf-steps', true );
94
-
95
- if ( ! is_array( $steps ) ) {
96
-
97
- $steps = array();
98
- }
99
-
100
- return $steps;
101
- }
102
-
103
- /**
104
- * Check thank you page exists.
105
- *
106
- * @since 1.0.0
107
- * @param array $order order data.
108
- *
109
- * @return bool
110
- */
111
- function is_thankyou_page_exists( $order ) {
112
-
113
- $thankyou_step_exist = false;
114
-
115
- $flow_id = wcf()->utils->get_flow_id_from_order( $order->get_id() );
116
-
117
- if ( $flow_id ) {
118
-
119
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
120
- $step_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
121
-
122
- if ( is_array( $flow_steps ) ) {
123
-
124
- $current_step_found = false;
125
-
126
- foreach ( $flow_steps as $index => $data ) {
127
-
128
- if ( $current_step_found ) {
129
-
130
- if ( 'thankyou' === $data['type'] ) {
131
-
132
- $thankyou_step_exist = true;
133
- break;
134
- }
135
- } else {
136
-
137
- if ( intval( $data['id'] ) === $step_id ) {
138
-
139
- $current_step_found = true;
140
- }
141
- }
142
- }
143
- }
144
- }
145
-
146
- return $thankyou_step_exist;
147
- }
148
-
149
- /**
150
- * Check thank you page exists.
151
- *
152
- * @since 1.0.0
153
- * @param array $order order data.
154
- *
155
- * @return bool
156
- */
157
- function get_thankyou_page_id( $order ) {
158
-
159
- $thankyou_step_id = false;
160
-
161
- $flow_id = wcf()->utils->get_flow_id_from_order( $order->get_id() );
162
-
163
- if ( $flow_id ) {
164
-
165
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
166
- $step_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
167
-
168
- if ( is_array( $flow_steps ) ) {
169
-
170
- $current_step_found = false;
171
-
172
- foreach ( $flow_steps as $index => $data ) {
173
-
174
- if ( $current_step_found ) {
175
-
176
- if ( 'thankyou' === $data['type'] ) {
177
-
178
- $thankyou_step_id = intval( $data['id'] );
179
- break;
180
- }
181
- } else {
182
-
183
- if ( intval( $data['id'] ) === $step_id ) {
184
-
185
- $current_step_found = true;
186
- }
187
- }
188
- }
189
- }
190
- }
191
-
192
- return $thankyou_step_id;
193
- }
194
- }
195
-
196
- /**
197
- * Kicking this off by calling 'get_instance()' method
198
- */
199
- Cartflows_Flow_Frontend::get_instance();
1
+ <?php
2
+ /**
3
+ * Frontend & Markup
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Flow Markup
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Flow_Frontend {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var object instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Initiator
25
+ */
26
+ public static function get_instance() {
27
+ if ( ! isset( self::$instance ) ) {
28
+ self::$instance = new self;
29
+ }
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Constructor
35
+ */
36
+ public function __construct() {
37
+
38
+ /* Analytics */
39
+ add_action( 'cartflows_wp_footer', array( $this, 'footer_markup' ) );
40
+ }
41
+
42
+ /**
43
+ * Footer markup
44
+ */
45
+ function footer_markup() {
46
+
47
+ if ( wcf()->utils->is_step_post_type() ) {
48
+ // @codingStandardsIgnoreStart
49
+ ?>
50
+ <?php if( $this->is_flow_testmode() ) { ?>
51
+ <div class="wcf-preview-mode">
52
+ <span><?php _e( 'Test mode is active — which displays random products for previewing. It can be deactivated from the flow settings in the admin dashboard.', 'cartflows' ); ?></span>
53
+ </div>
54
+ <?php } ?>
55
+ <?php
56
+ // @codingStandardsIgnoreEnd
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Check if flow test mode is enable.
62
+ *
63
+ * @since 1.0.0
64
+ * @param int $flow_id flow ID.
65
+ *
66
+ * @return boolean
67
+ */
68
+ function is_flow_testmode( $flow_id = '' ) {
69
+
70
+ if ( ! $flow_id ) {
71
+ $flow_id = wcf()->utils->get_flow_id();
72
+ }
73
+
74
+ $test_mode = wcf()->options->get_flow_meta_value( $flow_id, 'wcf-testing' );
75
+
76
+ if ( 'no' === $test_mode ) {
77
+ return false;
78
+ }
79
+
80
+ return true;
81
+ }
82
+
83
+ /**
84
+ * Get steps data.
85
+ *
86
+ * @since 1.0.0
87
+ * @param int $flow_id flow ID.
88
+ *
89
+ * @return array
90
+ */
91
+ function get_steps( $flow_id ) {
92
+
93
+ $steps = get_post_meta( $flow_id, 'wcf-steps', true );
94
+
95
+ if ( ! is_array( $steps ) ) {
96
+
97
+ $steps = array();
98
+ }
99
+
100
+ return $steps;
101
+ }
102
+
103
+ /**
104
+ * Check thank you page exists.
105
+ *
106
+ * @since 1.0.0
107
+ * @param array $order order data.
108
+ *
109
+ * @return bool
110
+ */
111
+ function is_thankyou_page_exists( $order ) {
112
+
113
+ $thankyou_step_exist = false;
114
+
115
+ $flow_id = wcf()->utils->get_flow_id_from_order( $order->get_id() );
116
+
117
+ if ( $flow_id ) {
118
+
119
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
120
+ $step_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
121
+
122
+ if ( is_array( $flow_steps ) ) {
123
+
124
+ $current_step_found = false;
125
+
126
+ foreach ( $flow_steps as $index => $data ) {
127
+
128
+ if ( $current_step_found ) {
129
+
130
+ if ( 'thankyou' === $data['type'] ) {
131
+
132
+ $thankyou_step_exist = true;
133
+ break;
134
+ }
135
+ } else {
136
+
137
+ if ( intval( $data['id'] ) === $step_id ) {
138
+
139
+ $current_step_found = true;
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ return $thankyou_step_exist;
147
+ }
148
+
149
+ /**
150
+ * Check thank you page exists.
151
+ *
152
+ * @since 1.0.0
153
+ * @param array $order order data.
154
+ *
155
+ * @return bool
156
+ */
157
+ function get_thankyou_page_id( $order ) {
158
+
159
+ $thankyou_step_id = false;
160
+
161
+ $flow_id = wcf()->utils->get_flow_id_from_order( $order->get_id() );
162
+
163
+ if ( $flow_id ) {
164
+
165
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
166
+ $step_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
167
+
168
+ if ( is_array( $flow_steps ) ) {
169
+
170
+ $current_step_found = false;
171
+
172
+ foreach ( $flow_steps as $index => $data ) {
173
+
174
+ if ( $current_step_found ) {
175
+
176
+ if ( 'thankyou' === $data['type'] ) {
177
+
178
+ $thankyou_step_id = intval( $data['id'] );
179
+ break;
180
+ }
181
+ } else {
182
+
183
+ if ( intval( $data['id'] ) === $step_id ) {
184
+
185
+ $current_step_found = true;
186
+ }
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ return $thankyou_step_id;
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Kicking this off by calling 'get_instance()' method
198
+ */
199
+ Cartflows_Flow_Frontend::get_instance();
classes/class-cartflows-frontend.php CHANGED
@@ -1,439 +1,439 @@
1
- <?php
2
- /**
3
- * CartFlows Frontend.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Class Cartflows_Frontend.
10
- */
11
- class Cartflows_Frontend {
12
-
13
- /**
14
- * Member Variable
15
- *
16
- * @var instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Initiator
22
- */
23
- public static function get_instance() {
24
- if ( ! isset( self::$instance ) ) {
25
- self::$instance = new self;
26
- }
27
- return self::$instance;
28
- }
29
-
30
- /**
31
- * Constructor
32
- */
33
- public function __construct() {
34
-
35
- /* Set / Destroy Flow Sessions. Set data */
36
- add_action( 'wp', array( $this, 'init_actions' ), 1 );
37
-
38
- /* Enqueue global required scripts */
39
- add_action( 'wp', array( $this, 'wp_actions' ), 55 );
40
-
41
- /* Modify the checkout order received url to go thank you page in our flow */
42
- add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
43
-
44
- }
45
-
46
- /**
47
- * Redirect to thank page if upsell not exists
48
- *
49
- * @param string $order_recieve_url url.
50
- * @param object $order order object.
51
- * @since 1.0.0
52
- */
53
- function redirect_to_thankyou_page( $order_recieve_url, $order ) {
54
-
55
- /* Only for thank you page */
56
- wcf()->logger->log( 'Start-' . __CLASS__ . '::' . __FUNCTION__ );
57
- wcf()->logger->log( 'Only for thank you page' );
58
-
59
- if ( wcf()->flow->is_thankyou_page_exists( $order ) ) {
60
-
61
- if ( _is_wcf_doing_checkout_ajax() ) {
62
-
63
- $checkout_id = wcf()->utils->get_checkout_id_from_post_data();
64
-
65
- if ( ! $checkout_id ) {
66
- $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
67
- }
68
- } else {
69
- $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
70
- }
71
-
72
- wcf()->logger->log( 'Checkout ID : ' . $checkout_id );
73
-
74
- if ( $checkout_id ) {
75
-
76
- $thankyou_step_id = wcf()->flow->get_thankyou_page_id( $order );
77
-
78
- if ( $thankyou_step_id ) {
79
-
80
- $order_recieve_url = get_permalink( $thankyou_step_id );
81
-
82
- $order_recieve_url = add_query_arg(
83
- array(
84
- 'wcf-order' => $order->get_id(),
85
- 'wcf-key' => $order->get_order_key(),
86
- ),
87
- $order_recieve_url
88
- );
89
- }
90
- }
91
- }
92
-
93
- wcf()->logger->log( 'End-' . __CLASS__ . '::' . __FUNCTION__ );
94
-
95
- return $order_recieve_url;
96
- }
97
-
98
- /**
99
- * Cancel and redirect to checkout
100
- *
101
- * @param string $return_url url.
102
- * @since 1.0.0
103
- */
104
- function redirect_to_checkout_on_cancel( $return_url ) {
105
-
106
- if ( _is_wcf_doing_checkout_ajax() ) {
107
-
108
- $checkout_id = wcf()->utils->get_checkout_id_from_post_data();
109
-
110
- if ( ! $checkout_id ) {
111
- $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
112
- }
113
- } else {
114
- $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
115
- }
116
-
117
- if ( $checkout_id ) {
118
-
119
- $return_url = add_query_arg(
120
- array(
121
- 'cancel_order' => 'true',
122
- '_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ),
123
- ),
124
- get_permalink( $checkout_id )
125
- );
126
- }
127
-
128
- return $return_url;
129
- }
130
-
131
-
132
- /**
133
- * Remove theme styles.
134
- *
135
- * @since 1.0.0
136
- */
137
- function remove_theme_styles() {
138
-
139
- if ( Cartflows_Compatibility::get_instance()->is_compatibility_theme_enabled() ) {
140
- return;
141
- }
142
-
143
- // get all styles data.
144
- global $wp_styles;
145
- global $wp_scripts;
146
-
147
- $get_stylesheet = 'themes/' . get_stylesheet() . '/';
148
- $get_template = 'themes/' . get_template() . '/';
149
-
150
- $remove_styles = apply_filters( 'cartflows_remove_theme_styles', true );
151
-
152
- if ( $remove_styles ) {
153
-
154
- // loop over all of the registered scripts..
155
- foreach ( $wp_styles->registered as $handle => $data ) {
156
-
157
- if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
158
-
159
- // remove it.
160
- wp_deregister_style( $handle );
161
- wp_dequeue_style( $handle );
162
- }
163
- }
164
- }
165
-
166
- $remove_scripts = apply_filters( 'cartflows_remove_theme_scripts', true );
167
-
168
- if ( $remove_scripts ) {
169
-
170
- // loop over all of the registered scripts.
171
- foreach ( $wp_scripts->registered as $handle => $data ) {
172
-
173
- if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
174
-
175
- // remove it.
176
- wp_deregister_script( $handle );
177
- wp_dequeue_script( $handle );
178
- }
179
- }
180
- }
181
-
182
- }
183
-
184
- /**
185
- * Update main order data in transient.
186
- *
187
- * @param array $woo_styles new styles array.
188
- * @since 1.0.0
189
- * @return array.
190
- */
191
- function woo_default_css( $woo_styles ) {
192
-
193
- $woo_styles = array(
194
- 'woocommerce-layout' => array(
195
- 'src' => plugins_url( 'assets/css/woocommerce-layout.css', WC_PLUGIN_FILE ),
196
- 'deps' => '',
197
- 'version' => WC_VERSION,
198
- 'media' => 'all',
199
- 'has_rtl' => true,
200
- ),
201
- 'woocommerce-smallscreen' => array(
202
- 'src' => plugins_url( 'assets/css/woocommerce-smallscreen.css', WC_PLUGIN_FILE ),
203
- 'deps' => 'woocommerce-layout',
204
- 'version' => WC_VERSION,
205
- 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
206
- 'has_rtl' => true,
207
- ),
208
- 'woocommerce-general' => array(
209
- 'src' => plugins_url( 'assets/css/woocommerce.css', WC_PLUGIN_FILE ),
210
- 'deps' => '',
211
- 'version' => WC_VERSION,
212
- 'media' => 'all',
213
- 'has_rtl' => true,
214
- ),
215
- );
216
-
217
- return $woo_styles;
218
- }
219
-
220
- /**
221
- * Init Actions.
222
- *
223
- * @since 1.0.0
224
- */
225
- function init_actions() {
226
-
227
- $this->set_flow_session();
228
- }
229
-
230
- /**
231
- * Set flow session.
232
- *
233
- * @since 1.0.0
234
- */
235
- function set_flow_session() {
236
-
237
- if ( wcf()->utils->is_step_post_type() ) {
238
-
239
- add_action( 'wp_head', array( $this, 'noindex_flow' ) );
240
-
241
- wcf()->utils->do_not_cache();
242
-
243
- /* Set key to support pixel */
244
- if ( isset( $_GET['wcf-key'] ) ) {
245
- $_GET['key'] = $_GET['wcf-key'];
246
- $_REQUEST['key'] = $_GET['wcf-key'];
247
- }
248
-
249
- if ( isset( $_GET['wcf-order'] ) ) {
250
- $_GET['order'] = $_GET['wcf-order'];
251
- $_REQUEST['order'] = $_GET['wcf-order'];
252
- $_GET['order-received'] = $_GET['wcf-order'];
253
- $_REQUEST['order-received'] = $_GET['wcf-order'];
254
- }
255
- }
256
- }
257
-
258
- /**
259
- * Add noindex, nofollow.
260
- *
261
- * @since 1.0.0
262
- */
263
- function noindex_flow() {
264
-
265
- $common = Cartflows_Helper::get_common_settings();
266
-
267
- if ( 'enable' === $common['disallow_indexing'] ) {
268
- echo '<meta name="robots" content="noindex,nofollow">';
269
- }
270
- }
271
-
272
- /**
273
- * WP Actions.
274
- *
275
- * @since 1.0.0
276
- */
277
- function wp_actions() {
278
-
279
- if ( wcf()->utils->is_step_post_type() ) {
280
-
281
- /* CSS Compatibility for All theme */
282
- add_filter( 'woocommerce_enqueue_styles', array( $this, 'woo_default_css' ), 9999 );
283
-
284
- add_action( 'wp_enqueue_scripts', array( $this, 'remove_theme_styles' ), 9999 );
285
- add_action( 'wp_enqueue_scripts', array( $this, 'global_flow_scripts' ), 20 );
286
-
287
- /* Load woo templates from plugin */
288
- add_filter( 'woocommerce_locate_template', array( $this, 'override_woo_template' ), 20, 3 );
289
-
290
- /* Add version class to body in frontend. */
291
- add_filter( 'body_class', array( $this, 'add_cartflows_lite_version_to_body' ) );
292
-
293
- /* Custom Script Option */
294
- add_action( 'wp_head', array( $this, 'custom_script_option' ) );
295
-
296
- /* Remove the action applied by the Flatsome theme */
297
- if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
298
- $this->remove_flatsome_action();
299
- }
300
- }
301
- }
302
-
303
- /**
304
- * Global flow scripts.
305
- *
306
- * @since 1.0.0
307
- */
308
- function global_flow_scripts() {
309
-
310
- global $post;
311
-
312
- $flow = get_post_meta( $post->ID, 'wcf-flow-id', true );
313
- $current_step = $post->ID;
314
- $next_step_link = '';
315
- $compatibility = Cartflows_Compatibility::get_instance();
316
-
317
- if ( _is_wcf_landing_type() ) {
318
-
319
- $next_step_id = wcf()->utils->get_next_step_id( $flow, $current_step );
320
- $next_step_link = get_permalink( $next_step_id );
321
- }
322
-
323
- $localize = array(
324
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
325
- 'is_pb_preview' => $compatibility->is_page_builder_preview(),
326
- 'current_theme' => $compatibility->get_current_theme(),
327
- 'current_flow' => $flow,
328
- 'current_step' => $current_step,
329
- 'next_step' => $next_step_link,
330
- );
331
-
332
- wp_localize_script( 'jquery', 'cartflows', apply_filters( 'global_cartflows_js_localize', $localize ) );
333
-
334
- wp_enqueue_style( 'wcf-frontend-global', CARTFLOWS_URL . 'assets/css/frontend.css', array(), CARTFLOWS_VER );
335
- wp_style_add_data( 'wcf-frontend-global', 'rtl', 'replace' );
336
-
337
- wp_enqueue_script(
338
- 'wcf-frontend-global',
339
- CARTFLOWS_URL . 'assets/js/frontend.js',
340
- array( 'jquery' ),
341
- CARTFLOWS_VER,
342
- true
343
- );
344
- }
345
-
346
- /**
347
- * Custom Script in head.
348
- *
349
- * @since 1.0.0
350
- */
351
- function custom_script_option() {
352
-
353
- /* Add custom script to header in frontend. */
354
- $script = $this->get_custom_script();
355
- if ( '' !== $script ) {
356
- if ( false === strpos( $script, '<script' ) ) {
357
- $script = '<script>' . $script . '</script>';
358
- }
359
- echo '<!-- Custom CartFlows Script -->';
360
- echo $script;
361
- echo '<!-- End Custom CartFlows Script -->';
362
- }
363
- }
364
-
365
- /**
366
- * Override woo templates.
367
- *
368
- * @param string $template new Template full path.
369
- * @param string $template_name Template name.
370
- * @param string $template_path Template Path.
371
- * @since 1.1.5
372
- * @return string.
373
- */
374
- function override_woo_template( $template, $template_name, $template_path ) {
375
-
376
- global $woocommerce;
377
-
378
- $_template = $template;
379
-
380
- $plugin_path = CARTFLOWS_DIR . 'woocommerce/template/';
381
-
382
- if ( file_exists( $plugin_path . $template_name ) ) {
383
- $template = $plugin_path . $template_name;
384
- }
385
-
386
- if ( ! $template ) {
387
- $template = $_template;
388
- }
389
-
390
- return $template;
391
- }
392
-
393
- /**
394
- * Remove the action applied by the Flatsome theme.
395
- *
396
- * @since 1.1.5
397
- * @return void.
398
- */
399
- function remove_flatsome_action() {
400
-
401
- // Remove action where flatsome dequeued the woocommerce's default styles.
402
- remove_action( 'wp_enqueue_scripts', 'flatsome_woocommerce_scripts_styles', 98 );
403
- }
404
-
405
- /**
406
- * Add version class to body in frontend.
407
- *
408
- * @since 1.1.5
409
- * @param array $classes classes.
410
- * @return array $classes classes.
411
- */
412
- function add_cartflows_lite_version_to_body( $classes ) {
413
-
414
- $classes[] = 'cartflows-' . CARTFLOWS_VER;
415
-
416
- return $classes;
417
-
418
- }
419
-
420
- /**
421
- * Get custom script data.
422
- *
423
- * @since 1.0.0
424
- */
425
- function get_custom_script() {
426
-
427
- global $post;
428
-
429
- $script = get_post_meta( $post->ID, 'wcf-custom-script', true );
430
-
431
- return $script;
432
- }
433
- }
434
-
435
- /**
436
- * Prepare if class 'Cartflows_Frontend' exist.
437
- * Kicking this off by calling 'get_instance()' method
438
- */
439
- Cartflows_Frontend::get_instance();
1
+ <?php
2
+ /**
3
+ * CartFlows Frontend.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Class Cartflows_Frontend.
10
+ */
11
+ class Cartflows_Frontend {
12
+
13
+ /**
14
+ * Member Variable
15
+ *
16
+ * @var instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Initiator
22
+ */
23
+ public static function get_instance() {
24
+ if ( ! isset( self::$instance ) ) {
25
+ self::$instance = new self;
26
+ }
27
+ return self::$instance;
28
+ }
29
+
30
+ /**
31
+ * Constructor
32
+ */
33
+ public function __construct() {
34
+
35
+ /* Set / Destroy Flow Sessions. Set data */
36
+ add_action( 'wp', array( $this, 'init_actions' ), 1 );
37
+
38
+ /* Enqueue global required scripts */
39
+ add_action( 'wp', array( $this, 'wp_actions' ), 55 );
40
+
41
+ /* Modify the checkout order received url to go thank you page in our flow */
42
+ add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
43
+
44
+ }
45
+
46
+ /**
47
+ * Redirect to thank page if upsell not exists
48
+ *
49
+ * @param string $order_recieve_url url.
50
+ * @param object $order order object.
51
+ * @since 1.0.0
52
+ */
53
+ function redirect_to_thankyou_page( $order_recieve_url, $order ) {
54
+
55
+ /* Only for thank you page */
56
+ wcf()->logger->log( 'Start-' . __CLASS__ . '::' . __FUNCTION__ );
57
+ wcf()->logger->log( 'Only for thank you page' );
58
+
59
+ if ( wcf()->flow->is_thankyou_page_exists( $order ) ) {
60
+
61
+ if ( _is_wcf_doing_checkout_ajax() ) {
62
+
63
+ $checkout_id = wcf()->utils->get_checkout_id_from_post_data();
64
+
65
+ if ( ! $checkout_id ) {
66
+ $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
67
+ }
68
+ } else {
69
+ $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
70
+ }
71
+
72
+ wcf()->logger->log( 'Checkout ID : ' . $checkout_id );
73
+
74
+ if ( $checkout_id ) {
75
+
76
+ $thankyou_step_id = wcf()->flow->get_thankyou_page_id( $order );
77
+
78
+ if ( $thankyou_step_id ) {
79
+
80
+ $order_recieve_url = get_permalink( $thankyou_step_id );
81
+
82
+ $order_recieve_url = add_query_arg(
83
+ array(
84
+ 'wcf-key' => $order->get_order_key(),
85
+ 'wcf-order' => $order->get_id(),
86
+ ),
87
+ $order_recieve_url
88
+ );
89
+ }
90
+ }
91
+ }
92
+
93
+ wcf()->logger->log( 'End-' . __CLASS__ . '::' . __FUNCTION__ );
94
+
95
+ return $order_recieve_url;
96
+ }
97
+
98
+ /**
99
+ * Cancel and redirect to checkout
100
+ *
101
+ * @param string $return_url url.
102
+ * @since 1.0.0
103
+ */
104
+ function redirect_to_checkout_on_cancel( $return_url ) {
105
+
106
+ if ( _is_wcf_doing_checkout_ajax() ) {
107
+
108
+ $checkout_id = wcf()->utils->get_checkout_id_from_post_data();
109
+
110
+ if ( ! $checkout_id ) {
111
+ $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
112
+ }
113
+ } else {
114
+ $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
115
+ }
116
+
117
+ if ( $checkout_id ) {
118
+
119
+ $return_url = add_query_arg(
120
+ array(
121
+ 'cancel_order' => 'true',
122
+ '_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ),
123
+ ),
124
+ get_permalink( $checkout_id )
125
+ );
126
+ }
127
+
128
+ return $return_url;
129
+ }
130
+
131
+
132
+ /**
133
+ * Remove theme styles.
134
+ *
135
+ * @since 1.0.0
136
+ */
137
+ function remove_theme_styles() {
138
+
139
+ if ( Cartflows_Compatibility::get_instance()->is_compatibility_theme_enabled() ) {
140
+ return;
141
+ }
142
+
143
+ // get all styles data.
144
+ global $wp_styles;
145
+ global $wp_scripts;
146
+
147
+ $get_stylesheet = 'themes/' . get_stylesheet() . '/';
148
+ $get_template = 'themes/' . get_template() . '/';
149
+
150
+ $remove_styles = apply_filters( 'cartflows_remove_theme_styles', true );
151
+
152
+ if ( $remove_styles ) {
153
+
154
+ // loop over all of the registered scripts..
155
+ foreach ( $wp_styles->registered as $handle => $data ) {
156
+
157
+ if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
158
+
159
+ // remove it.
160
+ wp_deregister_style( $handle );
161
+ wp_dequeue_style( $handle );
162
+ }
163
+ }
164
+ }
165
+
166
+ $remove_scripts = apply_filters( 'cartflows_remove_theme_scripts', true );
167
+
168
+ if ( $remove_scripts ) {
169
+
170
+ // loop over all of the registered scripts.
171
+ foreach ( $wp_scripts->registered as $handle => $data ) {
172
+
173
+ if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
174
+
175
+ // remove it.
176
+ wp_deregister_script( $handle );
177
+ wp_dequeue_script( $handle );
178
+ }
179
+ }
180
+ }
181
+
182
+ }
183
+
184
+ /**
185
+ * Update main order data in transient.
186
+ *
187
+ * @param array $woo_styles new styles array.
188
+ * @since 1.0.0
189
+ * @return array.
190
+ */
191
+ function woo_default_css( $woo_styles ) {
192
+
193
+ $woo_styles = array(
194
+ 'woocommerce-layout' => array(
195
+ 'src' => plugins_url( 'assets/css/woocommerce-layout.css', WC_PLUGIN_FILE ),
196
+ 'deps' => '',
197
+ 'version' => WC_VERSION,
198
+ 'media' => 'all',
199
+ 'has_rtl' => true,
200
+ ),
201
+ 'woocommerce-smallscreen' => array(
202
+ 'src' => plugins_url( 'assets/css/woocommerce-smallscreen.css', WC_PLUGIN_FILE ),
203
+ 'deps' => 'woocommerce-layout',
204
+ 'version' => WC_VERSION,
205
+ 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
206
+ 'has_rtl' => true,
207
+ ),
208
+ 'woocommerce-general' => array(
209
+ 'src' => plugins_url( 'assets/css/woocommerce.css', WC_PLUGIN_FILE ),
210
+ 'deps' => '',
211
+ 'version' => WC_VERSION,
212
+ 'media' => 'all',
213
+ 'has_rtl' => true,
214
+ ),
215
+ );
216
+
217
+ return $woo_styles;
218
+ }
219
+
220
+ /**
221
+ * Init Actions.
222
+ *
223
+ * @since 1.0.0
224
+ */
225
+ function init_actions() {
226
+
227
+ $this->set_flow_session();
228
+ }
229
+
230
+ /**
231
+ * Set flow session.
232
+ *
233
+ * @since 1.0.0
234
+ */
235
+ function set_flow_session() {
236
+
237
+ if ( wcf()->utils->is_step_post_type() ) {
238
+
239
+ add_action( 'wp_head', array( $this, 'noindex_flow' ) );
240
+
241
+ wcf()->utils->do_not_cache();
242
+
243
+ /* Set key to support pixel */
244
+ if ( isset( $_GET['wcf-key'] ) ) {
245
+ $_GET['key'] = $_GET['wcf-key'];
246
+ $_REQUEST['key'] = $_GET['wcf-key'];
247
+ }
248
+
249
+ if ( isset( $_GET['wcf-order'] ) ) {
250
+ $_GET['order'] = $_GET['wcf-order'];
251
+ $_REQUEST['order'] = $_GET['wcf-order'];
252
+ $_GET['order-received'] = $_GET['wcf-order'];
253
+ $_REQUEST['order-received'] = $_GET['wcf-order'];
254
+ }
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Add noindex, nofollow.
260
+ *
261
+ * @since 1.0.0
262
+ */
263
+ function noindex_flow() {
264
+
265
+ $common = Cartflows_Helper::get_common_settings();
266
+
267
+ if ( 'enable' === $common['disallow_indexing'] ) {
268
+ echo '<meta name="robots" content="noindex,nofollow">';
269
+ }
270
+ }
271
+
272
+ /**
273
+ * WP Actions.
274
+ *
275
+ * @since 1.0.0
276
+ */
277
+ function wp_actions() {
278
+
279
+ if ( wcf()->utils->is_step_post_type() ) {
280
+
281
+ /* CSS Compatibility for All theme */
282
+ add_filter( 'woocommerce_enqueue_styles', array( $this, 'woo_default_css' ), 9999 );
283
+
284
+ add_action( 'wp_enqueue_scripts', array( $this, 'remove_theme_styles' ), 9999 );
285
+ add_action( 'wp_enqueue_scripts', array( $this, 'global_flow_scripts' ), 20 );
286
+
287
+ /* Load woo templates from plugin */
288
+ add_filter( 'woocommerce_locate_template', array( $this, 'override_woo_template' ), 20, 3 );
289
+
290
+ /* Add version class to body in frontend. */
291
+ add_filter( 'body_class', array( $this, 'add_cartflows_lite_version_to_body' ) );
292
+
293
+ /* Custom Script Option */
294
+ add_action( 'wp_head', array( $this, 'custom_script_option' ) );
295
+
296
+ /* Remove the action applied by the Flatsome theme */
297
+ if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
298
+ $this->remove_flatsome_action();
299
+ }
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Global flow scripts.
305
+ *
306
+ * @since 1.0.0
307
+ */
308
+ function global_flow_scripts() {
309
+
310
+ global $post;
311
+
312
+ $flow = get_post_meta( $post->ID, 'wcf-flow-id', true );
313
+ $current_step = $post->ID;
314
+ $next_step_link = '';
315
+ $compatibility = Cartflows_Compatibility::get_instance();
316
+
317
+ if ( _is_wcf_landing_type() ) {
318
+
319
+ $next_step_id = wcf()->utils->get_next_step_id( $flow, $current_step );
320
+ $next_step_link = get_permalink( $next_step_id );
321
+ }
322
+
323
+ $localize = array(
324
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
325
+ 'is_pb_preview' => $compatibility->is_page_builder_preview(),
326
+ 'current_theme' => $compatibility->get_current_theme(),
327
+ 'current_flow' => $flow,
328
+ 'current_step' => $current_step,
329
+ 'next_step' => $next_step_link,
330
+ );
331
+
332
+ wp_localize_script( 'jquery', 'cartflows', apply_filters( 'global_cartflows_js_localize', $localize ) );
333
+
334
+ wp_enqueue_style( 'wcf-frontend-global', CARTFLOWS_URL . 'assets/css/frontend.css', array(), CARTFLOWS_VER );
335
+ wp_style_add_data( 'wcf-frontend-global', 'rtl', 'replace' );
336
+
337
+ wp_enqueue_script(
338
+ 'wcf-frontend-global',
339
+ CARTFLOWS_URL . 'assets/js/frontend.js',
340
+ array( 'jquery' ),
341
+ CARTFLOWS_VER,
342
+ true
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Custom Script in head.
348
+ *
349
+ * @since 1.0.0
350
+ */
351
+ function custom_script_option() {
352
+
353
+ /* Add custom script to header in frontend. */
354
+ $script = $this->get_custom_script();
355
+ if ( '' !== $script ) {
356
+ if ( false === strpos( $script, '<script' ) ) {
357
+ $script = '<script>' . $script . '</script>';
358
+ }
359
+ echo '<!-- Custom CartFlows Script -->';
360
+ echo $script;
361
+ echo '<!-- End Custom CartFlows Script -->';
362
+ }
363
+ }
364
+
365
+ /**
366
+ * Override woo templates.
367
+ *
368
+ * @param string $template new Template full path.
369
+ * @param string $template_name Template name.
370
+ * @param string $template_path Template Path.
371
+ * @since 1.1.5
372
+ * @return string.
373
+ */
374
+ function override_woo_template( $template, $template_name, $template_path ) {
375
+
376
+ global $woocommerce;
377
+
378
+ $_template = $template;
379
+
380
+ $plugin_path = CARTFLOWS_DIR . 'woocommerce/template/';
381
+
382
+ if ( file_exists( $plugin_path . $template_name ) ) {
383
+ $template = $plugin_path . $template_name;
384
+ }
385
+
386
+ if ( ! $template ) {
387
+ $template = $_template;
388
+ }
389
+
390
+ return $template;
391
+ }
392
+
393
+ /**
394
+ * Remove the action applied by the Flatsome theme.
395
+ *
396
+ * @since 1.1.5
397
+ * @return void.
398
+ */
399
+ function remove_flatsome_action() {
400
+
401
+ // Remove action where flatsome dequeued the woocommerce's default styles.
402
+ remove_action( 'wp_enqueue_scripts', 'flatsome_woocommerce_scripts_styles', 98 );
403
+ }
404
+
405
+ /**
406
+ * Add version class to body in frontend.
407
+ *
408
+ * @since 1.1.5
409
+ * @param array $classes classes.
410
+ * @return array $classes classes.
411
+ */
412
+ function add_cartflows_lite_version_to_body( $classes ) {
413
+
414
+ $classes[] = 'cartflows-' . CARTFLOWS_VER;
415
+
416
+ return $classes;
417
+
418
+ }
419
+
420
+ /**
421
+ * Get custom script data.
422
+ *
423
+ * @since 1.0.0
424
+ */
425
+ function get_custom_script() {
426
+
427
+ global $post;
428
+
429
+ $script = get_post_meta( $post->ID, 'wcf-custom-script', true );
430
+
431
+ return $script;
432
+ }
433
+ }
434
+
435
+ /**
436
+ * Prepare if class 'Cartflows_Frontend' exist.
437
+ * Kicking this off by calling 'get_instance()' method
438
+ */
439
+ Cartflows_Frontend::get_instance();
classes/class-cartflows-functions.php CHANGED
@@ -1,388 +1,388 @@
1
- <?php
2
- /**
3
- * CartFlows Functions.
4
- *
5
- * @package CARTFLOWS
6
- */
7
-
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit; // Exit if accessed directly.
10
- }
11
-
12
- /**
13
- * Check if cartflows pro activated.
14
- *
15
- * @since 1.0.0
16
- */
17
- function _is_cartflows_pro() {
18
-
19
- if ( defined( 'CARTFLOWS_PRO_FILE' ) ) {
20
- return true;
21
- }
22
-
23
- return false;
24
-
25
- }
26
-
27
- /**
28
- * Returns step id.
29
- *
30
- * @since 1.0.0
31
- */
32
- function _get_wcf_post_id() {
33
-
34
- global $post;
35
-
36
- if ( isset( $post->ID ) ) {
37
- return $post->ID;
38
- }
39
-
40
- return 0;
41
- }
42
-
43
- /**
44
- * Returns step id.
45
- *
46
- * @since 1.0.0
47
- */
48
- function _get_wcf_step_id() {
49
-
50
- if ( wcf()->utils->is_step_post_type() ) {
51
-
52
- global $post;
53
-
54
- return $post->ID;
55
- }
56
-
57
- return false;
58
- }
59
-
60
- /**
61
- * Check if it is a landing page?
62
- *
63
- * @since 1.0.0
64
- */
65
- function _is_wcf_landing_type() {
66
-
67
- if ( wcf()->utils->is_step_post_type() ) {
68
-
69
- global $post;
70
-
71
- if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
72
-
73
- return true;
74
- }
75
- }
76
-
77
- return false;
78
- }
79
-
80
- /**
81
- * Returns landing id.
82
- *
83
- * @since 1.0.0
84
- */
85
- function _get_wcf_landing_id() {
86
-
87
- if ( _is_wcf_landing_type() ) {
88
-
89
- global $post;
90
-
91
- return $post->ID;
92
- }
93
-
94
- return false;
95
- }
96
-
97
- /**
98
- * Is custom checkout?
99
- *
100
- * @param int $checkout_id checkout ID.
101
- * @since 1.0.0
102
- */
103
- function _is_wcf_meta_custom_checkout( $checkout_id ) {
104
-
105
- $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' );
106
-
107
- if ( 'yes' === $is_custom ) {
108
-
109
- return true;
110
- }
111
-
112
- return false;
113
- }
114
-
115
- /**
116
- * Check if page is cartflow checkout.
117
- *
118
- * @since 1.0.0
119
- * @return bool
120
- */
121
- function _is_wcf_checkout_type() {
122
-
123
- if ( wcf()->utils->is_step_post_type() ) {
124
-
125
- global $post;
126
-
127
- if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
128
-
129
- return true;
130
- }
131
- }
132
-
133
- return false;
134
- }
135
-
136
- /**
137
- * Check if AJAX call is in progress.
138
- *
139
- * @since 1.0.0
140
- * @return bool
141
- */
142
- function _is_wcf_doing_checkout_ajax() {
143
-
144
- if ( wp_doing_ajax() ) {
145
-
146
- if ( isset( $_GET['wc-ajax'] ) &&
147
- 'checkout' === $_GET['wc-ajax'] &&
148
- isset( $_POST['_wcf_checkout_id'] )
149
- ) {
150
- return true;
151
- }
152
- }
153
-
154
- return false;
155
- }
156
-
157
-
158
- /**
159
- * Returns checkout ID.
160
- *
161
- * @since 1.0.0
162
- * @return int/bool
163
- */
164
- function _get_wcf_checkout_id() {
165
-
166
- if ( _is_wcf_checkout_type() ) {
167
-
168
- global $post;
169
-
170
- return $post->ID;
171
- }
172
-
173
- return false;
174
- }
175
-
176
- /**
177
- * Check if it is checkout shortcode.
178
- *
179
- * @since 1.0.0
180
- * @return bool
181
- */
182
- function _is_wcf_checkout_shortcode() {
183
-
184
- global $post;
185
-
186
- if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) {
187
-
188
- return true;
189
- }
190
-
191
- return false;
192
- }
193
-
194
- /**
195
- * Check if it is checkout shortcode.
196
- *
197
- * @since 1.0.0
198
- * @param string $content shortcode content.
199
- * @return bool
200
- */
201
- function _get_wcf_checkout_id_from_shortcode( $content = '' ) {
202
-
203
- $checkout_id = 0;
204
-
205
- if ( ! empty( $content ) ) {
206
-
207
- $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) );
208
-
209
- preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches );
210
-
211
- if ( ! empty( $regex_matches ) ) {
212
-
213
- if ( 'cartflows_checkout' == $regex_matches[2] ) {
214
-
215
- $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) );
216
- $attribure_str = str_replace( '"', '', $attribure_str );
217
-
218
- $attributes = wp_parse_args( $attribure_str );
219
-
220
- if ( isset( $attributes['id'] ) ) {
221
- $checkout_id = $attributes['id'];
222
- }
223
- }
224
- }
225
- }
226
-
227
- return $checkout_id;
228
- }
229
-
230
- /**
231
- * Check if post type is upsell.
232
- *
233
- * @since 1.0.0
234
- * @return bool
235
- */
236
- function _is_wcf_upsell_type() {
237
-
238
- if ( wcf()->utils->is_step_post_type() ) {
239
-
240
- global $post;
241
-
242
- if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
243
-
244
- return true;
245
- }
246
- }
247
-
248
- return false;
249
- }
250
-
251
- /**
252
- * Returns upsell ID.
253
- *
254
- * @since 1.0.0
255
- * @return int/bool
256
- */
257
- function _get_wcf_upsell_id() {
258
-
259
- if ( _is_wcf_upsell_type() ) {
260
-
261
- global $post;
262
-
263
- return $post->ID;
264
- }
265
-
266
- return false;
267
- }
268
-
269
- /**
270
- * Check if post is of type downsell.
271
- *
272
- * @since 1.0.0
273
- * @return int/bool
274
- */
275
- function _is_wcf_downsell_type() {
276
-
277
- if ( wcf()->utils->is_step_post_type() ) {
278
-
279
- global $post;
280
-
281
- if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
282
-
283
- return true;
284
- }
285
- }
286
-
287
- return false;
288
- }
289
-
290
- /**
291
- * Get downsell page ID.
292
- *
293
- * @since 1.0.0
294
- * @return int/bool
295
- */
296
- function _get_wcf_downsell_id() {
297
-
298
- if ( _is_wcf_downsell_type() ) {
299
-
300
- global $post;
301
-
302
- return $post->ID;
303
- }
304
-
305
- return false;
306
- }
307
-
308
- /**
309
- * Check if page is of thank you type.
310
- *
311
- * @since 1.0.0
312
- * @return int/bool
313
- */
314
- function _is_wcf_thankyou_type() {
315
-
316
- if ( wcf()->utils->is_step_post_type() ) {
317
-
318
- global $post;
319
-
320
- if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
321
-
322
- return true;
323
- }
324
- }
325
-
326
- return false;
327
- }
328
-
329
- /**
330
- * Get thank you page ID.
331
- *
332
- * @since 1.0.0
333
- * @return int/bool
334
- */
335
- function _get_wcf_thankyou_id() {
336
-
337
- if ( _is_wcf_thankyou_type() ) {
338
-
339
- global $post;
340
-
341
- return $post->ID;
342
- }
343
-
344
- return false;
345
- }
346
-
347
-
348
- /**
349
- * Check if post type is upsell.
350
- *
351
- * @since 1.0.0
352
- * @return bool
353
- */
354
- function _is_wcf_base_offer_type() {
355
-
356
- if ( wcf()->utils->is_step_post_type() ) {
357
-
358
- global $post;
359
-
360
- $step_type = get_post_meta( $post->ID, 'wcf-step-type', true );
361
-
362
- if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
363
-
364
- return true;
365
- }
366
- }
367
-
368
- return false;
369
- }
370
-
371
- /**
372
- * Returns upsell ID.
373
- *
374
- * @since 1.0.0
375
- * @return int/bool
376
- */
377
- function _get_wcf_base_offer_id() {
378
-
379
- if ( _is_wcf_base_offer_type() ) {
380
-
381
- global $post;
382
-
383
- return $post->ID;
384
- }
385
-
386
- return false;
387
- }
388
-
1
+ <?php
2
+ /**
3
+ * CartFlows Functions.
4
+ *
5
+ * @package CARTFLOWS
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit; // Exit if accessed directly.
10
+ }
11
+
12
+ /**
13
+ * Check if cartflows pro activated.
14
+ *
15
+ * @since 1.0.0
16
+ */
17
+ function _is_cartflows_pro() {
18
+
19
+ if ( defined( 'CARTFLOWS_PRO_FILE' ) ) {
20
+ return true;
21
+ }
22
+
23
+ return false;
24
+
25
+ }
26
+
27
+ /**
28
+ * Returns step id.
29
+ *
30
+ * @since 1.0.0
31
+ */
32
+ function _get_wcf_post_id() {
33
+
34
+ global $post;
35
+
36
+ if ( isset( $post->ID ) ) {
37
+ return $post->ID;
38
+ }
39
+
40
+ return 0;
41
+ }
42
+
43
+ /**
44
+ * Returns step id.
45
+ *
46
+ * @since 1.0.0
47
+ */
48
+ function _get_wcf_step_id() {
49
+
50
+ if ( wcf()->utils->is_step_post_type() ) {
51
+
52
+ global $post;
53
+
54
+ return $post->ID;
55
+ }
56
+
57
+ return false;
58
+ }
59
+
60
+ /**
61
+ * Check if it is a landing page?
62
+ *
63
+ * @since 1.0.0
64
+ */
65
+ function _is_wcf_landing_type() {
66
+
67
+ if ( wcf()->utils->is_step_post_type() ) {
68
+
69
+ global $post;
70
+
71
+ if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
72
+
73
+ return true;
74
+ }
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Returns landing id.
82
+ *
83
+ * @since 1.0.0
84
+ */
85
+ function _get_wcf_landing_id() {
86
+
87
+ if ( _is_wcf_landing_type() ) {
88
+
89
+ global $post;
90
+
91
+ return $post->ID;
92
+ }
93
+
94
+ return false;
95
+ }
96
+
97
+ /**
98
+ * Is custom checkout?
99
+ *
100
+ * @param int $checkout_id checkout ID.
101
+ * @since 1.0.0
102
+ */
103
+ function _is_wcf_meta_custom_checkout( $checkout_id ) {
104
+
105
+ $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' );
106
+
107
+ if ( 'yes' === $is_custom ) {
108
+
109
+ return true;
110
+ }
111
+
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * Check if page is cartflow checkout.
117
+ *
118
+ * @since 1.0.0
119
+ * @return bool
120
+ */
121
+ function _is_wcf_checkout_type() {
122
+
123
+ if ( wcf()->utils->is_step_post_type() ) {
124
+
125
+ global $post;
126
+
127
+ if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
128
+
129
+ return true;
130
+ }
131
+ }
132
+
133
+ return false;
134
+ }
135
+
136
+ /**
137
+ * Check if AJAX call is in progress.
138
+ *
139
+ * @since 1.0.0
140
+ * @return bool
141
+ */
142
+ function _is_wcf_doing_checkout_ajax() {
143
+
144
+ if ( wp_doing_ajax() ) {
145
+
146
+ if ( isset( $_GET['wc-ajax'] ) &&
147
+ 'checkout' === $_GET['wc-ajax'] &&
148
+ isset( $_POST['_wcf_checkout_id'] )
149
+ ) {
150
+ return true;
151
+ }
152
+ }
153
+
154
+ return false;
155
+ }
156
+
157
+
158
+ /**
159
+ * Returns checkout ID.
160
+ *
161
+ * @since 1.0.0
162
+ * @return int/bool
163
+ */
164
+ function _get_wcf_checkout_id() {
165
+
166
+ if ( _is_wcf_checkout_type() ) {
167
+
168
+ global $post;
169
+
170
+ return $post->ID;
171
+ }
172
+
173
+ return false;
174
+ }
175
+
176
+ /**
177
+ * Check if it is checkout shortcode.
178
+ *
179
+ * @since 1.0.0
180
+ * @return bool
181
+ */
182
+ function _is_wcf_checkout_shortcode() {
183
+
184
+ global $post;
185
+
186
+ if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) {
187
+
188
+ return true;
189
+ }
190
+
191
+ return false;
192
+ }
193
+
194
+ /**
195
+ * Check if it is checkout shortcode.
196
+ *
197
+ * @since 1.0.0
198
+ * @param string $content shortcode content.
199
+ * @return bool
200
+ */
201
+ function _get_wcf_checkout_id_from_shortcode( $content = '' ) {
202
+
203
+ $checkout_id = 0;
204
+
205
+ if ( ! empty( $content ) ) {
206
+
207
+ $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) );
208
+
209
+ preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches );
210
+
211
+ if ( ! empty( $regex_matches ) ) {
212
+
213
+ if ( 'cartflows_checkout' == $regex_matches[2] ) {
214
+
215
+ $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) );
216
+ $attribure_str = str_replace( '"', '', $attribure_str );
217
+
218
+ $attributes = wp_parse_args( $attribure_str );
219
+
220
+ if ( isset( $attributes['id'] ) ) {
221
+ $checkout_id = $attributes['id'];
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ return $checkout_id;
228
+ }
229
+
230
+ /**
231
+ * Check if post type is upsell.
232
+ *
233
+ * @since 1.0.0
234
+ * @return bool
235
+ */
236
+ function _is_wcf_upsell_type() {
237
+
238
+ if ( wcf()->utils->is_step_post_type() ) {
239
+
240
+ global $post;
241
+
242
+ if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
243
+
244
+ return true;
245
+ }
246
+ }
247
+
248
+ return false;
249
+ }
250
+
251
+ /**
252
+ * Returns upsell ID.
253
+ *
254
+ * @since 1.0.0
255
+ * @return int/bool
256
+ */
257
+ function _get_wcf_upsell_id() {
258
+
259
+ if ( _is_wcf_upsell_type() ) {
260
+
261
+ global $post;
262
+
263
+ return $post->ID;
264
+ }
265
+
266
+ return false;
267
+ }
268
+
269
+ /**
270
+ * Check if post is of type downsell.
271
+ *
272
+ * @since 1.0.0
273
+ * @return int/bool
274
+ */
275
+ function _is_wcf_downsell_type() {
276
+
277
+ if ( wcf()->utils->is_step_post_type() ) {
278
+
279
+ global $post;
280
+
281
+ if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
282
+
283
+ return true;
284
+ }
285
+ }
286
+
287
+ return false;
288
+ }
289
+
290
+ /**
291
+ * Get downsell page ID.
292
+ *
293
+ * @since 1.0.0
294
+ * @return int/bool
295
+ */
296
+ function _get_wcf_downsell_id() {
297
+
298
+ if ( _is_wcf_downsell_type() ) {
299
+
300
+ global $post;
301
+
302
+ return $post->ID;
303
+ }
304
+
305
+ return false;
306
+ }
307
+
308
+ /**
309
+ * Check if page is of thank you type.
310
+ *
311
+ * @since 1.0.0
312
+ * @return int/bool
313
+ */
314
+ function _is_wcf_thankyou_type() {
315
+
316
+ if ( wcf()->utils->is_step_post_type() ) {
317
+
318
+ global $post;
319
+
320
+ if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
321
+
322
+ return true;
323
+ }
324
+ }
325
+
326
+ return false;
327
+ }
328
+
329
+ /**
330
+ * Get thank you page ID.
331
+ *
332
+ * @since 1.0.0
333
+ * @return int/bool
334
+ */
335
+ function _get_wcf_thankyou_id() {
336
+
337
+ if ( _is_wcf_thankyou_type() ) {
338
+
339
+ global $post;
340
+
341
+ return $post->ID;
342
+ }
343
+
344
+ return false;
345
+ }
346
+
347
+
348
+ /**
349
+ * Check if post type is upsell.
350
+ *
351
+ * @since 1.0.0
352
+ * @return bool
353
+ */
354
+ function _is_wcf_base_offer_type() {
355
+
356
+ if ( wcf()->utils->is_step_post_type() ) {
357
+
358
+ global $post;
359
+
360
+ $step_type = get_post_meta( $post->ID, 'wcf-step-type', true );
361
+
362
+ if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
363
+
364
+ return true;
365
+ }
366
+ }
367
+
368
+ return false;
369
+ }
370
+
371
+ /**
372
+ * Returns upsell ID.
373
+ *
374
+ * @since 1.0.0
375
+ * @return int/bool
376
+ */
377
+ function _get_wcf_base_offer_id() {
378
+
379
+ if ( _is_wcf_base_offer_type() ) {
380
+
381
+ global $post;
382
+
383
+ return $post->ID;
384
+ }
385
+
386
+ return false;
387
+ }
388
+
classes/class-cartflows-helper.php CHANGED
@@ -1,464 +1,464 @@
1
- <?php
2
- /**
3
- * CARTFLOWS Helper.
4
- *
5
- * @package CARTFLOWS
6
- */
7
-
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit; // Exit if accessed directly.
10
- }
11
-
12
- /**
13
- * Class Cartflows_Helper.
14
- */
15
- class Cartflows_Helper {
16
-
17
- /**
18
- * Common global data
19
- *
20
- * @var zapier
21
- */
22
- private static $common = null;
23
-
24
- /**
25
- * Installed Plugins
26
- *
27
- * @since 1.1.4
28
- *
29
- * @access private
30
- * @var array Installed plugins list.
31
- */
32
- private static $installed_plugins = null;
33
-
34
- /**
35
- * Checkout Fields
36
- *
37
- * @var checkout_fields
38
- */
39
- private static $checkout_fields = null;
40
-
41
- /**
42
- * Returns an option from the database for
43
- * the admin settings page.
44
- *
45
- * @param string $key The option key.
46
- * @param mixed $default Option default value if option is not available.
47
- * @param boolean $network_override Whether to allow the network admin setting to be overridden on subsites.
48
- * @return string Return the option value
49
- */
50
- public static function get_admin_settings_option( $key, $default = false, $network_override = false ) {
51
-
52
- // Get the site-wide option if we're in the network admin.
53
- if ( $network_override && is_multisite() ) {
54
- $value = get_site_option( $key, $default );
55
- } else {
56
- $value = get_option( $key, $default );
57
- }
58
-
59
- return $value;
60
- }
61
-
62
- /**
63
- * Updates an option from the admin settings page.
64
- *
65
- * @param string $key The option key.
66
- * @param mixed $value The value to update.
67
- * @param bool $network Whether to allow the network admin setting to be overridden on subsites.
68
- * @return mixed
69
- */
70
- static public function update_admin_settings_option( $key, $value, $network = false ) {
71
-
72
- // Update the site-wide option since we're in the network admin.
73
- if ( $network && is_multisite() ) {
74
- update_site_option( $key, $value );
75
- } else {
76
- update_option( $key, $value );
77
- }
78
-
79
- }
80
-
81
- /**
82
- * Get single setting
83
- *
84
- * @since 1.1.4
85
- *
86
- * @param string $key Option key.
87
- * @param string $default Option default value if not exist.
88
- * @return mixed
89
- */
90
- static public function get_common_setting( $key = '', $default = '' ) {
91
- $settings = self::get_common_settings();
92
-
93
- if ( $settings && array_key_exists( $key, $settings ) ) {
94
- return $settings[ $key ];
95
- }
96
-
97
- return $default;
98
- }
99
-
100
- /**
101
- * Get required plugins for page builder
102
- *
103
- * @since 1.1.4
104
- *
105
- * @param string $page_builder_slug Page builder slug.
106
- * @param string $default Default page builder.
107
- * @return array selected page builder required plugins list.
108
- */
109
- public static function get_required_plugins_for_page_builder( $page_builder_slug = '', $default = 'elementor' ) {
110
- $plugins = self::get_plugins_groupby_page_builders();
111
-
112
- if ( array_key_exists( $page_builder_slug, $plugins ) ) {
113
- return $plugins[ $page_builder_slug ];
114
- }
115
-
116
- return $plugins[ $default ];
117
- }
118
-
119
- /**
120
- * Get Plugins list by page builder.
121
- *
122
- * @since 1.1.4
123
- *
124
- * @return array Required Plugins list.
125
- */
126
- public static function get_plugins_groupby_page_builders() {
127
-
128
- $divi_status = self::get_plugin_status( 'divi-builder/divi-builder.php' );
129
- $theme_status = 'not-installed';
130
- if ( $divi_status ) {
131
- if ( true === Cartflows_Compatibility::get_instance()->is_divi_theme_installed() ) {
132
- $theme_status = 'installed';
133
- if ( false === Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
134
- $theme_status = 'deactivate';
135
- $divi_status = 'activate';
136
- } else {
137
- $divi_status = '';
138
- }
139
- }
140
- }
141
-
142
- $plugins = array(
143
- 'elementor' => array(
144
- 'title' => 'Elementor',
145
- 'plugins' => array(
146
- array(
147
- 'slug' => 'elementor', // For download from wp.org.
148
- 'init' => 'elementor/elementor.php',
149
- 'status' => self::get_plugin_status( 'elementor/elementor.php' ),
150
- ),
151
- ),
152
- ),
153
- 'divi' => array(
154
- 'title' => 'Divi',
155
- 'theme-status' => $theme_status,
156
- 'plugin-status' => $divi_status,
157
- 'plugins' => array(
158
- array(
159
- 'slug' => 'divi-builder', // For download from wp.org.
160
- 'init' => 'divi-builder/divi-builder.php',
161
- 'status' => $divi_status,
162
- ),
163
- ),
164
- ),
165
- );
166
-
167
- $plugins['beaver-builder'] = array(
168
- 'title' => 'Beaver Builder',
169
- 'plugins' => array(),
170
- );
171
-
172
- // Check Pro Exist.
173
- if ( file_exists( WP_PLUGIN_DIR . '/' . 'bb-plugin/fl-builder.php' ) && ! is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) ) {
174
- $plugins['beaver-builder']['plugins'][] = array(
175
- 'slug' => 'bb-plugin',
176
- 'init' => 'bb-plugin/fl-builder.php',
177
- 'status' => self::get_plugin_status( 'bb-plugin/fl-builder.php' ),
178
- );
179
- } else {
180
- $plugins['beaver-builder']['plugins'][] = array(
181
- 'slug' => 'beaver-builder-lite-version', // For download from wp.org.
182
- 'init' => 'beaver-builder-lite-version/fl-builder.php',
183
- 'status' => self::get_plugin_status( 'beaver-builder-lite-version/fl-builder.php' ),
184
- );
185
- }
186
-
187
- if ( file_exists( WP_PLUGIN_DIR . '/' . 'bb-ultimate-addon/bb-ultimate-addon.php' ) && ! is_plugin_active( 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' ) ) {
188
- $plugins['beaver-builder']['plugins'][] = array(
189
- 'slug' => 'bb-ultimate-addon',
190
- 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
191
- 'status' => self::get_plugin_status( 'bb-ultimate-addon/bb-ultimate-addon.php' ),
192
- );
193
- } else {
194
- $plugins['beaver-builder']['plugins'][] = array(
195
- 'slug' => 'ultimate-addons-for-beaver-builder-lite', // For download from wp.org.
196
- 'init' => 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php',
197
- 'status' => self::get_plugin_status( 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' ),
198
- );
199
- }
200
-
201
- return $plugins;
202
- }
203
-
204
- /**
205
- * Get plugin status
206
- *
207
- * @since 1.1.4
208
- *
209
- * @param string $plugin_init_file Plguin init file.
210
- * @return mixed
211
- */
212
- public static function get_plugin_status( $plugin_init_file ) {
213
-
214
- if ( null == self::$installed_plugins ) {
215
- self::$installed_plugins = get_plugins();
216
- }
217
-
218
- if ( ! isset( self::$installed_plugins[ $plugin_init_file ] ) ) {
219
- return 'install';
220
- } elseif ( ! is_plugin_active( $plugin_init_file ) ) {
221
- return 'activate';
222
- }
223
-
224
- return;
225
- }
226
-
227
- /**
228
- * Get zapier settings.
229
- *
230
- * @return array.
231
- */
232
- static public function get_common_settings() {
233
-
234
- if ( null === self::$common ) {
235
-
236
- $common_default = apply_filters(
237
- 'cartflows_common_settings_default',
238
- array(
239
- 'disallow_indexing' => 'disable',
240
- 'global_checkout' => '',
241
- 'default_page_builder' => 'elementor',
242
- )
243
- );
244
-
245
- $common = Cartflows_Helper::get_admin_settings_option( '_cartflows_common', false, true );
246
-
247
- $common = wp_parse_args( $common, $common_default );
248
-
249
- if ( ! did_action( 'wp' ) ) {
250
- return $common;
251
- } else {
252
- self::$common = $common;
253
- }
254
- }
255
-
256
- return self::$common;
257
- }
258
-
259
- /**
260
- * Get Checkout field.
261
- *
262
- * @param string $key Field key.
263
- * @param int $post_id Post id.
264
- * @return array.
265
- */
266
- static public function get_checkout_fields( $key, $post_id ) {
267
-
268
- $saved_fields = get_post_meta( $post_id, 'wcf_fields_' . $key, true );
269
-
270
- if ( ! $saved_fields ) {
271
- $saved_fields = array();
272
- }
273
-
274
- $fields = array_filter( $saved_fields );
275
-
276
- if ( empty( $fields ) ) {
277
- if ( 'billing' === $key || 'shipping' === $key ) {
278
-
279
- $fields = WC()->countries->get_address_fields( WC()->countries->get_base_country(), $key . '_' );
280
-
281
- update_post_meta( $post_id, 'wcf_fields_' . $key, $fields );
282
- }
283
- }
284
-
285
- return $fields;
286
- }
287
-
288
- /**
289
- * Add Checkout field.
290
- *
291
- * @param string $type Field type.
292
- * @param string $field_key Field key.
293
- * @param array $field_data Field data.
294
- * @param int $post_id Post id.
295
- * @return boolean.
296
- */
297
- static public function add_checkout_field( $type, $field_key, $field_data = array(), $post_id ) {
298
-
299
- $fields = self::get_checkout_fields( $type, $post_id );
300
-
301
- $fields[ $field_key ] = $field_data;
302
-
303
- update_post_meta( $post_id, 'wcf_fields_' . $type, $fields );
304
-
305
- return true;
306
- }
307
-
308
- /**
309
- * Get checkout fields settings.
310
- *
311
- * @param string $type Field type.
312
- * @param string $field_key Field key.
313
- * @param int $post_id Post id.
314
- * @return array.
315
- */
316
- static public function delete_checkout_field( $type, $field_key, $post_id ) {
317
-
318
- $fields = self::get_checkout_fields( $type, $post_id );
319
-
320
- if ( isset( $fields[ $field_key ] ) ) {
321
- unset( $fields[ $field_key ] );
322
- }
323
-
324
- update_post_meta( $post_id, 'wcf_fields_' . $type, $fields );
325
-
326
- return true;
327
- }
328
-
329
- /**
330
- * Get checkout fields settings.
331
- *
332
- * @return array.
333
- */
334
- static public function get_checkout_fields_settings() {
335
-
336
- if ( null === self::$checkout_fields ) {
337
- $checkout_fields_default = array(
338
- 'enable_customization' => 'disable',
339
- 'enable_billing_fields' => 'disable',
340
- );
341
-
342
- $billing_fields = self::get_checkout_fields( 'billing' );
343
-
344
- if ( is_array( $billing_fields ) && ! empty( $billing_fields ) ) {
345
-
346
- foreach ( $billing_fields as $key => $value ) {
347
-
348
- $checkout_fields_default[ $key ] = 'enable';
349
- }
350
- }
351
-
352
- $checkout_fields = Cartflows_Helper::get_admin_settings_option( '_wcf_checkout_fields', false, true );
353
-
354
- self::$checkout_fields = wp_parse_args( $checkout_fields, $checkout_fields_default );
355
- }
356
-
357
- return self::$checkout_fields;
358
- }
359
-
360
- /**
361
- * Get meta options
362
- *
363
- * @since 1.0.0
364
- * @param int $post_id Product ID.
365
- * @param string $key Meta Key.
366
- * @param string $default Default value.
367
- * @return string Meta Value.
368
- */
369
- static public function get_meta_option( $post_id, $key, $default = '' ) {
370
-
371
- $value = get_post_meta( $post_id, $key, true );
372
-
373
- if ( ! $value ) {
374
- $value = $default;
375
- }
376
-
377
- return $value;
378
- }
379
-
380
- /**
381
- * Save meta option
382
- *
383
- * @since 1.0.0
384
- * @param int $post_id Product ID.
385
- * @param array $args Arguments array.
386
- */
387
- static public function save_meta_option( $post_id, $args = array() ) {
388
-
389
- if ( is_array( $args ) && ! empty( $args ) ) {
390
-
391
- foreach ( $args as $key => $value ) {
392
-
393
- update_post_meta( $post_id, $key, $value );
394
- }
395
- }
396
- }
397
-
398
- /**
399
- * Check if Elementor page builder is installed
400
- *
401
- * @since 1.0.0
402
- *
403
- * @access public
404
- */
405
- static public function _is_elementor_installed() {
406
- $path = 'elementor/elementor.php';
407
- $plugins = get_plugins();
408
-
409
- return isset( $plugins[ $path ] );
410
- }
411
-
412
- /**
413
- * Check if Step has product assigned.
414
- *
415
- * @since 1.0.0
416
- * @param int $step_id step ID.
417
- *
418
- * @access public
419
- */
420
- static public function has_product_assigned( $step_id ) {
421
-
422
- $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
423
-
424
- if ( 'checkout' == $step_type ) {
425
- $product = get_post_meta( $step_id, 'wcf-checkout-products', true );
426
- } else {
427
- $product = get_post_meta( $step_id, 'wcf-offer-product', true );
428
- }
429
-
430
- if ( ! empty( $product ) ) {
431
- return true;
432
- }
433
- return false;
434
-
435
- }
436
-
437
- /**
438
- * Get attributes for cartflows wrap.
439
- *
440
- * @since 1.1.4
441
- *
442
- * @access public
443
- */
444
- static public function get_cartflows_container_atts() {
445
-
446
- $attributes = apply_filters( 'cartflows_container_atts', array() );
447
- $atts_string = '';
448
-
449
- foreach ( $attributes as $key => $value ) {
450
-
451
- if ( ! $value ) {
452
- continue;
453
- }
454
-
455
- if ( true === $value ) {
456
- $atts_string .= esc_html( $key ) . ' ';
457
- } else {
458
- $atts_string .= sprintf( '%s="%s" ', esc_html( $key ), esc_attr( $value ) );
459
- }
460
- }
461
-
462
- return $atts_string;
463
- }
464
- }
1
+ <?php
2
+ /**
3
+ * CARTFLOWS Helper.
4
+ *
5
+ * @package CARTFLOWS
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit; // Exit if accessed directly.
10
+ }
11
+
12
+ /**
13
+ * Class Cartflows_Helper.
14
+ */
15
+ class Cartflows_Helper {
16
+
17
+ /**
18
+ * Common global data
19
+ *
20
+ * @var zapier
21
+ */
22
+ private static $common = null;
23
+
24
+ /**
25
+ * Installed Plugins
26
+ *
27
+ * @since 1.1.4
28
+ *
29
+ * @access private
30
+ * @var array Installed plugins list.
31
+ */
32
+ private static $installed_plugins = null;
33
+
34
+ /**
35
+ * Checkout Fields
36
+ *
37
+ * @var checkout_fields
38
+ */
39
+ private static $checkout_fields = null;
40
+
41
+ /**
42
+ * Returns an option from the database for
43
+ * the admin settings page.
44
+ *
45
+ * @param string $key The option key.
46
+ * @param mixed $default Option default value if option is not available.
47
+ * @param boolean $network_override Whether to allow the network admin setting to be overridden on subsites.
48
+ * @return string Return the option value
49
+ */
50
+ public static function get_admin_settings_option( $key, $default = false, $network_override = false ) {
51
+
52
+ // Get the site-wide option if we're in the network admin.
53
+ if ( $network_override && is_multisite() ) {
54
+ $value = get_site_option( $key, $default );
55
+ } else {
56
+ $value = get_option( $key, $default );
57
+ }
58
+
59
+ return $value;
60
+ }
61
+
62
+ /**
63
+ * Updates an option from the admin settings page.
64
+ *
65
+ * @param string $key The option key.
66
+ * @param mixed $value The value to update.
67
+ * @param bool $network Whether to allow the network admin setting to be overridden on subsites.
68
+ * @return mixed
69
+ */
70
+ static public function update_admin_settings_option( $key, $value, $network = false ) {
71
+
72
+ // Update the site-wide option since we're in the network admin.
73
+ if ( $network && is_multisite() ) {
74
+ update_site_option( $key, $value );
75
+ } else {
76
+ update_option( $key, $value );
77
+ }
78
+
79
+ }
80
+
81
+ /**
82
+ * Get single setting
83
+ *
84
+ * @since 1.1.4
85
+ *
86
+ * @param string $key Option key.
87
+ * @param string $default Option default value if not exist.
88
+ * @return mixed
89
+ */
90
+ static public function get_common_setting( $key = '', $default = '' ) {
91
+ $settings = self::get_common_settings();
92
+
93
+ if ( $settings && array_key_exists( $key, $settings ) ) {
94
+ return $settings[ $key ];
95
+ }
96
+
97
+ return $default;
98
+ }
99
+
100
+ /**
101
+ * Get required plugins for page builder
102
+ *
103
+ * @since 1.1.4
104
+ *
105
+ * @param string $page_builder_slug Page builder slug.
106
+ * @param string $default Default page builder.
107
+ * @return array selected page builder required plugins list.
108
+ */
109
+ public static function get_required_plugins_for_page_builder( $page_builder_slug = '', $default = 'elementor' ) {
110
+ $plugins = self::get_plugins_groupby_page_builders();
111
+
112
+ if ( array_key_exists( $page_builder_slug, $plugins ) ) {
113
+ return $plugins[ $page_builder_slug ];
114
+ }
115
+
116
+ return $plugins[ $default ];
117
+ }
118
+
119
+ /**
120
+ * Get Plugins list by page builder.
121
+ *
122
+ * @since 1.1.4
123
+ *
124
+ * @return array Required Plugins list.
125
+ */
126
+ public static function get_plugins_groupby_page_builders() {
127
+
128
+ $divi_status = self::get_plugin_status( 'divi-builder/divi-builder.php' );
129
+ $theme_status = 'not-installed';
130
+ if ( $divi_status ) {
131
+ if ( true === Cartflows_Compatibility::get_instance()->is_divi_theme_installed() ) {
132
+ $theme_status = 'installed';
133
+ if ( false === Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
134
+ $theme_status = 'deactivate';
135
+ $divi_status = 'activate';
136
+ } else {
137
+ $divi_status = '';
138
+ }
139
+ }
140
+ }
141
+
142
+ $plugins = array(
143
+ 'elementor' => array(
144
+ 'title' => 'Elementor',
145
+ 'plugins' => array(
146
+ array(
147
+ 'slug' => 'elementor', // For download from wp.org.
148
+ 'init' => 'elementor/elementor.php',
149
+ 'status' => self::get_plugin_status( 'elementor/elementor.php' ),
150
+ ),
151
+ ),
152
+ ),
153
+ 'divi' => array(
154
+ 'title' => 'Divi',
155
+ 'theme-status' => $theme_status,
156
+ 'plugin-status' => $divi_status,
157
+ 'plugins' => array(
158
+ array(
159
+ 'slug' => 'divi-builder', // For download from wp.org.
160
+ 'init' => 'divi-builder/divi-builder.php',
161
+ 'status' => $divi_status,
162
+ ),
163
+ ),
164
+ ),
165
+ );
166
+
167
+ $plugins['beaver-builder'] = array(
168
+ 'title' => 'Beaver Builder',
169
+ 'plugins' => array(),
170
+ );
171
+
172
+ // Check Pro Exist.
173
+ if ( file_exists( WP_PLUGIN_DIR . '/' . 'bb-plugin/fl-builder.php' ) && ! is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) ) {
174
+ $plugins['beaver-builder']['plugins'][] = array(
175
+ 'slug' => 'bb-plugin',
176
+ 'init' => 'bb-plugin/fl-builder.php',
177
+ 'status' => self::get_plugin_status( 'bb-plugin/fl-builder.php' ),
178
+ );
179
+ } else {
180
+ $plugins['beaver-builder']['plugins'][] = array(
181
+ 'slug' => 'beaver-builder-lite-version', // For download from wp.org.
182
+ 'init' => 'beaver-builder-lite-version/fl-builder.php',
183
+ 'status' => self::get_plugin_status( 'beaver-builder-lite-version/fl-builder.php' ),
184
+ );
185
+ }
186
+
187
+ if ( file_exists( WP_PLUGIN_DIR . '/' . 'bb-ultimate-addon/bb-ultimate-addon.php' ) && ! is_plugin_active( 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' ) ) {
188
+ $plugins['beaver-builder']['plugins'][] = array(
189
+ 'slug' => 'bb-ultimate-addon',
190
+ 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
191
+ 'status' => self::get_plugin_status( 'bb-ultimate-addon/bb-ultimate-addon.php' ),
192
+ );
193
+ } else {
194
+ $plugins['beaver-builder']['plugins'][] = array(
195
+ 'slug' => 'ultimate-addons-for-beaver-builder-lite', // For download from wp.org.
196
+ 'init' => 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php',
197
+ 'status' => self::get_plugin_status( 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' ),
198
+ );
199
+ }
200
+
201
+ return $plugins;
202
+ }
203
+
204
+ /**
205
+ * Get plugin status
206
+ *
207
+ * @since 1.1.4
208
+ *
209
+ * @param string $plugin_init_file Plguin init file.
210
+ * @return mixed
211
+ */
212
+ public static function get_plugin_status( $plugin_init_file ) {
213
+
214
+ if ( null == self::$installed_plugins ) {
215
+ self::$installed_plugins = get_plugins();
216
+ }
217
+
218
+ if ( ! isset( self::$installed_plugins[ $plugin_init_file ] ) ) {
219
+ return 'install';
220
+ } elseif ( ! is_plugin_active( $plugin_init_file ) ) {
221
+ return 'activate';
222
+ }
223
+
224
+ return;
225
+ }
226
+
227
+ /**
228
+ * Get zapier settings.
229
+ *
230
+ * @return array.
231
+ */
232
+ static public function get_common_settings() {
233
+
234
+ if ( null === self::$common ) {
235
+
236
+ $common_default = apply_filters(
237
+ 'cartflows_common_settings_default',
238
+ array(
239
+ 'disallow_indexing' => 'disable',
240
+ 'global_checkout' => '',
241
+ 'default_page_builder' => 'elementor',
242
+ )
243
+ );
244
+
245
+ $common = Cartflows_Helper::get_admin_settings_option( '_cartflows_common', false, true );
246
+
247
+ $common = wp_parse_args( $common, $common_default );
248
+
249
+ if ( ! did_action( 'wp' ) ) {
250
+ return $common;
251
+ } else {
252
+ self::$common = $common;
253
+ }
254
+ }
255
+
256
+ return self::$common;
257
+ }
258
+
259
+ /**
260
+ * Get Checkout field.
261
+ *
262
+ * @param string $key Field key.
263
+ * @param int $post_id Post id.
264
+ * @return array.
265
+ */
266
+ static public function get_checkout_fields( $key, $post_id ) {
267
+
268
+ $saved_fields = get_post_meta( $post_id, 'wcf_fields_' . $key, true );
269
+
270
+ if ( ! $saved_fields ) {
271
+ $saved_fields = array();
272
+ }
273
+
274
+ $fields = array_filter( $saved_fields );
275
+
276
+ if ( empty( $fields ) ) {
277
+ if ( 'billing' === $key || 'shipping' === $key ) {
278
+
279
+ $fields = WC()->countries->get_address_fields( WC()->countries->get_base_country(), $key . '_' );
280
+
281
+ update_post_meta( $post_id, 'wcf_fields_' . $key, $fields );
282
+ }
283
+ }
284
+
285
+ return $fields;
286
+ }
287
+
288
+ /**
289
+ * Add Checkout field.
290
+ *
291
+ * @param string $type Field type.
292
+ * @param string $field_key Field key.
293
+ * @param array $field_data Field data.
294
+ * @param int $post_id Post id.
295
+ * @return boolean.
296
+ */
297
+ static public function add_checkout_field( $type, $field_key, $field_data = array(), $post_id ) {
298
+
299
+ $fields = self::get_checkout_fields( $type, $post_id );
300
+
301
+ $fields[ $field_key ] = $field_data;
302
+
303
+ update_post_meta( $post_id, 'wcf_fields_' . $type, $fields );
304
+
305
+ return true;
306
+ }
307
+
308
+ /**
309
+ * Get checkout fields settings.
310
+ *
311
+ * @param string $type Field type.
312
+ * @param string $field_key Field key.
313
+ * @param int $post_id Post id.
314
+ * @return array.
315
+ */
316
+ static public function delete_checkout_field( $type, $field_key, $post_id ) {
317
+
318
+ $fields = self::get_checkout_fields( $type, $post_id );
319
+
320
+ if ( isset( $fields[ $field_key ] ) ) {
321
+ unset( $fields[ $field_key ] );
322
+ }
323
+
324
+ update_post_meta( $post_id, 'wcf_fields_' . $type, $fields );
325
+
326
+ return true;
327
+ }
328
+
329
+ /**
330
+ * Get checkout fields settings.
331
+ *
332
+ * @return array.
333
+ */
334
+ static public function get_checkout_fields_settings() {
335
+
336
+ if ( null === self::$checkout_fields ) {
337
+ $checkout_fields_default = array(
338
+ 'enable_customization' => 'disable',
339
+ 'enable_billing_fields' => 'disable',
340
+ );
341
+
342
+ $billing_fields = self::get_checkout_fields( 'billing' );
343
+
344
+ if ( is_array( $billing_fields ) && ! empty( $billing_fields ) ) {
345
+
346
+ foreach ( $billing_fields as $key => $value ) {
347
+
348
+ $checkout_fields_default[ $key ] = 'enable';
349
+ }
350
+ }
351
+
352
+ $checkout_fields = Cartflows_Helper::get_admin_settings_option( '_wcf_checkout_fields', false, true );
353
+
354
+ self::$checkout_fields = wp_parse_args( $checkout_fields, $checkout_fields_default );
355
+ }
356
+
357
+ return self::$checkout_fields;
358
+ }
359
+
360
+ /**
361
+ * Get meta options
362
+ *
363
+ * @since 1.0.0
364
+ * @param int $post_id Product ID.
365
+ * @param string $key Meta Key.
366
+ * @param string $default Default value.
367
+ * @return string Meta Value.
368
+ */
369
+ static public function get_meta_option( $post_id, $key, $default = '' ) {
370
+
371
+ $value = get_post_meta( $post_id, $key, true );
372
+
373
+ if ( ! $value ) {
374
+ $value = $default;
375
+ }
376
+
377
+ return $value;
378
+ }
379
+
380
+ /**
381
+ * Save meta option
382
+ *
383
+ * @since 1.0.0
384
+ * @param int $post_id Product ID.
385
+ * @param array $args Arguments array.
386
+ */
387
+ static public function save_meta_option( $post_id, $args = array() ) {
388
+
389
+ if ( is_array( $args ) && ! empty( $args ) ) {
390
+
391
+ foreach ( $args as $key => $value ) {
392
+
393
+ update_post_meta( $post_id, $key, $value );
394
+ }
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Check if Elementor page builder is installed
400
+ *
401
+ * @since 1.0.0
402
+ *
403
+ * @access public
404
+ */
405
+ static public function _is_elementor_installed() {
406
+ $path = 'elementor/elementor.php';
407
+ $plugins = get_plugins();
408
+
409
+ return isset( $plugins[ $path ] );
410
+ }
411
+
412
+ /**
413
+ * Check if Step has product assigned.
414
+ *
415
+ * @since 1.0.0
416
+ * @param int $step_id step ID.
417
+ *
418
+ * @access public
419
+ */
420
+ static public function has_product_assigned( $step_id ) {
421
+
422
+ $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
423
+
424
+ if ( 'checkout' == $step_type ) {
425
+ $product = get_post_meta( $step_id, 'wcf-checkout-products', true );
426
+ } else {
427
+ $product = get_post_meta( $step_id, 'wcf-offer-product', true );
428
+ }
429
+
430
+ if ( ! empty( $product ) ) {
431
+ return true;
432
+ }
433
+ return false;
434
+
435
+ }
436
+
437
+ /**
438
+ * Get attributes for cartflows wrap.
439
+ *
440
+ * @since 1.1.4
441
+ *
442
+ * @access public
443
+ */
444
+ static public function get_cartflows_container_atts() {
445
+
446
+ $attributes = apply_filters( 'cartflows_container_atts', array() );
447
+ $atts_string = '';
448
+
449
+ foreach ( $attributes as $key => $value ) {
450
+
451
+ if ( ! $value ) {
452
+ continue;
453
+ }
454
+
455
+ if ( true === $value ) {
456
+ $atts_string .= esc_html( $key ) . ' ';
457
+ } else {
458
+ $atts_string .= sprintf( '%s="%s" ', esc_html( $key ), esc_attr( $value ) );
459
+ }
460
+ }
461
+
462
+ return $atts_string;
463
+ }
464
+ }
classes/class-cartflows-importer-core.php CHANGED
@@ -1,272 +1,272 @@
1
- <?php
2
- /**
3
- * Image Importer
4
- *
5
- * => How to use?
6
- *
7
- * $image = array(
8
- * 'url' => '<image-url>',
9
- * 'id' => '<image-id>',
10
- * );
11
- *
12
- * $downloaded_image = CartFlows_Importer_Core::get_instance()->import( $image );
13
- *
14
- * @package CartFlows
15
- * @since 1.0.0
16
- */
17
-
18
- if ( ! class_exists( 'CartFlows_Importer_Core' ) ) :
19
-
20
- /**
21
- * CartFlows Importer
22
- *
23
- * @since 1.0.0
24
- */
25
- class CartFlows_Importer_Core {
26
-
27
- /**
28
- * Instance
29
- *
30
- * @since 1.0.0
31
- * @var object Class object.
32
- * @access private
33
- */
34
- private static $instance;
35
-
36
- /**
37
- * Images IDs
38
- *
39
- * @var array The Array of already image IDs.
40
- * @since 1.0.0
41
- */
42
- private $already_imported_ids = array();
43
-
44
- /**
45
- * Initiator
46
- *
47
- * @since 1.0.0
48
- * @return object initialized object of class.
49
- */
50
- public static function get_instance() {
51
- if ( ! isset( self::$instance ) ) {
52
- self::$instance = new self;
53
- }
54
- return self::$instance;
55
- }
56
-
57
- /**
58
- * Constructor
59
- *
60
- * @since 1.0.0
61
- */
62
- public function __construct() {
63
-
64
- if ( ! function_exists( 'WP_Filesystem' ) ) {
65
- require_once ABSPATH . 'wp-admin/includes/file.php';
66
- }
67
-
68
- WP_Filesystem();
69
- }
70
-
71
- /**
72
- * Process Image Download
73
- *
74
- * @since 1.0.0
75
- * @param array $attachments Attachment array.
76
- * @return array Attachment array.
77
- */
78
- public function process( $attachments ) {
79
-
80
- $downloaded_images = array();
81
-
82
- foreach ( $attachments as $key => $attachment ) {
83
- $downloaded_images[] = $this->import( $attachment );
84
- }
85
-
86
- return $downloaded_images;
87
- }
88
-
89
- /**
90
- * Get Hash Image.
91
- *
92
- * @since 1.0.0
93
- * @param string $attachment_url Attachment URL.
94
- * @return string Hash string.
95
- */
96
- private function get_hash_image( $attachment_url ) {
97
- return sha1( $attachment_url );
98
- }
99
-
100
- /**
101
- * Get Saved Image.
102
- *
103
- * @since 1.0.0
104
- * @param string $attachment Attachment Data.
105
- * @return string Hash string.
106
- */
107
- private function get_saved_image( $attachment ) {
108
-
109
- wcf()->logger->import_log( 'importer-core.php File' );
110
-
111
- if ( apply_filters( 'cartflows_image_importer_skip_image', false, $attachment ) ) {
112
-
113
- self::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
114
-
115
- return $attachment;
116
- }
117
-
118
- global $wpdb;
119
-
120
- // Already imported? Then return!
121
- if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
122
-
123
- self::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
124
-
125
- return $this->already_imported_ids[ $attachment['id'] ];
126
- }
127
-
128
- // 1. Is already imported in Batch Import Process?
129
- $post_id = $wpdb->get_var(
130
- $wpdb->prepare(
131
- 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
132
- WHERE `meta_key` = \'_cartflows_image_hash\'
133
- AND `meta_value` = %s
134
- ;',
135
- $this->get_hash_image( $attachment['url'] )
136
- )
137
- );
138
-
139
- // 2. Is image already imported though XML?
140
- if ( empty( $post_id ) ) {
141
-
142
- // Get file name without extension.
143
- // To check it exist in attachment.
144
- $filename = preg_replace( '/\\.[^.\\s]{3,4}$/', '', basename( $attachment['url'] ) );
145
-
146
- $post_id = $wpdb->get_var(
147
- $wpdb->prepare(
148
- 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
149
- WHERE `meta_key` = \'_wp_attached_file\'
150
- AND `meta_value` LIKE %s
151
- ;',
152
- '%' . $filename . '%'
153
- )
154
- );
155
-
156
- self::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
157
- }
158
-
159
- if ( $post_id ) {
160
-
161
- $new_imgage_url = wp_get_attachment_url( $post_id );
162
- $new_attachment = array(
163
- 'id' => $post_id,
164
- 'url' => $new_imgage_url,
165
- );
166
- $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
167
-
168
- self::log( 'Download (✓) Replace (✓) - ' . $new_imgage_url );
169
- return $new_attachment;
170
- }
171
-
172
- return false;
173
- }
174
-
175
- /**
176
- * Import Image
177
- *
178
- * @since 1.0.0
179
- * @param array $attachment Attachment array.
180
- * @return array Attachment array.
181
- */
182
- public function import( $attachment ) {
183
-
184
- $saved_image = $this->get_saved_image( $attachment );
185
- if ( $saved_image ) {
186
- return $saved_image;
187
- }
188
-
189
- $args = array(
190
- 'timeout' => 300,
191
- );
192
-
193
- $file_content = wp_remote_retrieve_body( wp_safe_remote_get( $attachment['url'], $args ) );
194
-
195
- // Empty file content?
196
- if ( empty( $file_content ) ) {
197
-
198
- self::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
199
- self::log( 'Error: Failed wp_remote_retrieve_body().' );
200
-
201
- return $attachment;
202
- }
203
-
204
- // Extract the file name and extension from the URL.
205
- $filename = basename( $attachment['url'] );
206
-
207
- $upload = wp_upload_bits(
208
- $filename,
209
- null,
210
- $file_content
211
- );
212
-
213
- $post = array(
214
- 'post_title' => $filename,
215
- 'guid' => $upload['url'],
216
- );
217
-
218
- $info = wp_check_filetype( $upload['file'] );
219
- if ( $info ) {
220
- $post['post_mime_type'] = $info['type'];
221
- } else {
222
- // For now just return the origin attachment.
223
- return $attachment;
224
- }
225
-
226
- $post_id = wp_insert_attachment( $post, $upload['file'] );
227
- wp_update_attachment_metadata(
228
- $post_id,
229
- wp_generate_attachment_metadata( $post_id, $upload['file'] )
230
- );
231
- update_post_meta( $post_id, '_cartflows_image_hash', $this->get_hash_image( $attachment['url'] ) );
232
-
233
- $new_attachment = array(
234
- 'id' => $post_id,
235
- 'url' => $upload['url'],
236
- );
237
-
238
- self::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
239
-
240
- $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
241
-
242
- return $new_attachment;
243
- }
244
-
245
- /**
246
- * Debugging Log.
247
- *
248
- * @since 1.0.0
249
- * @param mixed $log Log data.
250
- * @return void
251
- */
252
- public static function log( $log ) {
253
-
254
- if ( ! WP_DEBUG_LOG ) {
255
- return;
256
- }
257
-
258
- if ( is_array( $log ) || is_object( $log ) ) {
259
- wcf()->logger->import_log( print_r( $log, true ) );
260
- } else {
261
- wcf()->logger->import_log( $log );
262
- }
263
- }
264
-
265
- }
266
-
267
- /**
268
- * Initialize class object with 'get_instance()' method
269
- */
270
- CartFlows_Importer_Core::get_instance();
271
-
272
- endif;
1
+ <?php
2
+ /**
3
+ * Image Importer
4
+ *
5
+ * => How to use?
6
+ *
7
+ * $image = array(
8
+ * 'url' => '<image-url>',
9
+ * 'id' => '<image-id>',
10
+ * );
11
+ *
12
+ * $downloaded_image = CartFlows_Importer_Core::get_instance()->import( $image );
13
+ *
14
+ * @package CartFlows
15
+ * @since 1.0.0
16
+ */
17
+
18
+ if ( ! class_exists( 'CartFlows_Importer_Core' ) ) :
19
+
20
+ /**
21
+ * CartFlows Importer
22
+ *
23
+ * @since 1.0.0
24
+ */
25
+ class CartFlows_Importer_Core {
26
+
27
+ /**
28
+ * Instance
29
+ *
30
+ * @since 1.0.0
31
+ * @var object Class object.
32
+ * @access private
33
+ */
34
+ private static $instance;
35
+
36
+ /**
37
+ * Images IDs
38
+ *
39
+ * @var array The Array of already image IDs.
40
+ * @since 1.0.0
41
+ */
42
+ private $already_imported_ids = array();
43
+
44
+ /**
45
+ * Initiator
46
+ *
47
+ * @since 1.0.0
48
+ * @return object initialized object of class.
49
+ */
50
+ public static function get_instance() {
51
+ if ( ! isset( self::$instance ) ) {
52
+ self::$instance = new self;
53
+ }
54
+ return self::$instance;
55
+ }
56
+
57
+ /**
58
+ * Constructor
59
+ *
60
+ * @since 1.0.0
61
+ */
62
+ public function __construct() {
63
+
64
+ if ( ! function_exists( 'WP_Filesystem' ) ) {
65
+ require_once ABSPATH . 'wp-admin/includes/file.php';
66
+ }
67
+
68
+ WP_Filesystem();
69
+ }
70
+
71
+ /**
72
+ * Process Image Download
73
+ *
74
+ * @since 1.0.0
75
+ * @param array $attachments Attachment array.
76
+ * @return array Attachment array.
77
+ */
78
+ public function process( $attachments ) {
79
+
80
+ $downloaded_images = array();
81
+
82
+ foreach ( $attachments as $key => $attachment ) {
83
+ $downloaded_images[] = $this->import( $attachment );
84
+ }
85
+
86
+ return $downloaded_images;
87
+ }
88
+
89
+ /**
90
+ * Get Hash Image.
91
+ *
92
+ * @since 1.0.0
93
+ * @param string $attachment_url Attachment URL.
94
+ * @return string Hash string.
95
+ */
96
+ private function get_hash_image( $attachment_url ) {
97
+ return sha1( $attachment_url );
98
+ }
99
+
100
+ /**
101
+ * Get Saved Image.
102
+ *
103
+ * @since 1.0.0
104
+ * @param string $attachment Attachment Data.
105
+ * @return string Hash string.
106
+ */
107
+ private function get_saved_image( $attachment ) {
108
+
109
+ wcf()->logger->import_log( 'importer-core.php File' );
110
+
111
+ if ( apply_filters( 'cartflows_image_importer_skip_image', false, $attachment ) ) {
112
+
113
+ self::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
114
+
115
+ return $attachment;
116
+ }
117
+
118
+ global $wpdb;
119
+
120
+ // Already imported? Then return!
121
+ if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
122
+
123
+ self::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
124
+
125
+ return $this->already_imported_ids[ $attachment['id'] ];
126
+ }
127
+
128
+ // 1. Is already imported in Batch Import Process?
129
+ $post_id = $wpdb->get_var(
130
+ $wpdb->prepare(
131
+ 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
132
+ WHERE `meta_key` = \'_cartflows_image_hash\'
133
+ AND `meta_value` = %s
134
+ ;',
135
+ $this->get_hash_image( $attachment['url'] )
136
+ )
137
+ );
138
+
139
+ // 2. Is image already imported though XML?
140
+ if ( empty( $post_id ) ) {
141
+
142
+ // Get file name without extension.
143
+ // To check it exist in attachment.
144
+ $filename = preg_replace( '/\\.[^.\\s]{3,4}$/', '', basename( $attachment['url'] ) );
145
+
146
+ $post_id = $wpdb->get_var(
147
+ $wpdb->prepare(
148
+ 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
149
+ WHERE `meta_key` = \'_wp_attached_file\'
150
+ AND `meta_value` LIKE %s
151
+ ;',
152
+ '%' . $filename . '%'
153
+ )
154
+ );
155
+
156
+ self::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
157
+ }
158
+
159
+ if ( $post_id ) {
160
+
161
+ $new_imgage_url = wp_get_attachment_url( $post_id );
162
+ $new_attachment = array(
163
+ 'id' => $post_id,
164
+ 'url' => $new_imgage_url,
165
+ );
166
+ $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
167
+
168
+ self::log( 'Download (✓) Replace (✓) - ' . $new_imgage_url );
169
+ return $new_attachment;
170
+ }
171
+
172
+ return false;
173
+ }
174
+
175
+ /**
176
+ * Import Image
177
+ *
178
+ * @since 1.0.0
179
+ * @param array $attachment Attachment array.
180
+ * @return array Attachment array.
181
+ */
182
+ public function import( $attachment ) {
183
+
184
+ $saved_image = $this->get_saved_image( $attachment );
185
+ if ( $saved_image ) {
186
+ return $saved_image;
187
+ }
188
+
189
+ $args = array(
190
+ 'timeout' => 300,
191
+ );
192
+
193
+ $file_content = wp_remote_retrieve_body( wp_safe_remote_get( $attachment['url'], $args ) );
194
+
195
+ // Empty file content?
196
+ if ( empty( $file_content ) ) {
197
+
198
+ self::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
199
+ self::log( 'Error: Failed wp_remote_retrieve_body().' );
200
+
201
+ return $attachment;
202
+ }
203
+
204
+ // Extract the file name and extension from the URL.
205
+ $filename = basename( $attachment['url'] );
206
+
207
+ $upload = wp_upload_bits(
208
+ $filename,
209
+ null,
210
+ $file_content
211
+ );
212
+
213
+ $post = array(
214
+ 'post_title' => $filename,
215
+ 'guid' => $upload['url'],
216
+ );
217
+
218
+ $info = wp_check_filetype( $upload['file'] );
219
+ if ( $info ) {
220
+ $post['post_mime_type'] = $info['type'];
221
+ } else {
222
+ // For now just return the origin attachment.
223
+ return $attachment;
224
+ }
225
+
226
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
227
+ wp_update_attachment_metadata(
228
+ $post_id,
229
+ wp_generate_attachment_metadata( $post_id, $upload['file'] )
230
+ );
231
+ update_post_meta( $post_id, '_cartflows_image_hash', $this->get_hash_image( $attachment['url'] ) );
232
+
233
+ $new_attachment = array(
234
+ 'id' => $post_id,
235
+ 'url' => $upload['url'],
236
+ );
237
+
238
+ self::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
239
+
240
+ $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
241
+
242
+ return $new_attachment;
243
+ }
244
+
245
+ /**
246
+ * Debugging Log.
247
+ *
248
+ * @since 1.0.0
249
+ * @param mixed $log Log data.
250
+ * @return void
251
+ */
252
+ public static function log( $log ) {
253
+
254
+ if ( ! WP_DEBUG_LOG ) {
255
+ return;
256
+ }
257
+
258
+ if ( is_array( $log ) || is_object( $log ) ) {
259
+ wcf()->logger->import_log( print_r( $log, true ) );
260
+ } else {
261
+ wcf()->logger->import_log( $log );
262
+ }
263
+ }
264
+
265
+ }
266
+
267
+ /**
268
+ * Initialize class object with 'get_instance()' method
269
+ */
270
+ CartFlows_Importer_Core::get_instance();
271
+
272
+ endif;
classes/class-cartflows-importer.php CHANGED
@@ -1,1569 +1,1569 @@
1
- <?php
2
- /**
3
- * CartFlows Admin
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Importer' ) ) :
10
-
11
- /**
12
- * CartFlows Import
13
- *
14
- * @since 1.0.0
15
- */
16
- class CartFlows_Importer {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.0
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.0
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
-
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.0.0
45
- */
46
- public function __construct() {
47
- add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
48
- add_action( 'wp_ajax_cartflows_load_steps', array( $this, 'load_templates' ) );
49
- add_action( 'wp_ajax_cartflows_step_import', array( $this, 'import_step' ) );
50
- add_action( 'wp_ajax_cartflows_create_flow', array( $this, 'create_flow' ) );
51
- add_action( 'wp_ajax_cartflows_default_flow', array( $this, 'create_default_flow' ) );
52
- add_action( 'wp_ajax_cartflows_step_create_blank', array( $this, 'step_create_blank' ) );
53
- add_action( 'wp_ajax_cartflows_import_flow_step', array( $this, 'import_flow' ) );
54
- add_action( 'admin_footer', array( $this, 'js_templates' ) );
55
- add_action( 'cartflows_import_complete', array( $this, 'clear_cache' ) );
56
-
57
- add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
58
-
59
- add_action( 'wp_ajax_cartflows_activate_plugin', array( $this, 'activate_plugin' ) );
60
-
61
- add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
62
- add_action( 'admin_init', array( $this, 'export_json' ) );
63
- add_action( 'admin_init', array( $this, 'import_json' ) );
64
- add_filter( 'post_row_actions', array( $this, 'export_link' ), 10, 2 );
65
- add_action( 'admin_action_cartflows_export_flow', array( $this, 'export_flow' ) );
66
- }
67
-
68
- /**
69
- * Add the export link to action list for flows row actions
70
- *
71
- * @since 1.1.4
72
- *
73
- * @param array $actions Actions array.
74
- * @param object $post Post object.
75
- *
76
- * @return array
77
- */
78
- function export_link( $actions, $post ) {
79
- if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
80
- $actions['export'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_export_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_export_nonce' ) . '" title="' . __( 'Export this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Export', 'cartflows' ) . '</a>';
81
- }
82
- return $actions;
83
- }
84
-
85
- /**
86
- * Add menus
87
- *
88
- * @since 1.1.4
89
- */
90
- function add_to_menus() {
91
- add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Export', 'cartflows' ), __( 'Flow Export', 'cartflows' ), 'export', 'flow_exporter', array( $this, 'exporter_markup' ) );
92
- add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Import', 'cartflows' ), __( 'Flow Import', 'cartflows' ), 'import', 'flow_importer', array( $this, 'importer_markup' ) );
93
- }
94
-
95
- /**
96
- * Export flow with steps and its meta
97
- *
98
- * @since 1.1.4
99
- */
100
- function export_flow() {
101
-
102
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_export_flow' == $_REQUEST['action'] ) ) ) {
103
- wp_die( __( 'No post to export has been supplied!', 'cartflows' ) );
104
- }
105
-
106
- if ( ! isset( $_GET['flow_export_nonce'] ) || ! wp_verify_nonce( $_GET['flow_export_nonce'], basename( __FILE__ ) ) ) {
107
- return;
108
- }
109
-
110
- // Get the original post id.
111
- $flow_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
112
-
113
- $flows = array();
114
- $flows[] = $this->get_flow_export_data( $flow_id );
115
- $flows = apply_filters( 'cartflows_export_data', $flows );
116
-
117
- nocache_headers();
118
- header( 'Content-Type: application/json; charset=utf-8' );
119
- header( 'Content-Disposition: attachment; filename=cartflows-flow-' . $flow_id . '-' . date( 'm-d-Y' ) . '.json' );
120
- header( 'Expires: 0' );
121
-
122
- echo json_encode( $flows );
123
- exit;
124
- }
125
-
126
- /**
127
- * Export flow markup
128
- *
129
- * @since 1.1.4
130
- */
131
- function exporter_markup() {
132
- include_once CARTFLOWS_DIR . 'includes/exporter.php';
133
- }
134
-
135
- /**
136
- * Import flow markup
137
- *
138
- * @since 1.1.4
139
- */
140
- function importer_markup() {
141
- include_once CARTFLOWS_DIR . 'includes/importer.php';
142
- }
143
-
144
- /**
145
- * Export flow
146
- *
147
- * @since 1.1.4
148
- */
149
- function export_json() {
150
- if ( empty( $_POST['cartflows-action'] ) || 'export' != $_POST['cartflows-action'] ) {
151
- return;
152
- }
153
-
154
- if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
155
- return;
156
- }
157
-
158
- if ( ! current_user_can( 'manage_options' ) ) {
159
- return;
160
- }
161
-
162
- $flows = $this->get_all_flow_export_data();
163
- $flows = apply_filters( 'cartflows_export_data', $flows );
164
-
165
- nocache_headers();
166
- header( 'Content-Type: application/json; charset=utf-8' );
167
- header( 'Content-Disposition: attachment; filename=cartflows-flow-export-' . date( 'm-d-Y' ) . '.json' );
168
- header( 'Expires: 0' );
169
-
170
- echo json_encode( $flows );
171
- exit;
172
- }
173
-
174
- /**
175
- * Get flow export data
176
- *
177
- * @since 1.1.4
178
- *
179
- * @param integer $flow_id Flow ID.
180
- * @return array
181
- */
182
- function get_flow_export_data( $flow_id ) {
183
-
184
- $export_all = apply_filters( 'cartflows_export_all', false );
185
-
186
- $valid_step_meta_keys = array(
187
- '_wp_page_template',
188
- '_thumbnail_id',
189
- 'classic-editor-remember',
190
- );
191
-
192
- $new_steps = array();
193
- $steps = get_post_meta( $flow_id, 'wcf-steps', true );
194
- if ( $steps ) {
195
- foreach ( $steps as $key => $step ) {
196
-
197
- // Add step post meta.
198
- $new_all_meta = array();
199
- $all_meta = get_post_meta( $step['id'] );
200
- if ( is_array( $all_meta ) ) {
201
-
202
- if ( $export_all ) {
203
- foreach ( $all_meta as $meta_key => $value ) {
204
- $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
205
- }
206
- } else {
207
-
208
- foreach ( $all_meta as $meta_key => $value ) {
209
- if ( substr( $meta_key, 0, strlen( 'wcf' ) ) === 'wcf' ) {
210
- $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
211
- } elseif ( in_array( $meta_key, $valid_step_meta_keys ) ) {
212
- $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
213
- }
214
- }
215
- }
216
- }
217
-
218
- // Add single step.
219
- $step_data_arr = array(
220
- 'title' => get_the_title( $step['id'] ),
221
- 'type' => $step['type'],
222
- 'meta' => $new_all_meta,
223
- 'post_content' => '',
224
- );
225
-
226
- if ( $export_all ) {
227
-
228
- $step_post_obj = get_post( $step['id'] );
229
-
230
- $step_data_arr['post_content'] = $step_post_obj->post_content;
231
- }
232
-
233
- $new_steps[] = $step_data_arr;
234
- }
235
- }
236
-
237
- // Add single flow.
238
- return array(
239
- 'title' => get_the_title( $flow_id ),
240
- 'steps' => $new_steps,
241
- );
242
- }
243
-
244
- /**
245
- * Get all flow export data
246
- *
247
- * @since 1.1.4
248
- */
249
- function get_all_flow_export_data() {
250
-
251
- $query_args = array(
252
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
253
-
254
- // Query performance optimization.
255
- 'fields' => 'ids',
256
- 'no_found_rows' => true,
257
- 'posts_per_page' => -1,
258
- );
259
-
260
- $query = new WP_Query( $query_args );
261
- $flows = array();
262
- if ( $query->posts ) {
263
- foreach ( $query->posts as $key => $post_id ) {
264
- $flows[] = $this->get_flow_export_data( $post_id );
265
- }
266
- }
267
-
268
- return $flows;
269
- }
270
-
271
- /**
272
- * Import our exported file
273
- *
274
- * @since 1.1.4
275
- */
276
- function import_json() {
277
- if ( empty( $_POST['cartflows-action'] ) || 'import' != $_POST['cartflows-action'] ) {
278
- return;
279
- }
280
-
281
- if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
282
- return;
283
- }
284
-
285
- if ( ! current_user_can( 'manage_options' ) ) {
286
- return;
287
- }
288
-
289
- $filename = $_FILES['file']['name'];
290
- $file_info = explode( '.', $filename );
291
- $extension = end( $file_info );
292
-
293
- if ( 'json' != $extension ) {
294
- wp_die( __( 'Please upload a valid .json file', 'cartflows' ) );
295
- }
296
-
297
- $file = $_FILES['file']['tmp_name'];
298
-
299
- if ( empty( $file ) ) {
300
- wp_die( __( 'Please upload a file to import', 'cartflows' ) );
301
- }
302
-
303
- // Retrieve the settings from the file and convert the JSON object to an array.
304
- $flows = json_decode( file_get_contents( $file ), true );
305
-
306
- if ( $flows ) {
307
-
308
- foreach ( $flows as $key => $flow ) {
309
-
310
- $flow_title = $flow['title'];
311
- if ( post_exists( $flow['title'] ) ) {
312
- $flow_title = $flow['title'] . ' Copy';
313
- }
314
-
315
- // Create post object.
316
- $new_flow_args = array(
317
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
318
- 'post_title' => $flow_title,
319
- 'post_status' => 'draft',
320
- );
321
-
322
- // Insert the post into the database.
323
- $flow_id = wp_insert_post( $new_flow_args );
324
-
325
- if ( $flow['steps'] ) {
326
- foreach ( $flow['steps'] as $key => $step ) {
327
-
328
- $new_step_id = wp_insert_post(
329
- array(
330
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
331
- 'post_title' => $step['title'],
332
- 'post_status' => 'publish',
333
- 'meta_input' => $step['meta'],
334
- 'post_content' => isset( $step['post_content'] ) ? $step['post_content'] : '',
335
- )
336
- );
337
-
338
- // Insert post meta.
339
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
340
-
341
- $step_taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
342
- $current_term = term_exists( $step['type'], $step_taxonomy );
343
-
344
- // // Set type object.
345
- $data = get_term( $current_term['term_id'], $step_taxonomy );
346
- $step_slug = $data->slug;
347
- wp_set_object_terms( $new_step_id, $data->slug, $step_taxonomy );
348
-
349
- // Set type.
350
- update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
351
-
352
- // Set flow.
353
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
354
-
355
- CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step['title'], $step_slug );
356
-
357
- if ( isset( $step['post_content'] ) && ! empty( $step['post_content'] ) ) {
358
-
359
- // Download and replace images.
360
- $content = $this->get_content( $step['post_content'] );
361
-
362
- // Update post content.
363
- wp_update_post(
364
- array(
365
- 'ID' => $new_step_id,
366
- 'post_content' => $content,
367
- )
368
- );
369
- }
370
- }
371
- }
372
- }
373
- }
374
-
375
- add_action( 'admin_notices', array( $this, 'imported_successfully' ) );
376
- }
377
-
378
- /**
379
- * Download and Replace hotlink images
380
- *
381
- * @since x.x.x
382
- *
383
- * @param string $content Mixed post content.
384
- * @return array Hotlink image array.
385
- */
386
- function get_content( $content = '' ) {
387
-
388
- $all_links = wp_extract_urls( $content );
389
- $image_links = array();
390
- $image_map = array();
391
-
392
- // Not have any link.
393
- if ( empty( $all_links ) ) {
394
- return $content;
395
- }
396
-
397
- foreach ( $all_links as $key => $link ) {
398
- if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $link ) ) {
399
- $image_links[] = $link;
400
- }
401
- }
402
-
403
- // Not have any image link.
404
- if ( empty( $image_links ) ) {
405
- return $content;
406
- }
407
-
408
- foreach ( $image_links as $key => $image_url ) {
409
-
410
- // Download remote image.
411
- $image = array(
412
- 'url' => $image_url,
413
- 'id' => rand( 000, 999 ),
414
- );
415
- $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
416
-
417
- // Old and New image mapping links.
418
- $image_map[ $image_url ] = $downloaded_image['url'];
419
- }
420
-
421
- // Replace old image links with new image links.
422
- foreach ( $image_map as $old_url => $new_url ) {
423
- $content = str_replace( $old_url, $new_url, $content );
424
- }
425
-
426
- return $content;
427
-
428
- }
429
-
430
- /**
431
- * Imported notice
432
- *
433
- * @since 1.1.4
434
- */
435
- function imported_successfully() {
436
- ?>
437
- <div class="notice notice-success">
438
- <p><?php _e( 'Successfully imported flows.', 'cartflows' ); ?></p>
439
- </div>
440
- <?php
441
- }
442
-
443
- /**
444
- * Clear Cache.
445
- *
446
- * @since 1.0.0
447
- */
448
- public function clear_cache() {
449
- // Clear 'Elementor' file cache.
450
- if ( class_exists( '\Elementor\Plugin' ) ) {
451
- Elementor\Plugin::$instance->files_manager->clear_cache();
452
- }
453
- }
454
-
455
- /**
456
- * JS Templates
457
- *
458
- * @since 1.0.0
459
- *
460
- * @return void
461
- */
462
- function js_templates() {
463
-
464
- // Loading Templates.
465
- ?>
466
- <script type="text/template" id="tmpl-cartflows-step-loading">
467
- <div class="template-message-block cartflows-step-loading">
468
- <h2>
469
- <span class="spinner"></span>
470
- <?php _e( 'Loading Steps', 'cartflows' ); ?>
471
- </h2>
472
- <p class="description"><?php _e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
473
- </div>
474
- </script>
475
-
476
- <?php
477
- // Search Templates.
478
- ?>
479
- <script type="text/template" id="tmpl-cartflows-searching-templates">
480
- <div class="template-message-block cartflows-searching-templates">
481
- <h2>
482
- <span class="spinner"></span>
483
- <?php _e( 'Searching Template..', 'cartflows' ); ?>
484
- </h2>
485
- <p class="description"><?php _e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
486
- </div>
487
- </script>
488
-
489
- <?php
490
- // CartFlows Importing Template.
491
- ?>
492
- <script type="text/template" id="tmpl-cartflows-step-importing">
493
- <div class="template-message-block cartflows-step-importing">
494
- <h2><span class="spinner"></span> <?php _e( 'Importing..', 'cartflows' ); ?></h2>
495
- </div>
496
- </script>
497
-
498
- <?php
499
- // CartFlows Imported.
500
- ?>
501
- <script type="text/template" id="tmpl-cartflows-step-imported">
502
- <div class="template-message-block cartflows-step-imported">
503
- <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
504
- <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
505
- </script>
506
-
507
- <?php
508
- // No templates.
509
- ?>
510
- <script type="text/template" id="tmpl-cartflows-no-steps">
511
- <div class="cartflows-no-steps">
512
- <div class="template-message-block">
513
- <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
514
- <p class="description"></p>
515
- </div>
516
- </div>
517
- </script>
518
-
519
- <?php
520
- // No templates.
521
- ?>
522
- <script type="text/template" id="tmpl-cartflows-no-flows">
523
- <div class="cartflows-no-flows">
524
- <div class="template-message-block">
525
- <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
526
- <p class="description"></p>
527
- </div>
528
- </div>
529
- </script>
530
-
531
- <?php
532
- // Error handling.
533
- ?>
534
- <script type="text/template" id="tmpl-templator-error">
535
- <div class="notice notice-error"><p>{{ data }}</p></div>
536
- </script>
537
-
538
- <?php
539
- // Redirect to Elementor.
540
- ?>
541
- <script type="text/template" id="tmpl-templator-redirect-to-elementor">
542
- <div class="template-message-block templator-redirect-to-elementor">
543
- <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
544
- <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php _e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
545
- </script>
546
-
547
- <?php
548
- /**
549
- * Responsive Buttons
550
- */
551
- ?>
552
- <script type="text/template" id="tmpl-cartflows-responsive-view">
553
- <span class="responsive-view">
554
- <span class="actions">
555
- <a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
556
- <a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
557
- <a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
558
- </span>
559
- </span>
560
- </script>
561
-
562
- <?php
563
- // Templates data.
564
- ?>
565
- <script type="text/template" id="tmpl-cartflows-flows-list">
566
-
567
- <# console.log( data.items.length ) #>
568
- <# console.log( data.items ) #>
569
- <# if ( data.items.length ) { #>
570
- <# for ( key in data.items ) { #>
571
- <#
572
- var flow_steps = [];
573
- if( data.items[ key ].flow_steps ) {
574
- flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
575
- return value['id'];
576
- });
577
- }
578
- #>
579
- <div class="inner">
580
- <div class="template">
581
- <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
582
- <div class="template-screenshot">
583
- <# if( data.items[ key ].featured_image_url ) { #>
584
- <img src="{{ data.items[ key ].featured_image_url }}" />
585
- <# } else { #>
586
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
587
- <# } #>
588
- </div>
589
- <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>flow={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
590
- <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
591
- <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
592
- <# } #>
593
- </span>
594
- <div class="template-id-container">
595
- <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
596
- <div class="template-actions">
597
-
598
- <#
599
- if( data.items[ key ].page_builder.slug ) {
600
- required_plugin_group = data.items[ key ].page_builder.slug;
601
- } else {
602
- required_plugin_group = '';
603
- }
604
-
605
- if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
606
- import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
607
- } else {
608
- import_btn_title = 'Import';
609
- } #>
610
-
611
- <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
612
- <a data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
613
- <# } else if( CartFlowsImportVars._is_pro_active ) { #>
614
- <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
615
- <# } else { #>
616
- <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
617
- <# } #>
618
- </div>
619
- </div>
620
- </div>
621
- </div>
622
- <# } #>
623
- <# } #>
624
- </script>
625
-
626
- <?php
627
- // Empty Step.
628
- ?>
629
- <script type="text/template" id="tmpl-cartflows-create-blank-step">
630
- <div class="inner">
631
- <div class="template">
632
- <span class="thumbnail site-preview cartflows-flow-preview">
633
- <div class="template-screenshot">
634
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
635
- </div>
636
- <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
637
- </span>
638
- <div class="template-id-container">
639
- <h3 class="template-name"> Blank </h3>
640
- <div class="template-actions">
641
- <a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create', 'cartflows' ); ?></a>
642
- </div>
643
- </div>
644
- </div>
645
- </div>
646
- </script>
647
-
648
- <?php
649
- // Templates data.
650
- ?>
651
- <script type="text/template" id="tmpl-cartflows-steps-list">
652
- <# if ( data.items.length ) { #>
653
- <# for ( key in data.items ) { #>
654
- <#
655
- var flow_steps = [];
656
- if( data.items[ key ].flow_steps ) {
657
- flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
658
- return value['id'];
659
- });
660
- }
661
- #>
662
- <div class="inner">
663
- <div class="template">
664
- <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
665
- <div class="template-screenshot">
666
- <# if( data.items[ key ].featured_image_url ) { #>
667
- <img src="{{ data.items[ key ].featured_image_url }}" />
668
- <# } else { #>
669
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
670
- <# } #>
671
- </div>
672
- <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
673
- <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>step={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
674
- <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
675
- <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
676
- <# } #>
677
- </span>
678
- <div class="template-id-container">
679
- <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
680
- <div class="template-actions">
681
-
682
- <#
683
-
684
- var step_slug = data.items[ key ].step_type.slug || '';
685
- var step_title = data.items[ key ].step_type.name || '';
686
- var import_btn_title = 'Import';
687
-
688
- var required_plugin_group = '';
689
- if( data.items[ key ].page_builder ) {
690
- required_plugin_group = data.items[ key ].page_builder.slug;
691
-
692
- if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
693
- import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
694
- }
695
- }
696
- #>
697
-
698
- <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
699
- <a data-slug="{{step_slug}}" data-title="{{step_title}}" data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
700
- <# } else if( CartFlowsImportVars._is_pro_active ) { #>
701
- <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
702
- <# } else { #>
703
- <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
704
- <# } #>
705
- </div>
706
- </div>
707
- </div>
708
- </div>
709
- <# } #>
710
- <# } #>
711
- </script>
712
-
713
- <?php
714
- /**
715
- * TMPL - Website Unreachable
716
- */
717
- ?>
718
- <script type="text/template" id="tmpl-cartflows-website-unreachable">
719
- <div class="postbox cartflows-website-unreachable">
720
- <h2><?php _e( 'Under Maintenance..', 'cartflows' ); ?></h2>
721
- <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly.', 'cartflows' ); ?></p>
722
- <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website..', 'cartflows' ); ?></p>
723
- </div>
724
- </script>
725
-
726
- <?php
727
- /**
728
- * TMPL - Filters
729
- */
730
- ?>
731
- <script type="text/template" id="tmpl-cartflows-page-builder-notice">
732
- <?php
733
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
734
- $page_builder = Cartflows_Helper::get_required_plugins_for_page_builder( Cartflows_Helper::get_common_setting( 'default_page_builder' ) );
735
- $title = $page_builder['title'];
736
-
737
- $plugin_string = '<a href="#" data-slug="' . esc_html( $default_page_builder ) . '" class="wcf-install-plugin">Please click here and activate ' . esc_html( $title ) . '</a>';
738
- $theme_status = '';
739
- if ( 'divi' === $default_page_builder ) {
740
-
741
- $theme_status = $page_builder['theme-status'];
742
- $plugin_status = $page_builder['plugin-status'];
743
-
744
- if ( 'deactivate' === $theme_status || 'install' === $plugin_status ) {
745
- $plugin_string = 'Please activate ' . esc_html( $title );
746
- } elseif ( ( 'deactivate' === $theme_status || 'not-installed' === $theme_status ) && 'install' === $plugin_status ) {
747
- $plugin_string = 'Please install and activate ' . esc_html( $title );
748
- }
749
- }
750
- ?>
751
- <div class="wcf-page-builder-message">
752
- <p><?php /* translators: %s: Plugin string */ printf( __( '%1$s to see CartFlows templates. If you prefer another page builder tool, you can <a href="%2$s" target="blank">select it here</a>.', 'cartflows' ), $plugin_string, admin_url( 'admin.php?page=' . CARTFLOWS_SETTINGS . '&action=common-settings#form-field-wcf_default_page_builder' ) ); ?></p>
753
- <p>If your preferred page builder is not available, feel free to <a href="#" data-slug="canvas" class="wcf-create-from-scratch-link">create your own</a> pages using page builder of your choice as CartFlows works with all major page builders.</p>
754
- <p>We plan to add design templates made with more page builder shortly!</p>
755
- </div>
756
- </script>
757
-
758
- <?php
759
- /**
760
- * TMPL - Filters
761
- */
762
- ?>
763
- <script type="text/template" id="tmpl-cartflows-term-filters-dropdown">
764
- <# if ( data ) { #>
765
- <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
766
- <# if ( data.args.show_all ) { #>
767
- <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
768
- <# } #>
769
- <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
770
- <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
771
- <# } #>
772
- <# for ( key in data.items ) { #>
773
- <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
774
- <# } #>
775
- </select>
776
- <# } #>
777
- </script>
778
-
779
- <script type="text/template" id="tmpl-cartflows-term-filters">
780
-
781
- <# if ( data ) { #>
782
-
783
- <?php /* <# if ( CartFlowsImportVars.flow_page_builder === data.args.remote_slug || CartFlowsImportVars.step_page_builder === data.args.remote_slug ) { #> */ ?>
784
- <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
785
-
786
- <# if ( data.args.show_all ) { #>
787
- <li>
788
- <a href="#" data-group="all"> All </a>
789
- </li>
790
- <# } #>
791
-
792
- <# for ( key in data.items ) { #>
793
- <li>
794
- <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</a>
795
- </li>
796
- <# } #>
797
-
798
- </ul>
799
-
800
- <?php
801
-
802
- /*
803
- <# } else { #>
804
- <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
805
-
806
- <# if ( data.args.show_all ) { #>
807
- <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
808
- <# } #>
809
-
810
- <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
811
- <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
812
- <# } #>
813
-
814
- <# for ( key in data.items ) { #>
815
- <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
816
- <# } #>
817
-
818
- </select>
819
- */
820
- ?>
821
-
822
- <?php /* <# } #> */ ?>
823
-
824
- <# } #>
825
- </script>
826
-
827
- <?php
828
- // Step Type.
829
- ?>
830
- <script type="text/template" id="tmpl-cartflows-step-types">
831
- <ul class="wcf-tab nav-tabs">
832
- <# if( data.items_count ) { #>
833
- <# for( key in data.items ) { #>
834
- <# console.log( data.items[ key ].id ) #>
835
- <li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
836
- <a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
837
- </li>
838
- <# } #>
839
- <# } #>
840
- </ul>
841
- </script>
842
-
843
- <?php
844
- // Add to library button.
845
- ?>
846
- <script type="text/template" id="tmpl-templator-add-to-library">
847
- <a class="templator-add-to-library page-title-action cartflows-load-steps-library"><i class="dashicons dashicons-cloud"></i><?php esc_attr_e( 'Import from Cloud', 'cartflows' ); ?></a>
848
- </script>
849
- <?php
850
- }
851
-
852
- /**
853
- * Enqueue scripts
854
- *
855
- * @since 1.0.0
856
- *
857
- * @hook admin_enqueue_scripts
858
- * @param string $hook Current page hook.
859
- */
860
- function scripts( $hook = '' ) {
861
-
862
- if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
863
- return;
864
- }
865
-
866
- wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
867
- wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
868
- wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
869
- wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
870
-
871
- $localize_vars = array(
872
- '_is_pro_active' => _is_cartflows_pro(),
873
-
874
- // Flow and its rest fields.
875
- 'flow' => CARTFLOWS_FLOW_POST_TYPE,
876
- 'flow_fields' => array(
877
- 'id',
878
- 'title',
879
- 'flow_type',
880
- 'page_builder',
881
- 'flow_steps',
882
- 'licence_status',
883
- 'featured_image_url',
884
- 'featured_media', // @required for field `featured_image_url`.
885
- ),
886
-
887
- // Flow type and rest fields.
888
- 'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
889
- 'flow_type_fields' => array(
890
- 'id',
891
- 'name',
892
- 'slug',
893
- ),
894
-
895
- // Flow page builder and rest fields.
896
- 'flow_page_builder' => CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER,
897
- 'flow_page_builder_fields' => array(
898
- 'id',
899
- 'name',
900
- 'slug',
901
- ),
902
-
903
- // Step page builder and rest fields.
904
- 'step_page_builder' => CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER,
905
- 'step_page_builder_fields' => array(
906
- 'id',
907
- 'name',
908
- 'slug',
909
- ),
910
-
911
- // Step and its rest fields.
912
- 'step' => CARTFLOWS_STEP_POST_TYPE,
913
- 'step_fields' => array(
914
- 'title',
915
- 'featured_image_url',
916
- 'featured_media', // @required for field `featured_image_url`.
917
- 'id',
918
- 'flow_type',
919
- 'step_type',
920
- 'page_builder',
921
- 'licence_status',
922
- ),
923
-
924
- // Step type and its rest fields.
925
- 'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
926
- 'step_type_fields' => array(
927
- 'id',
928
- 'name',
929
- 'slug',
930
- ),
931
-
932
- 'domain_url' => CARTFLOWS_DOMAIN_URL,
933
- 'server_url' => CARTFLOWS_TEMPLATES_URL,
934
- 'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
935
- 'site_url' => site_url(),
936
- 'import_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_importer' ),
937
- 'export_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_exporter' ),
938
- 'admin_url' => admin_url(),
939
- 'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
940
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
941
- 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
942
-
943
- 'required_plugins' => Cartflows_Helper::get_plugins_groupby_page_builders(),
944
-
945
- 'default_page_builder' => Cartflows_Helper::get_common_setting( 'default_page_builder' ),
946
- );
947
-
948
- // var_dump(Cartflows_Helper::get_common_setting( 'default_page_builder' ));
949
- // wp_die( );
950
- // Add thickbox.
951
- add_thickbox();
952
-
953
- wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
954
- wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
955
- }
956
-
957
- /**
958
- * Load Template
959
- *
960
- * @since 1.0.0
961
- *
962
- * @hook cartflows_load_steps
963
- * @return void
964
- */
965
- function load_templates() {
966
-
967
- check_ajax_referer( 'cf-load-steps', 'security' );
968
-
969
- $args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array();
970
- $templates = CartFlows_API::get_instance()->get_templates( $args );
971
-
972
- if ( $templates['templates_count'] ) {
973
- wp_send_json_success( $templates );
974
- } else {
975
- wp_send_json_error( $templates );
976
- }
977
- wp_die();
978
- }
979
-
980
- /**
981
- * Import.
982
- *
983
- * @since 1.0.0
984
- *
985
- * @hook wp_ajax_cartflows_import_flow_step
986
- * @return void
987
- */
988
- function import_flow() {
989
-
990
- check_ajax_referer( 'cf-import-flow-step', 'security' );
991
-
992
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
993
- $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
994
-
995
- wcf()->logger->import_log( '------------------------------------' );
996
- wcf()->logger->import_log( 'STARTED! Importing FLOW' );
997
- wcf()->logger->import_log( '------------------------------------' );
998
- wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
999
-
1000
- $response = CartFlows_API::get_instance()->get_template( $template_id );
1001
-
1002
- $post_content = isset( $response['data']['content']->rendered ) ? $response['data']['content']->rendered : '';
1003
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1004
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1005
- $post_content = $response['data']['divi_content'];
1006
- }
1007
- }
1008
-
1009
- if ( false === $response['success'] ) {
1010
- wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
1011
- wp_send_json_error( $response );
1012
- }
1013
-
1014
- wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . json_encode( $response ) );
1015
-
1016
- $new_step_id = wp_insert_post(
1017
- array(
1018
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1019
- 'post_title' => $response['title'],
1020
- 'post_content' => $post_content,
1021
- 'post_status' => 'publish',
1022
- )
1023
- );
1024
-
1025
- if ( is_wp_error( $new_step_id ) ) {
1026
- wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
1027
- wp_send_json_error( $new_step_id );
1028
- }
1029
-
1030
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1031
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1032
- update_post_meta( $new_step_id, 'divi_content', $response['data']['divi_content'] );
1033
- }
1034
- }
1035
-
1036
- /* Imported Step */
1037
- update_post_meta( $new_step_id, 'cartflows_imported_step', 'yes' );
1038
-
1039
- wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );
1040
- // insert post meta.
1041
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1042
- wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
1043
-
1044
- /**
1045
- * Import & Set type.
1046
- */
1047
- $term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
1048
- $term_slug = '';
1049
- if ( $term ) {
1050
-
1051
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1052
- $term_exist = term_exists( $term->name, $taxonomy );
1053
-
1054
- if ( empty( $term_exist ) ) {
1055
- $terms = array(
1056
- array(
1057
- 'name' => $term->name,
1058
- ),
1059
- );
1060
-
1061
- Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1062
- wcf()->logger->import_log( '(✓) Created new term ' . $term->name );
1063
- }
1064
-
1065
- $current_term = term_exists( $term->name, $taxonomy );
1066
-
1067
- // Set type object.
1068
- $data = get_term( $current_term['term_id'], $taxonomy );
1069
- $term_slug = $data->slug;
1070
- $term_name = $data->name;
1071
- wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1072
- wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
1073
-
1074
- // Set type.
1075
- update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
1076
- wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
1077
- }
1078
-
1079
- // Set flow.
1080
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1081
- wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1082
-
1083
- /**
1084
- * Update steps for the current flow.
1085
- */
1086
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1087
-
1088
- if ( ! is_array( $flow_steps ) ) {
1089
- $flow_steps = array();
1090
- }
1091
-
1092
- $flow_steps[] = array(
1093
- 'id' => $new_step_id,
1094
- 'title' => $response['title'],
1095
- 'type' => $term_slug,
1096
- );
1097
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1098
- wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1099
-
1100
- // Import Post Meta.
1101
- self::import_post_meta( $new_step_id, $response );
1102
-
1103
- wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
1104
- wcf()->logger->import_log( '------------------------------------' );
1105
- wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
1106
- wcf()->logger->import_log( '------------------------------------' );
1107
-
1108
- do_action( 'cartflows_import_complete' );
1109
- wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
1110
-
1111
- // Batch Process.
1112
- do_action( 'cartflows_after_template_import', $new_step_id, $response );
1113
-
1114
- /**
1115
- * End
1116
- */
1117
- wp_send_json_success( $new_step_id );
1118
- }
1119
-
1120
- /**
1121
- * Import Step.
1122
- *
1123
- * @since 1.0.0
1124
- * @hook wp_ajax_cartflows_step_import
1125
- *
1126
- * @return void
1127
- */
1128
- function create_default_flow() {
1129
-
1130
- check_ajax_referer( 'cf-default-flow', 'security' );
1131
-
1132
- // Create post object.
1133
- $new_flow_post = array(
1134
- 'post_content' => '',
1135
- 'post_status' => 'publish',
1136
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1137
- );
1138
-
1139
- // Insert the post into the database.
1140
- $flow_id = wp_insert_post( $new_flow_post );
1141
-
1142
- if ( is_wp_error( $flow_id ) ) {
1143
- wp_send_json_error( $flow_id->get_error_message() );
1144
- }
1145
-
1146
- $flow_steps = array();
1147
-
1148
- $steps_data = array(
1149
- 'landing' => __( 'Landing Page', 'cartflows' ),
1150
- 'checkout' => __( 'Checkout Page', 'cartflows' ),
1151
- 'thankyou' => __( 'Thank You Page', 'cartflows' ),
1152
- );
1153
-
1154
- foreach ( $steps_data as $slug => $title ) {
1155
-
1156
- $post_content = '';
1157
-
1158
- switch ( $slug ) {
1159
- case 'checkout':
1160
- $post_content = '';
1161
- break;
1162
- case 'thankyou':
1163
- $post_content = '';
1164
- break;
1165
- default:
1166
- $post_content = '';
1167
- break;
1168
- }
1169
-
1170
- $step_id = wp_insert_post(
1171
- array(
1172
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1173
- 'post_title' => $title,
1174
- 'post_content' => $post_content,
1175
- 'post_status' => 'publish',
1176
- )
1177
- );
1178
-
1179
- if ( is_wp_error( $step_id ) ) {
1180
- wp_send_json_error( $step_id->get_error_message() );
1181
- }
1182
-
1183
- if ( $step_id ) {
1184
-
1185
- $flow_steps[] = array(
1186
- 'id' => $step_id,
1187
- 'title' => $title,
1188
- 'type' => $slug,
1189
- );
1190
-
1191
- // insert post meta.
1192
- update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
1193
- update_post_meta( $step_id, 'wcf-step-type', $slug );
1194
-
1195
- wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1196
- wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1197
- }
1198
- }
1199
-
1200
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1201
-
1202
- wp_send_json_success( $flow_id );
1203
- }
1204
-
1205
- /**
1206
- * Create Flow
1207
- *
1208
- * @return void
1209
- */
1210
- function create_flow() {
1211
-
1212
- check_ajax_referer( 'cf-create-flow', 'security' );
1213
-
1214
- // Create post object.
1215
- $new_flow_post = array(
1216
- 'post_content' => '',
1217
- 'post_status' => 'publish',
1218
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1219
- );
1220
-
1221
- // Insert the post into the database.
1222
- $flow_id = wp_insert_post( $new_flow_post );
1223
-
1224
- if ( is_wp_error( $flow_id ) ) {
1225
- wp_send_json_error( $flow_id->get_error_message() );
1226
- }
1227
-
1228
- /* Imported Flow */
1229
- update_post_meta( $flow_id, 'cartflows_imported_flow', 'yes' );
1230
-
1231
- wp_send_json_success( $flow_id );
1232
- }
1233
-
1234
- /**
1235
- * Create Step
1236
- *
1237
- * @return void
1238
- */
1239
- function import_step() {
1240
-
1241
- check_ajax_referer( 'cf-step-import', 'security' );
1242
-
1243
- $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1244
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1245
- $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1246
- $step_type = isset( $_POST['step_type'] ) ? sanitize_title( $_POST['step_type'] ) : '';
1247
- $step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( $_POST['step_custom_title'] ) : $step_title;
1248
-
1249
- $cartflow_meta = Cartflows_Flow_Meta::get_instance();
1250
-
1251
- $post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
1252
-
1253
- wcf()->logger->import_log( '------------------------------------' );
1254
- wcf()->logger->import_log( 'STARTED! Importing STEP' );
1255
- wcf()->logger->import_log( '------------------------------------' );
1256
-
1257
- if ( empty( $template_id ) || empty( $post_id ) ) {
1258
- /* translators: %s: template ID */
1259
- $data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
1260
- wcf()->logger->import_log( $data );
1261
- wp_send_json_error( $data );
1262
- }
1263
-
1264
- wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
1265
-
1266
- $response = CartFlows_API::get_instance()->get_template( $template_id );
1267
-
1268
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1269
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1270
- update_post_meta( $post_id, 'divi_content', $response['data']['divi_content'] );
1271
-
1272
- wp_update_post(
1273
- array(
1274
- 'ID' => $post_id,
1275
- 'post_content' => $response['data']['divi_content'],
1276
- )
1277
- );
1278
- }
1279
- }
1280
-
1281
- /* Imported Step */
1282
- update_post_meta( $post_id, 'cartflows_imported_step', 'yes' );
1283
-
1284
- // Import Post Meta.
1285
- self::import_post_meta( $post_id, $response );
1286
-
1287
- do_action( 'cartflows_import_complete' );
1288
-
1289
- // Batch Process.
1290
- do_action( 'cartflows_after_template_import', $post_id, $response );
1291
-
1292
- wcf()->logger->import_log( '------------------------------------' );
1293
- wcf()->logger->import_log( 'COMPLETE! Importing Step' );
1294
- wcf()->logger->import_log( '------------------------------------' );
1295
-
1296
- wp_send_json_success( $post_id );
1297
- }
1298
-
1299
- /**
1300
- * Import Step.
1301
- *
1302
- * @since 1.0.0
1303
- * @hook wp_ajax_cartflows_step_create_blank
1304
- *
1305
- * @return void
1306
- */
1307
- function step_create_blank() {
1308
-
1309
- check_ajax_referer( 'cf-step-create-blank', 'security' );
1310
-
1311
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1312
- $step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( $_POST['step_type'] ) : '';
1313
- $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1314
-
1315
- if ( empty( $flow_id ) || empty( $step_type ) ) {
1316
- /* translators: %s: flow ID */
1317
- $data = sprintf( __( 'Invalid flow id %1$s OR step type %2$s.', 'cartflows' ), $flow_id, $step_type );
1318
- wcf()->logger->import_log( $data );
1319
- wp_send_json_error( $data );
1320
- }
1321
-
1322
- wcf()->logger->import_log( '------------------------------------' );
1323
- wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
1324
-
1325
- $step_type_title = str_replace( '-', ' ', $step_type );
1326
- $step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
1327
-
1328
- $new_step_id = wp_insert_post(
1329
- array(
1330
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1331
- 'post_title' => $step_title,
1332
- 'post_content' => '',
1333
- 'post_status' => 'publish',
1334
- )
1335
- );
1336
-
1337
- // insert post meta.
1338
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1339
-
1340
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1341
- $term_exist = term_exists( $step_type_title, $taxonomy );
1342
-
1343
- if ( empty( $term_exist ) ) {
1344
- $terms = array(
1345
- array(
1346
- 'name' => $step_type_title,
1347
- ),
1348
- );
1349
-
1350
- Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1351
- wcf()->logger->import_log( '(✓) Created new term ' . $step_type_title );
1352
- }
1353
-
1354
- $current_term = term_exists( $step_type_title, $taxonomy );
1355
-
1356
- // Set type object.
1357
- $data = get_term( $current_term['term_id'], $taxonomy );
1358
- $step_slug = $data->slug;
1359
- wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1360
- wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
1361
-
1362
- // Set type.
1363
- update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
1364
- wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
1365
-
1366
- // Set flow.
1367
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1368
- wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1369
-
1370
- CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
1371
-
1372
- wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
1373
- wcf()->logger->import_log( '------------------------------------' );
1374
-
1375
- wp_send_json_success( $new_step_id );
1376
- }
1377
-
1378
- /**
1379
- * Import Post Meta
1380
- *
1381
- * @since 1.0.0
1382
- *
1383
- * @param integer $post_id Post ID.
1384
- * @param array $response Post meta.
1385
- * @return void
1386
- */
1387
- public static function import_post_meta( $post_id, $response ) {
1388
-
1389
- $metadata = (array) $response['post_meta'];
1390
-
1391
- foreach ( $metadata as $meta_key => $meta_value ) {
1392
- $meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
1393
-
1394
- if ( $meta_value ) {
1395
-
1396
- if ( is_serialized( $meta_value, true ) ) {
1397
- $raw_data = maybe_unserialize( stripslashes( $meta_value ) );
1398
- } elseif ( is_array( $meta_value ) ) {
1399
- $raw_data = json_decode( stripslashes( $meta_value ), true );
1400
- } else {
1401
- $raw_data = $meta_value;
1402
- }
1403
-
1404
- if ( '_elementor_data' === $meta_key ) {
1405
- if ( is_array( $raw_data ) ) {
1406
- $raw_data = wp_slash( json_encode( $raw_data ) );
1407
- } else {
1408
- $raw_data = wp_slash( $raw_data );
1409
- }
1410
- }
1411
- if ( '_elementor_data' !== $meta_key && '_elementor_draft' !== $meta_key && '_fl_builder_data' !== $meta_key && '_fl_builder_draft' !== $meta_key ) {
1412
- if ( is_array( $raw_data ) ) {
1413
- wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . json_encode( $raw_data ) );
1414
- } else {
1415
- if ( ! is_object( $raw_data ) ) {
1416
- wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
1417
- }
1418
- }
1419
- }
1420
-
1421
- update_post_meta( $post_id, $meta_key, $raw_data );
1422
- }
1423
- }
1424
- }
1425
-
1426
- /**
1427
- * Import Template for Elementor
1428
- *
1429
- * @since 1.0.0
1430
- *
1431
- * @param integer $post_id Post ID.
1432
- * @param array $response Post meta.
1433
- * @param array $page_build_data Page build data.
1434
- * @return void
1435
- */
1436
- public static function import_template_elementor( $post_id, $response, $page_build_data ) {
1437
- if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
1438
- $data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
1439
- wcf()->logger->import_log( $data );
1440
- wp_send_json_error( $data );
1441
- }
1442
-
1443
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
1444
-
1445
- wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
1446
-
1447
- $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
1448
- $obj->import_single_template( $post_id );
1449
-
1450
- wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
1451
- }
1452
-
1453
- /**
1454
- * Supported post types
1455
- *
1456
- * @since 1.0.0
1457
- *
1458
- * @return array Supported post types.
1459
- */
1460
- public static function supported_post_types() {
1461
- return apply_filters(
1462
- 'cartflows_supported_post_types',
1463
- array(
1464
- CARTFLOWS_FLOW_POST_TYPE,
1465
- )
1466
- );
1467
- }
1468
-
1469
- /**
1470
- * Check supported post type
1471
- *
1472
- * @since 1.0.0
1473
- *
1474
- * @param string $post_type Post type.
1475
- * @return boolean Supported post type status.
1476
- */
1477
- public static function is_supported_post( $post_type = '' ) {
1478
- if ( in_array( $post_type, self::supported_post_types() ) ) {
1479
- return true;
1480
- }
1481
-
1482
- return false;
1483
- }
1484
-
1485
- /**
1486
- * Set steps to the flow
1487
- *
1488
- * @param integer $flow_id Flow ID.
1489
- * @param integer $new_step_id New step ID.
1490
- * @param string $step_title Flow Type.
1491
- * @param string $step_slug Flow Type.
1492
- */
1493
- function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
1494
- // Update steps for the current flow.
1495
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1496
-
1497
- if ( ! is_array( $flow_steps ) ) {
1498
- $flow_steps = array();
1499
- }
1500
-
1501
- $flow_steps[] = array(
1502
- 'id' => $new_step_id,
1503
- 'title' => $step_title,
1504
- 'type' => $step_slug,
1505
- );
1506
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1507
- wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1508
- }
1509
-
1510
- /**
1511
- * Localize variables in admin
1512
- *
1513
- * @param array $vars variables.
1514
- */
1515
- function localize_vars( $vars ) {
1516
-
1517
- $ajax_actions = array(
1518
- 'cf_step_import',
1519
- 'cf_load_steps',
1520
- 'cf_create_flow',
1521
- 'cf_default_flow',
1522
- 'cf_step_create_blank',
1523
- 'cf_import_flow_step',
1524
- );
1525
-
1526
- foreach ( $ajax_actions as $action ) {
1527
-
1528
- $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1529
- }
1530
-
1531
- return $vars;
1532
- }
1533
-
1534
- /**
1535
- * Ajax action to activate plugin
1536
- */
1537
- public function activate_plugin() {
1538
-
1539
- $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
1540
-
1541
- $activate = activate_plugin( $plugin_init, '', false, true );
1542
-
1543
- if ( is_wp_error( $activate ) ) {
1544
- wp_send_json_error(
1545
- array(
1546
- 'success' => false,
1547
- 'message' => $activate->get_error_message(),
1548
- 'init' => $plugin_init,
1549
- )
1550
- );
1551
- }
1552
-
1553
- wp_send_json_success(
1554
- array(
1555
- 'success' => true,
1556
- 'message' => __( 'Plugin Successfully Activated', 'cartflows' ),
1557
- 'init' => $plugin_init,
1558
- )
1559
- );
1560
- }
1561
-
1562
- }
1563
-
1564
- /**
1565
- * Initialize class object with 'get_instance()' method
1566
- */
1567
- CartFlows_Importer::get_instance();
1568
-
1569
- endif;
1
+ <?php
2
+ /**
3
+ * CartFlows Admin
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Importer' ) ) :
10
+
11
+ /**
12
+ * CartFlows Import
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class CartFlows_Importer {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.0
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.0
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.0.0
45
+ */
46
+ public function __construct() {
47
+ add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
48
+ add_action( 'wp_ajax_cartflows_load_steps', array( $this, 'load_templates' ) );
49
+ add_action( 'wp_ajax_cartflows_step_import', array( $this, 'import_step' ) );
50
+ add_action( 'wp_ajax_cartflows_create_flow', array( $this, 'create_flow' ) );
51
+ add_action( 'wp_ajax_cartflows_default_flow', array( $this, 'create_default_flow' ) );
52
+ add_action( 'wp_ajax_cartflows_step_create_blank', array( $this, 'step_create_blank' ) );
53
+ add_action( 'wp_ajax_cartflows_import_flow_step', array( $this, 'import_flow' ) );
54
+ add_action( 'admin_footer', array( $this, 'js_templates' ) );
55
+ add_action( 'cartflows_import_complete', array( $this, 'clear_cache' ) );
56
+
57
+ add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
58
+
59
+ add_action( 'wp_ajax_cartflows_activate_plugin', array( $this, 'activate_plugin' ) );
60
+
61
+ add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
62
+ add_action( 'admin_init', array( $this, 'export_json' ) );
63
+ add_action( 'admin_init', array( $this, 'import_json' ) );
64
+ add_filter( 'post_row_actions', array( $this, 'export_link' ), 10, 2 );
65
+ add_action( 'admin_action_cartflows_export_flow', array( $this, 'export_flow' ) );
66
+ }
67
+
68
+ /**
69
+ * Add the export link to action list for flows row actions
70
+ *
71
+ * @since 1.1.4
72
+ *
73
+ * @param array $actions Actions array.
74
+ * @param object $post Post object.
75
+ *
76
+ * @return array
77
+ */
78
+ function export_link( $actions, $post ) {
79
+ if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
80
+ $actions['export'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_export_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_export_nonce' ) . '" title="' . __( 'Export this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Export', 'cartflows' ) . '</a>';
81
+ }
82
+ return $actions;
83
+ }
84
+
85
+ /**
86
+ * Add menus
87
+ *
88
+ * @since 1.1.4
89
+ */
90
+ function add_to_menus() {
91
+ add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Export', 'cartflows' ), __( 'Flow Export', 'cartflows' ), 'export', 'flow_exporter', array( $this, 'exporter_markup' ) );
92
+ add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Import', 'cartflows' ), __( 'Flow Import', 'cartflows' ), 'import', 'flow_importer', array( $this, 'importer_markup' ) );
93
+ }
94
+
95
+ /**
96
+ * Export flow with steps and its meta
97
+ *
98
+ * @since 1.1.4
99
+ */
100
+ function export_flow() {
101
+
102
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_export_flow' == $_REQUEST['action'] ) ) ) {
103
+ wp_die( __( 'No post to export has been supplied!', 'cartflows' ) );
104
+ }
105
+
106
+ if ( ! isset( $_GET['flow_export_nonce'] ) || ! wp_verify_nonce( $_GET['flow_export_nonce'], basename( __FILE__ ) ) ) {
107
+ return;
108
+ }
109
+
110
+ // Get the original post id.
111
+ $flow_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
112
+
113
+ $flows = array();
114
+ $flows[] = $this->get_flow_export_data( $flow_id );
115
+ $flows = apply_filters( 'cartflows_export_data', $flows );
116
+
117
+ nocache_headers();
118
+ header( 'Content-Type: application/json; charset=utf-8' );
119
+ header( 'Content-Disposition: attachment; filename=cartflows-flow-' . $flow_id . '-' . date( 'm-d-Y' ) . '.json' );
120
+ header( 'Expires: 0' );
121
+
122
+ echo json_encode( $flows );
123
+ exit;
124
+ }
125
+
126
+ /**
127
+ * Export flow markup
128
+ *
129
+ * @since 1.1.4
130
+ */
131
+ function exporter_markup() {
132
+ include_once CARTFLOWS_DIR . 'includes/exporter.php';
133
+ }
134
+
135
+ /**
136
+ * Import flow markup
137
+ *
138
+ * @since 1.1.4
139
+ */
140
+ function importer_markup() {
141
+ include_once CARTFLOWS_DIR . 'includes/importer.php';
142
+ }
143
+
144
+ /**
145
+ * Export flow
146
+ *
147
+ * @since 1.1.4
148
+ */
149
+ function export_json() {
150
+ if ( empty( $_POST['cartflows-action'] ) || 'export' != $_POST['cartflows-action'] ) {
151
+ return;
152
+ }
153
+
154
+ if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
155
+ return;
156
+ }
157
+
158
+ if ( ! current_user_can( 'manage_options' ) ) {
159
+ return;
160
+ }
161
+
162
+ $flows = $this->get_all_flow_export_data();
163
+ $flows = apply_filters( 'cartflows_export_data', $flows );
164
+
165
+ nocache_headers();
166
+ header( 'Content-Type: application/json; charset=utf-8' );
167
+ header( 'Content-Disposition: attachment; filename=cartflows-flow-export-' . date( 'm-d-Y' ) . '.json' );
168
+ header( 'Expires: 0' );
169
+
170
+ echo json_encode( $flows );
171
+ exit;
172
+ }
173
+
174
+ /**
175
+ * Get flow export data
176
+ *
177
+ * @since 1.1.4
178
+ *
179
+ * @param integer $flow_id Flow ID.
180
+ * @return array
181
+ */
182
+ function get_flow_export_data( $flow_id ) {
183
+
184
+ $export_all = apply_filters( 'cartflows_export_all', false );
185
+
186
+ $valid_step_meta_keys = array(
187
+ '_wp_page_template',
188
+ '_thumbnail_id',
189
+ 'classic-editor-remember',
190
+ );
191
+
192
+ $new_steps = array();
193
+ $steps = get_post_meta( $flow_id, 'wcf-steps', true );
194
+ if ( $steps ) {
195
+ foreach ( $steps as $key => $step ) {
196
+
197
+ // Add step post meta.
198
+ $new_all_meta = array();
199
+ $all_meta = get_post_meta( $step['id'] );
200
+ if ( is_array( $all_meta ) ) {
201
+
202
+ if ( $export_all ) {
203
+ foreach ( $all_meta as $meta_key => $value ) {
204
+ $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
205
+ }
206
+ } else {
207
+
208
+ foreach ( $all_meta as $meta_key => $value ) {
209
+ if ( substr( $meta_key, 0, strlen( 'wcf' ) ) === 'wcf' ) {
210
+ $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
211
+ } elseif ( in_array( $meta_key, $valid_step_meta_keys ) ) {
212
+ $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ // Add single step.
219
+ $step_data_arr = array(
220
+ 'title' => get_the_title( $step['id'] ),
221
+ 'type' => $step['type'],
222
+ 'meta' => $new_all_meta,
223
+ 'post_content' => '',
224
+ );
225
+
226
+ if ( $export_all ) {
227
+
228
+ $step_post_obj = get_post( $step['id'] );
229
+
230
+ $step_data_arr['post_content'] = $step_post_obj->post_content;
231
+ }
232
+
233
+ $new_steps[] = $step_data_arr;
234
+ }
235
+ }
236
+
237
+ // Add single flow.
238
+ return array(
239
+ 'title' => get_the_title( $flow_id ),
240
+ 'steps' => $new_steps,
241
+ );
242
+ }
243
+
244
+ /**
245
+ * Get all flow export data
246
+ *
247
+ * @since 1.1.4
248
+ */
249
+ function get_all_flow_export_data() {
250
+
251
+ $query_args = array(
252
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
253
+
254
+ // Query performance optimization.
255
+ 'fields' => 'ids',
256
+ 'no_found_rows' => true,
257
+ 'posts_per_page' => -1,
258
+ );
259
+
260
+ $query = new WP_Query( $query_args );
261
+ $flows = array();
262
+ if ( $query->posts ) {
263
+ foreach ( $query->posts as $key => $post_id ) {
264
+ $flows[] = $this->get_flow_export_data( $post_id );
265
+ }
266
+ }
267
+
268
+ return $flows;
269
+ }
270
+
271
+ /**
272
+ * Import our exported file
273
+ *
274
+ * @since 1.1.4
275
+ */
276
+ function import_json() {
277
+ if ( empty( $_POST['cartflows-action'] ) || 'import' != $_POST['cartflows-action'] ) {
278
+ return;
279
+ }
280
+
281
+ if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
282
+ return;
283
+ }
284
+
285
+ if ( ! current_user_can( 'manage_options' ) ) {
286
+ return;
287
+ }
288
+
289
+ $filename = $_FILES['file']['name'];
290
+ $file_info = explode( '.', $filename );
291
+ $extension = end( $file_info );
292
+
293
+ if ( 'json' != $extension ) {
294
+ wp_die( __( 'Please upload a valid .json file', 'cartflows' ) );
295
+ }
296
+
297
+ $file = $_FILES['file']['tmp_name'];
298
+
299
+ if ( empty( $file ) ) {
300
+ wp_die( __( 'Please upload a file to import', 'cartflows' ) );
301
+ }
302
+
303
+ // Retrieve the settings from the file and convert the JSON object to an array.
304
+ $flows = json_decode( file_get_contents( $file ), true );
305
+
306
+ if ( $flows ) {
307
+
308
+ foreach ( $flows as $key => $flow ) {
309
+
310
+ $flow_title = $flow['title'];
311
+ if ( post_exists( $flow['title'] ) ) {
312
+ $flow_title = $flow['title'] . ' Copy';
313
+ }
314
+
315
+ // Create post object.
316
+ $new_flow_args = array(
317
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
318
+ 'post_title' => $flow_title,
319
+ 'post_status' => 'draft',
320
+ );
321
+
322
+ // Insert the post into the database.
323
+ $flow_id = wp_insert_post( $new_flow_args );
324
+
325
+ if ( $flow['steps'] ) {
326
+ foreach ( $flow['steps'] as $key => $step ) {
327
+
328
+ $new_step_id = wp_insert_post(
329
+ array(
330
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
331
+ 'post_title' => $step['title'],
332
+ 'post_status' => 'publish',
333
+ 'meta_input' => $step['meta'],
334
+ 'post_content' => isset( $step['post_content'] ) ? $step['post_content'] : '',
335
+ )
336
+ );
337
+
338
+ // Insert post meta.
339
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
340
+
341
+ $step_taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
342
+ $current_term = term_exists( $step['type'], $step_taxonomy );
343
+
344
+ // // Set type object.
345
+ $data = get_term( $current_term['term_id'], $step_taxonomy );
346
+ $step_slug = $data->slug;
347
+ wp_set_object_terms( $new_step_id, $data->slug, $step_taxonomy );
348
+
349
+ // Set type.
350
+ update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
351
+
352
+ // Set flow.
353
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
354
+
355
+ CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step['title'], $step_slug );
356
+
357
+ if ( isset( $step['post_content'] ) && ! empty( $step['post_content'] ) ) {
358
+
359
+ // Download and replace images.
360
+ $content = $this->get_content( $step['post_content'] );
361
+
362
+ // Update post content.
363
+ wp_update_post(
364
+ array(
365
+ 'ID' => $new_step_id,
366
+ 'post_content' => $content,
367
+ )
368
+ );
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+
375
+ add_action( 'admin_notices', array( $this, 'imported_successfully' ) );
376
+ }
377
+
378
+ /**
379
+ * Download and Replace hotlink images
380
+ *
381
+ * @since x.x.x
382
+ *
383
+ * @param string $content Mixed post content.
384
+ * @return array Hotlink image array.
385
+ */
386
+ function get_content( $content = '' ) {
387
+
388
+ $all_links = wp_extract_urls( $content );
389
+ $image_links = array();
390
+ $image_map = array();
391
+
392
+ // Not have any link.
393
+ if ( empty( $all_links ) ) {
394
+ return $content;
395
+ }
396
+
397
+ foreach ( $all_links as $key => $link ) {
398
+ if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $link ) ) {
399
+ $image_links[] = $link;
400
+ }
401
+ }
402
+
403
+ // Not have any image link.
404
+ if ( empty( $image_links ) ) {
405
+ return $content;
406
+ }
407
+
408
+ foreach ( $image_links as $key => $image_url ) {
409
+
410
+ // Download remote image.
411
+ $image = array(
412
+ 'url' => $image_url,
413
+ 'id' => rand( 000, 999 ),
414
+ );
415
+ $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
416
+
417
+ // Old and New image mapping links.
418
+ $image_map[ $image_url ] = $downloaded_image['url'];
419
+ }
420
+
421
+ // Replace old image links with new image links.
422
+ foreach ( $image_map as $old_url => $new_url ) {
423
+ $content = str_replace( $old_url, $new_url, $content );
424
+ }
425
+
426
+ return $content;
427
+
428
+ }
429
+
430
+ /**
431
+ * Imported notice
432
+ *
433
+ * @since 1.1.4
434
+ */
435
+ function imported_successfully() {
436
+ ?>
437
+ <div class="notice notice-success">
438
+ <p><?php _e( 'Successfully imported flows.', 'cartflows' ); ?></p>
439
+ </div>
440
+ <?php
441
+ }
442
+
443
+ /**
444
+ * Clear Cache.
445
+ *
446
+ * @since 1.0.0
447
+ */
448
+ public function clear_cache() {
449
+ // Clear 'Elementor' file cache.
450
+ if ( class_exists( '\Elementor\Plugin' ) ) {
451
+ Elementor\Plugin::$instance->files_manager->clear_cache();
452
+ }
453
+ }
454
+
455
+ /**
456
+ * JS Templates
457
+ *
458
+ * @since 1.0.0
459
+ *
460
+ * @return void
461
+ */
462
+ function js_templates() {
463
+
464
+ // Loading Templates.
465
+ ?>
466
+ <script type="text/template" id="tmpl-cartflows-step-loading">
467
+ <div class="template-message-block cartflows-step-loading">
468
+ <h2>
469
+ <span class="spinner"></span>
470
+ <?php _e( 'Loading Steps', 'cartflows' ); ?>
471
+ </h2>
472
+ <p class="description"><?php _e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
473
+ </div>
474
+ </script>
475
+
476
+ <?php
477
+ // Search Templates.
478
+ ?>
479
+ <script type="text/template" id="tmpl-cartflows-searching-templates">
480
+ <div class="template-message-block cartflows-searching-templates">
481
+ <h2>
482
+ <span class="spinner"></span>
483
+ <?php _e( 'Searching Template..', 'cartflows' ); ?>
484
+ </h2>
485
+ <p class="description"><?php _e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
486
+ </div>
487
+ </script>
488
+
489
+ <?php
490
+ // CartFlows Importing Template.
491
+ ?>
492
+ <script type="text/template" id="tmpl-cartflows-step-importing">
493
+ <div class="template-message-block cartflows-step-importing">
494
+ <h2><span class="spinner"></span> <?php _e( 'Importing..', 'cartflows' ); ?></h2>
495
+ </div>
496
+ </script>
497
+
498
+ <?php
499
+ // CartFlows Imported.
500
+ ?>
501
+ <script type="text/template" id="tmpl-cartflows-step-imported">
502
+ <div class="template-message-block cartflows-step-imported">
503
+ <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
504
+ <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
505
+ </script>
506
+
507
+ <?php
508
+ // No templates.
509
+ ?>
510
+ <script type="text/template" id="tmpl-cartflows-no-steps">
511
+ <div class="cartflows-no-steps">
512
+ <div class="template-message-block">
513
+ <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
514
+ <p class="description"></p>
515
+ </div>
516
+ </div>
517
+ </script>
518
+
519
+ <?php
520
+ // No templates.
521
+ ?>
522
+ <script type="text/template" id="tmpl-cartflows-no-flows">
523
+ <div class="cartflows-no-flows">
524
+ <div class="template-message-block">
525
+ <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
526
+ <p class="description"></p>
527
+ </div>
528
+ </div>
529
+ </script>
530
+
531
+ <?php
532
+ // Error handling.
533
+ ?>
534
+ <script type="text/template" id="tmpl-templator-error">
535
+ <div class="notice notice-error"><p>{{ data }}</p></div>
536
+ </script>
537
+
538
+ <?php
539
+ // Redirect to Elementor.
540
+ ?>
541
+ <script type="text/template" id="tmpl-templator-redirect-to-elementor">
542
+ <div class="template-message-block templator-redirect-to-elementor">
543
+ <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
544
+ <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php _e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
545
+ </script>
546
+
547
+ <?php
548
+ /**
549
+ * Responsive Buttons
550
+ */
551
+ ?>
552
+ <script type="text/template" id="tmpl-cartflows-responsive-view">
553
+ <span class="responsive-view">
554
+ <span class="actions">
555
+ <a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
556
+ <a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
557
+ <a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
558
+ </span>
559
+ </span>
560
+ </script>
561
+
562
+ <?php
563
+ // Templates data.
564
+ ?>
565
+ <script type="text/template" id="tmpl-cartflows-flows-list">
566
+
567
+ <# console.log( data.items.length ) #>
568
+ <# console.log( data.items ) #>
569
+ <# if ( data.items.length ) { #>
570
+ <# for ( key in data.items ) { #>
571
+ <#
572
+ var flow_steps = [];
573
+ if( data.items[ key ].flow_steps ) {
574
+ flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
575
+ return value['id'];
576
+ });
577
+ }
578
+ #>
579
+ <div class="inner">
580
+ <div class="template">
581
+ <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
582
+ <div class="template-screenshot">
583
+ <# if( data.items[ key ].featured_image_url ) { #>
584
+ <img src="{{ data.items[ key ].featured_image_url }}" />
585
+ <# } else { #>
586
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
587
+ <# } #>
588
+ </div>
589
+ <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>flow={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
590
+ <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
591
+ <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
592
+ <# } #>
593
+ </span>
594
+ <div class="template-id-container">
595
+ <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
596
+ <div class="template-actions">
597
+
598
+ <#
599
+ if( data.items[ key ].page_builder.slug ) {
600
+ required_plugin_group = data.items[ key ].page_builder.slug;
601
+ } else {
602
+ required_plugin_group = '';
603
+ }
604
+
605
+ if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
606
+ import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
607
+ } else {
608
+ import_btn_title = 'Import';
609
+ } #>
610
+
611
+ <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
612
+ <a data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
613
+ <# } else if( CartFlowsImportVars._is_pro_active ) { #>
614
+ <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
615
+ <# } else { #>
616
+ <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
617
+ <# } #>
618
+ </div>
619
+ </div>
620
+ </div>
621
+ </div>
622
+ <# } #>
623
+ <# } #>
624
+ </script>
625
+
626
+ <?php
627
+ // Empty Step.
628
+ ?>
629
+ <script type="text/template" id="tmpl-cartflows-create-blank-step">
630
+ <div class="inner">
631
+ <div class="template">
632
+ <span class="thumbnail site-preview cartflows-flow-preview">
633
+ <div class="template-screenshot">
634
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
635
+ </div>
636
+ <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
637
+ </span>
638
+ <div class="template-id-container">
639
+ <h3 class="template-name"> Blank </h3>
640
+ <div class="template-actions">
641
+ <a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create', 'cartflows' ); ?></a>
642
+ </div>
643
+ </div>
644
+ </div>
645
+ </div>
646
+ </script>
647
+
648
+ <?php
649
+ // Templates data.
650
+ ?>
651
+ <script type="text/template" id="tmpl-cartflows-steps-list">
652
+ <# if ( data.items.length ) { #>
653
+ <# for ( key in data.items ) { #>
654
+ <#
655
+ var flow_steps = [];
656
+ if( data.items[ key ].flow_steps ) {
657
+ flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
658
+ return value['id'];
659
+ });
660
+ }
661
+ #>
662
+ <div class="inner">
663
+ <div class="template">
664
+ <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
665
+ <div class="template-screenshot">
666
+ <# if( data.items[ key ].featured_image_url ) { #>
667
+ <img src="{{ data.items[ key ].featured_image_url }}" />
668
+ <# } else { #>
669
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
670
+ <# } #>
671
+ </div>
672
+ <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
673
+ <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>step={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
674
+ <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
675
+ <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
676
+ <# } #>
677
+ </span>
678
+ <div class="template-id-container">
679
+ <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
680
+ <div class="template-actions">
681
+
682
+ <#
683
+
684
+ var step_slug = data.items[ key ].step_type.slug || '';
685
+ var step_title = data.items[ key ].step_type.name || '';
686
+ var import_btn_title = 'Import';
687
+
688
+ var required_plugin_group = '';
689
+ if( data.items[ key ].page_builder ) {
690
+ required_plugin_group = data.items[ key ].page_builder.slug;
691
+
692
+ if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
693
+ import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
694
+ }
695
+ }
696
+ #>
697
+
698
+ <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
699
+ <a data-slug="{{step_slug}}" data-title="{{step_title}}" data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
700
+ <# } else if( CartFlowsImportVars._is_pro_active ) { #>
701
+ <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
702
+ <# } else { #>
703
+ <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
704
+ <# } #>
705
+ </div>
706
+ </div>
707
+ </div>
708
+ </div>
709
+ <# } #>
710
+ <# } #>
711
+ </script>
712
+
713
+ <?php
714
+ /**
715
+ * TMPL - Website Unreachable
716
+ */
717
+ ?>
718
+ <script type="text/template" id="tmpl-cartflows-website-unreachable">
719
+ <div class="postbox cartflows-website-unreachable">
720
+ <h2><?php _e( 'Under Maintenance..', 'cartflows' ); ?></h2>
721
+ <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly.', 'cartflows' ); ?></p>
722
+ <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website..', 'cartflows' ); ?></p>
723
+ </div>
724
+ </script>
725
+
726
+ <?php
727
+ /**
728
+ * TMPL - Filters
729
+ */
730
+ ?>
731
+ <script type="text/template" id="tmpl-cartflows-page-builder-notice">
732
+ <?php
733
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
734
+ $page_builder = Cartflows_Helper::get_required_plugins_for_page_builder( Cartflows_Helper::get_common_setting( 'default_page_builder' ) );
735
+ $title = $page_builder['title'];
736
+
737
+ $plugin_string = '<a href="#" data-slug="' . esc_html( $default_page_builder ) . '" class="wcf-install-plugin">Please click here and activate ' . esc_html( $title ) . '</a>';
738
+ $theme_status = '';
739
+ if ( 'divi' === $default_page_builder ) {
740
+
741
+ $theme_status = $page_builder['theme-status'];
742
+ $plugin_status = $page_builder['plugin-status'];
743
+
744
+ if ( 'deactivate' === $theme_status || 'install' === $plugin_status ) {
745
+ $plugin_string = 'Please activate ' . esc_html( $title );
746
+ } elseif ( ( 'deactivate' === $theme_status || 'not-installed' === $theme_status ) && 'install' === $plugin_status ) {
747
+ $plugin_string = 'Please install and activate ' . esc_html( $title );
748
+ }
749
+ }
750
+ ?>
751
+ <div class="wcf-page-builder-message">
752
+ <p><?php /* translators: %s: Plugin string */ printf( __( '%1$s to see CartFlows templates. If you prefer another page builder tool, you can <a href="%2$s" target="blank">select it here</a>.', 'cartflows' ), $plugin_string, admin_url( 'admin.php?page=' . CARTFLOWS_SETTINGS . '&action=common-settings#form-field-wcf_default_page_builder' ) ); ?></p>
753
+ <p>If your preferred page builder is not available, feel free to <a href="#" data-slug="canvas" class="wcf-create-from-scratch-link">create your own</a> pages using page builder of your choice as CartFlows works with all major page builders.</p>
754
+ <p>We plan to add design templates made with more page builder shortly!</p>
755
+ </div>
756
+ </script>
757
+
758
+ <?php
759
+ /**
760
+ * TMPL - Filters
761
+ */
762
+ ?>
763
+ <script type="text/template" id="tmpl-cartflows-term-filters-dropdown">
764
+ <# if ( data ) { #>
765
+ <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
766
+ <# if ( data.args.show_all ) { #>
767
+ <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
768
+ <# } #>
769
+ <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
770
+ <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
771
+ <# } #>
772
+ <# for ( key in data.items ) { #>
773
+ <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
774
+ <# } #>
775
+ </select>
776
+ <# } #>
777
+ </script>
778
+
779
+ <script type="text/template" id="tmpl-cartflows-term-filters">
780
+
781
+ <# if ( data ) { #>
782
+
783
+ <?php /* <# if ( CartFlowsImportVars.flow_page_builder === data.args.remote_slug || CartFlowsImportVars.step_page_builder === data.args.remote_slug ) { #> */ ?>
784
+ <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
785
+
786
+ <# if ( data.args.show_all ) { #>
787
+ <li>
788
+ <a href="#" data-group="all"> All </a>
789
+ </li>
790
+ <# } #>
791
+
792
+ <# for ( key in data.items ) { #>
793
+ <li>
794
+ <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</a>
795
+ </li>
796
+ <# } #>
797
+
798
+ </ul>
799
+
800
+ <?php
801
+
802
+ /*
803
+ <# } else { #>
804
+ <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
805
+
806
+ <# if ( data.args.show_all ) { #>
807
+ <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
808
+ <# } #>
809
+
810
+ <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
811
+ <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
812
+ <# } #>
813
+
814
+ <# for ( key in data.items ) { #>
815
+ <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
816
+ <# } #>
817
+
818
+ </select>
819
+ */
820
+ ?>
821
+
822
+ <?php /* <# } #> */ ?>
823
+
824
+ <# } #>
825
+ </script>
826
+
827
+ <?php
828
+ // Step Type.
829
+ ?>
830
+ <script type="text/template" id="tmpl-cartflows-step-types">
831
+ <ul class="wcf-tab nav-tabs">
832
+ <# if( data.items_count ) { #>
833
+ <# for( key in data.items ) { #>
834
+ <# console.log( data.items[ key ].id ) #>
835
+ <li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
836
+ <a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
837
+ </li>
838
+ <# } #>
839
+ <# } #>
840
+ </ul>
841
+ </script>
842
+
843
+ <?php
844
+ // Add to library button.
845
+ ?>
846
+ <script type="text/template" id="tmpl-templator-add-to-library">
847
+ <a class="templator-add-to-library page-title-action cartflows-load-steps-library"><i class="dashicons dashicons-cloud"></i><?php esc_attr_e( 'Import from Cloud', 'cartflows' ); ?></a>
848
+ </script>
849
+ <?php
850
+ }
851
+
852
+ /**
853
+ * Enqueue scripts
854
+ *
855
+ * @since 1.0.0
856
+ *
857
+ * @hook admin_enqueue_scripts
858
+ * @param string $hook Current page hook.
859
+ */
860
+ function scripts( $hook = '' ) {
861
+
862
+ if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
863
+ return;
864
+ }
865
+
866
+ wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
867
+ wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
868
+ wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
869
+ wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
870
+
871
+ $localize_vars = array(
872
+ '_is_pro_active' => _is_cartflows_pro(),
873
+
874
+ // Flow and its rest fields.
875
+ 'flow' => CARTFLOWS_FLOW_POST_TYPE,
876
+ 'flow_fields' => array(
877
+ 'id',
878
+ 'title',
879
+ 'flow_type',
880
+ 'page_builder',
881
+ 'flow_steps',
882
+ 'licence_status',
883
+ 'featured_image_url',
884
+ 'featured_media', // @required for field `featured_image_url`.
885
+ ),
886
+
887
+ // Flow type and rest fields.
888
+ 'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
889
+ 'flow_type_fields' => array(
890
+ 'id',
891
+ 'name',
892
+ 'slug',
893
+ ),
894
+
895
+ // Flow page builder and rest fields.
896
+ 'flow_page_builder' => CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER,
897
+ 'flow_page_builder_fields' => array(
898
+ 'id',
899
+ 'name',
900
+ 'slug',
901
+ ),
902
+
903
+ // Step page builder and rest fields.
904
+ 'step_page_builder' => CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER,
905
+ 'step_page_builder_fields' => array(
906
+ 'id',
907
+ 'name',
908
+ 'slug',
909
+ ),
910
+
911
+ // Step and its rest fields.
912
+ 'step' => CARTFLOWS_STEP_POST_TYPE,
913
+ 'step_fields' => array(
914
+ 'title',
915
+ 'featured_image_url',
916
+ 'featured_media', // @required for field `featured_image_url`.
917
+ 'id',
918
+ 'flow_type',
919
+ 'step_type',
920
+ 'page_builder',
921
+ 'licence_status',
922
+ ),
923
+
924
+ // Step type and its rest fields.
925
+ 'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
926
+ 'step_type_fields' => array(
927
+ 'id',
928
+ 'name',
929
+ 'slug',
930
+ ),
931
+
932
+ 'domain_url' => CARTFLOWS_DOMAIN_URL,
933
+ 'server_url' => CARTFLOWS_TEMPLATES_URL,
934
+ 'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
935
+ 'site_url' => site_url(),
936
+ 'import_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_importer' ),
937
+ 'export_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_exporter' ),
938
+ 'admin_url' => admin_url(),
939
+ 'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
940
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
941
+ 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
942
+
943
+ 'required_plugins' => Cartflows_Helper::get_plugins_groupby_page_builders(),
944
+
945
+ 'default_page_builder' => Cartflows_Helper::get_common_setting( 'default_page_builder' ),
946
+ );
947
+
948
+ // var_dump(Cartflows_Helper::get_common_setting( 'default_page_builder' ));
949
+ // wp_die( );
950
+ // Add thickbox.
951
+ add_thickbox();
952
+
953
+ wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
954
+ wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
955
+ }
956
+
957
+ /**
958
+ * Load Template
959
+ *
960
+ * @since 1.0.0
961
+ *
962
+ * @hook cartflows_load_steps
963
+ * @return void
964
+ */
965
+ function load_templates() {
966
+
967
+ check_ajax_referer( 'cf-load-steps', 'security' );
968
+
969
+ $args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array();
970
+ $templates = CartFlows_API::get_instance()->get_templates( $args );
971
+
972
+ if ( $templates['templates_count'] ) {
973
+ wp_send_json_success( $templates );
974
+ } else {
975
+ wp_send_json_error( $templates );
976
+ }
977
+ wp_die();
978
+ }
979
+
980
+ /**
981
+ * Import.
982
+ *
983
+ * @since 1.0.0
984
+ *
985
+ * @hook wp_ajax_cartflows_import_flow_step
986
+ * @return void
987
+ */
988
+ function import_flow() {
989
+
990
+ check_ajax_referer( 'cf-import-flow-step', 'security' );
991
+
992
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
993
+ $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
994
+
995
+ wcf()->logger->import_log( '------------------------------------' );
996
+ wcf()->logger->import_log( 'STARTED! Importing FLOW' );
997
+ wcf()->logger->import_log( '------------------------------------' );
998
+ wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
999
+
1000
+ $response = CartFlows_API::get_instance()->get_template( $template_id );
1001
+
1002
+ $post_content = isset( $response['data']['content']->rendered ) ? $response['data']['content']->rendered : '';
1003
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1004
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1005
+ $post_content = $response['data']['divi_content'];
1006
+ }
1007
+ }
1008
+
1009
+ if ( false === $response['success'] ) {
1010
+ wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
1011
+ wp_send_json_error( $response );
1012
+ }
1013
+
1014
+ wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . json_encode( $response ) );
1015
+
1016
+ $new_step_id = wp_insert_post(
1017
+ array(
1018
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1019
+ 'post_title' => $response['title'],
1020
+ 'post_content' => $post_content,
1021
+ 'post_status' => 'publish',
1022
+ )
1023
+ );
1024
+
1025
+ if ( is_wp_error( $new_step_id ) ) {
1026
+ wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
1027
+ wp_send_json_error( $new_step_id );
1028
+ }
1029
+
1030
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1031
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1032
+ update_post_meta( $new_step_id, 'divi_content', $response['data']['divi_content'] );
1033
+ }
1034
+ }
1035
+
1036
+ /* Imported Step */
1037
+ update_post_meta( $new_step_id, 'cartflows_imported_step', 'yes' );
1038
+
1039
+ wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );
1040
+ // insert post meta.
1041
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1042
+ wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
1043
+
1044
+ /**
1045
+ * Import & Set type.
1046
+ */
1047
+ $term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
1048
+ $term_slug = '';
1049
+ if ( $term ) {
1050
+
1051
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1052
+ $term_exist = term_exists( $term->name, $taxonomy );
1053
+
1054
+ if ( empty( $term_exist ) ) {
1055
+ $terms = array(
1056
+ array(
1057
+ 'name' => $term->name,
1058
+ ),
1059
+ );
1060
+
1061
+ Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1062
+ wcf()->logger->import_log( '(✓) Created new term ' . $term->name );
1063
+ }
1064
+
1065
+ $current_term = term_exists( $term->name, $taxonomy );
1066
+
1067
+ // Set type object.
1068
+ $data = get_term( $current_term['term_id'], $taxonomy );
1069
+ $term_slug = $data->slug;
1070
+ $term_name = $data->name;
1071
+ wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1072
+ wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
1073
+
1074
+ // Set type.
1075
+ update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
1076
+ wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
1077
+ }
1078
+
1079
+ // Set flow.
1080
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1081
+ wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1082
+
1083
+ /**
1084
+ * Update steps for the current flow.
1085
+ */
1086
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1087
+
1088
+ if ( ! is_array( $flow_steps ) ) {
1089
+ $flow_steps = array();
1090
+ }
1091
+
1092
+ $flow_steps[] = array(
1093
+ 'id' => $new_step_id,
1094
+ 'title' => $response['title'],
1095
+ 'type' => $term_slug,
1096
+ );
1097
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1098
+ wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1099
+
1100
+ // Import Post Meta.
1101
+ self::import_post_meta( $new_step_id, $response );
1102
+
1103
+ wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
1104
+ wcf()->logger->import_log( '------------------------------------' );
1105
+ wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
1106
+ wcf()->logger->import_log( '------------------------------------' );
1107
+
1108
+ do_action( 'cartflows_import_complete' );
1109
+ wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
1110
+
1111
+ // Batch Process.
1112
+ do_action( 'cartflows_after_template_import', $new_step_id, $response );
1113
+
1114
+ /**
1115
+ * End
1116
+ */
1117
+ wp_send_json_success( $new_step_id );
1118
+ }
1119
+
1120
+ /**
1121
+ * Import Step.
1122
+ *
1123
+ * @since 1.0.0
1124
+ * @hook wp_ajax_cartflows_step_import
1125
+ *
1126
+ * @return void
1127
+ */
1128
+ function create_default_flow() {
1129
+
1130
+ check_ajax_referer( 'cf-default-flow', 'security' );
1131
+
1132
+ // Create post object.
1133
+ $new_flow_post = array(
1134
+ 'post_content' => '',
1135
+ 'post_status' => 'publish',
1136
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1137
+ );
1138
+
1139
+ // Insert the post into the database.
1140
+ $flow_id = wp_insert_post( $new_flow_post );
1141
+
1142
+ if ( is_wp_error( $flow_id ) ) {
1143
+ wp_send_json_error( $flow_id->get_error_message() );
1144
+ }
1145
+
1146
+ $flow_steps = array();
1147
+
1148
+ $steps_data = array(
1149
+ 'landing' => __( 'Landing Page', 'cartflows' ),
1150
+ 'checkout' => __( 'Checkout Page', 'cartflows' ),
1151
+ 'thankyou' => __( 'Thank You Page', 'cartflows' ),
1152
+ );
1153
+
1154
+ foreach ( $steps_data as $slug => $title ) {
1155
+
1156
+ $post_content = '';
1157
+
1158
+ switch ( $slug ) {
1159
+ case 'checkout':
1160
+ $post_content = '';
1161
+ break;
1162
+ case 'thankyou':
1163
+ $post_content = '';
1164
+ break;
1165
+ default:
1166
+ $post_content = '';
1167
+ break;
1168
+ }
1169
+
1170
+ $step_id = wp_insert_post(
1171
+ array(
1172
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1173
+ 'post_title' => $title,
1174
+ 'post_content' => $post_content,
1175
+ 'post_status' => 'publish',
1176
+ )
1177
+ );
1178
+
1179
+ if ( is_wp_error( $step_id ) ) {
1180
+ wp_send_json_error( $step_id->get_error_message() );
1181
+ }
1182
+
1183
+ if ( $step_id ) {
1184
+
1185
+ $flow_steps[] = array(
1186
+ 'id' => $step_id,
1187
+ 'title' => $title,
1188
+ 'type' => $slug,
1189
+ );
1190
+
1191
+ // insert post meta.
1192
+ update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
1193
+ update_post_meta( $step_id, 'wcf-step-type', $slug );
1194
+
1195
+ wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1196
+ wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1197
+ }
1198
+ }
1199
+
1200
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1201
+
1202
+ wp_send_json_success( $flow_id );
1203
+ }
1204
+
1205
+ /**
1206
+ * Create Flow
1207
+ *
1208
+ * @return void
1209
+ */
1210
+ function create_flow() {
1211
+
1212
+ check_ajax_referer( 'cf-create-flow', 'security' );
1213
+
1214
+ // Create post object.
1215
+ $new_flow_post = array(
1216
+ 'post_content' => '',
1217
+ 'post_status' => 'publish',
1218
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1219
+ );
1220
+
1221
+ // Insert the post into the database.
1222
+ $flow_id = wp_insert_post( $new_flow_post );
1223
+
1224
+ if ( is_wp_error( $flow_id ) ) {
1225
+ wp_send_json_error( $flow_id->get_error_message() );
1226
+ }
1227
+
1228
+ /* Imported Flow */
1229
+ update_post_meta( $flow_id, 'cartflows_imported_flow', 'yes' );
1230
+
1231
+ wp_send_json_success( $flow_id );
1232
+ }
1233
+
1234
+ /**
1235
+ * Create Step
1236
+ *
1237
+ * @return void
1238
+ */
1239
+ function import_step() {
1240
+
1241
+ check_ajax_referer( 'cf-step-import', 'security' );
1242
+
1243
+ $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1244
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1245
+ $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1246
+ $step_type = isset( $_POST['step_type'] ) ? sanitize_title( $_POST['step_type'] ) : '';
1247
+ $step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( $_POST['step_custom_title'] ) : $step_title;
1248
+
1249
+ $cartflow_meta = Cartflows_Flow_Meta::get_instance();
1250
+
1251
+ $post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
1252
+
1253
+ wcf()->logger->import_log( '------------------------------------' );
1254
+ wcf()->logger->import_log( 'STARTED! Importing STEP' );
1255
+ wcf()->logger->import_log( '------------------------------------' );
1256
+
1257
+ if ( empty( $template_id ) || empty( $post_id ) ) {
1258
+ /* translators: %s: template ID */
1259
+ $data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
1260
+ wcf()->logger->import_log( $data );
1261
+ wp_send_json_error( $data );
1262
+ }
1263
+
1264
+ wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
1265
+
1266
+ $response = CartFlows_API::get_instance()->get_template( $template_id );
1267
+
1268
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1269
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1270
+ update_post_meta( $post_id, 'divi_content', $response['data']['divi_content'] );
1271
+
1272
+ wp_update_post(
1273
+ array(
1274
+ 'ID' => $post_id,
1275
+ 'post_content' => $response['data']['divi_content'],
1276
+ )
1277
+ );
1278
+ }
1279
+ }
1280
+
1281
+ /* Imported Step */
1282
+ update_post_meta( $post_id, 'cartflows_imported_step', 'yes' );
1283
+
1284
+ // Import Post Meta.
1285
+ self::import_post_meta( $post_id, $response );
1286
+
1287
+ do_action( 'cartflows_import_complete' );
1288
+
1289
+ // Batch Process.
1290
+ do_action( 'cartflows_after_template_import', $post_id, $response );
1291
+
1292
+ wcf()->logger->import_log( '------------------------------------' );
1293
+ wcf()->logger->import_log( 'COMPLETE! Importing Step' );
1294
+ wcf()->logger->import_log( '------------------------------------' );
1295
+
1296
+ wp_send_json_success( $post_id );
1297
+ }
1298
+
1299
+ /**
1300
+ * Import Step.
1301
+ *
1302
+ * @since 1.0.0
1303
+ * @hook wp_ajax_cartflows_step_create_blank
1304
+ *
1305
+ * @return void
1306
+ */
1307
+ function step_create_blank() {
1308
+
1309
+ check_ajax_referer( 'cf-step-create-blank', 'security' );
1310
+
1311
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1312
+ $step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( $_POST['step_type'] ) : '';
1313
+ $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1314
+
1315
+ if ( empty( $flow_id ) || empty( $step_type ) ) {
1316
+ /* translators: %s: flow ID */
1317
+ $data = sprintf( __( 'Invalid flow id %1$s OR step type %2$s.', 'cartflows' ), $flow_id, $step_type );
1318
+ wcf()->logger->import_log( $data );
1319
+ wp_send_json_error( $data );
1320
+ }
1321
+
1322
+ wcf()->logger->import_log( '------------------------------------' );
1323
+ wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
1324
+
1325
+ $step_type_title = str_replace( '-', ' ', $step_type );
1326
+ $step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
1327
+
1328
+ $new_step_id = wp_insert_post(
1329
+ array(
1330
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1331
+ 'post_title' => $step_title,
1332
+ 'post_content' => '',
1333
+ 'post_status' => 'publish',
1334
+ )
1335
+ );
1336
+
1337
+ // insert post meta.
1338
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1339
+
1340
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1341
+ $term_exist = term_exists( $step_type_title, $taxonomy );
1342
+
1343
+ if ( empty( $term_exist ) ) {
1344
+ $terms = array(
1345
+ array(
1346
+ 'name' => $step_type_title,
1347
+ ),
1348
+ );
1349
+
1350
+ Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1351
+ wcf()->logger->import_log( '(✓) Created new term ' . $step_type_title );
1352
+ }
1353
+
1354
+ $current_term = term_exists( $step_type_title, $taxonomy );
1355
+
1356
+ // Set type object.
1357
+ $data = get_term( $current_term['term_id'], $taxonomy );
1358
+ $step_slug = $data->slug;
1359
+ wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1360
+ wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
1361
+
1362
+ // Set type.
1363
+ update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
1364
+ wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
1365
+
1366
+ // Set flow.
1367
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1368
+ wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1369
+
1370
+ CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
1371
+
1372
+ wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
1373
+ wcf()->logger->import_log( '------------------------------------' );
1374
+
1375
+ wp_send_json_success( $new_step_id );
1376
+ }
1377
+
1378
+ /**
1379
+ * Import Post Meta
1380
+ *
1381
+ * @since 1.0.0
1382
+ *
1383
+ * @param integer $post_id Post ID.
1384
+ * @param array $response Post meta.
1385
+ * @return void
1386
+ */
1387
+ public static function import_post_meta( $post_id, $response ) {
1388
+
1389
+ $metadata = (array) $response['post_meta'];
1390
+
1391
+ foreach ( $metadata as $meta_key => $meta_value ) {
1392
+ $meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
1393
+
1394
+ if ( $meta_value ) {
1395
+
1396
+ if ( is_serialized( $meta_value, true ) ) {
1397
+ $raw_data = maybe_unserialize( stripslashes( $meta_value ) );
1398
+ } elseif ( is_array( $meta_value ) ) {
1399
+ $raw_data = json_decode( stripslashes( $meta_value ), true );
1400
+ } else {
1401
+ $raw_data = $meta_value;
1402
+ }
1403
+
1404
+ if ( '_elementor_data' === $meta_key ) {
1405
+ if ( is_array( $raw_data ) ) {
1406
+ $raw_data = wp_slash( json_encode( $raw_data ) );
1407
+ } else {
1408
+ $raw_data = wp_slash( $raw_data );
1409
+ }
1410
+ }
1411
+ if ( '_elementor_data' !== $meta_key && '_elementor_draft' !== $meta_key && '_fl_builder_data' !== $meta_key && '_fl_builder_draft' !== $meta_key ) {
1412
+ if ( is_array( $raw_data ) ) {
1413
+ wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . json_encode( $raw_data ) );
1414
+ } else {
1415
+ if ( ! is_object( $raw_data ) ) {
1416
+ wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
1417
+ }
1418
+ }
1419
+ }
1420
+
1421
+ update_post_meta( $post_id, $meta_key, $raw_data );
1422
+ }
1423
+ }
1424
+ }
1425
+
1426
+ /**
1427
+ * Import Template for Elementor
1428
+ *
1429
+ * @since 1.0.0
1430
+ *
1431
+ * @param integer $post_id Post ID.
1432
+ * @param array $response Post meta.
1433
+ * @param array $page_build_data Page build data.
1434
+ * @return void
1435
+ */
1436
+ public static function import_template_elementor( $post_id, $response, $page_build_data ) {
1437
+ if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
1438
+ $data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
1439
+ wcf()->logger->import_log( $data );
1440
+ wp_send_json_error( $data );
1441
+ }
1442
+
1443
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
1444
+
1445
+ wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
1446
+
1447
+ $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
1448
+ $obj->import_single_template( $post_id );
1449
+
1450
+ wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
1451
+ }
1452
+
1453
+ /**
1454
+ * Supported post types
1455
+ *
1456
+ * @since 1.0.0
1457
+ *
1458
+ * @return array Supported post types.
1459
+ */
1460
+ public static function supported_post_types() {
1461
+ return apply_filters(
1462
+ 'cartflows_supported_post_types',
1463
+ array(
1464
+ CARTFLOWS_FLOW_POST_TYPE,
1465
+ )
1466
+ );
1467
+ }
1468
+
1469
+ /**
1470
+ * Check supported post type
1471
+ *
1472
+ * @since 1.0.0
1473
+ *
1474
+ * @param string $post_type Post type.
1475
+ * @return boolean Supported post type status.
1476
+ */
1477
+ public static function is_supported_post( $post_type = '' ) {
1478
+ if ( in_array( $post_type, self::supported_post_types() ) ) {
1479
+ return true;
1480
+ }
1481
+
1482
+ return false;
1483
+ }
1484
+
1485
+ /**
1486
+ * Set steps to the flow
1487
+ *
1488
+ * @param integer $flow_id Flow ID.
1489
+ * @param integer $new_step_id New step ID.
1490
+ * @param string $step_title Flow Type.
1491
+ * @param string $step_slug Flow Type.
1492
+ */
1493
+ function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
1494
+ // Update steps for the current flow.
1495
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1496
+
1497
+ if ( ! is_array( $flow_steps ) ) {
1498
+ $flow_steps = array();
1499
+ }
1500
+
1501
+ $flow_steps[] = array(
1502
+ 'id' => $new_step_id,
1503
+ 'title' => $step_title,
1504
+ 'type' => $step_slug,
1505
+ );
1506
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1507
+ wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1508
+ }
1509
+
1510
+ /**
1511
+ * Localize variables in admin
1512
+ *
1513
+ * @param array $vars variables.
1514
+ */
1515
+ function localize_vars( $vars ) {
1516
+
1517
+ $ajax_actions = array(
1518
+ 'cf_step_import',
1519
+ 'cf_load_steps',
1520
+ 'cf_create_flow',
1521
+ 'cf_default_flow',
1522
+ 'cf_step_create_blank',
1523
+ 'cf_import_flow_step',
1524
+ );
1525
+
1526
+ foreach ( $ajax_actions as $action ) {
1527
+
1528
+ $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1529
+ }
1530
+
1531
+ return $vars;
1532
+ }
1533
+
1534
+ /**
1535
+ * Ajax action to activate plugin
1536
+ */
1537
+ public function activate_plugin() {
1538
+
1539
+ $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
1540
+
1541
+ $activate = activate_plugin( $plugin_init, '', false, true );
1542
+
1543
+ if ( is_wp_error( $activate ) ) {
1544
+ wp_send_json_error(
1545
+ array(
1546
+ 'success' => false,
1547
+ 'message' => $activate->get_error_message(),
1548
+ 'init' => $plugin_init,
1549
+ )
1550
+ );
1551
+ }
1552
+
1553
+ wp_send_json_success(
1554
+ array(
1555
+ 'success' => true,
1556
+ 'message' => __( 'Plugin Successfully Activated', 'cartflows' ),
1557
+ 'init' => $plugin_init,
1558
+ )
1559
+ );
1560
+ }
1561
+
1562
+ }
1563
+
1564
+ /**
1565
+ * Initialize class object with 'get_instance()' method
1566
+ */
1567
+ CartFlows_Importer::get_instance();
1568
+
1569
+ endif;
classes/class-cartflows-loader.php CHANGED
@@ -115,7 +115,7 @@ if ( ! class_exists( 'Cartflows_Loader' ) ) {
115
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
116
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
117
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
118
- define( 'CARTFLOWS_VER', '1.1.12' );
119
  define( 'CARTFLOWS_SLUG', 'cartflows' );
120
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
121
 
115
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
116
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
117
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
118
+ define( 'CARTFLOWS_VER', '1.1.13' );
119
  define( 'CARTFLOWS_SLUG', 'cartflows' );
120
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
121
 
classes/class-cartflows-logger.php CHANGED
@@ -1,101 +1,101 @@
1
- <?php
2
- /**
3
- * Logger.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Logger {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Member Variable
25
- *
26
- * @var logger
27
- */
28
- public $logger;
29
-
30
- /**
31
- * Initiator
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- */
43
- public function __construct() {
44
-
45
- /* Load WC Logger */
46
- add_action( 'init', array( $this, 'init_wc_logger' ), 99 );
47
- }
48
-
49
- /**
50
- * Inint Logger.
51
- *
52
- * @since 1.0.0
53
- */
54
- function init_wc_logger() {
55
- $this->logger = new WC_Logger();
56
- }
57
-
58
- /**
59
- * Write log
60
- *
61
- * @param string $message log message.
62
- * @param string $level type of log.
63
- * @since 1.0.0
64
- */
65
- function log( $message, $level = 'info' ) {
66
-
67
- $enable_log = apply_filters( 'cartflows_enable_log', 'enable' );
68
-
69
- if ( 'enable' === $enable_log &&
70
- is_a( $this->logger, 'WC_Logger' ) &&
71
- did_action( 'plugins_loaded' )
72
- ) {
73
-
74
- $this->logger->log( $level, $message, array( 'source' => 'cartflows' ) );
75
- }
76
- }
77
-
78
- /**
79
- * Write log
80
- *
81
- * @param string $message log message.
82
- * @param string $level type of log.
83
- * @since 1.0.0
84
- */
85
- function import_log( $message, $level = 'info' ) {
86
-
87
- if ( defined( 'WP_DEBUG' ) &&
88
- WP_DEBUG &&
89
- is_a( $this->logger, 'WC_Logger' ) &&
90
- did_action( 'plugins_loaded' )
91
- ) {
92
-
93
- $this->logger->log( $level, $message, array( 'source' => 'cartflows-import' ) );
94
- }
95
- }
96
- }
97
-
98
- /**
99
- * Kicking this off by calling 'get_instance()' method
100
- */
101
- Cartflows_Logger::get_instance();
1
+ <?php
2
+ /**
3
+ * Logger.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Logger {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var logger
27
+ */
28
+ public $logger;
29
+
30
+ /**
31
+ * Initiator
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ */
43
+ public function __construct() {
44
+
45
+ /* Load WC Logger */
46
+ add_action( 'init', array( $this, 'init_wc_logger' ), 99 );
47
+ }
48
+
49
+ /**
50
+ * Inint Logger.
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ function init_wc_logger() {
55
+ $this->logger = new WC_Logger();
56
+ }
57
+
58
+ /**
59
+ * Write log
60
+ *
61
+ * @param string $message log message.
62
+ * @param string $level type of log.
63
+ * @since 1.0.0
64
+ */
65
+ function log( $message, $level = 'info' ) {
66
+
67
+ $enable_log = apply_filters( 'cartflows_enable_log', 'enable' );
68
+
69
+ if ( 'enable' === $enable_log &&
70
+ is_a( $this->logger, 'WC_Logger' ) &&
71
+ did_action( 'plugins_loaded' )
72
+ ) {
73
+
74
+ $this->logger->log( $level, $message, array( 'source' => 'cartflows' ) );
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Write log
80
+ *
81
+ * @param string $message log message.
82
+ * @param string $level type of log.
83
+ * @since 1.0.0
84
+ */
85
+ function import_log( $message, $level = 'info' ) {
86
+
87
+ if ( defined( 'WP_DEBUG' ) &&
88
+ WP_DEBUG &&
89
+ is_a( $this->logger, 'WC_Logger' ) &&
90
+ did_action( 'plugins_loaded' )
91
+ ) {
92
+
93
+ $this->logger->log( $level, $message, array( 'source' => 'cartflows-import' ) );
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Kicking this off by calling 'get_instance()' method
100
+ */
101
+ Cartflows_Logger::get_instance();
classes/class-cartflows-meta-fields.php CHANGED
@@ -1,1482 +1,1482 @@
1
- <?php
2
- // @codingStandardsIgnoreStart
3
- /**
4
- * Meta Fields.
5
- *
6
- * @package CartFlows
7
- */
8
-
9
- /**
10
- * Class Cartflows_Meta_Fields.
11
- */
12
- class Cartflows_Meta_Fields {
13
-
14
- /**
15
- * Instance
16
- *
17
- * @var $instance
18
- */
19
- private static $instance;
20
-
21
- /**
22
- * Initiator
23
- */
24
- public static function get_instance() {
25
- if ( ! isset( self::$instance ) ) {
26
- self::$instance = new self;
27
- }
28
-
29
- return self::$instance;
30
- }
31
-
32
- /**
33
- * Constructor
34
- */
35
- public function __construct() {
36
-
37
- /* Add Scripts */
38
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_meta_scripts' ), 20 );
39
-
40
- add_action( 'wp_ajax_wcf_json_search_coupons', array( $this, 'json_search_coupons' ) );
41
-
42
- add_action( 'wp_ajax_wcf_add_checkout_custom_field', array( $this, 'add_checkout_custom_field' ) );
43
-
44
- add_action( 'wp_ajax_wcf_pro_add_checkout_custom_field', array( $this, 'add_pro_checkout_custom_field' ) );
45
-
46
- add_action( 'wp_ajax_wcf_delete_checkout_custom_field', array( $this, 'delete_checkout_custom_field' ) );
47
-
48
- add_action( 'wp_ajax_wcf_json_search_pages', array( $this, 'json_search_pages' ) );
49
-
50
- add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
51
- }
52
-
53
- public function admin_meta_scripts() {
54
-
55
- global $pagenow;
56
- global $post;
57
-
58
- $screen = get_current_screen();
59
-
60
- if (
61
- ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) &&
62
- wcf()->utils->is_step_post_type( $screen->post_type )
63
- ) {
64
-
65
- wp_enqueue_style( 'woocommerce_admin_styles' );
66
-
67
- wp_enqueue_script( 'select2' );
68
- wp_enqueue_script( 'wc-enhanced-select' );
69
-
70
- wp_enqueue_script(
71
- 'wcf-admin-meta',
72
- CARTFLOWS_URL . 'admin/meta-assets/js/admin-edit.js',
73
- array( 'jquery', 'select2', 'wp-color-picker' ),
74
- CARTFLOWS_VER,
75
- true
76
- );
77
-
78
- wp_enqueue_style( 'wcf-admin-meta', CARTFLOWS_URL . 'admin/meta-assets/css/admin-edit.css', array( 'wp-color-picker' ), CARTFLOWS_VER );
79
- wp_style_add_data( 'wcf-admin-meta', 'rtl', 'replace' );
80
-
81
- $localize = array(
82
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
83
- 'google_fonts' => CartFlows_Font_Families::get_google_fonts(),
84
- 'system_fonts' => CartFlows_Font_Families::get_system_fonts(),
85
- 'font_weights' => array(
86
- '100' => __( 'Thin 100', 'cartflows' ),
87
- '200' => __( 'Extra-Light 200', 'cartflows' ),
88
- '300' => __( 'Light 300', 'cartflows' ),
89
- '400' => __( 'Normal 400', 'cartflows' ),
90
- '500' => __( 'Medium 500', 'cartflows' ),
91
- '600' => __( 'Semi-Bold 600', 'cartflows' ),
92
- '700' => __( 'Bold 700', 'cartflows' ),
93
- '800' => __( 'Extra-Bold 800', 'cartflows' ),
94
- '900' => __( 'Ultra-Bold 900', 'cartflows' ),
95
- )
96
- );
97
-
98
- wp_localize_script( 'jquery', 'wcf', apply_filters( 'wcf_js_localize', $localize ) );
99
-
100
- do_action( 'cartflows_admin_meta_scripts' );
101
- }
102
- }
103
-
104
- /**
105
- * Function to search coupons
106
- */
107
- public function json_search_coupons() {
108
-
109
- check_admin_referer( 'wcf-json-search-coupons', 'security' );
110
-
111
- global $wpdb;
112
-
113
- $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
114
-
115
- if ( empty( $term ) ) {
116
- die();
117
- }
118
-
119
- $posts = wp_cache_get( 'wcf_search_coupons', 'wcf_funnel_Cart' );
120
-
121
- if ( false === $posts ) {
122
- $posts = $wpdb->get_results( // phpcs:ignore
123
- $wpdb->prepare(
124
- "SELECT *
125
- FROM {$wpdb->prefix}posts
126
- WHERE post_type = %s
127
- AND post_title LIKE %s
128
- AND post_status = %s",
129
- 'shop_coupon',
130
- $wpdb->esc_like( $term ) . '%',
131
- 'publish'
132
- )
133
- );
134
- wp_cache_set( 'wcf_search_coupons', $posts, 'wcf_funnel_Cart' );
135
- }
136
-
137
- $coupons_found = array();
138
- $all_discount_types = wc_get_coupon_types();
139
-
140
- if ( $posts ) {
141
- foreach ( $posts as $post ) {
142
-
143
- $discount_type = get_post_meta( $post->ID, 'discount_type', true );
144
-
145
- if ( ! empty( $all_discount_types[ $discount_type ] ) ) {
146
- $coupons_found[ get_the_title( $post->ID ) ] = get_the_title( $post->ID ) . ' (Type: ' . $all_discount_types[ $discount_type ] . ')';
147
- }
148
- }
149
- }
150
-
151
- wp_send_json( $coupons_found );
152
- }
153
-
154
- /**
155
- * [add_checkout_custom_field description]
156
- *
157
- * @hook wcf_add_checkout_custom_field
158
- */
159
- public function add_checkout_custom_field() {
160
-
161
- check_ajax_referer( 'wcf-add-checkout-custom-field', 'security' );
162
-
163
- $post_id = intval( $_POST['post_id'] );
164
- $add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
165
- $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
166
- $options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
167
- $label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
168
- $name = sanitize_text_field( wp_unslash( $_POST['name'] ) );
169
-
170
- if ( '' !== $name ) {
171
-
172
- $fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
173
- $field_keys = array_keys($fields);
174
-
175
- $name = $add_to . '_' . sanitize_key( $name );
176
- if( in_array($name, $field_keys) ) {
177
- $name = $name . '_' . rand( 0000, 9999 );
178
- }
179
-
180
- $field_data = array(
181
- 'type' => $type,
182
- 'label' => $label,
183
- 'placeholder' => '',
184
- 'class' => array( 'form-row-wide' ),
185
- 'label_class' => array(),
186
- 'required' => true,
187
- 'custom' => true,
188
- );
189
-
190
- if ( 'select' === $type ) {
191
-
192
- $options = explode( ',', $options );
193
- $field_data['options'] = array();
194
-
195
- if ( is_array( $options ) && ! empty( $options ) ) {
196
-
197
- foreach ( $options as $key => $value ) {
198
-
199
- $field_data['options'][ $value ] = $value;
200
- }
201
- }
202
- }
203
-
204
- Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
205
-
206
- $key = sanitize_key( $name );
207
- $name = 'wcf-' . $key;
208
-
209
- $field_args = array(
210
- 'label' => $label,
211
- 'name' => $name,
212
- 'value' => 'yes',
213
- 'after' => 'Enable',
214
- );
215
-
216
- $field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> | ';
217
- $field_args['after_html'] .= '<a class="wcf-cpf-action-remove">' . __( 'Remove', 'cartflows' ) . '</a>';
218
- $field_args['after_html'] .= '</span>';
219
-
220
- $field_markup = wcf()->meta->get_checkbox_field( $field_args );
221
-
222
- if( 'billing' === $add_to ) {
223
- $add_to_class = 'wcf-cb-fields';
224
- } else if( 'shipping' === $add_to ) {
225
- $add_to_class = 'wcf-sb-fields';
226
- }
227
-
228
- $data = array(
229
- 'field_data' => $field_data,
230
- 'field_args' => $field_args,
231
- 'add_to_class' => $add_to_class,
232
- 'markup' => $field_markup,
233
- );
234
-
235
- wp_send_json( $data );
236
- }
237
-
238
- wp_send_json( false );
239
-
240
- }
241
-
242
- /**
243
- * [add_checkout_custom_field description]
244
- *
245
- * @hook wcf_add_checkout_custom_field
246
- */
247
- public function add_pro_checkout_custom_field() {
248
-
249
- check_ajax_referer( 'wcf-pro-add-checkout-custom-field', 'security' );
250
-
251
- $post_id = intval( $_POST['post_id'] );
252
- $add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
253
- $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
254
- $options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
255
- $label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
256
- $name = sanitize_text_field( wp_unslash( str_replace(' ', '_', $_POST['label'] ) ) );
257
- $placeholder = sanitize_text_field( wp_unslash( $_POST['placeholder'] ) );
258
- $width = sanitize_text_field( wp_unslash( $_POST['width'] ) );
259
- $default_value = sanitize_text_field( wp_unslash( $_POST['default'] ) );
260
- $is_required = sanitize_text_field( wp_unslash( $_POST['required'] ) );
261
-
262
- $field_markup = '';
263
-
264
- if ( '' !== $name ) {
265
-
266
- $fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
267
- $field_keys = array_keys($fields);
268
-
269
- $name = $add_to . '_' . sanitize_key( $name );
270
- if( in_array($name, $field_keys) ) {
271
- $name = $name . '_' . rand( 0000, 9999 );
272
- }
273
-
274
- $field_data = array(
275
- 'type' => $type,
276
- 'label' => $label,
277
- 'placeholder' => $placeholder,
278
- 'class' => array( 'form-row-wide' ),
279
- 'label_class' => array(),
280
- 'required' => $is_required,
281
- 'custom' => true,
282
- 'default' => $default_value,
283
- 'options' => $options,
284
- );
285
-
286
- if ( 'select' === $type ) {
287
-
288
- $options = explode( ',', $options );
289
- $field_data['options'] = array();
290
-
291
- if ( is_array( $options ) && ! empty( $options ) ) {
292
-
293
- foreach ( $options as $key => $value ) {
294
-
295
- $field_data['options'][ $value ] = $value;
296
- }
297
- }
298
- }
299
-
300
- $width_args = array(
301
- 'wcf-field-width_'.$name => $width,
302
- );
303
-
304
- Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
305
- Cartflows_Helper::save_meta_option( $post_id, $width_args );
306
-
307
- $key = sanitize_key( $name );
308
- $name = 'wcf-' . $key;
309
-
310
- $field_args = array(
311
- 'type' => $type,
312
- 'label' => $label,
313
- 'name' => $name,
314
- 'value' => 'yes',
315
- 'placeholder' => $placeholder,
316
- 'width' => $width,
317
- 'after' => 'Enable',
318
- 'section' => $add_to,
319
- 'default' => $default_value,
320
- 'required' => $is_required,
321
- 'options' => $options,
322
- );
323
-
324
- $field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> ';
325
- $field_args['after_html'] .= '<a class="wcf-cpf-action-remove wp-ui-text-notification">'. __( 'Remove', 'cartflows' ).'</a>';
326
- $field_args['after_html'] .= '</span>';
327
-
328
- // $field_markup = wcf()->meta->get_checkbox_field( $field_args );
329
-
330
- $field_markup .= "<li class='wcf-field-item-edit-inactive wcf-field-item ui-sortable-handle'>";
331
- $field_markup .= $this->get_field_html_via_ajax($field_args);
332
- $field_markup .= "</li>";
333
-
334
- if( 'billing' === $add_to ) {
335
- $add_to_class = 'billing-field-sortable';
336
- $section = 'billing';
337
- } else if( 'shipping' === $add_to ) {
338
- $add_to_class = 'shipping-field-sortable';
339
- $section = 'shipping';
340
- }
341
-
342
- $data = array(
343
- 'field_data' => $field_data,
344
- 'field_args' => $field_args,
345
- 'add_to_class' => $add_to_class,
346
- 'markup' => $field_markup,
347
- 'section' => $section,
348
- );
349
-
350
- wp_send_json( $data );
351
- }
352
-
353
- wp_send_json( false );
354
-
355
- }
356
-
357
- /**
358
- * Get field html.
359
- *
360
- * @param array $args field arguments.
361
- * @return string
362
- */
363
- function get_field_html_via_ajax( $field_args ) {
364
-
365
- $value = $field_args['value'];
366
-
367
- $is_checkbox = false;
368
- $is_require = false;
369
- $is_select = false;
370
-
371
- $display = 'none';
372
-
373
- $field_content = '';
374
-
375
- if ( isset( $field_args['before'] ) ) {
376
- $field_content .= '<span>' . $field_args['before'] . '</span>';
377
- }
378
- $field_content .= '<input type="hidden" name="' . $field_args['name'] . '" value="no">';
379
- $field_content .= '<input type="checkbox" name="' . $field_args['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
380
-
381
- if ( isset( $field_args['after'] ) ) {
382
- $field_content .= $field_args['after'];
383
- }
384
-
385
- $type = isset( $field_args['type'] ) ? $field_args['type'] : '';
386
- $label = isset( $field_args['label'] ) ? $field_args['label'] : '';
387
- $help = isset( $field_args['help'] ) ? $field_args['help'] : '';
388
- $after_html = isset( $field_args['after_html'] ) ? $field_args['after_html'] : '';
389
- $name = isset( $field_args['name'] ) ? $field_args['name'] : '';
390
- $default = isset( $field_args['default']) ? $field_args['default'] : '';
391
- $required = isset( $field_args['required']) ? $field_args['required'] : '';
392
- $options = isset( $field_args['options']) ? $field_args['options'] : '';
393
- $width = isset( $field_args['width']) ? $field_args['width'] : '';
394
- $name_class = 'field-' . $field_args['name'];
395
-
396
- if( isset( $options ) && !empty( $options ) ){
397
- $options = implode(', ', $options );
398
- }else{
399
- $options = '';
400
- }
401
-
402
- if( 'yes' == $required ){
403
- $is_require = true;
404
- }
405
-
406
- if( 'checkbox' == $type ){
407
- $is_checkbox = true;
408
- }
409
-
410
- if( 'select' == $type ){
411
- $is_select = true;
412
- $display = 'block';
413
- }
414
-
415
- // echo "<pre>";
416
- // var_dump($after_html);
417
- // echo "</pre>";
418
-
419
- // $field_markup = wcf()->meta->get_only_checkbox_field( $field_args );
420
- ob_start();
421
-
422
- ?>
423
- <div class="wcf-field-item-bar">
424
- <div class="wcf-field-item-handle ui-sortable-handle">
425
- <label class="dashicons <?php if( 'no' == $value ){ echo 'dashicons-hidden'; } else{ echo 'dashicons-visibility';} ?> " for="<?php echo $field_args['name']; ?>"></label>
426
- <span class="item-title">
427
- <span class="wcf-field-item-title"><?php echo $label; if( $is_require ) { ?> <i>*</i> <?php } ?></span>
428
- <span class="is-submenu" style="display: none;">sub item</span>
429
- </span>
430
- <span class="item-controls">
431
- <span class="dashicons dashicons-menu"></span>
432
- <span class="item-order hide-if-js">
433
- <a href="#" class="item-move-up" aria-label="Move up">↑</a>
434
- |
435
- <a href="#" class="item-move-down" aria-label="Move down">↓</a>
436
- </span>
437
- <a class="item-edit" id="edit-64" href="javascript:void(0);" aria-label="My account. Menu item 1 of 5."><span class="screen-reader-text">Edit</span></a>
438
- </span>
439
- </div>
440
- </div>
441
- <div class="wcf-field-item-settings">
442
- <div class="wcf-field-item-settings-row-width">
443
- <?php
444
- echo wcf()->meta->get_select_field(
445
- array(
446
- 'label' => __( 'Field Width', 'cartflows' ),
447
- 'name' => 'wcf-field-width_' . str_replace( 'wcf-', '', $field_args['name'] ),
448
- 'value' => $width,
449
- 'options' => array(
450
- '33' => __( '33%', 'cartflows' ),
451
- '50' => __( '50%', 'cartflows' ),
452
- '100' => __( '100%', 'cartflows' ),
453
- ),
454
- )
455
- );
456
- ?>
457
- </div>
458
-
459
- <div class="wcf-field-item-settings-label">
460
- <?php
461
- echo wcf()->meta->get_text_field(
462
- array(
463
- 'label' => __( 'Field Label', 'cartflows' ),
464
- 'name' => 'wcf_label_text_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
465
- 'value' => $label,
466
- )
467
- );
468
-
469
- ?>
470
- <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace( 'wcf-', '', $field_args['name'] ); ?>">
471
- </div>
472
-
473
- <div class="wcf-field-item-select-options" style="display:<?php if( isset( $display ) ){ print $display; } ?>;" >
474
- <?php
475
- echo wcf()->meta->get_text_field(
476
- array(
477
- 'label' => __( 'Options', 'cartflows' ),
478
- 'name' => 'wcf_select_option_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
479
- 'value' => $options,
480
- )
481
- );
482
-
483
- ?>
484
- <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace( 'wcf-', '', $field_args['name'] ); ?>">
485
- </div>
486
-
487
- <div class="wcf-field-item-settings-default">
488
- <?php
489
- if( true == $is_checkbox ){
490
- echo wcf()->meta->get_select_field(
491
- array(
492
- 'label' => __( 'Default', 'cartflows' ),
493
- 'name' => 'wcf_label_default_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
494
- 'value' => $value,
495
- 'options' => array(
496
- '1' => __( 'Checked', 'cartflows' ),
497
- '0' => __( 'Un-Checked', 'cartflows' ),
498
- ),
499
- )
500
- );
501
- }else{
502
-
503
- echo wcf()->meta->get_text_field(
504
- array(
505
- 'label' => __( 'Default', 'cartflows' ),
506
- 'name' => 'wcf_label_default_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
507
- 'value' => $default,
508
- )
509
- );
510
- }
511
- ?>
512
- </div>
513
-
514
- <div class="wcf-field-item-settings-placeholder" <?php if( true == $is_checkbox ) {?> style="display: none;" <?php } ?> >
515
- <?php
516
- echo wcf()->meta->get_text_field(
517
- array(
518
- 'label' => __( 'Placeholder', 'cartflows' ),
519
- 'name' => 'wcf_label_placeholder_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
520
- 'value' => $label,
521
- )
522
- );
523
- ?>
524
- </div>
525
-
526
- <div class="wcf-field-item-settings-required">
527
- <?php
528
- echo wcf()->meta->get_checkbox_field(
529
- array(
530
- 'label' => __( 'Required', 'cartflows' ),
531
- 'name' => 'wcf_is_required_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
532
- 'value' => $required,
533
- )
534
- );
535
- ?>
536
- </div>
537
-
538
- <div class="wcf-field-item-settings-checkbox">
539
- <?php
540
- echo wcf()->meta->get_checkbox_field(
541
- array(
542
- 'label' => __( 'Enable this field', 'cartflows' ),
543
- 'name' => $field_args['name'],
544
- 'value' => $value,
545
- )
546
- );
547
- ?>
548
- </div>
549
-
550
- <?php
551
- if(isset( $field_args['after_html']) )
552
- {
553
- ?>
554
- <div class="wcf-field-item-settings-row-delete-cf">
555
- <?php echo $field_args['after_html']; ?>
556
- </div>
557
- <?php
558
- }
559
- ?>
560
- <!--
561
- <label for="<?php echo $field_args['name']; ?>">
562
- <?php _e( 'Label', 'cartflows' ); ?><br>
563
- <input type="text" value="<?php echo $field_args['label']; ?>">
564
-
565
- <?php if( isset( $field_markup ) ) { echo $field_markup; }?>
566
-
567
- <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace('wcf-', '', $field_args['name'] ); ?>">
568
- </label> -->
569
- </div>
570
-
571
- <?php
572
-
573
- return ob_get_clean();
574
- }
575
-
576
- /**
577
- * [delete_checkout_custom_field description]
578
- *
579
- * @hook wcf_delete_checkout_custom_field
580
- * @return [type] [description]
581
- */
582
- public function delete_checkout_custom_field() {
583
-
584
- check_ajax_referer( 'wcf-delete-checkout-custom-field', 'security' );
585
-
586
- $post_id = intval( $_POST['post_id'] );
587
- $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
588
- $key = sanitize_text_field( wp_unslash( $_POST['key'] ) );
589
-
590
- if ( '' !== $key ) {
591
-
592
- Cartflows_Helper::delete_checkout_field( $type, $key, $post_id );
593
-
594
- wp_send_json( true );
595
-
596
- }
597
-
598
- wp_send_json( false );
599
-
600
- }
601
-
602
- /**
603
- * Function to search coupons
604
- */
605
- public function json_search_pages() {
606
-
607
- check_ajax_referer( 'wcf-json-search-pages', 'security' );
608
-
609
- $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
610
-
611
- if ( empty( $term ) ) {
612
- die( 'not found' );
613
- }
614
-
615
- $search_string = $term;
616
- $data = array();
617
- $result = array();
618
-
619
- add_filter( 'posts_search', array( $this, 'search_only_titles' ), 10, 2 );
620
-
621
- $query = new WP_Query(
622
- array(
623
- 's' => $search_string,
624
- 'post_type' => 'page',
625
- 'posts_per_page' => - 1,
626
- )
627
- );
628
-
629
- if ( $query->have_posts() ) {
630
- while ( $query->have_posts() ) {
631
- $query->the_post();
632
- $title = get_the_title();
633
- $title .= ( 0 != $query->post->post_parent ) ? ' (' . get_the_title( $query->post->post_parent ) . ')' : '';
634
- $id = get_the_id();
635
- $data[] = array(
636
- 'id' => $id,
637
- 'text' => $title,
638
- );
639
- }
640
- }
641
-
642
- if ( is_array( $data ) && ! empty( $data ) ) {
643
- $result[] = array(
644
- 'text' => '',
645
- 'children' => $data,
646
- );
647
- }
648
-
649
- wp_reset_postdata();
650
-
651
- // return the result in json.
652
- wp_send_json( $result );
653
- }
654
-
655
- public function search_only_titles( $search, $wp_query ) {
656
- if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
657
- global $wpdb;
658
-
659
- $q = $wp_query->query_vars;
660
- $n = ! empty( $q['exact'] ) ? '' : '%';
661
-
662
- $search = array();
663
-
664
- foreach ( (array) $q['search_terms'] as $term ) {
665
- $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
666
- }
667
-
668
- if ( ! is_user_logged_in() ) {
669
- $search[] = "$wpdb->posts.post_password = ''";
670
- }
671
-
672
- $search = ' AND ' . implode( ' AND ', $search );
673
- }
674
-
675
- return $search;
676
- }
677
-
678
- function get_field( $field_data, $field_content ) {
679
-
680
- $label = isset( $field_data['label'] ) ? $field_data['label'] : '';
681
- $help = isset( $field_data['help'] ) ? $field_data['help'] : '';
682
- $after_html = isset( $field_data['after_html'] ) ? $field_data['after_html'] : '';
683
-
684
- $name_class = 'field-' . $field_data['name'];
685
-
686
- $field_html = '<div class="wcf-field-row ' . $name_class . '">';
687
-
688
- if( ! empty( $label ) || ! empty( $help ) ) {
689
- $field_html .= '<div class="wcf-field-row-heading">';
690
- if( ! empty( $label ) ) {
691
- $field_html .= '<label>' . esc_html( $label ) . '</label>';
692
- }
693
- if ( ! empty( $help ) ) {
694
- $field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help">';
695
- // $field_html .= '<span class="wcf-tooltip" data-tooltip= "'. esc_attr( $help ) .'"></span>';
696
- $field_html .= '</i>';
697
- $field_html .= '<span class="wcf-tooltip-text">';
698
- $field_html .= $help;
699
- $field_html .= '</span>';
700
- }
701
- $field_html .= '</div>';
702
- }
703
-
704
- $field_html .= '<div class="wcf-field-row-content">';
705
- $field_html .= $field_content;
706
-
707
- if ( ! empty( $after_html ) ) {
708
- $field_html .= $after_html;
709
- }
710
-
711
- $field_html .= '</div>';
712
- $field_html .= '</div>';
713
-
714
- return $field_html;
715
- }
716
-
717
- function get_text_field( $field_data ) {
718
-
719
- $value = $field_data['value'];
720
-
721
- $attr = '';
722
-
723
- if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
724
-
725
- foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
726
- $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
727
- }
728
- }
729
-
730
- $field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
731
-
732
- return $this->get_field( $field_data, $field_content );
733
- }
734
-
735
- function get_shortcode_field( $field_data ) {
736
-
737
- $attr = '';
738
-
739
- $attr_fields = array(
740
- 'readonly' => 'readonly',
741
- 'onfocus' => 'this.select()',
742
- 'onmouseup' => 'return false',
743
- );
744
-
745
- if ( $attr_fields && is_array( $attr_fields ) ) {
746
-
747
- foreach ( $attr_fields as $attr_key => $attr_value ) {
748
- $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
749
- }
750
- }
751
-
752
- $field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $field_data['content'] . '" ' . $attr . '>';
753
-
754
- return $this->get_field( $field_data, $field_content );
755
- }
756
-
757
- function get_display_field( $field_data ) {
758
-
759
- $field_content = $field_data['content'];
760
-
761
- return $this->get_field( $field_data, $field_content );
762
- }
763
-
764
- function get_hr_line_field( $field_data ) {
765
-
766
- $field_data = array(
767
- 'name' => 'wcf-hr-line',
768
- 'content' => '<hr>'
769
- );
770
-
771
- $field_content = $field_data['content'];
772
-
773
- return $this->get_field( $field_data, $field_content );
774
- }
775
-
776
- function get_number_field( $field_data ) {
777
-
778
- $value = $field_data['value'];
779
-
780
- $attr = '';
781
-
782
- if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
783
-
784
- foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
785
- $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
786
- }
787
- }
788
-
789
- $field_content = '<input type="number" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
790
-
791
- return $this->get_field( $field_data, $field_content );
792
- }
793
-
794
- function get_hidden_field( $field_data ) {
795
-
796
- $value = $field_data['value'];
797
-
798
- $attr = '';
799
-
800
- if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
801
-
802
- foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
803
- $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
804
- }
805
- }
806
-
807
- $field_content = '<input type="hidden" id="' . $field_data['name'] . '" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
808
-
809
- return $this->get_field( $field_data, $field_content );
810
- }
811
-
812
- function get_area_field( $field_data ) {
813
-
814
- $value = $field_data['value'];
815
-
816
- $field_content = '<textarea name="' . $field_data['name'] . '" rows="10" cols="50">';
817
- $field_content .= $value;
818
- $field_content .= '</textarea>';
819
-
820
- return $this->get_field( $field_data, $field_content );
821
- }
822
-
823
- function get_only_checkbox_field( $field_data ) {
824
- // echo "<pre>";
825
- // var_dump($field_data);
826
- // echo "</pre>";
827
-
828
- $value = $field_data['value'];
829
-
830
-
831
- $field_content = '';
832
- if ( isset( $field_data['before'] ) ) {
833
- $field_content .= '<span>' . $field_data['before'] . '</span>';
834
- }
835
- $field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
836
- $field_content .= '<input type="checkbox" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
837
-
838
- if ( isset( $field_data['after'] ) ) {
839
- $field_content .= '<span>' . $field_data['after'] . '</span>';
840
- }
841
-
842
- if ( isset( $field_data['after_html'] ) ) {
843
- $field_content .= '<span>' . $field_data['after_html'] . '</span>';
844
- }
845
-
846
- return $field_content;
847
- }
848
-
849
- function get_checkbox_field( $field_data ) {
850
-
851
- $value = $field_data['value'];
852
-
853
- $field_content = '';
854
- if ( isset( $field_data['before'] ) ) {
855
- $field_content .= '<span>' . $field_data['before'] . '</span>';
856
- }
857
- $field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
858
- $field_content .= '<input type="checkbox" id="'.$field_data['name'].'" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
859
-
860
- if ( isset( $field_data['after'] ) ) {
861
- $field_content .= '<span>' . $field_data['after'] . '</span>';
862
- }
863
-
864
- return $this->get_field( $field_data, $field_content );
865
- }
866
-
867
- function get_radio_field( $field_data ) {
868
-
869
- $value = $field_data['value'];
870
- $field_content = '';
871
-
872
- if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
873
-
874
- foreach ( $field_data['options'] as $data_key => $data_value ) {
875
-
876
- $field_content .= '<div class="wcf-radio-option">';
877
- $field_content .= '<input type="radio" name="' . $field_data['name'] . '" value="' . $data_key . '" ' . checked( $data_key, $value, false ) . '>';
878
- $field_content .= $data_value;
879
- $field_content .= '</div>';
880
- }
881
- }
882
-
883
- return $this->get_field( $field_data, $field_content );
884
- }
885
-
886
- function get_font_family_field( $field_data ) {
887
-
888
- $value = $field_data['value'];
889
-
890
- $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
891
-
892
- $field_content = '<select class="wcf-field-font-family" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
893
-
894
- $field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
895
-
896
- $field_content .= '<optgroup label="Other System Fonts">';
897
- foreach ( CartFlows_Font_Families::get_system_fonts() as $name => $variants ) {
898
- $field_content .= '<option value="' . esc_attr( $name ) . '" ' . selected( $name, $value, false ) . '>' . esc_attr( $name ) . '</option>';
899
- }
900
- $field_content .= '</optgroup>';
901
- $field_content .= '<optgroup label="Google">';
902
- foreach ( CartFlows_Font_Families::get_google_fonts() as $name => $single_font ) {
903
- $variants = wcf_get_prop( $single_font, '0' );
904
- $category = wcf_get_prop( $single_font, '1' );
905
- $font_value = '\'' . esc_attr( $name ) . '\', ' . esc_attr( $category );
906
- $field_content .= '<option value="' . esc_attr( $font_value ) . '" ' . selected( $font_value, $value, false ) . '>' . esc_attr( $name ) . '</option>';
907
- }
908
- $field_content .= '</optgroup>';
909
-
910
- $field_content .= '</select>';
911
-
912
- return $this->get_field( $field_data, $field_content );
913
- }
914
-
915
- function get_font_weight_field( $field_data ) {
916
-
917
- $value = $field_data['value'];
918
-
919
- $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
920
-
921
- $field_content = '<select data-selected="'.esc_attr( $value ).'" class="wcf-field-font-weight" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
922
-
923
- $field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
924
-
925
- $field_content .= '</select>';
926
-
927
- return $this->get_field( $field_data, $field_content );
928
- }
929
-
930
- function get_select_field( $field_data ) {
931
-
932
- $value = $field_data['value'];
933
- $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
934
-
935
- $field_content = '<select name="' . $field_data['name'] . '">';
936
-
937
-
938
- if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
939
-
940
- foreach ( $field_data['options'] as $data_key => $data_value ) {
941
-
942
- $disabled = '';
943
-
944
- if ( array_key_exists( $data_key, $pro_options ) ) {
945
- $disabled = 'disabled ';
946
- $data_value = $pro_options[ $data_key ];
947
- }
948
-
949
- $field_content .= '<option value="' . $data_key . '" ' . selected( $value, $data_key, false ) . ' ' . $disabled .'>' . $data_value . '</option>';
950
- }
951
- }
952
-
953
- $field_content .= '</select>';
954
-
955
- if ( isset( $field_data['after'] ) ) {
956
- $field_content .= '<span>' . $field_data['after'] . '</span>';
957
- }
958
-
959
- return $this->get_field( $field_data, $field_content );
960
- }
961
-
962
- function get_color_picker_field( $field_data ) {
963
-
964
- $value = $field_data['value'];
965
-
966
- $field_content = '<input class="wcf-color-picker" type="text" name="' . $field_data['name'] . '" value="' . $value . '">';
967
-
968
- return $this->get_field( $field_data, $field_content );
969
- }
970
-
971
- function get_product_selection_field( $field_data ) {
972
-
973
- $value = $field_data['value'];
974
-
975
- $multiple = '';
976
-
977
- if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
978
- $multiple = ' multiple="multiple"';
979
- }
980
-
981
- $allow_clear = '';
982
-
983
- if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
984
- $allow_clear = ' data-allow_clear="allow_clear"';
985
- }
986
-
987
- $field_content = '<select
988
- name="' . $field_data['name'] . '[]"
989
- class="wcf-product-search" ' . $multiple . $allow_clear . '
990
- data-placeholder="' . __( 'Search for a product&hellip;', 'cartflows' ) . '"
991
- data-action="woocommerce_json_search_products_and_variations">';
992
-
993
- if ( is_array( $value ) && ! empty( $value ) ) {
994
-
995
- foreach ( $value as $data_key => $product_id ) {
996
-
997
- $product = wc_get_product( $product_id );
998
-
999
- // posts.
1000
- if ( ! empty( $product ) ) {
1001
- $post_title = $product->get_name() . ' (#' . $product_id . ')';
1002
-
1003
- $field_content .= '<option value="' . $product_id . '" selected="selected" >' . $post_title . '</option>';
1004
- }
1005
- }
1006
- }
1007
- $field_content .= '</select>';
1008
-
1009
- return $this->get_field( $field_data, $field_content );
1010
- }
1011
-
1012
- function get_coupon_selection_field( $field_data ) {
1013
-
1014
- $value = $field_data['value'];
1015
-
1016
- $multiple = '';
1017
-
1018
- if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
1019
- $multiple = ' multiple="multiple"';
1020
- }
1021
-
1022
- $allow_clear = '';
1023
-
1024
- if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
1025
- $allow_clear = ' data-allow_clear="allow_clear"';
1026
- }
1027
-
1028
- $field_content = '<select
1029
- name="' . $field_data['name'] . '[]"
1030
- class="wc-coupon-search wcf-coupon-search" ' . $multiple . $allow_clear . '
1031
- data-placeholder="' . __( 'Search for a coupon&hellip;', 'cartflows' ) . '"
1032
- data-action="wcf_json_search_coupons">';
1033
-
1034
- if ( is_array( $value ) && ! empty( $value ) ) {
1035
-
1036
- $all_discount_types = wc_get_coupon_types();
1037
-
1038
- foreach ( $value as $coupon_title ) {
1039
-
1040
- $coupon = new WC_Coupon( $coupon_title );
1041
-
1042
- $discount_type = $coupon->get_discount_type();
1043
-
1044
- if ( isset( $discount_type ) && $discount_type ) {
1045
- $discount_type = ' ( Type: ' . $all_discount_types[ $discount_type ] . ' )';
1046
- }
1047
-
1048
- $field_content .= '<option value="' . $coupon_title . '" selected="selected">' . $coupon_title . $discount_type . '</option>';
1049
- }
1050
- }
1051
-
1052
- $field_content .= '</select>';
1053
-
1054
- return $this->get_field( $field_data, $field_content );
1055
- }
1056
-
1057
- function get_page_selection_field( $field_data ) {
1058
-
1059
- $value = $field_data['value'];
1060
-
1061
- $multiple = '';
1062
-
1063
- if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
1064
- $multiple = 'multiple="multiple"';
1065
- }
1066
-
1067
- $field_content = '<select
1068
- name="' . $field_data['name'] . '[]"
1069
- class="wcf-search-pages" ' . $multiple . '"
1070
- data-action="wcf_json_search_pages">';
1071
-
1072
- if ( is_array( $value ) && ! empty( $value ) ) {
1073
-
1074
- foreach ( $value as $data_key => $data_value ) {
1075
-
1076
- $field_content .= '<option value="' . $data_value . '">' . get_the_title( $data_value ) . '</option>';
1077
- }
1078
- }
1079
-
1080
- $field_content .= '</select>';
1081
-
1082
- return $this->get_field( $field_data, $field_content );
1083
- }
1084
-
1085
- function get_section( $field_data ) {
1086
- $field_html = '<div class="wcf-field-row wcf-field-section">';
1087
- $field_html .= '<div class="wcf-field-section-heading" colspan="2">';
1088
- $field_html .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1089
-
1090
- if ( isset( $field_data['help'] ) ) {
1091
- $field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help" title="' . esc_attr( $field_data['help'] ) . '"></i>';
1092
- }
1093
- $field_html .= '</div>';
1094
- $field_html .= '</div>';
1095
- return $field_html;
1096
- }
1097
-
1098
- function get_description_field( $field_data ) {
1099
-
1100
- $field_html = '<div class="wcf-field-row wcf-field-desc ' . $field_data['name'] . '">';
1101
- $field_html .= '<div class="wcf-field-desc-content">';
1102
- $field_html .= $field_data['content'];
1103
- $field_html .= '</div>';
1104
- $field_html .= '</div>';
1105
-
1106
- return $field_html;
1107
- }
1108
-
1109
- function get_checkout_field_repeater( $field_data ) {
1110
-
1111
- $value = array();
1112
-
1113
- $value[0] = array(
1114
- 'add_to' => '',
1115
- 'type' => '',
1116
- 'label' => '',
1117
- 'name' => '',
1118
- );
1119
-
1120
- $field_content = '';
1121
-
1122
- $field_content .= '<div class="wcf-field-row">';
1123
- // $field_content .= '<div class="wcf-field-row-heading">';
1124
- // $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1125
- // $field_content .= '</div>';
1126
- $field_content .= '<div class="wcf-field-row-content">';
1127
- $field_content .= '<div class="wcf-cpf-wrap">';
1128
-
1129
- foreach ( $value as $p_key => $p_data ) {
1130
- $field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
1131
- $field_content .= '<div class="wcf-cpf-row-header">';
1132
- $field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
1133
- $field_content .= '</div>';
1134
-
1135
- $field_content .= '<div class="wcf-cpf-row-standard-fields">';
1136
-
1137
- /* Add To */
1138
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
1139
- $field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
1140
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1141
- $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
1142
- $field_content .= '<option value="billing">Billing</option>';
1143
- $field_content .= '<option value="shipping">Shipping</option>';
1144
- $field_content .= '</select>';
1145
- $field_content .= '</span>';
1146
- $field_content .= '</div>';
1147
-
1148
- /* Type */
1149
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
1150
- $field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
1151
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1152
- $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
1153
- $field_content .= '<option value="text">Text</option>';
1154
- $field_content .= '<option value="textarea">Textarea</option>';
1155
- $field_content .= '<option value="select">Select</option>';
1156
- $field_content .= '<option value="checkbox">Checkbox</option>';
1157
- $field_content .= '</select>';
1158
- $field_content .= '</span>';
1159
- $field_content .= '</div>';
1160
-
1161
- /* Textarea */
1162
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
1163
- $field_content .= '<span class="wcf-cpf-row-setting-label">Options *</span>';
1164
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1165
- $field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
1166
- $field_content .= '</span>';
1167
- $field_content .= '</div>';
1168
-
1169
- /* Label */
1170
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
1171
- $field_content .= '<span class="wcf-cpf-row-setting-label">Label *</span>';
1172
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1173
- $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
1174
- $field_content .= '</span>';
1175
- $field_content .= '</div>';
1176
-
1177
- /* Name */
1178
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-name">';
1179
- $field_content .= '<span class="wcf-cpf-row-setting-label">Name *</span>';
1180
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1181
- $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][name]" class="wcf-cpf-name">';
1182
- $field_content .= '</span>';
1183
- $field_content .= '</div>';
1184
-
1185
- $field_content .= '</div>';
1186
- $field_content .= '</div>';
1187
- }
1188
-
1189
- /* Add New Custom Field */
1190
- $field_content .= '<div class="wcf-cpf-add-row">';
1191
- $field_content .= '<div class="wcf-cpf-add-wrap">';
1192
- $field_content .= '<button class="button button-secondary wcf-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
1193
- $field_content .= '</div>';
1194
- $field_content .= '</div>';
1195
- /* End Add new custom field */
1196
-
1197
- $field_content .= '</div>';
1198
- $field_content .= '</div>';
1199
- $field_content .= '</div>';
1200
-
1201
- return $field_content;
1202
- }
1203
-
1204
- function get_pro_checkout_field_repeater( $field_data ) {
1205
-
1206
- $value = array();
1207
-
1208
- $value[0] = array(
1209
- 'add_to' => '',
1210
- 'type' => '',
1211
- 'label' => '',
1212
- 'name' => '',
1213
- );
1214
-
1215
- $field_content = '';
1216
-
1217
- $field_content .= '<div class="wcf-field-row">';
1218
- // $field_content .= '<div class="wcf-field-row-heading">';
1219
- // $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1220
- // $field_content .= '</div>';
1221
- $field_content .= '<div class="wcf-field-row-content">';
1222
- $field_content .= '<div class="wcf-cpf-wrap">';
1223
-
1224
- foreach ( $value as $p_key => $p_data ) {
1225
- $field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
1226
- $field_content .= '<div class="wcf-cpf-row-header">';
1227
- $field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
1228
- $field_content .= '</div>';
1229
-
1230
- $field_content .= '<div class="wcf-cpf-row-standard-fields">';
1231
-
1232
- /* Add To */
1233
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
1234
- $field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
1235
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1236
- $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
1237
- $field_content .= '<option value="billing">Billing</option>';
1238
- $field_content .= '<option value="shipping">Shipping</option>';
1239
- $field_content .= '</select>';
1240
- $field_content .= '</span>';
1241
- $field_content .= '</div>';
1242
-
1243
- /* Type */
1244
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
1245
- $field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
1246
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1247
- $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
1248
- $field_content .= '<option value="text">Text</option>';
1249
- $field_content .= '<option value="textarea">Textarea</option>';
1250
- $field_content .= '<option value="select">Select</option>';
1251
- $field_content .= '<option value="checkbox">Checkbox</option>';
1252
- $field_content .= '<option value="hidden">Hidden</option>';
1253
- $field_content .= '</select>';
1254
- $field_content .= '</span>';
1255
- $field_content .= '</div>';
1256
-
1257
- /* Label */
1258
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
1259
- $field_content .= '<span class="wcf-cpf-row-setting-label">Label <i>*</i></span>';
1260
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1261
- $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
1262
- $field_content .= '<span id="wcf-cpf-label-error-msg"></span>';
1263
- $field_content .= '</span>';
1264
- $field_content .= '</div>';
1265
-
1266
- /* Default */
1267
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-default">';
1268
- $field_content .= '<span class="wcf-cpf-row-setting-label">Default</span>';
1269
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1270
- $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][default]" class="wcf-cpf-default">';
1271
- $field_content .= '<span id="wcf-cpf-default-error-msg"></span>';
1272
- $field_content .= '</span>';
1273
- $field_content .= '</div>';
1274
-
1275
- /* Placeholder */
1276
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-placeholder">';
1277
- $field_content .= '<span class="wcf-cpf-row-setting-label">Placeholder</span>';
1278
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1279
- $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][placeholder]" class="wcf-cpf-placeholder">';
1280
- $field_content .= '<span id="wcf-cpf-placeholder-error-msg"></span>';
1281
- $field_content .= '</span>';
1282
- $field_content .= '</div>';
1283
-
1284
- /* Options */
1285
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
1286
- $field_content .= '<span class="wcf-cpf-row-setting-label">Options <i>*</i></span>';
1287
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1288
- $field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
1289
- $field_content .= '</span>';
1290
- $field_content .= '</div>';
1291
-
1292
- /* Width */
1293
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-width">';
1294
- $field_content .= '<span class="wcf-cpf-row-setting-label">Width</span>';
1295
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1296
- $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][width]" class="wcf-cpf-width">';
1297
- $field_content .= '<option value="33">33%</option>';
1298
- $field_content .= '<option value="50">50%</option>';
1299
- $field_content .= '<option value="100" selected>100%</option>';
1300
- $field_content .= '</select>';
1301
- $field_content .= '</span>';
1302
- $field_content .= '</div>';
1303
-
1304
- /* Required */
1305
- $field_content .= '<div class="wcf-cpf-fields wcf-cpf-required">';
1306
- $field_content .= '<span class="wcf-cpf-row-setting-label">Required</span>';
1307
- $field_content .= '<span class="wcf-cpf-row-setting-field">';
1308
- $field_content .= '<input type="hidden" value="no" name="wcf-checkout-custom-fields[' . $p_key . '][required]" class="wcf-cpf-required">';
1309
- $field_content .= '<input type="checkbox" value="yes" name="wcf-checkout-custom-fields[' . $p_key . '][required]" class="wcf-cpf-required">';
1310
- $field_content .= '<span id="wcf-cpf-required-error-msg"></span>';
1311
- $field_content .= '</span>';
1312
- $field_content .= '</div>';
1313
-
1314
- $field_content .= '</div>';
1315
- $field_content .= '</div>';
1316
- }
1317
-
1318
- /* Add New Custom Field */
1319
- $field_content .= '<div class="wcf-cpf-add-row">';
1320
- $field_content .= '<div class="wcf-cpf-add-wrap">';
1321
- $field_content .= '<button class="button button-secondary wcf-pro-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
1322
- $field_content .= '</div>';
1323
- $field_content .= '</div>';
1324
- /* End Add new custom field */
1325
-
1326
- $field_content .= '</div>';
1327
- $field_content .= '</div>';
1328
- $field_content .= '</div>';
1329
-
1330
- return $field_content;
1331
- }
1332
-
1333
- function get_product_selection_repeater( $field_data ) {
1334
-
1335
- $value = $field_data['value'];
1336
-
1337
- if ( ! is_array( $value ) ) {
1338
-
1339
- $value[0] = array(
1340
- 'product' => '',
1341
- );
1342
- } else {
1343
-
1344
- if ( ! isset( $value[0] ) ) {
1345
-
1346
- $value[0] = array(
1347
- 'product' => '',
1348
- );
1349
- }
1350
- }
1351
-
1352
- $field_html = '';
1353
-
1354
- $field_html .= '<script type="text/html" id="tmpl-wcf-product-repeater">';
1355
- $field_html .= $this->generate_product_repeater_html( '{{id}}' );
1356
- $field_html .= '</script>';
1357
-
1358
- $field_html .= '<div class="wcf-field-row">';
1359
- $field_html .= '<div class="wcf-field-row-content">';
1360
- $field_html .= '<div class="wcf-repeatables-wrap">';
1361
-
1362
- if ( is_array( $value ) ) {
1363
-
1364
- foreach ( $value as $p_key => $p_data ) {
1365
-
1366
- $selected_options = '';
1367
-
1368
- if ( isset( $p_data['product'] ) ) {
1369
-
1370
- $product = wc_get_product( $p_data['product'] );
1371
-
1372
- // posts.
1373
- if ( ! empty( $product ) ) {
1374
- $post_title = $product->get_name() . ' (#' . $p_data['product'] . ')';
1375
-
1376
- $selected_options = '<option value="' . $p_data['product'] . '" selected="selected" >' . $post_title . '</option>';
1377
- }
1378
- }
1379
-
1380
- $field_html .= $this->generate_product_repeater_html( $p_key, $selected_options );
1381
- }
1382
- }
1383
-
1384
- $field_html .= '<div class="wcf-add-repeatable-row">';
1385
- $field_html .= '<div class="submit wcf-add-repeatable-wrap">';
1386
- $field_html .= '<button class="button-primary wcf-add-repeatable" data-name="wcf-checkout-products">Add New Product</button>';
1387
- $field_html .= '</div>';
1388
- $field_html .= '</div>';
1389
- $field_html .= '</div>';
1390
- $field_html .= '</div>';
1391
- $field_html .= '</div>';
1392
-
1393
- return $field_html;
1394
- }
1395
-
1396
- function generate_product_repeater_html( $id, $options = '' ) {
1397
-
1398
- $field_html = '<div class="wcf-repeatable-row" data-key="' . $id . '">';
1399
-
1400
- $field_html .= '<div class="wcf-repeatable-row-standard-fields">';
1401
-
1402
- /* Product Name */
1403
- $field_html .= '<div class="wcf-repeatable-fields wcf-sel-product">';
1404
- $field_html .= '<span class="wcf-repeatable-row-setting-field">';
1405
- $field_html .= '<select
1406
- name="wcf-checkout-products[' . $id . '][product]"
1407
- class="wcf-product-search"
1408
- data-allow_clear="allow_clear"
1409
- data-placeholder="' . __( 'Search for a product&hellip;', 'cartflows' ) . '"
1410
- data-action="woocommerce_json_search_products_and_variations">';
1411
- $field_html .= $options;
1412
- $field_html .= '</select>';
1413
- $field_html .= '</span>';
1414
- $field_html .= '<span class="wcf-repeatable-row-actions">';
1415
- $field_html .= '<a class="wcf-remove-row wcf-repeatable-remove button" data-type="product">';
1416
- $field_html .= '<span class="dashicons dashicons-trash"></span>';
1417
- $field_html .= '<span class="wcf-repeatable-remove-button">'. __( 'Remove', 'cartflows' ).'</span>';
1418
- $field_html .= '</a>';
1419
- $field_html .= '</span>';
1420
- $field_html .= '</div>';
1421
- $field_html .= '</div>';
1422
- $field_html .= '</div>';
1423
-
1424
- return $field_html;
1425
- }
1426
-
1427
- function get_image_field( $field_data ) {
1428
-
1429
- $value = $field_data['value'];
1430
-
1431
- $attr = '';
1432
-
1433
- if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
1434
-
1435
- foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
1436
- $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
1437
- }
1438
- }
1439
-
1440
- $display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
1441
-
1442
- $field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
1443
- if( isset( $value ) ){
1444
- $field_content .= '<img src="'. $value .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
1445
- }
1446
- $field_content .= '</div>';
1447
- // $field_content .= '<input type="hidden" id="wcf-image-id" class="wcf-image-id" name="wcf-image-id[image-id]" value="">';
1448
- $field_content .= '<input type="hidden" id="wcf-image-value" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
1449
-
1450
- $field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
1451
-
1452
- $display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
1453
-
1454
- $field_content .= '<button type="button" class="wcf-remove-image button-secondary" style="'.$display_remove_button.'">Remove Image</button>';
1455
-
1456
- return $this->get_field( $field_data, $field_content );
1457
- }
1458
-
1459
- /**
1460
- * Localize variables in admin
1461
- *
1462
- * @param array $vars variables.
1463
- */
1464
- function localize_vars( $vars ) {
1465
-
1466
- $ajax_actions = array(
1467
- 'wcf_add_checkout_custom_field',
1468
- 'wcf_pro_add_checkout_custom_field',
1469
- 'wcf_delete_checkout_custom_field',
1470
- 'wcf_json_search_pages',
1471
- 'wcf_json_search_coupons'
1472
- );
1473
-
1474
- foreach ( $ajax_actions as $action ) {
1475
-
1476
- $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1477
- }
1478
-
1479
- return $vars;
1480
- }
1481
- }
1482
- // @codingStandardsIgnoreEnd
1
+ <?php
2
+ // @codingStandardsIgnoreStart
3
+ /**
4
+ * Meta Fields.
5
+ *
6
+ * @package CartFlows
7
+ */
8
+
9
+ /**
10
+ * Class Cartflows_Meta_Fields.
11
+ */
12
+ class Cartflows_Meta_Fields {
13
+
14
+ /**
15
+ * Instance
16
+ *
17
+ * @var $instance
18
+ */
19
+ private static $instance;
20
+
21
+ /**
22
+ * Initiator
23
+ */
24
+ public static function get_instance() {
25
+ if ( ! isset( self::$instance ) ) {
26
+ self::$instance = new self;
27
+ }
28
+
29
+ return self::$instance;
30
+ }
31
+
32
+ /**
33
+ * Constructor
34
+ */
35
+ public function __construct() {
36
+
37
+ /* Add Scripts */
38
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_meta_scripts' ), 20 );
39
+
40
+ add_action( 'wp_ajax_wcf_json_search_coupons', array( $this, 'json_search_coupons' ) );
41
+
42
+ add_action( 'wp_ajax_wcf_add_checkout_custom_field', array( $this, 'add_checkout_custom_field' ) );
43
+
44
+ add_action( 'wp_ajax_wcf_pro_add_checkout_custom_field', array( $this, 'add_pro_checkout_custom_field' ) );
45
+
46
+ add_action( 'wp_ajax_wcf_delete_checkout_custom_field', array( $this, 'delete_checkout_custom_field' ) );
47
+
48
+ add_action( 'wp_ajax_wcf_json_search_pages', array( $this, 'json_search_pages' ) );
49
+
50
+ add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
51
+ }
52
+
53
+ public function admin_meta_scripts() {
54
+
55
+ global $pagenow;
56
+ global $post;
57
+
58
+ $screen = get_current_screen();
59
+
60
+ if (
61
+ ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) &&
62
+ wcf()->utils->is_step_post_type( $screen->post_type )
63
+ ) {
64
+
65
+ wp_enqueue_style( 'woocommerce_admin_styles' );
66
+
67
+ wp_enqueue_script( 'select2' );
68
+ wp_enqueue_script( 'wc-enhanced-select' );
69
+
70
+ wp_enqueue_script(
71
+ 'wcf-admin-meta',
72
+ CARTFLOWS_URL . 'admin/meta-assets/js/admin-edit.js',
73
+ array( 'jquery', 'select2', 'wp-color-picker' ),
74
+ CARTFLOWS_VER,
75
+ true
76
+ );
77
+
78
+ wp_enqueue_style( 'wcf-admin-meta', CARTFLOWS_URL . 'admin/meta-assets/css/admin-edit.css', array( 'wp-color-picker' ), CARTFLOWS_VER );
79
+ wp_style_add_data( 'wcf-admin-meta', 'rtl', 'replace' );
80
+
81
+ $localize = array(
82
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
83
+ 'google_fonts' => CartFlows_Font_Families::get_google_fonts(),
84
+ 'system_fonts' => CartFlows_Font_Families::get_system_fonts(),
85
+ 'font_weights' => array(
86
+ '100' => __( 'Thin 100', 'cartflows' ),
87
+ '200' => __( 'Extra-Light 200', 'cartflows' ),
88
+ '300' => __( 'Light 300', 'cartflows' ),
89
+ '400' => __( 'Normal 400', 'cartflows' ),
90
+ '500' => __( 'Medium 500', 'cartflows' ),
91
+ '600' => __( 'Semi-Bold 600', 'cartflows' ),
92
+ '700' => __( 'Bold 700', 'cartflows' ),
93
+ '800' => __( 'Extra-Bold 800', 'cartflows' ),
94
+ '900' => __( 'Ultra-Bold 900', 'cartflows' ),
95
+ )
96
+ );
97
+
98
+ wp_localize_script( 'jquery', 'wcf', apply_filters( 'wcf_js_localize', $localize ) );
99
+
100
+ do_action( 'cartflows_admin_meta_scripts' );
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Function to search coupons
106
+ */
107
+ public function json_search_coupons() {
108
+
109
+ check_admin_referer( 'wcf-json-search-coupons', 'security' );
110
+
111
+ global $wpdb;
112
+
113
+ $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
114
+
115
+ if ( empty( $term ) ) {
116
+ die();
117
+ }
118
+
119
+ $posts = wp_cache_get( 'wcf_search_coupons', 'wcf_funnel_Cart' );
120
+
121
+ if ( false === $posts ) {
122
+ $posts = $wpdb->get_results( // phpcs:ignore
123
+ $wpdb->prepare(
124
+ "SELECT *
125
+ FROM {$wpdb->prefix}posts
126
+ WHERE post_type = %s
127
+ AND post_title LIKE %s
128
+ AND post_status = %s",
129
+ 'shop_coupon',
130
+ $wpdb->esc_like( $term ) . '%',
131
+ 'publish'
132
+ )
133
+ );
134
+ wp_cache_set( 'wcf_search_coupons', $posts, 'wcf_funnel_Cart' );
135
+ }
136
+
137
+ $coupons_found = array();
138
+ $all_discount_types = wc_get_coupon_types();
139
+
140
+ if ( $posts ) {
141
+ foreach ( $posts as $post ) {
142
+
143
+ $discount_type = get_post_meta( $post->ID, 'discount_type', true );
144
+
145
+ if ( ! empty( $all_discount_types[ $discount_type ] ) ) {
146
+ $coupons_found[ get_the_title( $post->ID ) ] = get_the_title( $post->ID ) . ' (Type: ' . $all_discount_types[ $discount_type ] . ')';
147
+ }
148
+ }
149
+ }
150
+
151
+ wp_send_json( $coupons_found );
152
+ }
153
+
154
+ /**
155
+ * [add_checkout_custom_field description]
156
+ *
157
+ * @hook wcf_add_checkout_custom_field
158
+ */
159
+ public function add_checkout_custom_field() {
160
+
161
+ check_ajax_referer( 'wcf-add-checkout-custom-field', 'security' );
162
+
163
+ $post_id = intval( $_POST['post_id'] );
164
+ $add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
165
+ $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
166
+ $options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
167
+ $label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
168
+ $name = sanitize_text_field( wp_unslash( $_POST['name'] ) );
169
+
170
+ if ( '' !== $name ) {
171
+
172
+ $fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
173
+ $field_keys = array_keys($fields);
174
+
175
+ $name = $add_to . '_' . sanitize_key( $name );
176
+ if( in_array($name, $field_keys) ) {
177
+ $name = $name . '_' . rand( 0000, 9999 );
178
+ }
179
+
180
+ $field_data = array(
181
+ 'type' => $type,
182
+ 'label' => $label,
183
+ 'placeholder' => '',
184
+ 'class' => array( 'form-row-wide' ),
185
+ 'label_class' => array(),
186
+ 'required' => true,
187
+ 'custom' => true,
188
+ );
189
+
190
+ if ( 'select' === $type ) {
191
+
192
+ $options = explode( ',', $options );
193
+ $field_data['options'] = array();
194
+
195
+ if ( is_array( $options ) && ! empty( $options ) ) {
196
+
197
+ foreach ( $options as $key => $value ) {
198
+
199
+ $field_data['options'][ $value ] = $value;
200
+ }
201
+ }
202
+ }
203
+
204
+ Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
205
+
206
+ $key = sanitize_key( $name );
207
+ $name = 'wcf-' . $key;
208
+
209
+ $field_args = array(
210
+ 'label' => $label,
211
+ 'name' => $name,
212
+ 'value' => 'yes',
213
+ 'after' => 'Enable',
214
+ );
215
+
216
+ $field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> | ';
217
+ $field_args['after_html'] .= '<a class="wcf-cpf-action-remove">' . __( 'Remove', 'cartflows' ) . '</a>';
218
+ $field_args['after_html'] .= '</span>';
219
+
220
+ $field_markup = wcf()->meta->get_checkbox_field( $field_args );
221
+
222
+ if( 'billing' === $add_to ) {
223
+ $add_to_class = 'wcf-cb-fields';
224
+ } else if( 'shipping' === $add_to ) {
225
+ $add_to_class = 'wcf-sb-fields';
226
+ }
227
+
228
+ $data = array(
229
+ 'field_data' => $field_data,
230
+ 'field_args' => $field_args,
231
+ 'add_to_class' => $add_to_class,
232
+ 'markup' => $field_markup,
233
+ );
234
+
235
+ wp_send_json( $data );
236
+ }
237
+
238
+ wp_send_json( false );
239
+
240
+ }
241
+
242
+ /**
243
+ * [add_checkout_custom_field description]
244
+ *
245
+ * @hook wcf_add_checkout_custom_field
246
+ */
247
+ public function add_pro_checkout_custom_field() {
248
+
249
+ check_ajax_referer( 'wcf-pro-add-checkout-custom-field', 'security' );
250
+
251
+ $post_id = intval( $_POST['post_id'] );
252
+ $add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
253
+ $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
254
+ $options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
255
+ $label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
256
+ $name = sanitize_text_field( wp_unslash( str_replace(' ', '_', $_POST['label'] ) ) );
257
+ $placeholder = sanitize_text_field( wp_unslash( $_POST['placeholder'] ) );
258
+ $width = sanitize_text_field( wp_unslash( $_POST['width'] ) );
259
+ $default_value = sanitize_text_field( wp_unslash( $_POST['default'] ) );
260
+ $is_required = sanitize_text_field( wp_unslash( $_POST['required'] ) );
261
+
262
+ $field_markup = '';
263
+
264
+ if ( '' !== $name ) {
265
+
266
+ $fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
267
+ $field_keys = array_keys($fields);
268
+
269
+ $name = $add_to . '_' . sanitize_key( $name );
270
+ if( in_array($name, $field_keys) ) {
271
+ $name = $name . '_' . rand( 0000, 9999 );
272
+ }
273
+
274
+ $field_data = array(
275
+ 'type' => $type,
276
+ 'label' => $label,
277
+ 'placeholder' => $placeholder,
278
+ 'class' => array( 'form-row-wide' ),
279
+ 'label_class' => array(),
280
+ 'required' => $is_required,
281
+ 'custom' => true,
282
+ 'default' => $default_value,
283
+ 'options' => $options,
284
+ );
285
+
286
+ if ( 'select' === $type ) {
287
+
288
+ $options = explode( ',', $options );
289
+ $field_data['options'] = array();
290
+
291
+ if ( is_array( $options ) && ! empty( $options ) ) {
292
+
293
+ foreach ( $options as $key => $value ) {
294
+
295
+ $field_data['options'][ $value ] = $value;
296
+ }
297
+ }
298
+ }
299
+
300
+ $width_args = array(
301
+ 'wcf-field-width_'.$name => $width,
302
+ );
303
+
304
+ Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
305
+ Cartflows_Helper::save_meta_option( $post_id, $width_args );
306
+
307
+ $key = sanitize_key( $name );
308
+ $name = 'wcf-' . $key;
309
+
310
+ $field_args = array(
311
+ 'type' => $type,
312
+ 'label' => $label,
313
+ 'name' => $name,
314
+ 'value' => 'yes',
315
+ 'placeholder' => $placeholder,
316
+ 'width' => $width,
317
+ 'after' => 'Enable',
318
+ 'section' => $add_to,
319
+ 'default' => $default_value,
320
+ 'required' => $is_required,
321
+ 'options' => $options,
322
+ );
323
+
324
+ $field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> ';
325
+ $field_args['after_html'] .= '<a class="wcf-cpf-action-remove wp-ui-text-notification">'. __( 'Remove', 'cartflows' ).'</a>';
326
+ $field_args['after_html'] .= '</span>';
327
+
328
+ // $field_markup = wcf()->meta->get_checkbox_field( $field_args );
329
+
330
+ $field_markup .= "<li class='wcf-field-item-edit-inactive wcf-field-item ui-sortable-handle'>";
331
+ $field_markup .= $this->get_field_html_via_ajax($field_args);
332
+ $field_markup .= "</li>";
333
+
334
+ if( 'billing' === $add_to ) {
335
+ $add_to_class = 'billing-field-sortable';
336
+ $section = 'billing';
337
+ } else if( 'shipping' === $add_to ) {
338
+ $add_to_class = 'shipping-field-sortable';
339
+ $section = 'shipping';
340
+ }
341
+
342
+ $data = array(
343
+ 'field_data' => $field_data,
344
+ 'field_args' => $field_args,
345
+ 'add_to_class' => $add_to_class,
346
+ 'markup' => $field_markup,
347
+ 'section' => $section,
348
+ );
349
+
350
+ wp_send_json( $data );
351
+ }
352
+
353
+ wp_send_json( false );
354
+
355
+ }
356
+
357
+ /**
358
+ * Get field html.
359
+ *
360
+ * @param array $args field arguments.
361
+ * @return string
362
+ */
363
+ function get_field_html_via_ajax( $field_args ) {
364
+
365
+ $value = $field_args['value'];
366
+
367
+ $is_checkbox = false;
368
+ $is_require = false;
369
+ $is_select = false;
370
+
371
+ $display = 'none';
372
+
373
+ $field_content = '';
374
+
375
+ if ( isset( $field_args['before'] ) ) {
376
+ $field_content .= '<span>' . $field_args['before'] . '</span>';
377
+ }
378
+ $field_content .= '<input type="hidden" name="' . $field_args['name'] . '" value="no">';
379
+ $field_content .= '<input type="checkbox" name="' . $field_args['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
380
+
381
+ if ( isset( $field_args['after'] ) ) {
382
+ $field_content .= $field_args['after'];
383
+ }
384
+
385
+ $type = isset( $field_args['type'] ) ? $field_args['type'] : '';
386
+ $label = isset( $field_args['label'] ) ? $field_args['label'] : '';
387
+ $help = isset( $field_args['help'] ) ? $field_args['help'] : '';
388
+ $after_html = isset( $field_args['after_html'] ) ? $field_args['after_html'] : '';
389
+ $name = isset( $field_args['name'] ) ? $field_args['name'] : '';
390
+ $default = isset( $field_args['default']) ? $field_args['default'] : '';
391
+ $required = isset( $field_args['required']) ? $field_args['required'] : '';
392
+ $options = isset( $field_args['options']) ? $field_args['options'] : '';
393
+ $width = isset( $field_args['width']) ? $field_args['width'] : '';
394
+ $name_class = 'field-' . $field_args['name'];
395
+
396
+ if( isset( $options ) && !empty( $options ) ){
397
+ $options = implode(', ', $options );
398
+ }else{
399
+ $options = '';
400
+ }
401
+
402
+ if( 'yes' == $required ){
403
+ $is_require = true;
404
+ }
405
+
406
+ if( 'checkbox' == $type ){
407
+ $is_checkbox = true;
408
+ }
409
+
410
+ if( 'select' == $type ){
411
+ $is_select = true;
412
+ $display = 'block';
413
+ }
414
+
415
+ // echo "<pre>";
416
+ // var_dump($after_html);
417
+ // echo "</pre>";
418
+
419
+ // $field_markup = wcf()->meta->get_only_checkbox_field( $field_args );
420
+ ob_start();
421
+
422
+ ?>
423
+ <div class="wcf-field-item-bar">
424
+ <div class="wcf-field-item-handle ui-sortable-handle">
425
+ <label class="dashicons <?php if( 'no' == $value ){ echo 'dashicons-hidden'; } else{ echo 'dashicons-visibility';} ?> " for="<?php echo $field_args['name']; ?>"></label>
426
+ <span class="item-title">
427
+ <span class="wcf-field-item-title"><?php echo $label; if( $is_require ) { ?> <i>*</i> <?php } ?></span>
428
+ <span class="is-submenu" style="display: none;">sub item</span>
429
+ </span>
430
+ <span class="item-controls">
431
+ <span class="dashicons dashicons-menu"></span>
432
+ <span class="item-order hide-if-js">
433
+ <a href="#" class="item-move-up" aria-label="Move up">↑</a>
434
+ |
435
+ <a href="#" class="item-move-down" aria-label="Move down">↓</a>
436
+ </span>
437
+ <a class="item-edit" id="edit-64" href="javascript:void(0);" aria-label="My account. Menu item 1 of 5."><span class="screen-reader-text">Edit</span></a>
438
+ </span>
439
+ </div>
440
+ </div>
441
+ <div class="wcf-field-item-settings">
442
+ <div class="wcf-field-item-settings-row-width">
443
+ <?php
444
+ echo wcf()->meta->get_select_field(
445
+ array(
446
+ 'label' => __( 'Field Width', 'cartflows' ),
447
+ 'name' => 'wcf-field-width_' . str_replace( 'wcf-', '', $field_args['name'] ),
448
+ 'value' => $width,
449
+ 'options' => array(
450
+ '33' => __( '33%', 'cartflows' ),
451
+ '50' => __( '50%', 'cartflows' ),
452
+ '100' => __( '100%', 'cartflows' ),
453
+ ),
454
+ )
455
+ );
456
+ ?>
457
+ </div>
458
+
459
+ <div class="wcf-field-item-settings-label">
460
+ <?php
461
+ echo wcf()->meta->get_text_field(
462
+ array(
463
+ 'label' => __( 'Field Label', 'cartflows' ),
464
+ 'name' => 'wcf_label_text_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
465
+ 'value' => $label,
466
+ )
467
+ );
468
+
469
+ ?>
470
+ <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace( 'wcf-', '', $field_args['name'] ); ?>">
471
+ </div>
472
+
473
+ <div class="wcf-field-item-select-options" style="display:<?php if( isset( $display ) ){ print $display; } ?>;" >
474
+ <?php
475
+ echo wcf()->meta->get_text_field(
476
+ array(
477
+ 'label' => __( 'Options', 'cartflows' ),
478
+ 'name' => 'wcf_select_option_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
479
+ 'value' => $options,
480
+ )
481
+ );
482
+
483
+ ?>
484
+ <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace( 'wcf-', '', $field_args['name'] ); ?>">
485
+ </div>
486
+
487
+ <div class="wcf-field-item-settings-default">
488
+ <?php
489
+ if( true == $is_checkbox ){
490
+ echo wcf()->meta->get_select_field(
491
+ array(
492
+ 'label' => __( 'Default', 'cartflows' ),
493
+ 'name' => 'wcf_label_default_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
494
+ 'value' => $value,
495
+ 'options' => array(
496
+ '1' => __( 'Checked', 'cartflows' ),
497
+ '0' => __( 'Un-Checked', 'cartflows' ),
498
+ ),
499
+ )
500
+ );
501
+ }else{
502
+
503
+ echo wcf()->meta->get_text_field(
504
+ array(
505
+ 'label' => __( 'Default', 'cartflows' ),
506
+ 'name' => 'wcf_label_default_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
507
+ 'value' => $default,
508
+ )
509
+ );
510
+ }
511
+ ?>
512
+ </div>
513
+
514
+ <div class="wcf-field-item-settings-placeholder" <?php if( true == $is_checkbox ) {?> style="display: none;" <?php } ?> >
515
+ <?php
516
+ echo wcf()->meta->get_text_field(
517
+ array(
518
+ 'label' => __( 'Placeholder', 'cartflows' ),
519
+ 'name' => 'wcf_label_placeholder_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
520
+ 'value' => $label,
521
+ )
522
+ );
523
+ ?>
524
+ </div>
525
+
526
+ <div class="wcf-field-item-settings-required">
527
+ <?php
528
+ echo wcf()->meta->get_checkbox_field(
529
+ array(
530
+ 'label' => __( 'Required', 'cartflows' ),
531
+ 'name' => 'wcf_is_required_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
532
+ 'value' => $required,
533
+ )
534
+ );
535
+ ?>
536
+ </div>
537
+
538
+ <div class="wcf-field-item-settings-checkbox">
539
+ <?php
540
+ echo wcf()->meta->get_checkbox_field(
541
+ array(
542
+ 'label' => __( 'Enable this field', 'cartflows' ),
543
+ 'name' => $field_args['name'],
544
+ 'value' => $value,
545
+ )
546
+ );
547
+ ?>
548
+ </div>
549
+
550
+ <?php
551
+ if(isset( $field_args['after_html']) )
552
+ {
553
+ ?>
554
+ <div class="wcf-field-item-settings-row-delete-cf">
555
+ <?php echo $field_args['after_html']; ?>
556
+ </div>
557
+ <?php
558
+ }
559
+ ?>
560
+ <!--
561
+ <label for="<?php echo $field_args['name']; ?>">
562
+ <?php _e( 'Label', 'cartflows' ); ?><br>
563
+ <input type="text" value="<?php echo $field_args['label']; ?>">
564
+
565
+ <?php if( isset( $field_markup ) ) { echo $field_markup; }?>
566
+
567
+ <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace('wcf-', '', $field_args['name'] ); ?>">
568
+ </label> -->
569
+ </div>
570
+
571
+ <?php
572
+
573
+ return ob_get_clean();
574
+ }
575
+
576
+ /**
577
+ * [delete_checkout_custom_field description]
578
+ *
579
+ * @hook wcf_delete_checkout_custom_field
580
+ * @return [type] [description]
581
+ */
582
+ public function delete_checkout_custom_field() {
583
+
584
+ check_ajax_referer( 'wcf-delete-checkout-custom-field', 'security' );
585
+
586
+ $post_id = intval( $_POST['post_id'] );
587
+ $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
588
+ $key = sanitize_text_field( wp_unslash( $_POST['key'] ) );
589
+
590
+ if ( '' !== $key ) {
591
+
592
+ Cartflows_Helper::delete_checkout_field( $type, $key, $post_id );
593
+
594
+ wp_send_json( true );
595
+
596
+ }
597
+
598
+ wp_send_json( false );
599
+
600
+ }
601
+
602
+ /**
603
+ * Function to search coupons
604
+ */
605
+ public function json_search_pages() {
606
+
607
+ check_ajax_referer( 'wcf-json-search-pages', 'security' );
608
+
609
+ $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
610
+
611
+ if ( empty( $term ) ) {
612
+ die( 'not found' );
613
+ }
614
+
615
+ $search_string = $term;
616
+ $data = array();
617
+ $result = array();
618
+
619
+ add_filter( 'posts_search', array( $this, 'search_only_titles' ), 10, 2 );
620
+
621
+ $query = new WP_Query(
622
+ array(
623
+ 's' => $search_string,
624
+ 'post_type' => 'page',
625
+ 'posts_per_page' => - 1,
626
+ )
627
+ );
628
+
629
+ if ( $query->have_posts() ) {
630
+ while ( $query->have_posts() ) {
631
+ $query->the_post();
632
+ $title = get_the_title();
633
+ $title .= ( 0 != $query->post->post_parent ) ? ' (' . get_the_title( $query->post->post_parent ) . ')' : '';
634
+ $id = get_the_id();
635
+ $data[] = array(
636
+ 'id' => $id,
637
+ 'text' => $title,
638
+ );
639
+ }
640
+ }
641
+
642
+ if ( is_array( $data ) && ! empty( $data ) ) {
643
+ $result[] = array(
644
+ 'text' => '',
645
+ 'children' => $data,
646
+ );
647
+ }
648
+
649
+ wp_reset_postdata();
650
+
651
+ // return the result in json.
652
+ wp_send_json( $result );
653
+ }
654
+
655
+ public function search_only_titles( $search, $wp_query ) {
656
+ if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
657
+ global $wpdb;
658
+
659
+ $q = $wp_query->query_vars;
660
+ $n = ! empty( $q['exact'] ) ? '' : '%';
661
+
662
+ $search = array();
663
+
664
+ foreach ( (array) $q['search_terms'] as $term ) {
665
+ $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
666
+ }
667
+
668
+ if ( ! is_user_logged_in() ) {
669
+ $search[] = "$wpdb->posts.post_password = ''";
670
+ }
671
+
672
+ $search = ' AND ' . implode( ' AND ', $search );
673
+ }
674
+
675
+ return $search;
676
+ }
677
+
678
+ function get_field( $field_data, $field_content ) {
679
+
680
+ $label = isset( $field_data['label'] ) ? $field_data['label'] : '';
681
+ $help = isset( $field_data['help'] ) ? $field_data['help'] : '';
682
+ $after_html = isset( $field_data['after_html'] ) ? $field_data['after_html'] : '';
683
+
684
+ $name_class = 'field-' . $field_data['name'];
685
+
686
+ $field_html = '<div class="wcf-field-row ' . $name_class . '">';
687
+
688
+ if( ! empty( $label ) || ! empty( $help ) ) {
689
+ $field_html .= '<div class="wcf-field-row-heading">';
690
+ if( ! empty( $label ) ) {
691
+ $field_html .= '<label>' . esc_html( $label ) . '</label>';
692
+ }
693
+ if ( ! empty( $help ) ) {
694
+ $field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help">';
695
+ // $field_html .= '<span class="wcf-tooltip" data-tooltip= "'. esc_attr( $help ) .'"></span>';
696
+ $field_html .= '</i>';
697
+ $field_html .= '<span class="wcf-tooltip-text">';
698
+ $field_html .= $help;
699
+ $field_html .= '</span>';
700
+ }
701
+ $field_html .= '</div>';
702
+ }
703
+
704
+ $field_html .= '<div class="wcf-field-row-content">';
705
+ $field_html .= $field_content;
706
+
707
+ if ( ! empty( $after_html ) ) {
708
+ $field_html .= $after_html;
709
+ }
710
+
711
+ $field_html .= '</div>';
712
+ $field_html .= '</div>';
713
+
714
+ return $field_html;
715
+ }
716
+
717
+ function get_text_field( $field_data ) {
718
+
719
+ $value = $field_data['value'];
720
+
721
+ $attr = '';
722
+
723
+ if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
724
+
725
+ foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
726
+ $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
727
+ }
728
+ }
729
+
730
+ $field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
731
+
732
+ return $this->get_field( $field_data, $field_content );
733
+ }
734
+
735
+ function get_shortcode_field( $field_data ) {
736
+
737
+ $attr = '';
738
+
739
+ $attr_fields = array(
740
+ 'readonly' => 'readonly',
741
+ 'onfocus' => 'this.select()',
742
+ 'onmouseup' => 'return false',
743
+ );
744
+
745
+ if ( $attr_fields && is_array( $attr_fields ) ) {
746
+
747
+ foreach ( $attr_fields as $attr_key => $attr_value ) {
748
+ $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
749
+ }
750
+ }
751
+
752
+ $field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $field_data['content'] . '" ' . $attr . '>';
753
+
754
+ return $this->get_field( $field_data, $field_content );
755
+ }
756
+
757
+ function get_display_field( $field_data ) {
758
+
759
+ $field_content = $field_data['content'];
760
+
761
+ return $this->get_field( $field_data, $field_content );
762
+ }
763
+
764
+ function get_hr_line_field( $field_data ) {
765
+
766
+ $field_data = array(
767
+ 'name' => 'wcf-hr-line',
768
+ 'content' => '<hr>'
769
+ );
770
+
771
+ $field_content = $field_data['content'];
772
+
773
+ return $this->get_field( $field_data, $field_content );
774
+ }
775
+
776
+ function get_number_field( $field_data ) {
777
+
778
+ $value = $field_data['value'];
779
+
780
+ $attr = '';
781
+
782
+ if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
783
+
784
+ foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
785
+ $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
786
+ }
787
+ }
788
+
789
+ $field_content = '<input type="number" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
790
+
791
+ return $this->get_field( $field_data, $field_content );
792
+ }
793
+
794
+ function get_hidden_field( $field_data ) {
795
+
796
+ $value = $field_data['value'];
797
+
798
+ $attr = '';
799
+
800
+ if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
801
+
802
+ foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
803
+ $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
804
+ }
805
+ }
806
+
807
+ $field_content = '<input type="hidden" id="' . $field_data['name'] . '" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
808
+
809
+ return $this->get_field( $field_data, $field_content );
810
+ }
811
+
812
+ function get_area_field( $field_data ) {
813
+
814
+ $value = $field_data['value'];
815
+
816
+ $field_content = '<textarea name="' . $field_data['name'] . '" rows="10" cols="50">';
817
+ $field_content .= $value;
818
+ $field_content .= '</textarea>';
819
+
820
+ return $this->get_field( $field_data, $field_content );
821
+ }
822
+
823
+ function get_only_checkbox_field( $field_data ) {
824
+ // echo "<pre>";
825
+ // var_dump($field_data);
826
+ // echo "</pre>";
827
+
828
+ $value = $field_data['value'];
829
+
830
+
831
+ $field_content = '';
832
+ if ( isset( $field_data['before'] ) ) {
833
+ $field_content .= '<span>' . $field_data['before'] . '</span>';
834
+ }
835
+ $field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
836
+ $field_content .= '<input type="checkbox" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
837
+
838
+ if ( isset( $field_data['after'] ) ) {
839
+ $field_content .= '<span>' . $field_data['after'] . '</span>';
840
+ }
841
+
842
+ if ( isset( $field_data['after_html'] ) ) {
843
+ $field_content .= '<span>' . $field_data['after_html'] . '</span>';
844
+ }
845
+
846
+ return $field_content;
847
+ }
848
+
849
+ function get_checkbox_field( $field_data ) {
850
+
851
+ $value = $field_data['value'];
852
+
853
+ $field_content = '';
854
+ if ( isset( $field_data['before'] ) ) {
855
+ $field_content .= '<span>' . $field_data['before'] . '</span>';
856
+ }
857
+ $field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
858
+ $field_content .= '<input type="checkbox" id="'.$field_data['name'].'" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
859
+
860
+ if ( isset( $field_data['after'] ) ) {
861
+ $field_content .= '<span>' . $field_data['after'] . '</span>';
862
+ }
863
+
864
+ return $this->get_field( $field_data, $field_content );
865
+ }
866
+
867
+ function get_radio_field( $field_data ) {
868
+
869
+ $value = $field_data['value'];
870
+ $field_content = '';
871
+
872
+ if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
873
+
874
+ foreach ( $field_data['options'] as $data_key => $data_value ) {
875
+
876
+ $field_content .= '<div class="wcf-radio-option">';
877
+ $field_content .= '<input type="radio" name="' . $field_data['name'] . '" value="' . $data_key . '" ' . checked( $data_key, $value, false ) . '>';
878
+ $field_content .= $data_value;
879
+ $field_content .= '</div>';
880
+ }
881
+ }
882
+
883
+ return $this->get_field( $field_data, $field_content );
884
+ }
885
+
886
+ function get_font_family_field( $field_data ) {
887
+
888
+ $value = $field_data['value'];
889
+
890
+ $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
891
+
892
+ $field_content = '<select class="wcf-field-font-family" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
893
+
894
+ $field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
895
+
896
+ $field_content .= '<optgroup label="Other System Fonts">';
897
+ foreach ( CartFlows_Font_Families::get_system_fonts() as $name => $variants ) {
898
+ $field_content .= '<option value="' . esc_attr( $name ) . '" ' . selected( $name, $value, false ) . '>' . esc_attr( $name ) . '</option>';
899
+ }
900
+ $field_content .= '</optgroup>';
901
+ $field_content .= '<optgroup label="Google">';
902
+ foreach ( CartFlows_Font_Families::get_google_fonts() as $name => $single_font ) {
903
+ $variants = wcf_get_prop( $single_font, '0' );
904
+ $category = wcf_get_prop( $single_font, '1' );
905
+ $font_value = '\'' . esc_attr( $name ) . '\', ' . esc_attr( $category );
906
+ $field_content .= '<option value="' . esc_attr( $font_value ) . '" ' . selected( $font_value, $value, false ) . '>' . esc_attr( $name ) . '</option>';
907
+ }
908
+ $field_content .= '</optgroup>';
909
+
910
+ $field_content .= '</select>';
911
+
912
+ return $this->get_field( $field_data, $field_content );
913
+ }
914
+
915
+ function get_font_weight_field( $field_data ) {
916
+
917
+ $value = $field_data['value'];
918
+
919
+ $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
920
+
921
+ $field_content = '<select data-selected="'.esc_attr( $value ).'" class="wcf-field-font-weight" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
922
+
923
+ $field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
924
+
925
+ $field_content .= '</select>';
926
+
927
+ return $this->get_field( $field_data, $field_content );
928
+ }
929
+
930
+ function get_select_field( $field_data ) {
931
+
932
+ $value = $field_data['value'];
933
+ $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
934
+
935
+ $field_content = '<select name="' . $field_data['name'] . '">';
936
+
937
+
938
+ if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
939
+
940
+ foreach ( $field_data['options'] as $data_key => $data_value ) {
941
+
942
+ $disabled = '';
943
+
944
+ if ( array_key_exists( $data_key, $pro_options ) ) {
945
+ $disabled = 'disabled ';
946
+ $data_value = $pro_options[ $data_key ];
947
+ }
948
+
949
+ $field_content .= '<option value="' . $data_key . '" ' . selected( $value, $data_key, false ) . ' ' . $disabled .'>' . $data_value . '</option>';
950
+ }
951
+ }
952
+
953
+ $field_content .= '</select>';
954
+
955
+ if ( isset( $field_data['after'] ) ) {
956
+ $field_content .= '<span>' . $field_data['after'] . '</span>';
957
+ }
958
+
959
+ return $this->get_field( $field_data, $field_content );
960
+ }
961
+
962
+ function get_color_picker_field( $field_data ) {
963
+
964
+ $value = $field_data['value'];
965
+
966
+ $field_content = '<input class="wcf-color-picker" type="text" name="' . $field_data['name'] . '" value="' . $value . '">';
967
+
968
+ return $this->get_field( $field_data, $field_content );
969
+ }
970
+
971
+ function get_product_selection_field( $field_data ) {
972
+
973
+ $value = $field_data['value'];
974
+
975
+ $multiple = '';
976
+
977
+ if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
978
+ $multiple = ' multiple="multiple"';
979
+ }
980
+
981
+ $allow_clear = '';
982
+
983
+ if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
984
+ $allow_clear = ' data-allow_clear="allow_clear"';
985
+ }
986
+
987
+ $field_content = '<select
988
+ name="' . $field_data['name'] . '[]"
989
+ class="wcf-product-search" ' . $multiple . $allow_clear . '
990
+ data-placeholder="' . __( 'Search for a product&hellip;', 'cartflows' ) . '"
991
+ data-action="woocommerce_json_search_products_and_variations">';
992
+
993
+ if ( is_array( $value ) && ! empty( $value ) ) {
994
+
995
+ foreach ( $value as $data_key => $product_id ) {
996
+
997
+ $product = wc_get_product( $product_id );
998
+
999
+ // posts.
1000
+ if ( ! empty( $product ) ) {
1001
+ $post_title = $product->get_name() . ' (#' . $product_id . ')';
1002
+
1003
+ $field_content .= '<option value="' . $product_id . '" selected="selected" >' . $post_title . '</option>';
1004
+ }
1005
+ }
1006
+ }
1007
+ $field_content .= '</select>';
1008
+
1009
+ return $this->get_field( $field_data, $field_content );
1010
+ }
1011
+
1012
+ function get_coupon_selection_field( $field_data ) {
1013
+
1014
+ $value = $field_data['value'];
1015
+
1016
+ $multiple = '';
1017
+
1018
+ if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
1019
+ $multiple = ' multiple="multiple"';
1020
+ }
1021
+
1022
+ $allow_clear = '';
1023
+
1024
+ if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
1025
+ $allow_clear = ' data-allow_clear="allow_clear"';
1026
+ }
1027
+
1028
+ $field_content = '<select
1029
+ name="' . $field_data['name'] . '[]"
1030
+ class="wc-coupon-search wcf-coupon-search" ' . $multiple . $allow_clear . '
1031
+ data-placeholder="' . __( 'Search for a coupon&hellip;', 'cartflows' ) . '"
1032
+ data-action="wcf_json_search_coupons">';
1033
+
1034
+ if ( is_array( $value ) && ! empty( $value ) ) {
1035
+
1036
+ $all_discount_types = wc_get_coupon_types();
1037
+
1038
+ foreach ( $value as $coupon_title ) {
1039
+
1040
+ $coupon = new WC_Coupon( $coupon_title );
1041
+
1042
+ $discount_type = $coupon->get_discount_type();
1043
+
1044
+ if ( isset( $discount_type ) && $discount_type ) {
1045
+ $discount_type = ' ( Type: ' . $all_discount_types[ $discount_type ] . ' )';
1046
+ }
1047
+
1048
+ $field_content .= '<option value="' . $coupon_title . '" selected="selected">' . $coupon_title . $discount_type . '</option>';
1049
+ }
1050
+ }
1051
+
1052
+ $field_content .= '</select>';
1053
+
1054
+ return $this->get_field( $field_data, $field_content );
1055
+ }
1056
+
1057
+ function get_page_selection_field( $field_data ) {
1058
+
1059
+ $value = $field_data['value'];
1060
+
1061
+ $multiple = '';
1062
+
1063
+ if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
1064
+ $multiple = 'multiple="multiple"';
1065
+ }
1066
+
1067
+ $field_content = '<select
1068
+ name="' . $field_data['name'] . '[]"
1069
+ class="wcf-search-pages" ' . $multiple . '"
1070
+ data-action="wcf_json_search_pages">';
1071
+
1072
+ if ( is_array( $value ) && ! empty( $value ) ) {
1073
+
1074
+ foreach ( $value as $data_key => $data_value ) {
1075
+
1076
+ $field_content .= '<option value="' . $data_value . '">' . get_the_title( $data_value ) . '</option>';
1077
+ }
1078
+ }
1079
+
1080
+ $field_content .= '</select>';
1081
+
1082
+ return $this->get_field( $field_data, $field_content );
1083
+ }
1084
+
1085
+ function get_section( $field_data ) {
1086
+ $field_html = '<div class="wcf-field-row wcf-field-section">';
1087
+ $field_html .= '<div class="wcf-field-section-heading" colspan="2">';
1088
+ $field_html .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1089
+
1090
+ if ( isset( $field_data['help'] ) ) {
1091
+ $field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help" title="' . esc_attr( $field_data['help'] ) . '"></i>';
1092
+ }
1093
+ $field_html .= '</div>';
1094
+ $field_html .= '</div>';
1095
+ return $field_html;
1096
+ }
1097
+
1098
+ function get_description_field( $field_data ) {
1099
+
1100
+ $field_html = '<div class="wcf-field-row wcf-field-desc ' . $field_data['name'] . '">';
1101
+ $field_html .= '<div class="wcf-field-desc-content">';
1102
+ $field_html .= $field_data['content'];
1103
+ $field_html .= '</div>';
1104
+ $field_html .= '</div>';
1105
+
1106
+ return $field_html;
1107
+ }
1108
+
1109
+ function get_checkout_field_repeater( $field_data ) {
1110
+
1111
+ $value = array();
1112
+
1113
+ $value[0] = array(
1114
+ 'add_to' => '',
1115
+ 'type' => '',
1116
+ 'label' => '',
1117
+ 'name' => '',
1118
+ );
1119
+
1120
+ $field_content = '';
1121
+
1122
+ $field_content .= '<div class="wcf-field-row">';
1123
+ // $field_content .= '<div class="wcf-field-row-heading">';
1124
+ // $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1125
+ // $field_content .= '</div>';
1126
+ $field_content .= '<div class="wcf-field-row-content">';
1127
+ $field_content .= '<div class="wcf-cpf-wrap">';
1128
+
1129
+ foreach ( $value as $p_key => $p_data ) {
1130
+ $field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
1131
+ $field_content .= '<div class="wcf-cpf-row-header">';
1132
+ $field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
1133
+ $field_content .= '</div>';
1134
+
1135
+ $field_content .= '<div class="wcf-cpf-row-standard-fields">';
1136
+
1137
+ /* Add To */
1138
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
1139
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
1140
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1141
+ $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
1142
+ $field_content .= '<option value="billing">Billing</option>';
1143
+ $field_content .= '<option value="shipping">Shipping</option>';
1144
+ $field_content .= '</select>';
1145
+ $field_content .= '</span>';
1146
+ $field_content .= '</div>';
1147
+
1148
+ /* Type */
1149
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
1150
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
1151
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1152
+ $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
1153
+ $field_content .= '<option value="text">Text</option>';
1154
+ $field_content .= '<option value="textarea">Textarea</option>';
1155
+ $field_content .= '<option value="select">Select</option>';
1156
+ $field_content .= '<option value="checkbox">Checkbox</option>';
1157
+ $field_content .= '</select>';
1158
+ $field_content .= '</span>';
1159
+ $field_content .= '</div>';
1160
+
1161
+ /* Textarea */
1162
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
1163
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Options *</span>';
1164
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1165
+ $field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
1166
+ $field_content .= '</span>';
1167
+ $field_content .= '</div>';
1168
+
1169
+ /* Label */
1170
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
1171
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Label *</span>';
1172
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1173
+ $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
1174
+ $field_content .= '</span>';
1175
+ $field_content .= '</div>';
1176
+
1177
+ /* Name */
1178
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-name">';
1179
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Name *</span>';
1180
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1181
+ $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][name]" class="wcf-cpf-name">';
1182
+ $field_content .= '</span>';
1183
+ $field_content .= '</div>';
1184
+
1185
+ $field_content .= '</div>';
1186
+ $field_content .= '</div>';
1187
+ }
1188
+
1189
+ /* Add New Custom Field */
1190
+ $field_content .= '<div class="wcf-cpf-add-row">';
1191
+ $field_content .= '<div class="wcf-cpf-add-wrap">';
1192
+ $field_content .= '<button class="button button-secondary wcf-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
1193
+ $field_content .= '</div>';
1194
+ $field_content .= '</div>';
1195
+ /* End Add new custom field */
1196
+
1197
+ $field_content .= '</div>';
1198
+ $field_content .= '</div>';
1199
+ $field_content .= '</div>';
1200
+
1201
+ return $field_content;
1202
+ }
1203
+
1204
+ function get_pro_checkout_field_repeater( $field_data ) {
1205
+
1206
+ $value = array();
1207
+
1208
+ $value[0] = array(
1209
+ 'add_to' => '',
1210
+ 'type' => '',
1211
+ 'label' => '',
1212
+ 'name' => '',
1213
+ );
1214
+
1215
+ $field_content = '';
1216
+
1217
+ $field_content .= '<div class="wcf-field-row">';
1218
+ // $field_content .= '<div class="wcf-field-row-heading">';
1219
+ // $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1220
+ // $field_content .= '</div>';
1221
+ $field_content .= '<div class="wcf-field-row-content">';
1222
+ $field_content .= '<div class="wcf-cpf-wrap">';
1223
+
1224
+ foreach ( $value as $p_key => $p_data ) {
1225
+ $field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
1226
+ $field_content .= '<div class="wcf-cpf-row-header">';
1227
+ $field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
1228
+ $field_content .= '</div>';
1229
+
1230
+ $field_content .= '<div class="wcf-cpf-row-standard-fields">';
1231
+
1232
+ /* Add To */
1233
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
1234
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
1235
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1236
+ $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
1237
+ $field_content .= '<option value="billing">Billing</option>';
1238
+ $field_content .= '<option value="shipping">Shipping</option>';
1239
+ $field_content .= '</select>';
1240
+ $field_content .= '</span>';
1241
+ $field_content .= '</div>';
1242
+
1243
+ /* Type */
1244
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
1245
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
1246
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1247
+ $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
1248
+ $field_content .= '<option value="text">Text</option>';
1249
+ $field_content .= '<option value="textarea">Textarea</option>';
1250
+ $field_content .= '<option value="select">Select</option>';
1251
+ $field_content .= '<option value="checkbox">Checkbox</option>';
1252
+ $field_content .= '<option value="hidden">Hidden</option>';
1253
+ $field_content .= '</select>';
1254
+ $field_content .= '</span>';
1255
+ $field_content .= '</div>';
1256
+
1257
+ /* Label */
1258
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
1259
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Label <i>*</i></span>';
1260
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1261
+ $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
1262
+ $field_content .= '<span id="wcf-cpf-label-error-msg"></span>';
1263
+ $field_content .= '</span>';
1264
+ $field_content .= '</div>';
1265
+
1266
+ /* Default */
1267
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-default">';
1268
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Default</span>';
1269
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1270
+ $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][default]" class="wcf-cpf-default">';
1271
+ $field_content .= '<span id="wcf-cpf-default-error-msg"></span>';
1272
+ $field_content .= '</span>';
1273
+ $field_content .= '</div>';
1274
+
1275
+ /* Placeholder */
1276
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-placeholder">';
1277
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Placeholder</span>';
1278
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1279
+ $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][placeholder]" class="wcf-cpf-placeholder">';
1280
+ $field_content .= '<span id="wcf-cpf-placeholder-error-msg"></span>';
1281
+ $field_content .= '</span>';
1282
+ $field_content .= '</div>';
1283
+
1284
+ /* Options */
1285
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
1286
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Options <i>*</i></span>';
1287
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1288
+ $field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
1289
+ $field_content .= '</span>';
1290
+ $field_content .= '</div>';
1291
+
1292
+ /* Width */
1293
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-width">';
1294
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Width</span>';
1295
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1296
+ $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][width]" class="wcf-cpf-width">';
1297
+ $field_content .= '<option value="33">33%</option>';
1298
+ $field_content .= '<option value="50">50%</option>';
1299
+ $field_content .= '<option value="100" selected>100%</option>';
1300
+ $field_content .= '</select>';
1301
+ $field_content .= '</span>';
1302
+ $field_content .= '</div>';
1303
+
1304
+ /* Required */
1305
+ $field_content .= '<div class="wcf-cpf-fields wcf-cpf-required">';
1306
+ $field_content .= '<span class="wcf-cpf-row-setting-label">Required</span>';
1307
+ $field_content .= '<span class="wcf-cpf-row-setting-field">';
1308
+ $field_content .= '<input type="hidden" value="no" name="wcf-checkout-custom-fields[' . $p_key . '][required]" class="wcf-cpf-required">';
1309
+ $field_content .= '<input type="checkbox" value="yes" name="wcf-checkout-custom-fields[' . $p_key . '][required]" class="wcf-cpf-required">';
1310
+ $field_content .= '<span id="wcf-cpf-required-error-msg"></span>';
1311
+ $field_content .= '</span>';
1312
+ $field_content .= '</div>';
1313
+
1314
+ $field_content .= '</div>';
1315
+ $field_content .= '</div>';
1316
+ }
1317
+
1318
+ /* Add New Custom Field */
1319
+ $field_content .= '<div class="wcf-cpf-add-row">';
1320
+ $field_content .= '<div class="wcf-cpf-add-wrap">';
1321
+ $field_content .= '<button class="button button-secondary wcf-pro-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
1322
+ $field_content .= '</div>';
1323
+ $field_content .= '</div>';
1324
+ /* End Add new custom field */
1325
+
1326
+ $field_content .= '</div>';
1327
+ $field_content .= '</div>';
1328
+ $field_content .= '</div>';
1329
+
1330
+ return $field_content;
1331
+ }
1332
+
1333
+ function get_product_selection_repeater( $field_data ) {
1334
+
1335
+ $value = $field_data['value'];
1336
+
1337
+ if ( ! is_array( $value ) ) {
1338
+
1339
+ $value[0] = array(
1340
+ 'product' => '',
1341
+ );
1342
+ } else {
1343
+
1344
+ if ( ! isset( $value[0] ) ) {
1345
+
1346
+ $value[0] = array(
1347
+ 'product' => '',
1348
+ );
1349
+ }
1350
+ }
1351
+
1352
+ $field_html = '';
1353
+
1354
+ $field_html .= '<script type="text/html" id="tmpl-wcf-product-repeater">';
1355
+ $field_html .= $this->generate_product_repeater_html( '{{id}}' );
1356
+ $field_html .= '</script>';
1357
+
1358
+ $field_html .= '<div class="wcf-field-row">';
1359
+ $field_html .= '<div class="wcf-field-row-content">';
1360
+ $field_html .= '<div class="wcf-repeatables-wrap">';
1361
+
1362
+ if ( is_array( $value ) ) {
1363
+
1364
+ foreach ( $value as $p_key => $p_data ) {
1365
+
1366
+ $selected_options = '';
1367
+
1368
+ if ( isset( $p_data['product'] ) ) {
1369
+
1370
+ $product = wc_get_product( $p_data['product'] );
1371
+
1372
+ // posts.
1373
+ if ( ! empty( $product ) ) {
1374
+ $post_title = $product->get_name() . ' (#' . $p_data['product'] . ')';
1375
+
1376
+ $selected_options = '<option value="' . $p_data['product'] . '" selected="selected" >' . $post_title . '</option>';
1377
+ }
1378
+ }
1379
+
1380
+ $field_html .= $this->generate_product_repeater_html( $p_key, $selected_options );
1381
+ }
1382
+ }
1383
+
1384
+ $field_html .= '<div class="wcf-add-repeatable-row">';
1385
+ $field_html .= '<div class="submit wcf-add-repeatable-wrap">';
1386
+ $field_html .= '<button class="button-primary wcf-add-repeatable" data-name="wcf-checkout-products">Add New Product</button>';
1387
+ $field_html .= '</div>';
1388
+ $field_html .= '</div>';
1389
+ $field_html .= '</div>';
1390
+ $field_html .= '</div>';
1391
+ $field_html .= '</div>';
1392
+
1393
+ return $field_html;
1394
+ }
1395
+
1396
+ function generate_product_repeater_html( $id, $options = '' ) {
1397
+
1398
+ $field_html = '<div class="wcf-repeatable-row" data-key="' . $id . '">';
1399
+
1400
+ $field_html .= '<div class="wcf-repeatable-row-standard-fields">';
1401
+
1402
+ /* Product Name */
1403
+ $field_html .= '<div class="wcf-repeatable-fields wcf-sel-product">';
1404
+ $field_html .= '<span class="wcf-repeatable-row-setting-field">';
1405
+ $field_html .= '<select
1406
+ name="wcf-checkout-products[' . $id . '][product]"
1407
+ class="wcf-product-search"
1408
+ data-allow_clear="allow_clear"
1409
+ data-placeholder="' . __( 'Search for a product&hellip;', 'cartflows' ) . '"
1410
+ data-action="woocommerce_json_search_products_and_variations">';
1411
+ $field_html .= $options;
1412
+ $field_html .= '</select>';
1413
+ $field_html .= '</span>';
1414
+ $field_html .= '<span class="wcf-repeatable-row-actions">';
1415
+ $field_html .= '<a class="wcf-remove-row wcf-repeatable-remove button" data-type="product">';
1416
+ $field_html .= '<span class="dashicons dashicons-trash"></span>';
1417
+ $field_html .= '<span class="wcf-repeatable-remove-button">'. __( 'Remove', 'cartflows' ).'</span>';
1418
+ $field_html .= '</a>';
1419
+ $field_html .= '</span>';
1420
+ $field_html .= '</div>';
1421
+ $field_html .= '</div>';
1422
+ $field_html .= '</div>';
1423
+
1424
+ return $field_html;
1425
+ }
1426
+
1427
+ function get_image_field( $field_data ) {
1428
+
1429
+ $value = $field_data['value'];
1430
+
1431
+ $attr = '';
1432
+
1433
+ if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
1434
+
1435
+ foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
1436
+ $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
1437
+ }
1438
+ }
1439
+
1440
+ $display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
1441
+
1442
+ $field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
1443
+ if( isset( $value ) ){
1444
+ $field_content .= '<img src="'. $value .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
1445
+ }
1446
+ $field_content .= '</div>';
1447
+ // $field_content .= '<input type="hidden" id="wcf-image-id" class="wcf-image-id" name="wcf-image-id[image-id]" value="">';
1448
+ $field_content .= '<input type="hidden" id="wcf-image-value" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
1449
+
1450
+ $field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
1451
+
1452
+ $display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
1453
+
1454
+ $field_content .= '<button type="button" class="wcf-remove-image button-secondary" style="'.$display_remove_button.'">Remove Image</button>';
1455
+
1456
+ return $this->get_field( $field_data, $field_content );
1457
+ }
1458
+
1459
+ /**
1460
+ * Localize variables in admin
1461
+ *
1462
+ * @param array $vars variables.
1463
+ */
1464
+ function localize_vars( $vars ) {
1465
+
1466
+ $ajax_actions = array(
1467
+ 'wcf_add_checkout_custom_field',
1468
+ 'wcf_pro_add_checkout_custom_field',
1469
+ 'wcf_delete_checkout_custom_field',
1470
+ 'wcf_json_search_pages',
1471
+ 'wcf_json_search_coupons'
1472
+ );
1473
+
1474
+ foreach ( $ajax_actions as $action ) {
1475
+
1476
+ $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1477
+ }
1478
+
1479
+ return $vars;
1480
+ }
1481
+ }
1482
+ // @codingStandardsIgnoreEnd
classes/class-cartflows-meta.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /**
3
- * CartFlows Meta
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'Cartflows_Meta' ) ) :
10
-
11
- /**
12
- * CartFlows_Meta
13
- *
14
- * @since 1.0.0
15
- */
16
- class Cartflows_Meta {
17
- /**
18
- * Constructor
19
- *
20
- * @since 1.0.0
21
- */
22
- public function __construct() {
23
- }
24
-
25
- /**
26
- * Flow & Step Actions
27
- *
28
- * @param array $options options.
29
- * @param int $post_id post ID.
30
- */
31
- function right_column_footer( $options, $post_id ) {
32
- ?>
33
- <div class="wcf-column-right-footer">
34
- <?php submit_button( __( 'Update', 'cartflows' ), 'primary', 'save', false ); ?>
35
-
36
- <?php
37
- $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
38
- if ( $flow_id ) {
39
- ?>
40
- <a href="<?php echo esc_url( get_edit_post_link( $flow_id ) ); ?>" class="button pull-right wcf-back-to-flow-edit">
41
- <i class="dashicons dashicons-arrow-left-alt"></i>
42
- <?php _e( 'Back to edit Flow', 'cartflows' ); ?>
43
- </a>
44
- <?php } ?>
45
-
46
- </div>
47
- <?php
48
- }
49
-
50
- /**
51
- * Script Header (Used for add script into header)
52
- *
53
- * @param array $options options.
54
- * @param int $post_id post ID.
55
- */
56
- function tab_custom_script( $options, $post_id ) {
57
- ?>
58
- <div class="wcf-<?php echo wcf()->utils->get_step_type( $post_id ); ?>-custom-script-header wcf-tab-content widefat">
59
- <?php
60
- /* Script added onto the header */
61
- echo wcf()->meta->get_area_field(
62
- array(
63
- 'label' => __( 'Custom Script', 'cartflows' ),
64
- 'name' => 'wcf-custom-script',
65
- 'value' => htmlspecialchars( $options['wcf-custom-script'] ),
66
- 'help' => __( 'Custom script lets you add your own custom script on front end of this flow page.', 'cartflows' ),
67
- )
68
- );
69
- ?>
70
- </div>
71
- <?php
72
- }
73
- }
74
-
75
- endif;
1
+ <?php
2
+ /**
3
+ * CartFlows Meta
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'Cartflows_Meta' ) ) :
10
+
11
+ /**
12
+ * CartFlows_Meta
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Cartflows_Meta {
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @since 1.0.0
21
+ */
22
+ public function __construct() {
23
+ }
24
+
25
+ /**
26
+ * Flow & Step Actions
27
+ *
28
+ * @param array $options options.
29
+ * @param int $post_id post ID.
30
+ */
31
+ function right_column_footer( $options, $post_id ) {
32
+ ?>
33
+ <div class="wcf-column-right-footer">
34
+ <?php submit_button( __( 'Update', 'cartflows' ), 'primary', 'save', false ); ?>
35
+
36
+ <?php
37
+ $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
38
+ if ( $flow_id ) {
39
+ ?>
40
+ <a href="<?php echo esc_url( get_edit_post_link( $flow_id ) ); ?>" class="button pull-right wcf-back-to-flow-edit">
41
+ <i class="dashicons dashicons-arrow-left-alt"></i>
42
+ <?php _e( 'Back to edit Flow', 'cartflows' ); ?>
43
+ </a>
44
+ <?php } ?>
45
+
46
+ </div>
47
+ <?php
48
+ }
49
+
50
+ /**
51
+ * Script Header (Used for add script into header)
52
+ *
53
+ * @param array $options options.
54
+ * @param int $post_id post ID.
55
+ */
56
+ function tab_custom_script( $options, $post_id ) {
57
+ ?>
58
+ <div class="wcf-<?php echo wcf()->utils->get_step_type( $post_id ); ?>-custom-script-header wcf-tab-content widefat">
59
+ <?php
60
+ /* Script added onto the header */
61
+ echo wcf()->meta->get_area_field(
62
+ array(
63
+ 'label' => __( 'Custom Script', 'cartflows' ),
64
+ 'name' => 'wcf-custom-script',
65
+ 'value' => htmlspecialchars( $options['wcf-custom-script'] ),
66
+ 'help' => __( 'Custom script lets you add your own custom script on front end of this flow page.', 'cartflows' ),
67
+ )
68
+ );
69
+ ?>
70
+ </div>
71
+ <?php
72
+ }
73
+ }
74
+
75
+ endif;
classes/class-cartflows-thrive-compatibility.php CHANGED
@@ -1,77 +1,77 @@
1
- <?php
2
- /**
3
- * Thrive Visual Editor Compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Class for Thrive Visual Editor Compatibility
10
- */
11
- class Cartflows_Thrive_Compatibility {
12
-
13
- /**
14
- * Member Variable
15
- *
16
- * @var instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Initiator
22
- */
23
- public static function get_instance() {
24
- if ( ! isset( self::$instance ) ) {
25
- self::$instance = new self;
26
- }
27
- return self::$instance;
28
- }
29
-
30
- /**
31
- * Constructor
32
- */
33
- public function __construct() {
34
-
35
- // Add CartFlows post type in the thrive page editor.
36
- add_filter( 'tve_post_type_can_use_landing_page', array( $this, 'send_post_type_to_thrive' ) );
37
-
38
- // add_filter( 'tve_landing_page_post_types', array( $this, 'send_post_type_to_thrive' ) );.
39
- add_filter( 'tcb_can_use_landing_pages', array( $this, 'display_change_template_option' ) );
40
-
41
- add_filter( 'tcb_has_templates_tab', array( $this, 'display_change_template_option' ) );
42
- }
43
-
44
- /**
45
- * Return step post type for Thrive Architect.
46
- *
47
- * @since 1.0.0
48
- * @param array $post_type_pt the current step post type.
49
- * @return array $post_type_pt current step post type.
50
- */
51
- function send_post_type_to_thrive( $post_type_pt ) {
52
-
53
- $post_type_pt[] = CARTFLOWS_STEP_POST_TYPE;
54
-
55
- return $post_type_pt;
56
- }
57
-
58
- /**
59
- * Return true/false to show change template option.
60
- *
61
- * @since 1.0.0
62
- * @param array $bool true/false.
63
- * @return array $bool true/false.
64
- */
65
- function display_change_template_option( $bool ) {
66
-
67
- if ( wcf()->utils->is_step_post_type() ) {
68
- $bool = true;
69
- }
70
- return $bool;
71
- }
72
- }
73
-
74
- /**
75
- * Kicking this off by calling 'get_instance()' method
76
- */
77
- Cartflows_Thrive_Compatibility::get_instance();
1
+ <?php
2
+ /**
3
+ * Thrive Visual Editor Compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Class for Thrive Visual Editor Compatibility
10
+ */
11
+ class Cartflows_Thrive_Compatibility {
12
+
13
+ /**
14
+ * Member Variable
15
+ *
16
+ * @var instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Initiator
22
+ */
23
+ public static function get_instance() {
24
+ if ( ! isset( self::$instance ) ) {
25
+ self::$instance = new self;
26
+ }
27
+ return self::$instance;
28
+ }
29
+
30
+ /**
31
+ * Constructor
32
+ */
33
+ public function __construct() {
34
+
35
+ // Add CartFlows post type in the thrive page editor.
36
+ add_filter( 'tve_post_type_can_use_landing_page', array( $this, 'send_post_type_to_thrive' ) );
37
+
38
+ // add_filter( 'tve_landing_page_post_types', array( $this, 'send_post_type_to_thrive' ) );.
39
+ add_filter( 'tcb_can_use_landing_pages', array( $this, 'display_change_template_option' ) );
40
+
41
+ add_filter( 'tcb_has_templates_tab', array( $this, 'display_change_template_option' ) );
42
+ }
43
+
44
+ /**
45
+ * Return step post type for Thrive Architect.
46
+ *
47
+ * @since 1.0.0
48
+ * @param array $post_type_pt the current step post type.
49
+ * @return array $post_type_pt current step post type.
50
+ */
51
+ function send_post_type_to_thrive( $post_type_pt ) {
52
+
53
+ $post_type_pt[] = CARTFLOWS_STEP_POST_TYPE;
54
+
55
+ return $post_type_pt;
56
+ }
57
+
58
+ /**
59
+ * Return true/false to show change template option.
60
+ *
61
+ * @since 1.0.0
62
+ * @param array $bool true/false.
63
+ * @return array $bool true/false.
64
+ */
65
+ function display_change_template_option( $bool ) {
66
+
67
+ if ( wcf()->utils->is_step_post_type() ) {
68
+ $bool = true;
69
+ }
70
+ return $bool;
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Kicking this off by calling 'get_instance()' method
76
+ */
77
+ Cartflows_Thrive_Compatibility::get_instance();
classes/class-cartflows-update.php CHANGED
@@ -1,77 +1,77 @@
1
- <?php
2
- /**
3
- * Update Compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- if ( ! class_exists( 'Cartflows_Update' ) ) :
9
-
10
- /**
11
- * CartFlows Update initial setup
12
- *
13
- * @since 1.0.0
14
- */
15
- class Cartflows_Update {
16
-
17
- /**
18
- * Class instance.
19
- *
20
- * @access private
21
- * @var $instance Class instance.
22
- */
23
- private static $instance;
24
-
25
- /**
26
- * Initiator
27
- */
28
- public static function get_instance() {
29
- if ( ! isset( self::$instance ) ) {
30
- self::$instance = new self();
31
- }
32
- return self::$instance;
33
- }
34
-
35
- /**
36
- * Constructor
37
- */
38
- public function __construct() {
39
- add_action( 'admin_init', __CLASS__ . '::init' );
40
- }
41
-
42
- /**
43
- * Init
44
- *
45
- * @since 1.0.0
46
- * @return void
47
- */
48
- static public function init() {
49
-
50
- do_action( 'cartflows_update_before' );
51
-
52
- // Get auto saved version number.
53
- $saved_version = get_option( 'cartflows-version', false );
54
-
55
- // Update auto saved version number.
56
- if ( ! $saved_version ) {
57
- update_option( 'cartflows-version', CARTFLOWS_VER );
58
- }
59
-
60
- // If equals then return.
61
- if ( version_compare( $saved_version, CARTFLOWS_VER, '=' ) ) {
62
- return;
63
- }
64
-
65
- // Update auto saved version number.
66
- update_option( 'cartflows-version', CARTFLOWS_VER );
67
-
68
- do_action( 'cartflows_update_after' );
69
- }
70
- }
71
-
72
- /**
73
- * Kicking this off by calling 'get_instance()' method
74
- */
75
- Cartflows_Update::get_instance();
76
-
77
- endif;
1
+ <?php
2
+ /**
3
+ * Update Compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ if ( ! class_exists( 'Cartflows_Update' ) ) :
9
+
10
+ /**
11
+ * CartFlows Update initial setup
12
+ *
13
+ * @since 1.0.0
14
+ */
15
+ class Cartflows_Update {
16
+
17
+ /**
18
+ * Class instance.
19
+ *
20
+ * @access private
21
+ * @var $instance Class instance.
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Initiator
27
+ */
28
+ public static function get_instance() {
29
+ if ( ! isset( self::$instance ) ) {
30
+ self::$instance = new self();
31
+ }
32
+ return self::$instance;
33
+ }
34
+
35
+ /**
36
+ * Constructor
37
+ */
38
+ public function __construct() {
39
+ add_action( 'admin_init', __CLASS__ . '::init' );
40
+ }
41
+
42
+ /**
43
+ * Init
44
+ *
45
+ * @since 1.0.0
46
+ * @return void
47
+ */
48
+ static public function init() {
49
+
50
+ do_action( 'cartflows_update_before' );
51
+
52
+ // Get auto saved version number.
53
+ $saved_version = get_option( 'cartflows-version', false );
54
+
55
+ // Update auto saved version number.
56
+ if ( ! $saved_version ) {
57
+ update_option( 'cartflows-version', CARTFLOWS_VER );
58
+ }
59
+
60
+ // If equals then return.
61
+ if ( version_compare( $saved_version, CARTFLOWS_VER, '=' ) ) {
62
+ return;
63
+ }
64
+
65
+ // Update auto saved version number.
66
+ update_option( 'cartflows-version', CARTFLOWS_VER );
67
+
68
+ do_action( 'cartflows_update_after' );
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Kicking this off by calling 'get_instance()' method
74
+ */
75
+ Cartflows_Update::get_instance();
76
+
77
+ endif;
classes/class-cartflows-utils.php CHANGED
@@ -1,344 +1,344 @@
1
- <?php
2
- /**
3
- * Utils.
4
- *
5
- * @package CARTFLOWS
6
- */
7
-
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit; // Exit if accessed directly.
10
- }
11
-
12
- /**
13
- * Class Cartflows_Utils.
14
- */
15
- class Cartflows_Utils {
16
-
17
- /**
18
- * Member Variable
19
- *
20
- * @var instance
21
- */
22
- private static $instance;
23
-
24
- /**
25
- * Initiator
26
- */
27
- public static function get_instance() {
28
- if ( ! isset( self::$instance ) ) {
29
- self::$instance = new self;
30
- }
31
- return self::$instance;
32
- }
33
-
34
- /**
35
- * Constructor
36
- */
37
- function __construct() {
38
- }
39
-
40
- /**
41
- * Get current post type
42
- *
43
- * @param string $post_type post type.
44
- * @return string
45
- */
46
- function current_post_type( $post_type = '' ) {
47
-
48
- if ( '' === $post_type ) {
49
- $post_type = get_post_type();
50
- }
51
-
52
- return $post_type;
53
- }
54
-
55
- /**
56
- * Check if post type is of step.
57
- *
58
- * @param string $post_type post type.
59
- * @return bool
60
- */
61
- function is_step_post_type( $post_type = '' ) {
62
-
63
- if ( $this->get_step_post_type() === $this->current_post_type( $post_type ) ) {
64
-
65
- return true;
66
- }
67
-
68
- return false;
69
- }
70
-
71
- /**
72
- * Check if post type is of flow.
73
- *
74
- * @param string $post_type post type.
75
- * @return bool
76
- */
77
- function is_flow_post_type( $post_type = '' ) {
78
-
79
- if ( $this->get_flow_post_type() === $this->current_post_type( $post_type ) ) {
80
-
81
- return true;
82
- }
83
-
84
- return false;
85
- }
86
-
87
- /**
88
- * Get post type of step.
89
- *
90
- * @return string
91
- */
92
- function get_step_post_type() {
93
-
94
- return CARTFLOWS_STEP_POST_TYPE;
95
- }
96
-
97
- /**
98
- * Get post type of flow.
99
- *
100
- * @return string
101
- */
102
- function get_flow_post_type() {
103
-
104
- return CARTFLOWS_FLOW_POST_TYPE;
105
- }
106
-
107
- /**
108
- * Get flow id
109
- *
110
- * @return int
111
- */
112
- function get_flow_id() {
113
-
114
- global $post;
115
-
116
- return get_post_meta( $post->ID, 'wcf-flow-id', true );
117
- }
118
-
119
- /**
120
- * Get flow id by step
121
- *
122
- * @param int $step_id step ID.
123
- * @return int
124
- */
125
- function get_flow_id_from_step_id( $step_id ) {
126
-
127
- return get_post_meta( $step_id, 'wcf-flow-id', true );
128
- }
129
-
130
- /**
131
- * Get flow steps by id
132
- *
133
- * @param int $flow_id flow ID.
134
- * @return int
135
- */
136
- function get_flow_steps( $flow_id ) {
137
-
138
- $steps = get_post_meta( $flow_id, 'wcf-steps', true );
139
-
140
- if ( is_array( $steps ) && ! empty( $steps ) ) {
141
- return $steps;
142
- }
143
-
144
- return false;
145
- }
146
-
147
- /**
148
- * Get template type of step
149
- *
150
- * @param int $step_id step ID.
151
- * @return int
152
- */
153
- function get_step_type( $step_id ) {
154
-
155
- return get_post_meta( $step_id, 'wcf-step-type', true );
156
- }
157
-
158
- /**
159
- * Get next id for step
160
- *
161
- * @param int $flow_id flow ID.
162
- * @param int $step_id step ID.
163
- * @return bool
164
- */
165
- function get_next_step_id( $flow_id, $step_id ) {
166
-
167
- $steps = $this->get_flow_steps( $flow_id );
168
- $step_id = intval( $step_id );
169
-
170
- if ( ! $steps ) {
171
- return false;
172
- }
173
-
174
- foreach ( $steps as $i => $step ) {
175
-
176
- if ( intval( $step['id'] ) === $step_id ) {
177
-
178
- $next_i = $i + 1;
179
-
180
- if ( isset( $steps[ $next_i ] ) ) {
181
-
182
- $navigation = $steps[ $next_i ];
183
-
184
- return intval( $navigation['id'] );
185
- }
186
-
187
- break;
188
- }
189
- }
190
-
191
- return false;
192
- }
193
-
194
- /**
195
- * Get next id for step
196
- *
197
- * @param int $order_id order ID.
198
- * @return int
199
- */
200
- function get_flow_id_from_order( $order_id ) {
201
-
202
- $flow_id = get_post_meta( $order_id, '_wcf_flow_id', true );
203
-
204
- return intval( $flow_id );
205
- }
206
-
207
- /**
208
- * Get checkout id for order
209
- *
210
- * @param int $order_id order ID.
211
- * @return int
212
- */
213
- function get_checkout_id_from_order( $order_id ) {
214
-
215
- $checkout_id = get_post_meta( $order_id, '_wcf_checkout_id', true );
216
-
217
- return intval( $checkout_id );
218
- }
219
-
220
- /**
221
- * We are using this function mostly in ajax on checkout page
222
- *
223
- * @return bool
224
- */
225
- function get_checkout_id_from_post_data() {
226
-
227
- if ( isset( $_POST['_wcf_checkout_id'] ) ) {
228
-
229
- $checkout_id = filter_var( $_POST['_wcf_checkout_id'], FILTER_SANITIZE_NUMBER_INT );
230
-
231
- return intval( $checkout_id );
232
- }
233
-
234
- return false;
235
- }
236
-
237
- /**
238
- * We are using this function mostly in ajax on checkout page
239
- *
240
- * @return bool
241
- */
242
- function get_flow_id_from_post_data() {
243
-
244
- if ( isset( $_POST['_wcf_flow_id'] ) ) {
245
-
246
- $flow_id = filter_var( $_POST['_wcf_flow_id'], FILTER_SANITIZE_NUMBER_INT );
247
-
248
- return intval( $flow_id );
249
- }
250
-
251
- return false;
252
- }
253
-
254
- /**
255
- * Check for thank you page
256
- *
257
- * @param int $step_id step ID.
258
- * @return bool
259
- */
260
- function check_is_thankyou_page( $step_id ) {
261
-
262
- $step_type = $this->get_step_type( $step_id );
263
-
264
- if ( 'thankyou' === $step_type ) {
265
-
266
- return true;
267
- }
268
-
269
- return false;
270
- }
271
-
272
- /**
273
- * Check for offer page
274
- *
275
- * @param int $step_id step ID.
276
- * @return bool
277
- */
278
- function check_is_offer_page( $step_id ) {
279
-
280
- $step_type = $this->get_step_type( $step_id );
281
-
282
- if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
283
-
284
- return true;
285
- }
286
-
287
- return false;
288
- }
289
-
290
- /**
291
- * Define constant for cache
292
- *
293
- * @return void
294
- */
295
- function do_not_cache() {
296
-
297
- wc_maybe_define_constant( 'DONOTCACHEPAGE', true );
298
- wc_maybe_define_constant( 'DONOTCACHEOBJECT', true );
299
- wc_maybe_define_constant( 'DONOTCACHEDB', true );
300
-
301
- nocache_headers();
302
- }
303
-
304
- /**
305
- * Get linking url
306
- *
307
- * @param array $args query args.
308
- * @return string
309
- */
310
- function get_linking_url( $args = array() ) {
311
-
312
- $url = get_home_url();
313
-
314
- $url = add_query_arg( $args, $url );
315
-
316
- return $url;
317
- }
318
- }
319
-
320
- /**
321
- * Get a specific property of an array without needing to check if that property exists.
322
- *
323
- * Provide a default value if you want to return a specific value if the property is not set.
324
- *
325
- * @param array $array Array from which the property's value should be retrieved.
326
- * @param string $prop Name of the property to be retrieved.
327
- * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null.
328
- *
329
- * @return null|string|mixed The value
330
- */
331
- function wcf_get_prop( $array, $prop, $default = null ) {
332
-
333
- if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) {
334
- return $default;
335
- }
336
-
337
- if ( isset( $array[ $prop ] ) ) {
338
- $value = $array[ $prop ];
339
- } else {
340
- $value = '';
341
- }
342
-
343
- return empty( $value ) && null !== $default ? $default : $value;
344
- }
1
+ <?php
2
+ /**
3
+ * Utils.
4
+ *
5
+ * @package CARTFLOWS
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit; // Exit if accessed directly.
10
+ }
11
+
12
+ /**
13
+ * Class Cartflows_Utils.
14
+ */
15
+ class Cartflows_Utils {
16
+
17
+ /**
18
+ * Member Variable
19
+ *
20
+ * @var instance
21
+ */
22
+ private static $instance;
23
+
24
+ /**
25
+ * Initiator
26
+ */
27
+ public static function get_instance() {
28
+ if ( ! isset( self::$instance ) ) {
29
+ self::$instance = new self;
30
+ }
31
+ return self::$instance;
32
+ }
33
+
34
+ /**
35
+ * Constructor
36
+ */
37
+ function __construct() {
38
+ }
39
+
40
+ /**
41
+ * Get current post type
42
+ *
43
+ * @param string $post_type post type.
44
+ * @return string
45
+ */
46
+ function current_post_type( $post_type = '' ) {
47
+
48
+ if ( '' === $post_type ) {
49
+ $post_type = get_post_type();
50
+ }
51
+
52
+ return $post_type;
53
+ }
54
+
55
+ /**
56
+ * Check if post type is of step.
57
+ *
58
+ * @param string $post_type post type.
59
+ * @return bool
60
+ */
61
+ function is_step_post_type( $post_type = '' ) {
62
+
63
+ if ( $this->get_step_post_type() === $this->current_post_type( $post_type ) ) {
64
+
65
+ return true;
66
+ }
67
+
68
+ return false;
69
+ }
70
+
71
+ /**
72
+ * Check if post type is of flow.
73
+ *
74
+ * @param string $post_type post type.
75
+ * @return bool
76
+ */
77
+ function is_flow_post_type( $post_type = '' ) {
78
+
79
+ if ( $this->get_flow_post_type() === $this->current_post_type( $post_type ) ) {
80
+
81
+ return true;
82
+ }
83
+
84
+ return false;
85
+ }
86
+
87
+ /**
88
+ * Get post type of step.
89
+ *
90
+ * @return string
91
+ */
92
+ function get_step_post_type() {
93
+
94
+ return CARTFLOWS_STEP_POST_TYPE;
95
+ }
96
+
97
+ /**
98
+ * Get post type of flow.
99
+ *
100
+ * @return string
101
+ */
102
+ function get_flow_post_type() {
103
+
104
+ return CARTFLOWS_FLOW_POST_TYPE;
105
+ }
106
+
107
+ /**
108
+ * Get flow id
109
+ *
110
+ * @return int
111
+ */
112
+ function get_flow_id() {
113
+
114
+ global $post;
115
+
116
+ return get_post_meta( $post->ID, 'wcf-flow-id', true );
117
+ }
118
+
119
+ /**
120
+ * Get flow id by step
121
+ *
122
+ * @param int $step_id step ID.
123
+ * @return int
124
+ */
125
+ function get_flow_id_from_step_id( $step_id ) {
126
+
127
+ return get_post_meta( $step_id, 'wcf-flow-id', true );
128
+ }
129
+
130
+ /**
131
+ * Get flow steps by id
132
+ *
133
+ * @param int $flow_id flow ID.
134
+ * @return int
135
+ */
136
+ function get_flow_steps( $flow_id ) {
137
+
138
+ $steps = get_post_meta( $flow_id, 'wcf-steps', true );
139
+
140
+ if ( is_array( $steps ) && ! empty( $steps ) ) {
141
+ return $steps;
142
+ }
143
+
144
+ return false;
145
+ }
146
+
147
+ /**
148
+ * Get template type of step
149
+ *
150
+ * @param int $step_id step ID.
151
+ * @return int
152
+ */
153
+ function get_step_type( $step_id ) {
154
+
155
+ return get_post_meta( $step_id, 'wcf-step-type', true );
156
+ }
157
+
158
+ /**
159
+ * Get next id for step
160
+ *
161
+ * @param int $flow_id flow ID.
162
+ * @param int $step_id step ID.
163
+ * @return bool
164
+ */
165
+ function get_next_step_id( $flow_id, $step_id ) {
166
+
167
+ $steps = $this->get_flow_steps( $flow_id );
168
+ $step_id = intval( $step_id );
169
+
170
+ if ( ! $steps ) {
171
+ return false;
172
+ }
173
+
174
+ foreach ( $steps as $i => $step ) {
175
+
176
+ if ( intval( $step['id'] ) === $step_id ) {
177
+
178
+ $next_i = $i + 1;
179
+
180
+ if ( isset( $steps[ $next_i ] ) ) {
181
+
182
+ $navigation = $steps[ $next_i ];
183
+
184
+ return intval( $navigation['id'] );
185
+ }
186
+
187
+ break;
188
+ }
189
+ }
190
+
191
+ return false;
192
+ }
193
+
194
+ /**
195
+ * Get next id for step
196
+ *
197
+ * @param int $order_id order ID.
198
+ * @return int
199
+ */
200
+ function get_flow_id_from_order( $order_id ) {
201
+
202
+ $flow_id = get_post_meta( $order_id, '_wcf_flow_id', true );
203
+
204
+ return intval( $flow_id );
205
+ }
206
+
207
+ /**
208
+ * Get checkout id for order
209
+ *
210
+ * @param int $order_id order ID.
211
+ * @return int
212
+ */
213
+ function get_checkout_id_from_order( $order_id ) {
214
+
215
+ $checkout_id = get_post_meta( $order_id, '_wcf_checkout_id', true );
216
+
217
+ return intval( $checkout_id );
218
+ }
219
+
220
+ /**
221
+ * We are using this function mostly in ajax on checkout page
222
+ *
223
+ * @return bool
224
+ */
225
+ function get_checkout_id_from_post_data() {
226
+
227
+ if ( isset( $_POST['_wcf_checkout_id'] ) ) {
228
+
229
+ $checkout_id = filter_var( $_POST['_wcf_checkout_id'], FILTER_SANITIZE_NUMBER_INT );
230
+
231
+ return intval( $checkout_id );
232
+ }
233
+
234
+ return false;
235
+ }
236
+
237
+ /**
238
+ * We are using this function mostly in ajax on checkout page
239
+ *
240
+ * @return bool
241
+ */
242
+ function get_flow_id_from_post_data() {
243
+
244
+ if ( isset( $_POST['_wcf_flow_id'] ) ) {
245
+
246
+ $flow_id = filter_var( $_POST['_wcf_flow_id'], FILTER_SANITIZE_NUMBER_INT );
247
+
248
+ return intval( $flow_id );
249
+ }
250
+
251
+ return false;
252
+ }
253
+
254
+ /**
255
+ * Check for thank you page
256
+ *
257
+ * @param int $step_id step ID.
258
+ * @return bool
259
+ */
260
+ function check_is_thankyou_page( $step_id ) {
261
+
262
+ $step_type = $this->get_step_type( $step_id );
263
+
264
+ if ( 'thankyou' === $step_type ) {
265
+
266
+ return true;
267
+ }
268
+
269
+ return false;
270
+ }
271
+
272
+ /**
273
+ * Check for offer page
274
+ *
275
+ * @param int $step_id step ID.
276
+ * @return bool
277
+ */
278
+ function check_is_offer_page( $step_id ) {
279
+
280
+ $step_type = $this->get_step_type( $step_id );
281
+
282
+ if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
283
+
284
+ return true;
285
+ }
286
+
287
+ return false;
288
+ }
289
+
290
+ /**
291
+ * Define constant for cache
292
+ *
293
+ * @return void
294
+ */
295
+ function do_not_cache() {
296
+
297
+ wc_maybe_define_constant( 'DONOTCACHEPAGE', true );
298
+ wc_maybe_define_constant( 'DONOTCACHEOBJECT', true );
299
+ wc_maybe_define_constant( 'DONOTCACHEDB', true );
300
+
301
+ nocache_headers();
302
+ }
303
+
304
+ /**
305
+ * Get linking url
306
+ *
307
+ * @param array $args query args.
308
+ * @return string
309
+ */
310
+ function get_linking_url( $args = array() ) {
311
+
312
+ $url = get_home_url();
313
+
314
+ $url = add_query_arg( $args, $url );
315
+
316
+ return $url;
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Get a specific property of an array without needing to check if that property exists.
322
+ *
323
+ * Provide a default value if you want to return a specific value if the property is not set.
324
+ *
325
+ * @param array $array Array from which the property's value should be retrieved.
326
+ * @param string $prop Name of the property to be retrieved.
327
+ * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null.
328
+ *
329
+ * @return null|string|mixed The value
330
+ */
331
+ function wcf_get_prop( $array, $prop, $default = null ) {
332
+
333
+ if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) {
334
+ return $default;
335
+ }
336
+
337
+ if ( isset( $array[ $prop ] ) ) {
338
+ $value = $array[ $prop ];
339
+ } else {
340
+ $value = '';
341
+ }
342
+
343
+ return empty( $value ) && null !== $default ? $default : $value;
344
+ }
classes/class-cartflows-wizard.php CHANGED
@@ -1,447 +1,447 @@
1
- <?php
2
- /**
3
- * Schema Pro - Schema Wizard
4
- *
5
- * @package Schema Pro
6
- */
7
-
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
- }
11
-
12
- if ( ! class_exists( 'CartFlows_Wizard' ) ) :
13
-
14
- /**
15
- * CartFlows_Wizard class.
16
- */
17
- class CartFlows_Wizard {
18
-
19
- /**
20
- * Hook in tabs.
21
- */
22
- public function __construct() {
23
- if ( apply_filters( 'cartflows_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
24
- add_action( 'admin_menu', array( $this, 'admin_menus' ) );
25
- add_action( 'admin_init', array( $this, 'setup_wizard' ) );
26
- add_action( 'admin_notices', array( $this, 'show_setup_wizard' ) );
27
- add_action( 'wp_ajax_page_builder_step_save', array( $this, 'page_builder_step_save' ) );
28
-
29
- add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
30
- }
31
- }
32
-
33
- /**
34
- * Show action links on the plugin screen.
35
- *
36
- * @since 1.0.0
37
- * @return void
38
- */
39
- function show_setup_wizard() {
40
-
41
- $status = get_option( 'wcf_setup_complete', false );
42
-
43
- if ( false === $status ) { ?>
44
- <div class="notice notice-info">
45
- <p><b><?php _e( 'Thanks for installing and using CartFlows!', 'cartflows' ); ?></b></p>
46
- <p><?php _e( 'It is easy to use the CartFlows. Please use the setup wizard to quick start setup.', 'cartflows' ); ?></p>
47
- <p><a href="<?php echo esc_url( admin_url( 'index.php?page=cartflow-setup' ) ); ?>" class="button button-primary">Start Wizard!</a></p>
48
- </div>
49
- <?php
50
- }
51
- }
52
-
53
- /**
54
- * Add admin menus/screens.
55
- */
56
- public function admin_menus() {
57
- add_dashboard_page( '', '', 'manage_options', 'cartflow-setup', '' );
58
- }
59
-
60
- /**
61
- * Show the setup wizard.
62
- */
63
- public function setup_wizard() {
64
-
65
- if ( empty( $_GET['page'] ) || 'cartflow-setup' !== $_GET['page'] ) {
66
- return;
67
- }
68
-
69
- $this->steps = array(
70
- 'basic-config' => array(
71
- 'name' => __( 'Welcome', 'cartflows' ),
72
- 'view' => array( $this, 'welcome_step' ),
73
- 'handler' => array( $this, 'welcome_step_save' ),
74
- ),
75
- 'page-builder' => array(
76
- 'name' => __( 'Page Builder', 'cartflows' ),
77
- 'view' => array( $this, 'page_builder_step' ),
78
- // 'handler' => array( $this, 'page_builder_step_save' ),
79
- ),
80
- 'setup-ready' => array(
81
- 'name' => __( 'Ready!', 'cartflows' ),
82
- 'view' => array( $this, 'ready_step' ),
83
- 'handler' => '',
84
- ),
85
- );
86
-
87
- $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
88
-
89
- wp_enqueue_style( 'cartflows-setup', CARTFLOWS_URL . 'admin/assets/css/setup-wizard.css', array( 'dashicons' ), CARTFLOWS_VER );
90
- wp_style_add_data( 'cartflows-setup', 'rtl', 'replace' );
91
- wp_enqueue_script( 'cartflows-setup', CARTFLOWS_URL . 'admin/assets/js/setup-wizard.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
92
-
93
- wp_enqueue_media();
94
-
95
- if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
96
- call_user_func( $this->steps[ $this->step ]['handler'] );
97
- }
98
-
99
- ob_start();
100
- $this->setup_wizard_header();
101
- $this->setup_wizard_steps();
102
- $this->setup_wizard_content();
103
- $this->setup_wizard_footer();
104
- exit;
105
- }
106
-
107
- /**
108
- * Get current step slug
109
- */
110
- public function get_current_step_slug() {
111
- $keys = array_keys( $this->steps );
112
- return $keys[ array_search( $this->step, array_keys( $this->steps ) ) ];
113
- }
114
-
115
- /**
116
- * Get previous step link
117
- */
118
- public function get_prev_step_link() {
119
- $keys = array_keys( $this->steps );
120
- return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) - 1 ] );
121
- }
122
-
123
- /**
124
- * Get next step link
125
- */
126
- public function get_next_step_link() {
127
- $keys = array_keys( $this->steps );
128
- return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] );
129
- }
130
-
131
- /**
132
- * Get next step link
133
- */
134
- public function get_next_step_plain_link() {
135
- $keys = array_keys( $this->steps );
136
- $step = $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ];
137
- return admin_url( 'index.php?page=cartflow-setup&step=' . $step );
138
- }
139
-
140
- /**
141
- * Setup Wizard Header.
142
- */
143
- public function setup_wizard_header() {
144
- ?>
145
- <!DOCTYPE html>
146
- <html>
147
- <head>
148
- <meta name="viewport" content="width=device-width" />
149
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
150
- <title><?php _e( 'CartFlows Setup', 'cartflows' ); ?></title>
151
-
152
- <script type="text/javascript">
153
- addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
154
- var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
155
- var pagenow = '';
156
- </script>
157
- <?php wp_print_scripts( array( 'cartflows-setup' ) ); ?>
158
- <?php do_action( 'admin_print_styles' ); ?>
159
- <?php do_action( 'admin_head' ); ?>
160
- </head>
161
- <body class="cartflows-setup wp-core-ui cartflows-step-<?php echo esc_attr( $this->get_current_step_slug() ); ?>">
162
- <div id="cartflows-logo">
163
- <h1>CartFlows</h1>
164
- </div>
165
- <?php
166
- }
167
-
168
- /**
169
- * Setup Wizard Footer.
170
- */
171
- public function setup_wizard_footer() {
172
-
173
- $admin_url = admin_url( 'admin.php?page=cartflows_settings' );
174
- ?>
175
- <div class="close-button-wrapper">
176
- <a href="<?php echo esc_url( $admin_url ); ?>" class="wizard-close-link" ><?php _e( 'Exit Setup Wizard', 'cartflows' ); ?></a>
177
- </div>
178
- </body>
179
- </html>
180
- <?php
181
- }
182
-
183
- /**
184
- * Output the steps.
185
- */
186
- public function setup_wizard_steps() {
187
-
188
- $ouput_steps = $this->steps;
189
- ?>
190
- <ol class="cartflows-setup-steps">
191
- <?php
192
- foreach ( $ouput_steps as $step_key => $step ) :
193
- $classes = '';
194
- $activated = false;
195
- if ( $step_key === $this->step ) {
196
- $classes = 'active';
197
- $activated = true;
198
- } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
199
- $classes = 'done';
200
- $activated = true;
201
- }
202
- ?>
203
- <li class="<?php echo esc_attr( $classes ); ?>">
204
- <span><?php echo esc_html( $step['name'] ); ?></span>
205
- </li>
206
- <?php endforeach; ?>
207
- </ol>
208
- <?php
209
- }
210
-
211
- /**
212
- * Output the content for the current step.
213
- */
214
- public function setup_wizard_content() {
215
- echo '<div class="cartflows-setup-content">';
216
- call_user_func( $this->steps[ $this->step ]['view'] );
217
- echo '</div>';
218
- }
219
-
220
- /**
221
- * Introduction step.
222
- */
223
- public function welcome_step() {
224
- ?>
225
- <h1><?php _e( 'Thank you for choosing CartFlows!', 'cartflows' ); ?></h1>
226
- <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
227
- <form method="post">
228
- <div class="cartflows-setup-actions step">
229
- <div class="button-prev-wrap">
230
- </div>
231
- <div class="button-next-wrap">
232
- <input type="submit" class="uct-activate button-primary button button-large button-next" value="<?php _e( 'Lets Go »', 'cartflows' ); ?>" name="save_step" />
233
- </div>
234
- <?php wp_nonce_field( 'cartflow-setup' ); ?>
235
- </div>
236
- </form>
237
- <?php
238
- }
239
-
240
- /**
241
- * Save Locale Settings.
242
- */
243
- public function welcome_step_save() {
244
- check_admin_referer( 'cartflow-setup' );
245
-
246
- // Update site title & tagline.
247
- $redirect_url = $this->get_next_step_link();
248
-
249
- wp_redirect( esc_url_raw( $redirect_url ) );
250
- exit;
251
- }
252
-
253
- /**
254
- * Locale settings
255
- */
256
- public function page_builder_step() {
257
- ?>
258
-
259
- <h1><?php _e( 'Page Builder', 'cartflows' ); ?></h1>
260
- <p class="description"><?php _e( 'Select a page builder which you want to use for creating your new flows.', 'cartflows' ); ?></p>
261
- <form method="post">
262
- <table class="cartflows-table widefat">
263
- <tr class="cartflows-row">
264
- <td class="cartflows-row-heading">
265
- <label><?php esc_html_e( 'Select Page Builder', 'cartflows' ); ?></label>
266
- <i class="cartflows-heading-help dashicons dashicons-editor-help" title="<?php echo esc_attr__( 'Add locations for where this Schema should appear.', 'cartflows' ); ?>"></i>
267
- </td>
268
- <td class="cartflows-row-content">
269
- <?php
270
- $installed_plugins = get_plugins();
271
- $plugins = array(
272
- array(
273
- 'title' => __( 'Elementor', 'cartflows' ),
274
- 'value' => 'elementor',
275
- 'data' => array(
276
- 'slug' => 'elementor',
277
- 'init' => 'elementor/elementor.php',
278
- 'active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
279
- 'install' => isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
280
- ),
281
- ),
282
- );
283
- ?>
284
- <select name="page-builder" class="page-builder-list" data-redirect-link="<?php echo esc_url_raw( $this->get_next_step_plain_link() ); ?>">
285
- <?php
286
- foreach ( $plugins as $key => $plugin ) {
287
- echo '<option value="' . esc_attr( $plugin['value'] ) . '" data-install="' . esc_attr( $plugin['data']['install'] ) . '" data-active="' . esc_attr( $plugin['data']['active'] ) . '" data-slug="' . esc_attr( $plugin['data']['slug'] ) . '" data-init="' . esc_attr( $plugin['data']['init'] ) . '">' . esc_html( $plugin['title'] ) . '</option>';
288
- }
289
- ?>
290
- </select>
291
- </td>
292
- </tr>
293
- </table>
294
- <p><?php _e( 'The above plugin will be installed and activated for you!', 'cartflows' ); ?></p>
295
- <div class="cartflows-setup-actions step">
296
- <div class="button-prev-wrap">
297
- <a href="<?php echo esc_url( $this->get_prev_step_link() ); ?>" class="button-primary button button-large button-prev" ><?php _e( '« Previous', 'cartflows' ); ?></a>
298
- </div>
299
- <div class="button-next-wrap">
300
- <a href="#" class="button button-primary wcf-install-plugins"><?php _e( 'Next »', 'cartflows' ); ?></a>
301
- <!-- <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Next »', 'cartflows' ); ?>" name="save_step" /> -->
302
- </div>
303
- <?php wp_nonce_field( 'cartflow-setup' ); ?>
304
- </div>
305
- </form>
306
- <?php
307
- }
308
-
309
- /**
310
- * Save Locale Settings.
311
- */
312
- function page_builder_step_save() {
313
-
314
- check_ajax_referer( 'wcf-page-builder-step-save', 'security' );
315
-
316
- $stored = get_option( 'wcf_setup', array() );
317
- $page_builder = isset( $_POST['page_builder'] ) ? sanitize_text_field( $_POST['page_builder'] ) : '';
318
- $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
319
-
320
- if ( $page_builder ) {
321
- $stored['page-builder'] = $page_builder;
322
- }
323
-
324
- update_option( 'wcf_setup', $stored );
325
-
326
- $activate = activate_plugin( $plugin_init, '', false, true );
327
-
328
- if ( is_wp_error( $activate ) ) {
329
- wp_send_json_error(
330
- array(
331
- 'success' => false,
332
- 'message' => $activate->get_error_message(),
333
- )
334
- );
335
- }
336
-
337
- wp_send_json_success( $stored );
338
- }
339
-
340
- /**
341
- * Get Location rules of schema for Custom meta box.
342
- *
343
- * @param array $enabled_on Enabled on rules.
344
- * @param array $exclude_from Exlcude on rules.
345
- * @return array
346
- */
347
- public static function get_display_rules_for_meta_box( $enabled_on, $exclude_from ) {
348
- $locations = array();
349
- $enabled_location = array();
350
- $exclude_location = array();
351
-
352
- $args = array(
353
- 'public' => true,
354
- '_builtin' => true,
355
- );
356
- $post_types = get_post_types( $args );
357
- unset( $post_types['attachment'] );
358
-
359
- $args['_builtin'] = false;
360
- $custom_post_type = get_post_types( $args );
361
- $post_types = array_merge( $post_types, $custom_post_type );
362
-
363
- if ( ! empty( $enabled_on ) && isset( $enabled_on['rule'] ) ) {
364
- $enabled_location = $enabled_on['rule'];
365
- }
366
- if ( ! empty( $exclude_from ) && isset( $exclude_from['rule'] ) ) {
367
- $exclude_location = $exclude_from['rule'];
368
- }
369
-
370
- if ( in_array( 'specifics', $enabled_location ) || ( in_array( 'basic-singulars', $enabled_location ) && ! in_array( 'basic-singulars', $exclude_location ) ) ) {
371
- foreach ( $post_types as $post_type ) {
372
- $locations[ $post_type ] = 1;
373
- }
374
- } else {
375
- foreach ( $post_types as $post_type ) {
376
- $key = $post_type . '|all';
377
- if ( in_array( $key, $enabled_location ) && ! in_array( $key, $exclude_location ) ) {
378
- $locations[ $post_type ] = 1;
379
- }
380
- }
381
- }
382
- return $locations;
383
- }
384
-
385
- /**
386
- * Final step.
387
- */
388
- public function ready_step() {
389
-
390
- // Set setup wizard status to complete.
391
- update_option( 'wcf_setup_complete', true );
392
- ?>
393
- <h1><?php _e( 'Congratulations!', 'cartflows' ); ?></h1>
394
-
395
- <div class="cartflows-setup-next-steps">
396
- <div class="cartflows-setup-next-steps-last">
397
-
398
- <p class="success">
399
- <?php
400
- _e( 'You\'ve successfully completed the setup before you begin setting now you can use it.', 'cartflows' )
401
- ?>
402
- </p>
403
-
404
-
405
- <ul class="wcf-wizard-next-steps">
406
- <li class="wcf-wizard-next-step-item">
407
- <div class="wcf-wizard-next-step-description">
408
- <p class="next-step-heading">Next step</p>
409
- <h3 class="next-step-description">Create First Flow</h3>
410
- <p class="next-step-extra-info">You're ready to add flows to your website.</p>
411
- </div>
412
- <div class="wcf-wizard-next-step-action">
413
- <p class="wc-setup-actions step">
414
- <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=cartflows_flow&add-new-flow' ) ); ?>" type="button" class="button button-primary button-hero" ><?php _e( 'Create a flow', 'cartflows' ); ?></a>
415
- </p>
416
- </div>
417
- </li>
418
- </ul>
419
-
420
- </div>
421
- </div>
422
- <?php
423
- }
424
-
425
- /**
426
- * Localize variables in admin
427
- *
428
- * @param array $vars variables.
429
- */
430
- function localize_vars( $vars ) {
431
-
432
- $ajax_actions = array(
433
- 'wcf_page_builder_step_save',
434
- );
435
-
436
- foreach ( $ajax_actions as $action ) {
437
-
438
- $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
439
- }
440
-
441
- return $vars;
442
- }
443
- }
444
-
445
- new CartFlows_Wizard();
446
-
447
- endif;
1
+ <?php
2
+ /**
3
+ * Schema Pro - Schema Wizard
4
+ *
5
+ * @package Schema Pro
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ if ( ! class_exists( 'CartFlows_Wizard' ) ) :
13
+
14
+ /**
15
+ * CartFlows_Wizard class.
16
+ */
17
+ class CartFlows_Wizard {
18
+
19
+ /**
20
+ * Hook in tabs.
21
+ */
22
+ public function __construct() {
23
+ if ( apply_filters( 'cartflows_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
24
+ add_action( 'admin_menu', array( $this, 'admin_menus' ) );
25
+ add_action( 'admin_init', array( $this, 'setup_wizard' ) );
26
+ add_action( 'admin_notices', array( $this, 'show_setup_wizard' ) );
27
+ add_action( 'wp_ajax_page_builder_step_save', array( $this, 'page_builder_step_save' ) );
28
+
29
+ add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Show action links on the plugin screen.
35
+ *
36
+ * @since 1.0.0
37
+ * @return void
38
+ */
39
+ function show_setup_wizard() {
40
+
41
+ $status = get_option( 'wcf_setup_complete', false );
42
+
43
+ if ( false === $status ) { ?>
44
+ <div class="notice notice-info">
45
+ <p><b><?php _e( 'Thanks for installing and using CartFlows!', 'cartflows' ); ?></b></p>
46
+ <p><?php _e( 'It is easy to use the CartFlows. Please use the setup wizard to quick start setup.', 'cartflows' ); ?></p>
47
+ <p><a href="<?php echo esc_url( admin_url( 'index.php?page=cartflow-setup' ) ); ?>" class="button button-primary">Start Wizard!</a></p>
48
+ </div>
49
+ <?php
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Add admin menus/screens.
55
+ */
56
+ public function admin_menus() {
57
+ add_dashboard_page( '', '', 'manage_options', 'cartflow-setup', '' );
58
+ }
59
+
60
+ /**
61
+ * Show the setup wizard.
62
+ */
63
+ public function setup_wizard() {
64
+
65
+ if ( empty( $_GET['page'] ) || 'cartflow-setup' !== $_GET['page'] ) {
66
+ return;
67
+ }
68
+
69
+ $this->steps = array(
70
+ 'basic-config' => array(
71
+ 'name' => __( 'Welcome', 'cartflows' ),
72
+ 'view' => array( $this, 'welcome_step' ),
73
+ 'handler' => array( $this, 'welcome_step_save' ),
74
+ ),
75
+ 'page-builder' => array(
76
+ 'name' => __( 'Page Builder', 'cartflows' ),
77
+ 'view' => array( $this, 'page_builder_step' ),
78
+ // 'handler' => array( $this, 'page_builder_step_save' ),
79
+ ),
80
+ 'setup-ready' => array(
81
+ 'name' => __( 'Ready!', 'cartflows' ),
82
+ 'view' => array( $this, 'ready_step' ),
83
+ 'handler' => '',
84
+ ),
85
+ );
86
+
87
+ $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
88
+
89
+ wp_enqueue_style( 'cartflows-setup', CARTFLOWS_URL . 'admin/assets/css/setup-wizard.css', array( 'dashicons' ), CARTFLOWS_VER );
90
+ wp_style_add_data( 'cartflows-setup', 'rtl', 'replace' );
91
+ wp_enqueue_script( 'cartflows-setup', CARTFLOWS_URL . 'admin/assets/js/setup-wizard.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
92
+
93
+ wp_enqueue_media();
94
+
95
+ if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
96
+ call_user_func( $this->steps[ $this->step ]['handler'] );
97
+ }
98
+
99
+ ob_start();
100
+ $this->setup_wizard_header();
101
+ $this->setup_wizard_steps();
102
+ $this->setup_wizard_content();
103
+ $this->setup_wizard_footer();
104
+ exit;
105
+ }
106
+
107
+ /**
108
+ * Get current step slug
109
+ */
110
+ public function get_current_step_slug() {
111
+ $keys = array_keys( $this->steps );
112
+ return $keys[ array_search( $this->step, array_keys( $this->steps ) ) ];
113
+ }
114
+
115
+ /**
116
+ * Get previous step link
117
+ */
118
+ public function get_prev_step_link() {
119
+ $keys = array_keys( $this->steps );
120
+ return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) - 1 ] );
121
+ }
122
+
123
+ /**
124
+ * Get next step link
125
+ */
126
+ public function get_next_step_link() {
127
+ $keys = array_keys( $this->steps );
128
+ return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] );
129
+ }
130
+
131
+ /**
132
+ * Get next step link
133
+ */
134
+ public function get_next_step_plain_link() {
135
+ $keys = array_keys( $this->steps );
136
+ $step = $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ];
137
+ return admin_url( 'index.php?page=cartflow-setup&step=' . $step );
138
+ }
139
+
140
+ /**
141
+ * Setup Wizard Header.
142
+ */
143
+ public function setup_wizard_header() {
144
+ ?>
145
+ <!DOCTYPE html>
146
+ <html>
147
+ <head>
148
+ <meta name="viewport" content="width=device-width" />
149
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
150
+ <title><?php _e( 'CartFlows Setup', 'cartflows' ); ?></title>
151
+
152
+ <script type="text/javascript">
153
+ addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
154
+ var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
155
+ var pagenow = '';
156
+ </script>
157
+ <?php wp_print_scripts( array( 'cartflows-setup' ) ); ?>
158
+ <?php do_action( 'admin_print_styles' ); ?>
159
+ <?php do_action( 'admin_head' ); ?>
160
+ </head>
161
+ <body class="cartflows-setup wp-core-ui cartflows-step-<?php echo esc_attr( $this->get_current_step_slug() ); ?>">
162
+ <div id="cartflows-logo">
163
+ <h1>CartFlows</h1>
164
+ </div>
165
+ <?php
166
+ }
167
+
168
+ /**
169
+ * Setup Wizard Footer.
170
+ */
171
+ public function setup_wizard_footer() {
172
+
173
+ $admin_url = admin_url( 'admin.php?page=cartflows_settings' );
174
+ ?>
175
+ <div class="close-button-wrapper">
176
+ <a href="<?php echo esc_url( $admin_url ); ?>" class="wizard-close-link" ><?php _e( 'Exit Setup Wizard', 'cartflows' ); ?></a>
177
+ </div>
178
+ </body>
179
+ </html>
180
+ <?php
181
+ }
182
+
183
+ /**
184
+ * Output the steps.
185
+ */
186
+ public function setup_wizard_steps() {
187
+
188
+ $ouput_steps = $this->steps;
189
+ ?>
190
+ <ol class="cartflows-setup-steps">
191
+ <?php
192
+ foreach ( $ouput_steps as $step_key => $step ) :
193
+ $classes = '';
194
+ $activated = false;
195
+ if ( $step_key === $this->step ) {
196
+ $classes = 'active';
197
+ $activated = true;
198
+ } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
199
+ $classes = 'done';
200
+ $activated = true;
201
+ }
202
+ ?>
203
+ <li class="<?php echo esc_attr( $classes ); ?>">
204
+ <span><?php echo esc_html( $step['name'] ); ?></span>
205
+ </li>
206
+ <?php endforeach; ?>
207
+ </ol>
208
+ <?php
209
+ }
210
+
211
+ /**
212
+ * Output the content for the current step.
213
+ */
214
+ public function setup_wizard_content() {
215
+ echo '<div class="cartflows-setup-content">';
216
+ call_user_func( $this->steps[ $this->step ]['view'] );
217
+ echo '</div>';
218
+ }
219
+
220
+ /**
221
+ * Introduction step.
222
+ */
223
+ public function welcome_step() {
224
+ ?>
225
+ <h1><?php _e( 'Thank you for choosing CartFlows!', 'cartflows' ); ?></h1>
226
+ <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
227
+ <form method="post">
228
+ <div class="cartflows-setup-actions step">
229
+ <div class="button-prev-wrap">
230
+ </div>
231
+ <div class="button-next-wrap">
232
+ <input type="submit" class="uct-activate button-primary button button-large button-next" value="<?php _e( 'Lets Go »', 'cartflows' ); ?>" name="save_step" />
233
+ </div>
234
+ <?php wp_nonce_field( 'cartflow-setup' ); ?>
235
+ </div>
236
+ </form>
237
+ <?php
238
+ }
239
+
240
+ /**
241
+ * Save Locale Settings.
242
+ */
243
+ public function welcome_step_save() {
244
+ check_admin_referer( 'cartflow-setup' );
245
+
246
+ // Update site title & tagline.
247
+ $redirect_url = $this->get_next_step_link();
248
+
249
+ wp_redirect( esc_url_raw( $redirect_url ) );
250
+ exit;
251
+ }
252
+
253
+ /**
254
+ * Locale settings
255
+ */
256
+ public function page_builder_step() {
257
+ ?>
258
+
259
+ <h1><?php _e( 'Page Builder', 'cartflows' ); ?></h1>
260
+ <p class="description"><?php _e( 'Select a page builder which you want to use for creating your new flows.', 'cartflows' ); ?></p>
261
+ <form method="post">
262
+ <table class="cartflows-table widefat">
263
+ <tr class="cartflows-row">
264
+ <td class="cartflows-row-heading">
265
+ <label><?php esc_html_e( 'Select Page Builder', 'cartflows' ); ?></label>
266
+ <i class="cartflows-heading-help dashicons dashicons-editor-help" title="<?php echo esc_attr__( 'Add locations for where this Schema should appear.', 'cartflows' ); ?>"></i>
267
+ </td>
268
+ <td class="cartflows-row-content">
269
+ <?php
270
+ $installed_plugins = get_plugins();
271
+ $plugins = array(
272
+ array(
273
+ 'title' => __( 'Elementor', 'cartflows' ),
274
+ 'value' => 'elementor',
275
+ 'data' => array(
276
+ 'slug' => 'elementor',
277
+ 'init' => 'elementor/elementor.php',
278
+ 'active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
279
+ 'install' => isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
280
+ ),
281
+ ),
282
+ );
283
+ ?>
284
+ <select name="page-builder" class="page-builder-list" data-redirect-link="<?php echo esc_url_raw( $this->get_next_step_plain_link() ); ?>">
285
+ <?php
286
+ foreach ( $plugins as $key => $plugin ) {
287
+ echo '<option value="' . esc_attr( $plugin['value'] ) . '" data-install="' . esc_attr( $plugin['data']['install'] ) . '" data-active="' . esc_attr( $plugin['data']['active'] ) . '" data-slug="' . esc_attr( $plugin['data']['slug'] ) . '" data-init="' . esc_attr( $plugin['data']['init'] ) . '">' . esc_html( $plugin['title'] ) . '</option>';
288
+ }
289
+ ?>
290
+ </select>
291
+ </td>
292
+ </tr>
293
+ </table>
294
+ <p><?php _e( 'The above plugin will be installed and activated for you!', 'cartflows' ); ?></p>
295
+ <div class="cartflows-setup-actions step">
296
+ <div class="button-prev-wrap">
297
+ <a href="<?php echo esc_url( $this->get_prev_step_link() ); ?>" class="button-primary button button-large button-prev" ><?php _e( '« Previous', 'cartflows' ); ?></a>
298
+ </div>
299
+ <div class="button-next-wrap">
300
+ <a href="#" class="button button-primary wcf-install-plugins"><?php _e( 'Next »', 'cartflows' ); ?></a>
301
+ <!-- <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Next »', 'cartflows' ); ?>" name="save_step" /> -->
302
+ </div>
303
+ <?php wp_nonce_field( 'cartflow-setup' ); ?>
304
+ </div>
305
+ </form>
306
+ <?php
307
+ }
308
+
309
+ /**
310
+ * Save Locale Settings.
311
+ */
312
+ function page_builder_step_save() {
313
+
314
+ check_ajax_referer( 'wcf-page-builder-step-save', 'security' );
315
+
316
+ $stored = get_option( 'wcf_setup', array() );
317
+ $page_builder = isset( $_POST['page_builder'] ) ? sanitize_text_field( $_POST['page_builder'] ) : '';
318
+ $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
319
+
320
+ if ( $page_builder ) {
321
+ $stored['page-builder'] = $page_builder;
322
+ }
323
+
324
+ update_option( 'wcf_setup', $stored );
325
+
326
+ $activate = activate_plugin( $plugin_init, '', false, true );
327
+
328
+ if ( is_wp_error( $activate ) ) {
329
+ wp_send_json_error(
330
+ array(
331
+ 'success' => false,
332
+ 'message' => $activate->get_error_message(),
333
+ )
334
+ );
335
+ }
336
+
337
+ wp_send_json_success( $stored );
338
+ }
339
+
340
+ /**
341
+ * Get Location rules of schema for Custom meta box.
342
+ *
343
+ * @param array $enabled_on Enabled on rules.
344
+ * @param array $exclude_from Exlcude on rules.
345
+ * @return array
346
+ */
347
+ public static function get_display_rules_for_meta_box( $enabled_on, $exclude_from ) {
348
+ $locations = array();
349
+ $enabled_location = array();
350
+ $exclude_location = array();
351
+
352
+ $args = array(
353
+ 'public' => true,
354
+ '_builtin' => true,
355
+ );
356
+ $post_types = get_post_types( $args );
357
+ unset( $post_types['attachment'] );
358
+
359
+ $args['_builtin'] = false;
360
+ $custom_post_type = get_post_types( $args );
361
+ $post_types = array_merge( $post_types, $custom_post_type );
362
+
363
+ if ( ! empty( $enabled_on ) && isset( $enabled_on['rule'] ) ) {
364
+ $enabled_location = $enabled_on['rule'];
365
+ }
366
+ if ( ! empty( $exclude_from ) && isset( $exclude_from['rule'] ) ) {
367
+ $exclude_location = $exclude_from['rule'];
368
+ }
369
+
370
+ if ( in_array( 'specifics', $enabled_location ) || ( in_array( 'basic-singulars', $enabled_location ) && ! in_array( 'basic-singulars', $exclude_location ) ) ) {
371
+ foreach ( $post_types as $post_type ) {
372
+ $locations[ $post_type ] = 1;
373
+ }
374
+ } else {
375
+ foreach ( $post_types as $post_type ) {
376
+ $key = $post_type . '|all';
377
+ if ( in_array( $key, $enabled_location ) && ! in_array( $key, $exclude_location ) ) {
378
+ $locations[ $post_type ] = 1;
379
+ }
380
+ }
381
+ }
382
+ return $locations;
383
+ }
384
+
385
+ /**
386
+ * Final step.
387
+ */
388
+ public function ready_step() {
389
+
390
+ // Set setup wizard status to complete.
391
+ update_option( 'wcf_setup_complete', true );
392
+ ?>
393
+ <h1><?php _e( 'Congratulations!', 'cartflows' ); ?></h1>
394
+
395
+ <div class="cartflows-setup-next-steps">
396
+ <div class="cartflows-setup-next-steps-last">
397
+
398
+ <p class="success">
399
+ <?php
400
+ _e( 'You\'ve successfully completed the setup before you begin setting now you can use it.', 'cartflows' )
401
+ ?>
402
+ </p>
403
+
404
+
405
+ <ul class="wcf-wizard-next-steps">
406
+ <li class="wcf-wizard-next-step-item">
407
+ <div class="wcf-wizard-next-step-description">
408
+ <p class="next-step-heading">Next step</p>
409
+ <h3 class="next-step-description">Create First Flow</h3>
410
+ <p class="next-step-extra-info">You're ready to add flows to your website.</p>
411
+ </div>
412
+ <div class="wcf-wizard-next-step-action">
413
+ <p class="wc-setup-actions step">
414
+ <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=cartflows_flow&add-new-flow' ) ); ?>" type="button" class="button button-primary button-hero" ><?php _e( 'Create a flow', 'cartflows' ); ?></a>
415
+ </p>
416
+ </div>
417
+ </li>
418
+ </ul>
419
+
420
+ </div>
421
+ </div>
422
+ <?php
423
+ }
424
+
425
+ /**
426
+ * Localize variables in admin
427
+ *
428
+ * @param array $vars variables.
429
+ */
430
+ function localize_vars( $vars ) {
431
+
432
+ $ajax_actions = array(
433
+ 'wcf_page_builder_step_save',
434
+ );
435
+
436
+ foreach ( $ajax_actions as $action ) {
437
+
438
+ $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
439
+ }
440
+
441
+ return $vars;
442
+ }
443
+ }
444
+
445
+ new CartFlows_Wizard();
446
+
447
+ endif;
includes/admin/cartflows-general.php CHANGED
@@ -1,143 +1,151 @@
1
- <?php
2
- /**
3
- * General settings
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- $settings = Cartflows_Helper::get_common_settings();
9
-
10
- ?>
11
-
12
- <form method="post" class="wrap wcf-clear" action="" >
13
- <div class="wrap wcf-addon-wrap wcf-clear wcf-container">
14
- <input type="hidden" name="action" value="wcf_save_common_settings">
15
- <h1 class="screen-reader-text"><?php _e( 'General Settings', 'cartflows' ); ?></h1>
16
-
17
- <div id="poststuff">
18
- <div id="post-body" class="columns-2">
19
- <div id="post-body-content">
20
- <div class="postbox introduction">
21
- <h2 class="hndle wcf-normal-cusror ui-sortable-handle">
22
- <span><?php _e( 'Getting Started', 'cartflows' ); ?></span>
23
- </h2>
24
- <div class="inside">
25
- <div class="iframe-wrap">
26
- <iframe width="560" height="315" src="https://www.youtube.com/embed/SlE0moPKjMY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
27
- </div>
28
- <p>
29
- <?php
30
- esc_attr_e( 'Modernizing WordPress eCommerce!', 'cartflows' );
31
- ?>
32
- </p>
33
- </div>
34
- </div>
35
-
36
- <div class="general-settings-form postbox">
37
- <h2 class="hndle wcf-normal-cusror ui-sortable-handle">
38
- <span><?php _e( 'General Settings', 'cartflows' ); ?></span>
39
- </h2>
40
- <div class="inside">
41
- <div class="form-wrap">
42
- <?php
43
-
44
- do_action( 'cartflows_before_settings_fields', $settings );
45
-
46
- echo Cartflows_Admin_Fields::checkobox_field(
47
- array(
48
- 'id' => 'wcf_disallow_indexing',
49
- 'name' => '_cartflows_common[disallow_indexing]',
50
- 'title' => __( 'Disallow search engines from indexing flows', 'cartflows' ),
51
- 'value' => $settings['disallow_indexing'],
52
- )
53
- );
54
- echo Cartflows_Admin_Fields::flow_checkout_selection_field(
55
- array(
56
- 'id' => 'wcf_global_checkout',
57
- 'name' => '_cartflows_common[global_checkout]',
58
- 'title' => __( 'Global Checkout', 'cartflows' ),
59
- 'value' => $settings['global_checkout'],
60
- )
61
- );
62
-
63
- echo Cartflows_Admin_Fields::select_field(
64
- array(
65
- 'id' => 'wcf_default_page_builder',
66
- 'name' => '_cartflows_common[default_page_builder]',
67
- 'title' => __( 'Show Templates designed with', 'cartflows' ),
68
- 'description' => __( 'CartFlows offers flow templates that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list so you will only see templates that are made using that page builder..', 'cartflows' ),
69
- 'value' => $settings['default_page_builder'],
70
- 'options' => array(
71
- 'elementor' => __( 'Elementor', 'cartflows' ),
72
- 'beaver-builder' => __( 'Beaver Builder', 'cartflows' ),
73
- 'divi' => __( 'Divi', 'cartflows' ),
74
- 'other' => __( 'Other', 'cartflows' ),
75
- ),
76
- )
77
- );
78
-
79
- do_action( 'cartflows_after_settings_fields', $settings );
80
-
81
- ?>
82
- </div>
83
- <?php submit_button( __( 'Save Changes', 'cartflows' ), 'cartflows-common-setting-save-btn button-primary button', 'submit', false ); ?>
84
- <?php wp_nonce_field( 'cartflows-common-settings', 'cartflows-common-settings-nonce' ); ?>
85
- </div>
86
- </div>
87
- </div>
88
- <div class="postbox-container" id="postbox-container-1">
89
- <div id="side-sortables">
90
-
91
- <div class="postbox">
92
- <h2 class="hndle">
93
- <span class="dashicons dashicons-book"></span>
94
- <span><?php esc_html_e( 'Knowledge Base', 'cartflows' ); ?></span>
95
- </h2>
96
- <div class="inside">
97
- <p>
98
- <?php esc_html_e( 'Not sure how something works? Take a peek at the knowledge base and learn.', 'cartflows' ); ?>
99
- </p>
100
- <p>
101
- <a href="<?php echo esc_url( 'https://cartflows.com/docs' ); ?>" target="_blank" rel="noopener"><?php _e( 'Visit Knowledge Base »', 'cartflows' ); ?></a>
102
- </p>
103
- </div>
104
- </div>
105
-
106
- <div class="postbox">
107
- <h2 class="hndle">
108
- <span class="dashicons dashicons-groups"></span>
109
- <span><?php esc_html_e( 'Community', 'cartflows' ); ?></span>
110
- </h2>
111
- <div class="inside">
112
- <p>
113
- <?php esc_html_e( 'Join the community of super helpful CartFlows users. Say hello, ask questions, give feedback and help each other!', 'cartflows' ); ?>
114
- </p>
115
- <p>
116
- <a href="<?php echo esc_url( 'https://www.facebook.com/groups/cartflows/' ); ?>" target="_blank" rel="noopener"><?php _e( 'Join Our Facebook Group »', 'cartflows' ); ?></a>
117
- </p>
118
- </div>
119
- </div>
120
-
121
- <div class="postbox">
122
- <h2 class="hndle">
123
- <span class="dashicons dashicons-sos"></span>
124
- <span><?php esc_html_e( 'Five Star Support', 'cartflows' ); ?></span>
125
- </h2>
126
- <div class="inside">
127
- <p>
128
- <?php esc_html_e( 'Got a question? Get in touch with CartFlows developers. We\'re happy to help!', 'cartflows' ); ?>
129
- </p>
130
- <p>
131
- <a href="<?php echo esc_url( 'https://cartflows.com/contact' ); ?>" target="_blank" rel="noopener"><?php _e( 'Submit a Ticket »', 'cartflows' ); ?></a>
132
- </p>
133
- </div>
134
- </div>
135
-
136
- </div>
137
- </div>
138
- </div>
139
- <!-- /post-body -->
140
- <br class="clear">
141
- </div>
142
- </div>
143
- </form>
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * General settings
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ $settings = Cartflows_Helper::get_common_settings();
9
+
10
+ ?>
11
+
12
+ <form method="post" class="wrap wcf-clear" action="" >
13
+ <div class="wrap wcf-addon-wrap wcf-clear wcf-container">
14
+ <input type="hidden" name="action" value="wcf_save_common_settings">
15
+ <h1 class="screen-reader-text"><?php _e( 'General Settings', 'cartflows' ); ?></h1>
16
+
17
+ <div id="poststuff">
18
+ <div id="post-body" class="columns-2">
19
+ <div id="post-body-content">
20
+ <div class="postbox introduction">
21
+ <h2 class="hndle wcf-normal-cusror ui-sortable-handle">
22
+ <span><?php _e( 'Getting Started', 'cartflows' ); ?></span>
23
+ </h2>
24
+ <div class="inside">
25
+ <div class="iframe-wrap">
26
+ <iframe width="560" height="315" src="https://www.youtube.com/embed/SlE0moPKjMY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
27
+ </div>
28
+ <p>
29
+ <?php
30
+ esc_attr_e( 'Modernizing WordPress eCommerce!', 'cartflows' );
31
+ ?>
32
+ </p>
33
+ </div>
34
+ </div>
35
+
36
+ <div class="general-settings-form postbox">
37
+ <h2 class="hndle wcf-normal-cusror ui-sortable-handle">
38
+ <span><?php _e( 'General Settings', 'cartflows' ); ?></span>
39
+ </h2>
40
+ <div class="inside">
41
+ <div class="form-wrap">
42
+ <?php
43
+
44
+ do_action( 'cartflows_before_settings_fields', $settings );
45
+
46
+ echo Cartflows_Admin_Fields::checkobox_field(
47
+ array(
48
+ 'id' => 'wcf_disallow_indexing',
49
+ 'name' => '_cartflows_common[disallow_indexing]',
50
+ 'title' => __( 'Disallow search engines from indexing flows', 'cartflows' ),
51
+ 'value' => $settings['disallow_indexing'],
52
+ )
53
+ );
54
+ echo Cartflows_Admin_Fields::flow_checkout_selection_field(
55
+ array(
56
+ 'id' => 'wcf_global_checkout',
57
+ 'name' => '_cartflows_common[global_checkout]',
58
+ 'title' => __( 'Global Checkout', 'cartflows' ),
59
+ 'value' => $settings['global_checkout'],
60
+ )
61
+ );
62
+
63
+ echo Cartflows_Admin_Fields::select_field(
64
+ array(
65
+ 'id' => 'wcf_default_page_builder',
66
+ 'name' => '_cartflows_common[default_page_builder]',
67
+ 'title' => __( 'Show Templates designed with', 'cartflows' ),
68
+ 'description' => __( 'CartFlows offers flow templates that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list so you will only see templates that are made using that page builder..', 'cartflows' ),
69
+ 'value' => $settings['default_page_builder'],
70
+ 'options' => array(
71
+ 'elementor' => __( 'Elementor', 'cartflows' ),
72
+ 'beaver-builder' => __( 'Beaver Builder', 'cartflows' ),
73
+ 'divi' => __( 'Divi', 'cartflows' ),
74
+ 'other' => __( 'Other', 'cartflows' ),
75
+ ),
76
+ )
77
+ );
78
+
79
+ do_action( 'cartflows_after_settings_fields', $settings );
80
+
81
+ ?>
82
+ </div>
83
+ <?php submit_button( __( 'Save Changes', 'cartflows' ), 'cartflows-common-setting-save-btn button-primary button', 'submit', false ); ?>
84
+ <?php wp_nonce_field( 'cartflows-common-settings', 'cartflows-common-settings-nonce' ); ?>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ <div class="postbox-container" id="postbox-container-1">
89
+ <div id="side-sortables">
90
+
91
+ <div class="postbox">
92
+ <h2 class="hndle">
93
+ <span class="dashicons dashicons-book"></span>
94
+ <span><?php esc_html_e( 'Knowledge Base', 'cartflows' ); ?></span>
95
+ </h2>
96
+ <div class="inside">
97
+ <p>
98
+ <?php esc_html_e( 'Not sure how something works? Take a peek at the knowledge base and learn.', 'cartflows' ); ?>
99
+ </p>
100
+ <p>
101
+ <a href="<?php echo esc_url( 'https://cartflows.com/docs' ); ?>" target="_blank" rel="noopener"><?php _e( 'Visit Knowledge Base »', 'cartflows' ); ?></a>
102
+ </p>
103
+ </div>
104
+ </div>
105
+
106
+ <div class="postbox">
107
+ <h2 class="hndle">
108
+ <span class="dashicons dashicons-groups"></span>
109
+ <span><?php esc_html_e( 'Community', 'cartflows' ); ?></span>
110
+ </h2>
111
+ <div class="inside">
112
+ <p>
113
+ <?php esc_html_e( 'Join the community of super helpful CartFlows users. Say hello, ask questions, give feedback and help each other!', 'cartflows' ); ?>
114
+ </p>
115
+ <p>
116
+ <a href="<?php echo esc_url( 'https://www.facebook.com/groups/cartflows/' ); ?>" target="_blank" rel="noopener"><?php _e( 'Join Our Facebook Group »', 'cartflows' ); ?></a>
117
+ </p>
118
+ </div>
119
+ </div>
120
+
121
+ <div class="postbox">
122
+ <h2 class="hndle">
123
+ <span class="dashicons dashicons-sos"></span>
124
+ <span><?php esc_html_e( 'Five Star Support', 'cartflows' ); ?></span>
125
+ </h2>
126
+ <div class="inside">
127
+ <p>
128
+ <?php esc_html_e( 'Got a question? Get in touch with CartFlows developers. We\'re happy to help!', 'cartflows' ); ?>
129
+ </p>
130
+ <p>
131
+ <a href="<?php echo esc_url( 'https://cartflows.com/contact' ); ?>" target="_blank" rel="noopener"><?php _e( 'Submit a Ticket »', 'cartflows' ); ?></a>
132
+ </p>
133
+ </div>
134
+ </div>
135
+
136
+ </div>
137
+ </div>
138
+ </div>
139
+ <!-- /post-body -->
140
+ <br class="clear">
141
+ </div>
142
+ </div>
143
+ </form>
144
+
145
+
146
+ <?php
147
+ /**
148
+ * Loads Zapier settings admin view.
149
+ */
150
+ do_action( 'cartflows_after_general_settings' );
151
+ ?>
includes/exporter.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * Exporter
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- ?>
9
- <div class="cartflows-ie">
10
- <div class="postbox">
11
- <div class="inside">
12
- <h3><?php _e( 'Export Flows to a JSON file', 'cartflows' ); ?></h3>
13
- <p><?php _e( 'This tool allows you to generate and download a JSON file containing a list of all flows.', 'cartflows' ); ?></p>
14
- <form method="post">
15
- <p><input type="hidden" name="cartflows-action" value="export" /></p>
16
- <p style="margin-bottom:0">
17
- <?php wp_nonce_field( 'cartflows-action-nonce', 'cartflows-action-nonce' ); ?>
18
- <?php submit_button( __( 'Export', 'cartflows' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
19
- </p>
20
- </form>
21
- </div>
22
- </div>
23
- </div>
1
+ <?php
2
+ /**
3
+ * Exporter
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ ?>
9
+ <div class="cartflows-ie">
10
+ <div class="postbox">
11
+ <div class="inside">
12
+ <h3><?php _e( 'Export Flows to a JSON file', 'cartflows' ); ?></h3>
13
+ <p><?php _e( 'This tool allows you to generate and download a JSON file containing a list of all flows.', 'cartflows' ); ?></p>
14
+ <form method="post">
15
+ <p><input type="hidden" name="cartflows-action" value="export" /></p>
16
+ <p style="margin-bottom:0">
17
+ <?php wp_nonce_field( 'cartflows-action-nonce', 'cartflows-action-nonce' ); ?>
18
+ <?php submit_button( __( 'Export', 'cartflows' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
19
+ </p>
20
+ </form>
21
+ </div>
22
+ </div>
23
+ </div>
includes/importer.php CHANGED
@@ -1,26 +1,26 @@
1
- <?php
2
- /**
3
- * Importer
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- ?>
9
- <div class="cartflows-ie">
10
- <div class="postbox">
11
- <div class="inside">
12
- <h3><?php _e( 'Import Flows to a JSON file', 'cartflows' ); ?></h3>
13
- <p><?php _e( 'This tool allows you to import the flows from the JSON file.', 'cartflows' ); ?></p>
14
- <form method="post" enctype="multipart/form-data">
15
- <p>
16
- <input type="file" name="file"/>
17
- <input type="hidden" name="cartflows-action" value="import" />
18
- </p>
19
- <p style="margin-bottom:0">
20
- <?php wp_nonce_field( 'cartflows-action-nonce', 'cartflows-action-nonce' ); ?>
21
- <?php submit_button( __( 'Import', 'cartflows' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
22
- </p>
23
- </form>
24
- </div>
25
- </div>
26
- </div>
1
+ <?php
2
+ /**
3
+ * Importer
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ ?>
9
+ <div class="cartflows-ie">
10
+ <div class="postbox">
11
+ <div class="inside">
12
+ <h3><?php _e( 'Import Flows to a JSON file', 'cartflows' ); ?></h3>
13
+ <p><?php _e( 'This tool allows you to import the flows from the JSON file.', 'cartflows' ); ?></p>
14
+ <form method="post" enctype="multipart/form-data">
15
+ <p>
16
+ <input type="file" name="file"/>
17
+ <input type="hidden" name="cartflows-action" value="import" />
18
+ </p>
19
+ <p style="margin-bottom:0">
20
+ <?php wp_nonce_field( 'cartflows-action-nonce', 'cartflows-action-nonce' ); ?>
21
+ <?php submit_button( __( 'Import', 'cartflows' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
22
+ </p>
23
+ </form>
24
+ </div>
25
+ </div>
26
+ </div>
languages/cartflows.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the CartFlows package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: CartFlows 1.1.12\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
- "POT-Creation-Date: 2019-03-22 09:55:54+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -51,40 +51,40 @@ msgid ""
51
  "Please read information about how to set up Global Checkout %1$shere%2$s."
52
  msgstr ""
53
 
54
- #: classes/class-cartflows-admin.php:109 classes/class-cartflows-admin.php:110
55
  #: includes/admin/cartflows-general-bck.php:34
56
  msgid "Settings"
57
  msgstr ""
58
 
59
- #: classes/class-cartflows-admin.php:309
60
  msgid "Flows Library"
61
  msgstr ""
62
 
63
- #: classes/class-cartflows-admin.php:316
64
  #: modules/flow/view/meta-flow-steps.php:145
65
  msgid "Ready Templates"
66
  msgstr ""
67
 
68
- #: classes/class-cartflows-admin.php:319
69
  #: modules/flow/view/meta-flow-steps.php:148
70
  msgid "Create Your Own"
71
  msgstr ""
72
 
73
- #: classes/class-cartflows-admin.php:330
74
  #: modules/flow/view/meta-flow-steps.php:160
75
  msgid "Search Sites"
76
  msgstr ""
77
 
78
- #: classes/class-cartflows-admin.php:331
79
  #: modules/flow/view/meta-flow-steps.php:161
80
  msgid "Search Flow..."
81
  msgstr ""
82
 
83
- #: classes/class-cartflows-admin.php:348
84
  msgid "Design Your Flow"
85
  msgstr ""
86
 
87
- #: classes/class-cartflows-admin.php:349
88
  #: modules/flow/view/meta-flow-steps.php:192
89
  msgid "Learn How"
90
  msgstr ""
@@ -351,7 +351,7 @@ msgstr ""
351
 
352
  #: classes/class-cartflows-meta-fields.php:492
353
  #: classes/class-cartflows-meta-fields.php:505
354
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:452
355
  msgid "Default"
356
  msgstr ""
357
 
@@ -398,7 +398,7 @@ msgid "Back to edit Flow"
398
  msgstr ""
399
 
400
  #: classes/class-cartflows-meta.php:63
401
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:189
402
  #: modules/landing/classes/class-cartflows-landing-meta.php:136
403
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:148
404
  msgid "Custom Script"
@@ -649,207 +649,215 @@ msgstr ""
649
  msgid "Checkout Layout"
650
  msgstr ""
651
 
652
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:153
653
  #: modules/landing/classes/class-cartflows-landing-meta.php:130
654
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:130
655
  msgid "Shortcodes"
656
  msgstr ""
657
 
658
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:159
659
  msgid "Select Product"
660
  msgstr ""
661
 
662
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:165
663
  msgid "Order Bump"
664
  msgstr ""
665
 
666
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:171
667
  msgid "Checkout Design"
668
  msgstr ""
669
 
670
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:177
671
  msgid "Checkout Fields"
672
  msgstr ""
673
 
674
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:183
675
- msgid "Logo ( Optional )"
676
  msgstr ""
677
 
678
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:245
679
  msgid "Add this shortcode to your checkout page"
680
  msgstr ""
681
 
682
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:297
683
  #. translators: %s: link
684
  msgid "Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature"
685
  msgstr ""
686
 
687
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:325
688
  #. translators: %s: link
689
  msgid "Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature"
690
  msgstr ""
691
 
692
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:353
693
  msgid "One Column (Available in CartFlows Pro) "
694
  msgstr ""
695
 
696
  #: modules/checkout/classes/class-cartflows-checkout-meta.php:359
 
 
 
 
697
  msgid "Checkout Skin"
698
  msgstr ""
699
 
700
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:363
701
  msgid "One Column"
702
  msgstr ""
703
 
704
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:364
705
  msgid "Two Column"
706
  msgstr ""
707
 
708
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:373
 
 
 
 
709
  msgid "Primary Color"
710
  msgstr ""
711
 
712
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:382
713
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:417
714
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:463
715
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:555
716
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:203
717
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:226
718
  msgid "Font Family"
719
  msgstr ""
720
 
721
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:390
722
  msgid "Advance Options"
723
  msgstr ""
724
 
725
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:402
726
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:211
727
  msgid "Heading"
728
  msgstr ""
729
 
730
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:408
731
  msgid "Heading Color"
732
  msgstr ""
733
 
734
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:426
735
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:472
736
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:564
737
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:235
738
  msgid "Font Weight"
739
  msgstr ""
740
 
741
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:434
742
  msgid "Input Fields"
743
  msgstr ""
744
 
745
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:442
746
  msgid "Floating Labels (Available in CartFlows Pro)"
747
  msgstr ""
748
 
749
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:448
750
  msgid "Style"
751
  msgstr ""
752
 
753
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:453
754
  msgid "Floating Labels"
755
  msgstr ""
756
 
757
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:480
758
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:572
759
  msgid "Size"
760
  msgstr ""
761
 
762
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:484
763
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:576
764
  msgid "Extra Small"
765
  msgstr ""
766
 
767
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:485
768
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:577
769
  msgid "Small"
770
  msgstr ""
771
 
772
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:486
773
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:578
774
  msgid "Medium"
775
  msgstr ""
776
 
777
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:487
778
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:579
779
  msgid "Large"
780
  msgstr ""
781
 
782
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:488
783
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:580
784
  msgid "Extra Large"
785
  msgstr ""
786
 
787
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:489
788
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:581
789
  msgid "Custom"
790
  msgstr ""
791
 
792
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:496
793
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:588
794
  msgid "Top Bottom Spacing"
795
  msgstr ""
796
 
797
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:504
798
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:596
799
  msgid "Left Right Spacing"
800
  msgstr ""
801
 
802
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:512
803
  msgid "Text / Placeholder Color"
804
  msgstr ""
805
 
806
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:520
807
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:620
808
  msgid "Background Color"
809
  msgstr ""
810
 
811
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:528
812
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:636
813
  msgid "Border Color"
814
  msgstr ""
815
 
816
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:535
817
  msgid "Label Color"
818
  msgstr ""
819
 
820
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:548
821
  msgid "Buttons"
822
  msgstr ""
823
 
824
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:604
825
  msgid "Text Color"
826
  msgstr ""
827
 
828
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:612
829
  msgid "Text Hover Color"
830
  msgstr ""
831
 
832
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:628
833
  msgid "Background Hover Color"
834
  msgstr ""
835
 
836
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:644
837
  msgid "Border Hover Color"
838
  msgstr ""
839
 
840
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:657
841
  msgid "Sections"
842
  msgstr ""
843
 
844
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:663
845
  msgid "Highlight Area Background Color"
846
  msgstr ""
847
 
848
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:702
849
  msgid "Header Logo"
850
  msgstr ""
851
 
852
- #: modules/checkout/classes/class-cartflows-checkout-meta.php:710
853
  msgid "Logo Width (In px)"
854
  msgstr ""
855
 
@@ -933,8 +941,8 @@ msgstr ""
933
 
934
  #: modules/flow/classes/class-cartflows-flow-post-type.php:61
935
  #: modules/flow/classes/class-cartflows-flow-post-type.php:63
936
- #: modules/flow/classes/class-cartflows-step-post-type.php:149
937
- #: modules/flow/classes/class-cartflows-step-post-type.php:151
938
  msgid "Add New"
939
  msgstr ""
940
 
@@ -956,57 +964,57 @@ msgstr ""
956
 
957
  #: modules/flow/classes/class-cartflows-flow-post-type.php:252
958
  #: modules/flow/classes/class-cartflows-flow-post-type.php:258
959
- #: modules/flow/classes/class-cartflows-step-post-type.php:397
960
- #: modules/flow/classes/class-cartflows-step-post-type.php:403
961
  #. translators: %s: singular custom post type name
962
  msgid "%s updated."
963
  msgstr ""
964
 
965
  #: modules/flow/classes/class-cartflows-flow-post-type.php:254
966
- #: modules/flow/classes/class-cartflows-step-post-type.php:399
967
  #. translators: %s: singular custom post type name
968
  msgid "Custom %s updated."
969
  msgstr ""
970
 
971
  #: modules/flow/classes/class-cartflows-flow-post-type.php:256
972
- #: modules/flow/classes/class-cartflows-step-post-type.php:401
973
  #. translators: %s: singular custom post type name
974
  msgid "Custom %s deleted."
975
  msgstr ""
976
 
977
  #: modules/flow/classes/class-cartflows-flow-post-type.php:260
978
- #: modules/flow/classes/class-cartflows-step-post-type.php:405
979
  #. translators: %1$s: singular custom post type name ,%2$s: date and time of
980
  #. the revision
981
  msgid "%1$s restored to revision from %2$s"
982
  msgstr ""
983
 
984
  #: modules/flow/classes/class-cartflows-flow-post-type.php:262
985
- #: modules/flow/classes/class-cartflows-step-post-type.php:407
986
  #. translators: %s: singular custom post type name
987
  msgid "%s published."
988
  msgstr ""
989
 
990
  #: modules/flow/classes/class-cartflows-flow-post-type.php:264
991
- #: modules/flow/classes/class-cartflows-step-post-type.php:409
992
  #. translators: %s: singular custom post type name
993
  msgid "%s saved."
994
  msgstr ""
995
 
996
  #: modules/flow/classes/class-cartflows-flow-post-type.php:266
997
- #: modules/flow/classes/class-cartflows-step-post-type.php:411
998
  #. translators: %s: singular custom post type name
999
  msgid "%s submitted."
1000
  msgstr ""
1001
 
1002
  #: modules/flow/classes/class-cartflows-flow-post-type.php:268
1003
- #: modules/flow/classes/class-cartflows-step-post-type.php:413
1004
  #. translators: %s: singular custom post type name
1005
  msgid "%s scheduled for."
1006
  msgstr ""
1007
 
1008
  #: modules/flow/classes/class-cartflows-flow-post-type.php:270
1009
- #: modules/flow/classes/class-cartflows-step-post-type.php:415
1010
  #. translators: %s: singular custom post type name
1011
  msgid "%s draft updated."
1012
  msgstr ""
@@ -1016,61 +1024,61 @@ msgstr ""
1016
  msgid "Next Step"
1017
  msgstr ""
1018
 
1019
- #: modules/flow/classes/class-cartflows-step-post-type.php:145
1020
  msgid "Search Steps"
1021
  msgstr ""
1022
 
1023
- #: modules/flow/classes/class-cartflows-step-post-type.php:146
1024
  msgid "All Steps"
1025
  msgstr ""
1026
 
1027
- #: modules/flow/classes/class-cartflows-step-post-type.php:147
1028
  #: modules/flow/view/meta-flow-steps.php:99
1029
  msgid "Edit Step"
1030
  msgstr ""
1031
 
1032
- #: modules/flow/classes/class-cartflows-step-post-type.php:148
1033
  #: modules/flow/view/meta-flow-steps.php:95
1034
  msgid "View Step"
1035
  msgstr ""
1036
 
1037
- #: modules/flow/classes/class-cartflows-step-post-type.php:150
1038
  msgid "Update Step"
1039
  msgstr ""
1040
 
1041
- #: modules/flow/classes/class-cartflows-step-post-type.php:152
1042
  msgid "New Step Name"
1043
  msgstr ""
1044
 
1045
- #: modules/flow/classes/class-cartflows-step-post-type.php:175
1046
  msgid "Step Type"
1047
  msgstr ""
1048
 
1049
- #: modules/flow/classes/class-cartflows-step-post-type.php:184
1050
  msgid "Step Flow"
1051
  msgstr ""
1052
 
1053
- #: modules/flow/classes/class-cartflows-step-post-type.php:201
1054
  #: modules/flow/view/meta-flow-steps.php:11
1055
  msgid "Landing"
1056
  msgstr ""
1057
 
1058
- #: modules/flow/classes/class-cartflows-step-post-type.php:207
1059
  #: modules/flow/view/meta-flow-steps.php:12
1060
  msgid "Checkout"
1061
  msgstr ""
1062
 
1063
- #: modules/flow/classes/class-cartflows-step-post-type.php:213
1064
  #: modules/flow/view/meta-flow-steps.php:13
1065
  msgid "Thank You"
1066
  msgstr ""
1067
 
1068
- #: modules/flow/classes/class-cartflows-step-post-type.php:219
1069
  #: modules/flow/view/meta-flow-steps.php:14
1070
  msgid "Upsell"
1071
  msgstr ""
1072
 
1073
- #: modules/flow/classes/class-cartflows-step-post-type.php:225
1074
  #: modules/flow/view/meta-flow-steps.php:15
1075
  msgid "Downsell"
1076
  msgstr ""
@@ -1278,6 +1286,30 @@ msgid ""
1278
  "are a new customer, please proceed to the Billing &amp; Shipping section."
1279
  msgstr ""
1280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1281
  #: woocommerce/template/checkout/review-order.php:26
1282
  msgid "Product"
1283
  msgstr ""
@@ -1357,17 +1389,17 @@ msgctxt "flow singular name"
1357
  msgid "Flow"
1358
  msgstr ""
1359
 
1360
- #: modules/flow/classes/class-cartflows-step-post-type.php:143
1361
  msgctxt "flow step general name"
1362
  msgid "Steps"
1363
  msgstr ""
1364
 
1365
- #: modules/flow/classes/class-cartflows-step-post-type.php:144
1366
  msgctxt "flow step singular name"
1367
  msgid "Step"
1368
  msgstr ""
1369
 
1370
- #: modules/flow/classes/class-cartflows-step-post-type.php:263
1371
  msgctxt "cartflows"
1372
  msgid "Template for Page Builders"
1373
  msgstr ""
2
  # This file is distributed under the same license as the CartFlows package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: CartFlows 1.1.13\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
+ "POT-Creation-Date: 2019-04-09 10:46:26+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
51
  "Please read information about how to set up Global Checkout %1$shere%2$s."
52
  msgstr ""
53
 
54
+ #: classes/class-cartflows-admin.php:115 classes/class-cartflows-admin.php:116
55
  #: includes/admin/cartflows-general-bck.php:34
56
  msgid "Settings"
57
  msgstr ""
58
 
59
+ #: classes/class-cartflows-admin.php:315
60
  msgid "Flows Library"
61
  msgstr ""
62
 
63
+ #: classes/class-cartflows-admin.php:322
64
  #: modules/flow/view/meta-flow-steps.php:145
65
  msgid "Ready Templates"
66
  msgstr ""
67
 
68
+ #: classes/class-cartflows-admin.php:325
69
  #: modules/flow/view/meta-flow-steps.php:148
70
  msgid "Create Your Own"
71
  msgstr ""
72
 
73
+ #: classes/class-cartflows-admin.php:336
74
  #: modules/flow/view/meta-flow-steps.php:160
75
  msgid "Search Sites"
76
  msgstr ""
77
 
78
+ #: classes/class-cartflows-admin.php:337
79
  #: modules/flow/view/meta-flow-steps.php:161
80
  msgid "Search Flow..."
81
  msgstr ""
82
 
83
+ #: classes/class-cartflows-admin.php:354
84
  msgid "Design Your Flow"
85
  msgstr ""
86
 
87
+ #: classes/class-cartflows-admin.php:355
88
  #: modules/flow/view/meta-flow-steps.php:192
89
  msgid "Learn How"
90
  msgstr ""
351
 
352
  #: classes/class-cartflows-meta-fields.php:492
353
  #: classes/class-cartflows-meta-fields.php:505
354
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:459
355
  msgid "Default"
356
  msgstr ""
357
 
398
  msgstr ""
399
 
400
  #: classes/class-cartflows-meta.php:63
401
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:191
402
  #: modules/landing/classes/class-cartflows-landing-meta.php:136
403
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:148
404
  msgid "Custom Script"
649
  msgid "Checkout Layout"
650
  msgstr ""
651
 
652
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:155
653
  #: modules/landing/classes/class-cartflows-landing-meta.php:130
654
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:130
655
  msgid "Shortcodes"
656
  msgstr ""
657
 
658
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:161
659
  msgid "Select Product"
660
  msgstr ""
661
 
662
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:167
663
  msgid "Order Bump"
664
  msgstr ""
665
 
666
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:173
667
  msgid "Checkout Design"
668
  msgstr ""
669
 
670
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:179
671
  msgid "Checkout Fields"
672
  msgstr ""
673
 
674
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:185
675
+ msgid "Logo (Optional)"
676
  msgstr ""
677
 
678
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:250
679
  msgid "Add this shortcode to your checkout page"
680
  msgstr ""
681
 
682
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:302
683
  #. translators: %s: link
684
  msgid "Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature"
685
  msgstr ""
686
 
687
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:330
688
  #. translators: %s: link
689
  msgid "Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature"
690
  msgstr ""
691
 
692
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:358
693
  msgid "One Column (Available in CartFlows Pro) "
694
  msgstr ""
695
 
696
  #: modules/checkout/classes/class-cartflows-checkout-meta.php:359
697
+ msgid "Two Step (Available in CartFlows Pro) "
698
+ msgstr ""
699
+
700
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:365
701
  msgid "Checkout Skin"
702
  msgstr ""
703
 
704
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:369
705
  msgid "One Column"
706
  msgstr ""
707
 
708
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:370
709
  msgid "Two Column"
710
  msgstr ""
711
 
712
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:371
713
+ msgid "Two Step"
714
+ msgstr ""
715
+
716
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:380
717
  msgid "Primary Color"
718
  msgstr ""
719
 
720
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:389
721
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:424
722
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:470
723
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:562
724
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:203
725
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:226
726
  msgid "Font Family"
727
  msgstr ""
728
 
729
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:397
730
  msgid "Advance Options"
731
  msgstr ""
732
 
733
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:409
734
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:211
735
  msgid "Heading"
736
  msgstr ""
737
 
738
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:415
739
  msgid "Heading Color"
740
  msgstr ""
741
 
742
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:433
743
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:479
744
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:571
745
  #: modules/thankyou/classes/class-cartflows-thankyou-meta.php:235
746
  msgid "Font Weight"
747
  msgstr ""
748
 
749
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:441
750
  msgid "Input Fields"
751
  msgstr ""
752
 
753
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:449
754
  msgid "Floating Labels (Available in CartFlows Pro)"
755
  msgstr ""
756
 
757
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:455
758
  msgid "Style"
759
  msgstr ""
760
 
761
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:460
762
  msgid "Floating Labels"
763
  msgstr ""
764
 
765
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:487
766
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:579
767
  msgid "Size"
768
  msgstr ""
769
 
770
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:491
771
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:583
772
  msgid "Extra Small"
773
  msgstr ""
774
 
775
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:492
776
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:584
777
  msgid "Small"
778
  msgstr ""
779
 
780
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:493
781
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:585
782
  msgid "Medium"
783
  msgstr ""
784
 
785
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:494
786
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:586
787
  msgid "Large"
788
  msgstr ""
789
 
790
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:495
791
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:587
792
  msgid "Extra Large"
793
  msgstr ""
794
 
795
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:496
796
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:588
797
  msgid "Custom"
798
  msgstr ""
799
 
800
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:503
801
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:595
802
  msgid "Top Bottom Spacing"
803
  msgstr ""
804
 
805
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:511
806
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:603
807
  msgid "Left Right Spacing"
808
  msgstr ""
809
 
810
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:519
811
  msgid "Text / Placeholder Color"
812
  msgstr ""
813
 
814
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:527
815
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:627
816
  msgid "Background Color"
817
  msgstr ""
818
 
819
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:535
820
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:643
821
  msgid "Border Color"
822
  msgstr ""
823
 
824
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:542
825
  msgid "Label Color"
826
  msgstr ""
827
 
828
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:555
829
  msgid "Buttons"
830
  msgstr ""
831
 
832
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:611
833
  msgid "Text Color"
834
  msgstr ""
835
 
836
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:619
837
  msgid "Text Hover Color"
838
  msgstr ""
839
 
840
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:635
841
  msgid "Background Hover Color"
842
  msgstr ""
843
 
844
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:651
845
  msgid "Border Hover Color"
846
  msgstr ""
847
 
848
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:664
849
  msgid "Sections"
850
  msgstr ""
851
 
852
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:670
853
  msgid "Highlight Area Background Color"
854
  msgstr ""
855
 
856
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:709
857
  msgid "Header Logo"
858
  msgstr ""
859
 
860
+ #: modules/checkout/classes/class-cartflows-checkout-meta.php:717
861
  msgid "Logo Width (In px)"
862
  msgstr ""
863
 
941
 
942
  #: modules/flow/classes/class-cartflows-flow-post-type.php:61
943
  #: modules/flow/classes/class-cartflows-flow-post-type.php:63
944
+ #: modules/flow/classes/class-cartflows-step-post-type.php:150
945
+ #: modules/flow/classes/class-cartflows-step-post-type.php:152
946
  msgid "Add New"
947
  msgstr ""
948
 
964
 
965
  #: modules/flow/classes/class-cartflows-flow-post-type.php:252
966
  #: modules/flow/classes/class-cartflows-flow-post-type.php:258
967
+ #: modules/flow/classes/class-cartflows-step-post-type.php:413
968
+ #: modules/flow/classes/class-cartflows-step-post-type.php:419
969
  #. translators: %s: singular custom post type name
970
  msgid "%s updated."
971
  msgstr ""
972
 
973
  #: modules/flow/classes/class-cartflows-flow-post-type.php:254
974
+ #: modules/flow/classes/class-cartflows-step-post-type.php:415
975
  #. translators: %s: singular custom post type name
976
  msgid "Custom %s updated."
977
  msgstr ""
978
 
979
  #: modules/flow/classes/class-cartflows-flow-post-type.php:256
980
+ #: modules/flow/classes/class-cartflows-step-post-type.php:417
981
  #. translators: %s: singular custom post type name
982
  msgid "Custom %s deleted."
983
  msgstr ""
984
 
985
  #: modules/flow/classes/class-cartflows-flow-post-type.php:260
986
+ #: modules/flow/classes/class-cartflows-step-post-type.php:421
987
  #. translators: %1$s: singular custom post type name ,%2$s: date and time of
988
  #. the revision
989
  msgid "%1$s restored to revision from %2$s"
990
  msgstr ""
991
 
992
  #: modules/flow/classes/class-cartflows-flow-post-type.php:262
993
+ #: modules/flow/classes/class-cartflows-step-post-type.php:423
994
  #. translators: %s: singular custom post type name
995
  msgid "%s published."
996
  msgstr ""
997
 
998
  #: modules/flow/classes/class-cartflows-flow-post-type.php:264
999
+ #: modules/flow/classes/class-cartflows-step-post-type.php:425
1000
  #. translators: %s: singular custom post type name
1001
  msgid "%s saved."
1002
  msgstr ""
1003
 
1004
  #: modules/flow/classes/class-cartflows-flow-post-type.php:266
1005
+ #: modules/flow/classes/class-cartflows-step-post-type.php:427
1006
  #. translators: %s: singular custom post type name
1007
  msgid "%s submitted."
1008
  msgstr ""
1009
 
1010
  #: modules/flow/classes/class-cartflows-flow-post-type.php:268
1011
+ #: modules/flow/classes/class-cartflows-step-post-type.php:429
1012
  #. translators: %s: singular custom post type name
1013
  msgid "%s scheduled for."
1014
  msgstr ""
1015
 
1016
  #: modules/flow/classes/class-cartflows-flow-post-type.php:270
1017
+ #: modules/flow/classes/class-cartflows-step-post-type.php:431
1018
  #. translators: %s: singular custom post type name
1019
  msgid "%s draft updated."
1020
  msgstr ""
1024
  msgid "Next Step"
1025
  msgstr ""
1026
 
1027
+ #: modules/flow/classes/class-cartflows-step-post-type.php:146
1028
  msgid "Search Steps"
1029
  msgstr ""
1030
 
1031
+ #: modules/flow/classes/class-cartflows-step-post-type.php:147
1032
  msgid "All Steps"
1033
  msgstr ""
1034
 
1035
+ #: modules/flow/classes/class-cartflows-step-post-type.php:148
1036
  #: modules/flow/view/meta-flow-steps.php:99
1037
  msgid "Edit Step"
1038
  msgstr ""
1039
 
1040
+ #: modules/flow/classes/class-cartflows-step-post-type.php:149
1041
  #: modules/flow/view/meta-flow-steps.php:95
1042
  msgid "View Step"
1043
  msgstr ""
1044
 
1045
+ #: modules/flow/classes/class-cartflows-step-post-type.php:151
1046
  msgid "Update Step"
1047
  msgstr ""
1048
 
1049
+ #: modules/flow/classes/class-cartflows-step-post-type.php:153
1050
  msgid "New Step Name"
1051
  msgstr ""
1052
 
1053
+ #: modules/flow/classes/class-cartflows-step-post-type.php:176
1054
  msgid "Step Type"
1055
  msgstr ""
1056
 
1057
+ #: modules/flow/classes/class-cartflows-step-post-type.php:185
1058
  msgid "Step Flow"
1059
  msgstr ""
1060
 
1061
+ #: modules/flow/classes/class-cartflows-step-post-type.php:202
1062
  #: modules/flow/view/meta-flow-steps.php:11
1063
  msgid "Landing"
1064
  msgstr ""
1065
 
1066
+ #: modules/flow/classes/class-cartflows-step-post-type.php:208
1067
  #: modules/flow/view/meta-flow-steps.php:12
1068
  msgid "Checkout"
1069
  msgstr ""
1070
 
1071
+ #: modules/flow/classes/class-cartflows-step-post-type.php:214
1072
  #: modules/flow/view/meta-flow-steps.php:13
1073
  msgid "Thank You"
1074
  msgstr ""
1075
 
1076
+ #: modules/flow/classes/class-cartflows-step-post-type.php:220
1077
  #: modules/flow/view/meta-flow-steps.php:14
1078
  msgid "Upsell"
1079
  msgstr ""
1080
 
1081
+ #: modules/flow/classes/class-cartflows-step-post-type.php:226
1082
  #: modules/flow/view/meta-flow-steps.php:15
1083
  msgid "Downsell"
1084
  msgstr ""
1286
  "are a new customer, please proceed to the Billing &amp; Shipping section."
1287
  msgstr ""
1288
 
1289
+ #: woocommerce/template/checkout/payment.php:33
1290
+ msgid ""
1291
+ "Sorry, it seems that there are no available payment methods for your state. "
1292
+ "Please contact us if you require assistance or wish to make alternate "
1293
+ "arrangements."
1294
+ msgstr ""
1295
+
1296
+ #: woocommerce/template/checkout/payment.php:33
1297
+ msgid "Please fill in your details above to see available payment methods."
1298
+ msgstr ""
1299
+
1300
+ #: woocommerce/template/checkout/payment.php:42
1301
+ #. translators: $1 and $2 opening and closing emphasis tags respectively
1302
+ msgid ""
1303
+ "Since your browser does not support JavaScript, or it is disabled, please "
1304
+ "ensure you click the %1$sUpdate Totals%2$s button before placing your "
1305
+ "order. You may be charged more than the amount stated above if you fail to "
1306
+ "do so."
1307
+ msgstr ""
1308
+
1309
+ #: woocommerce/template/checkout/payment.php:44
1310
+ msgid "Update totals"
1311
+ msgstr ""
1312
+
1313
  #: woocommerce/template/checkout/review-order.php:26
1314
  msgid "Product"
1315
  msgstr ""
1389
  msgid "Flow"
1390
  msgstr ""
1391
 
1392
+ #: modules/flow/classes/class-cartflows-step-post-type.php:144
1393
  msgctxt "flow step general name"
1394
  msgid "Steps"
1395
  msgstr ""
1396
 
1397
+ #: modules/flow/classes/class-cartflows-step-post-type.php:145
1398
  msgctxt "flow step singular name"
1399
  msgid "Step"
1400
  msgstr ""
1401
 
1402
+ #: modules/flow/classes/class-cartflows-step-post-type.php:264
1403
  msgctxt "cartflows"
1404
  msgid "Template for Page Builders"
1405
  msgstr ""
modules/checkout/classes/class-cartflows-checkout-meta.php CHANGED
@@ -1,765 +1,772 @@
1
- <?php
2
- /**
3
- * Checkout post meta
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Checkout_Meta extends Cartflows_Meta {
12
-
13
- /**
14
- * Instance
15
- *
16
- * @var $instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Meta Option
22
- *
23
- * @var $meta_option
24
- */
25
- private static $meta_option = null;
26
-
27
- /**
28
- * Initiator
29
- */
30
- public static function get_instance() {
31
- if ( ! isset( self::$instance ) ) {
32
- self::$instance = new self;
33
- }
34
-
35
- return self::$instance;
36
- }
37
-
38
- /**
39
- * Constructor
40
- */
41
- public function __construct() {
42
-
43
- /* Init Metabox */
44
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
- }
47
-
48
- /**
49
- * Init Metabox
50
- */
51
- public function init_metabox() {
52
-
53
- add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
- }
56
-
57
- /**
58
- * Setup Metabox
59
- */
60
- function setup_meta_box() {
61
-
62
- // Get all posts.
63
- $post_types = get_post_types();
64
-
65
- if ( _is_wcf_checkout_type() ) {
66
- add_meta_box(
67
- 'wcf-checkout-settings', // Id.
68
- __( 'Checkout Layout', 'cartflows' ), // Title.
69
- array( $this, 'markup_meta_box' ), // Callback.
70
- wcf()->utils->get_step_post_type(), // Post_type.
71
- 'normal', // Context.
72
- 'high' // Priority.
73
- );
74
- }
75
- }
76
-
77
- /**
78
- * Metabox Markup
79
- *
80
- * @param object $post Post object.
81
- * @return void
82
- */
83
- function markup_meta_box( $post ) {
84
-
85
- wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
86
-
87
- $stored = get_post_meta( $post->ID );
88
-
89
- $checkout_meta = self::get_meta_option( $post->ID );
90
-
91
- // Set stored and override defaults.
92
- foreach ( $stored as $key => $value ) {
93
- if ( array_key_exists( $key, $checkout_meta ) ) {
94
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
95
- } else {
96
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
97
- }
98
- }
99
-
100
- // Get defaults.
101
- $meta = self::get_meta_option( $post->ID );
102
- $checkout_data = array();
103
-
104
- foreach ( $meta as $key => $value ) {
105
-
106
- $checkout_data[ $key ] = $meta[ $key ]['default'];
107
- }
108
-
109
- /*
110
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
111
-
112
- foreach ( $billing_fields as $key => $value ) {
113
-
114
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
115
- }
116
-
117
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
118
-
119
- foreach ( $shipping_fields as $key => $value ) {
120
-
121
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
122
- }
123
-
124
- $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
125
-
126
- foreach ( $additional_fields as $key => $value ) {
127
-
128
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
129
- }
130
- */
131
-
132
- do_action( 'wcf_checkout_settings_markup_before' );
133
- $this->tabs_markup( $checkout_data, $post->ID );
134
- do_action( 'wcf_checkout_settings_markup_after' );
135
- }
136
-
137
- /**
138
- * Page Header Tabs
139
- *
140
- * @param array $options options.
141
- * @param int $post_id post ID.
142
- */
143
- function tabs_markup( $options, $post_id ) {
144
-
145
- $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
146
-
147
- if ( empty( $active_tab ) ) {
148
- $active_tab = 'wcf-checkout-shortcodes';
149
- }
150
-
151
- $tabs = array(
152
- array(
153
- 'title' => __( 'Shortcodes', 'cartflows' ),
154
- 'id' => 'wcf-checkout-shortcodes',
155
- 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
156
- 'icon' => 'dashicons-editor-code',
157
- ),
158
- array(
159
- 'title' => __( 'Select Product', 'cartflows' ),
160
- 'id' => 'wcf-checkout-general',
161
- 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
162
- 'icon' => 'dashicons-info',
163
- ),
164
- array(
165
- 'title' => __( 'Order Bump', 'cartflows' ),
166
- 'id' => 'wcf-product-order-bump',
167
- 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
168
- 'icon' => 'dashicons-cart',
169
- ),
170
- array(
171
- 'title' => __( 'Checkout Design', 'cartflows' ),
172
- 'id' => 'wcf-checkout-style',
173
- 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
174
- 'icon' => 'dashicons-admin-customizer',
175
- ),
176
- array(
177
- 'title' => __( 'Checkout Fields', 'cartflows' ),
178
- 'id' => 'wcf-checkout-custom-fields',
179
- 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
180
- 'icon' => 'dashicons-welcome-widgets-menus',
181
- ),
182
- array(
183
- 'title' => __( 'Logo ( Optional )', 'cartflows' ),
184
- 'id' => 'wcf-checkout-header',
185
- 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
186
- 'icon' => 'dashicons-format-image',
187
- ),
188
- array(
189
- 'title' => __( 'Custom Script', 'cartflows' ),
190
- 'id' => 'wcf-checkout-custom-script-header',
191
- 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
192
- 'icon' => 'dashicons-format-aside',
193
- ),
194
- );
195
-
196
- ?>
197
- <div class="wcf-checkout-table wcf-metabox-wrap widefat">
198
- <div class="wcf-table-container">
199
- <div class="wcf-column-left">
200
- <div class="wcf-tab-wrapper">
201
-
202
- <?php foreach ( $tabs as $key => $tab ) { ?>
203
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
204
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
205
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
206
- </div>
207
- <?php } ?>
208
-
209
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
210
- </div>
211
- </div>
212
- <div class="wcf-column-right">
213
- <?php $this->tab_shortcodes( $options, $post_id ); ?>
214
- <?php $this->tab_general( $options, $post_id ); ?>
215
- <?php $this->tab_style( $options, $post_id ); ?>
216
- <?php $this->tab_product_bump( $options, $post_id ); ?>
217
- <?php $this->tab_custom_fields( $options, $post_id ); ?>
218
- <?php $this->tab_header_content( $options, $post_id ); ?>
219
- <?php $this->tab_custom_script( $options, $post_id ); ?>
220
- <?php $this->right_column_footer( $options, $post_id ); ?>
221
- </div>
222
- </div>
223
- </div>
224
-
225
- <?php
226
- }
227
-
228
- /**
229
- * Shortcodes tab
230
- *
231
- * @param array $options options.
232
- * @param int $post_id post ID.
233
- */
234
- function tab_shortcodes( $options, $post_id ) {
235
- ?>
236
- <div class="wcf-checkout-shortcodes wcf-tab-content widefat">
237
-
238
- <?php
239
-
240
- echo wcf()->meta->get_shortcode_field(
241
- array(
242
- 'label' => 'Checkout Page',
243
- 'name' => 'wcf-checkout-shortcode',
244
- 'content' => '[cartflows_checkout]',
245
- 'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
246
- )
247
- );
248
- ?>
249
- </div>
250
- <?php
251
- }
252
-
253
-
254
- /**
255
- * General tab
256
- *
257
- * @param array $options options.
258
- * @param int $post_id post ID.
259
- */
260
- function tab_general( $options, $post_id ) {
261
- ?>
262
- <div class="wcf-checkout-general wcf-tab-content widefat">
263
-
264
- <?php
265
-
266
- echo wcf()->meta->get_product_selection_repeater(
267
- array(
268
- 'name' => 'wcf-checkout-products',
269
- 'value' => $options['wcf-checkout-products'],
270
- 'allow_clear' => true,
271
- )
272
- );
273
-
274
- do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
275
-
276
- ?>
277
- </div>
278
- <?php
279
- }
280
-
281
- /**
282
- * Product bump tab
283
- *
284
- * @param array $options options.
285
- * @param int $post_id post ID.
286
- */
287
- function tab_product_bump( $options, $post_id ) {
288
- ?>
289
- <div class="wcf-product-order-bump wcf-tab-content widefat">
290
- <?php
291
- if ( ! _is_cartflows_pro() ) {
292
-
293
- echo wcf()->meta->get_description_field(
294
- array(
295
- 'name' => 'wcf-upgrade-to-pro',
296
- /* translators: %s: link */
297
- 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
298
- )
299
- );
300
- }
301
- ?>
302
-
303
- <?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
304
- </div>
305
- <?php
306
- }
307
- /**
308
- * Tab custom fields
309
- *
310
- * @param array $options options.
311
- * @param int $post_id post ID.
312
- */
313
- function tab_custom_fields( $options, $post_id ) {
314
- ?>
315
- <div class="wcf-checkout-custom-fields wcf-tab-content widefat">
316
- <?php
317
- /* Custom Checkout Fields Section */
318
-
319
- if ( ! _is_cartflows_pro() ) {
320
-
321
- echo wcf()->meta->get_description_field(
322
- array(
323
- 'name' => 'wcf-upgrade-to-pro',
324
- /* translators: %s: link */
325
- 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
326
- )
327
- );
328
- }
329
- ?>
330
- <?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
331
- </div>
332
- <?php
333
- }
334
-
335
- /**
336
- * Tab style
337
- *
338
- * @param array $options options.
339
- * @param int $post_id post ID.
340
- */
341
- function tab_style( $options, $post_id ) {
342
- ?>
343
-
344
- <div class="wcf-checkout-style wcf-tab-content widefat">
345
- <div class="wcf-cs-fields">
346
- <div class="wcf-cs-checkbox-field">
347
- <?php
348
-
349
- $layout_pro_option = array();
350
-
351
- if ( ! _is_cartflows_pro() ) {
352
- $layout_pro_option = array(
353
- 'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
354
- );
355
- }
356
-
357
- echo wcf()->meta->get_select_field(
358
- array(
359
- 'label' => __( 'Checkout Skin', 'cartflows' ),
360
- 'name' => 'wcf-checkout-layout',
361
- 'value' => $options['wcf-checkout-layout'],
362
- 'options' => array(
363
- 'one-column' => __( 'One Column', 'cartflows' ),
364
- 'two-column' => __( 'Two Column', 'cartflows' ),
365
- ),
366
- 'pro-options' => $layout_pro_option,
367
-
368
- )
369
- );
370
-
371
- echo wcf()->meta->get_color_picker_field(
372
- array(
373
- 'label' => __( 'Primary Color', 'cartflows' ),
374
- 'name' => 'wcf-primary-color',
375
- 'value' => $options['wcf-primary-color'],
376
- )
377
- );
378
-
379
- echo wcf()->meta->get_font_family_field(
380
- array(
381
- 'for' => 'wcf-base',
382
- 'label' => __( 'Font Family', 'cartflows' ),
383
- 'name' => 'wcf-base-font-family',
384
- 'value' => $options['wcf-base-font-family'],
385
- )
386
- );
387
-
388
- echo wcf()->meta->get_checkbox_field(
389
- array(
390
- 'label' => __( 'Advance Options', 'cartflows' ),
391
- 'name' => 'wcf-advance-options-fields',
392
- 'value' => $options['wcf-advance-options-fields'],
393
- 'after' => 'Enable',
394
- )
395
- );
396
- ?>
397
- </div>
398
- <div class="wcf-cs-fields-options">
399
- <?php
400
- echo wcf()->meta->get_section(
401
- array(
402
- 'label' => __( 'Heading', 'cartflows' ),
403
- )
404
- );
405
-
406
- echo wcf()->meta->get_color_picker_field(
407
- array(
408
- 'label' => __( 'Heading Color', 'cartflows' ),
409
- 'name' => 'wcf-heading-color',
410
- 'value' => $options['wcf-heading-color'],
411
- )
412
- );
413
-
414
- echo wcf()->meta->get_font_family_field(
415
- array(
416
- 'for' => 'wcf-heading',
417
- 'label' => __( 'Font Family', 'cartflows' ),
418
- 'name' => 'wcf-heading-font-family',
419
- 'value' => $options['wcf-heading-font-family'],
420
- )
421
- );
422
-
423
- echo wcf()->meta->get_font_weight_field(
424
- array(
425
- 'for' => 'wcf-heading',
426
- 'label' => __( 'Font Weight', 'cartflows' ),
427
- 'name' => 'wcf-heading-font-weight',
428
- 'value' => $options['wcf-heading-font-weight'],
429
- )
430
- );
431
-
432
- echo wcf()->meta->get_section(
433
- array(
434
- 'label' => __( 'Input Fields', 'cartflows' ),
435
- )
436
- );
437
-
438
- $fields_skin_pro_option = array();
439
-
440
- if ( ! _is_cartflows_pro() ) {
441
- $fields_skin_pro_option = array(
442
- 'skin-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
443
- );
444
- }
445
-
446
- echo wcf()->meta->get_select_field(
447
- array(
448
- 'label' => __( 'Style', 'cartflows' ),
449
- 'name' => 'wcf-fields-skins',
450
- 'value' => $options['wcf-fields-skins'],
451
- 'options' => array(
452
- 'default' => __( 'Default', 'cartflows' ),
453
- 'style-one' => __( 'Floating Labels', 'cartflows' ),
454
- ),
455
- 'pro-options' => $fields_skin_pro_option,
456
-
457
- )
458
- );
459
-
460
- echo wcf()->meta->get_font_family_field(
461
- array(
462
- 'for' => 'wcf-input',
463
- 'label' => __( 'Font Family', 'cartflows' ),
464
- 'name' => 'wcf-input-font-family',
465
- 'value' => $options['wcf-input-font-family'],
466
- )
467
- );
468
-
469
- echo wcf()->meta->get_font_weight_field(
470
- array(
471
- 'for' => 'wcf-input',
472
- 'label' => __( 'Font Weight', 'cartflows' ),
473
- 'name' => 'wcf-input-font-weight',
474
- 'value' => $options['wcf-input-font-weight'],
475
- )
476
- );
477
-
478
- echo wcf()->meta->get_select_field(
479
- array(
480
- 'label' => __( 'Size', 'cartflows' ),
481
- 'name' => 'wcf-input-field-size',
482
- 'value' => $options['wcf-input-field-size'],
483
- 'options' => array(
484
- '33px' => __( 'Extra Small', 'cartflows' ),
485
- '38px' => __( 'Small', 'cartflows' ),
486
- '44px' => __( 'Medium', 'cartflows' ),
487
- '58px' => __( 'Large', 'cartflows' ),
488
- '68px' => __( 'Extra Large', 'cartflows' ),
489
- 'custom' => __( 'Custom', 'cartflows' ),
490
- ),
491
- )
492
- );
493
-
494
- echo wcf()->meta->get_number_field(
495
- array(
496
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
497
- 'name' => 'wcf-field-tb-padding',
498
- 'value' => $options['wcf-field-tb-padding'],
499
- )
500
- );
501
-
502
- echo wcf()->meta->get_number_field(
503
- array(
504
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
505
- 'name' => 'wcf-field-lr-padding',
506
- 'value' => $options['wcf-field-lr-padding'],
507
- )
508
- );
509
-
510
- echo wcf()->meta->get_color_picker_field(
511
- array(
512
- 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
513
- 'name' => 'wcf-field-color',
514
- 'value' => $options['wcf-field-color'],
515
- )
516
- );
517
-
518
- echo wcf()->meta->get_color_picker_field(
519
- array(
520
- 'label' => __( 'Background Color', 'cartflows' ),
521
- 'name' => 'wcf-field-bg-color',
522
- 'value' => $options['wcf-field-bg-color'],
523
- )
524
- );
525
-
526
- echo wcf()->meta->get_color_picker_field(
527
- array(
528
- 'label' => __( 'Border Color', 'cartflows' ),
529
- 'name' => 'wcf-field-border-color',
530
- 'value' => $options['wcf-field-border-color'],
531
- )
532
- );
533
- echo wcf()->meta->get_color_picker_field(
534
- array(
535
- 'label' => __( 'Label Color', 'cartflows' ),
536
- 'name' => 'wcf-field-label-color',
537
- 'value' => $options['wcf-field-label-color'],
538
- )
539
- );
540
-
541
- ?>
542
- </div>
543
- <div class="wcf-cs-button-options">
544
- <?php
545
-
546
- echo wcf()->meta->get_section(
547
- array(
548
- 'label' => __( 'Buttons', 'cartflows' ),
549
- )
550
- );
551
-
552
- echo wcf()->meta->get_font_family_field(
553
- array(
554
- 'for' => 'wcf-button',
555
- 'label' => __( 'Font Family', 'cartflows' ),
556
- 'name' => 'wcf-button-font-family',
557
- 'value' => $options['wcf-button-font-family'],
558
- )
559
- );
560
-
561
- echo wcf()->meta->get_font_weight_field(
562
- array(
563
- 'for' => 'wcf-button',
564
- 'label' => __( 'Font Weight', 'cartflows' ),
565
- 'name' => 'wcf-button-font-weight',
566
- 'value' => $options['wcf-button-font-weight'],
567
- )
568
- );
569
-
570
- echo wcf()->meta->get_select_field(
571
- array(
572
- 'label' => __( 'Size', 'cartflows' ),
573
- 'name' => 'wcf-input-button-size',
574
- 'value' => $options['wcf-input-button-size'],
575
- 'options' => array(
576
- '33px' => __( 'Extra Small', 'cartflows' ),
577
- '38px' => __( 'Small', 'cartflows' ),
578
- '44px' => __( 'Medium', 'cartflows' ),
579
- '58px' => __( 'Large', 'cartflows' ),
580
- '68px' => __( 'Extra Large', 'cartflows' ),
581
- 'custom' => __( 'Custom', 'cartflows' ),
582
- ),
583
- )
584
- );
585
-
586
- echo wcf()->meta->get_number_field(
587
- array(
588
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
589
- 'name' => 'wcf-submit-tb-padding',
590
- 'value' => $options['wcf-submit-tb-padding'],
591
- )
592
- );
593
-
594
- echo wcf()->meta->get_number_field(
595
- array(
596
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
597
- 'name' => 'wcf-submit-lr-padding',
598
- 'value' => $options['wcf-submit-lr-padding'],
599
- )
600
- );
601
-
602
- echo wcf()->meta->get_color_picker_field(
603
- array(
604
- 'label' => __( 'Text Color', 'cartflows' ),
605
- 'name' => 'wcf-submit-color',
606
- 'value' => $options['wcf-submit-color'],
607
- )
608
- );
609
-
610
- echo wcf()->meta->get_color_picker_field(
611
- array(
612
- 'label' => __( 'Text Hover Color', 'cartflows' ),
613
- 'name' => 'wcf-submit-hover-color',
614
- 'value' => $options['wcf-submit-hover-color'],
615
- )
616
- );
617
-
618
- echo wcf()->meta->get_color_picker_field(
619
- array(
620
- 'label' => __( 'Background Color', 'cartflows' ),
621
- 'name' => 'wcf-submit-bg-color',
622
- 'value' => $options['wcf-submit-bg-color'],
623
- )
624
- );
625
-
626
- echo wcf()->meta->get_color_picker_field(
627
- array(
628
- 'label' => __( 'Background Hover Color', 'cartflows' ),
629
- 'name' => 'wcf-submit-bg-hover-color',
630
- 'value' => $options['wcf-submit-bg-hover-color'],
631
- )
632
- );
633
-
634
- echo wcf()->meta->get_color_picker_field(
635
- array(
636
- 'label' => __( 'Border Color', 'cartflows' ),
637
- 'name' => 'wcf-submit-border-color',
638
- 'value' => $options['wcf-submit-border-color'],
639
- )
640
- );
641
-
642
- echo wcf()->meta->get_color_picker_field(
643
- array(
644
- 'label' => __( 'Border Hover Color', 'cartflows' ),
645
- 'name' => 'wcf-submit-border-hover-color',
646
- 'value' => $options['wcf-submit-border-hover-color'],
647
- )
648
- );
649
-
650
- ?>
651
- </div>
652
- <div class="wcf-cs-section-options">
653
- <?php
654
-
655
- echo wcf()->meta->get_section(
656
- array(
657
- 'label' => __( 'Sections', 'cartflows' ),
658
- )
659
- );
660
-
661
- echo wcf()->meta->get_color_picker_field(
662
- array(
663
- 'label' => __( 'Highlight Area Background Color', 'cartflows' ),
664
- 'name' => 'wcf-hl-bg-color',
665
- 'value' => $options['wcf-hl-bg-color'],
666
- )
667
- );
668
-
669
- echo wcf()->meta->get_hidden_field(
670
- array(
671
- 'name' => 'wcf-field-google-font-url',
672
- 'value' => $options['wcf-field-google-font-url'],
673
- )
674
- );
675
- ?>
676
- </div>
677
- <?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
678
- </div>
679
- </div>
680
- <?php
681
- }
682
-
683
-
684
- /**
685
- * Tab Header (Used for add logo into header)
686
- *
687
- * @param array $options options.
688
- * @param int $post_id post ID.
689
- */
690
- function tab_header_content( $options, $post_id ) {
691
- ?>
692
-
693
- <div class="wcf-checkout-header wcf-tab-content widefat">
694
- <?php
695
-
696
- $layout_pro_option = array();
697
-
698
- echo wcf()->meta->get_image_field(
699
- array(
700
- 'name' => 'wcf-header-logo-image',
701
- 'value' => $options['wcf-header-logo-image'],
702
- 'label' => __( 'Header Logo', 'cartflows' ),
703
- )
704
- );
705
-
706
- echo wcf()->meta->get_number_field(
707
- array(
708
- 'name' => 'wcf-header-logo-width',
709
- 'value' => $options['wcf-header-logo-width'],
710
- 'label' => __( 'Logo Width (In px)', 'cartflows' ),
711
- )
712
- );
713
- ?>
714
- <?php do_action( 'cartflows_checkout_header_tab_content', $options, $post_id ); ?>
715
- </div>
716
- <?php
717
- }
718
- /**
719
- * Get metabox options
720
- *
721
- * @param int $post_id post ID.
722
- */
723
- public static function get_meta_option( $post_id ) {
724
-
725
- if ( null === self::$meta_option ) {
726
-
727
- /**
728
- * Set metabox options
729
- *
730
- * @see http://php.net/manual/en/filter.filters.sanitize.php
731
- */
732
- self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
733
- }
734
-
735
- return self::$meta_option;
736
- }
737
-
738
- /**
739
- * Metabox Save
740
- *
741
- * @param number $post_id Post ID.
742
- * @return void
743
- */
744
- function save_meta_box( $post_id ) {
745
-
746
- // Checks save status.
747
- $is_autosave = wp_is_post_autosave( $post_id );
748
- $is_revision = wp_is_post_revision( $post_id );
749
-
750
- $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( $_POST['nonce-checkout-step-meta'], 'save-nonce-checkout-step-meta' ) ) ? true : false;
751
-
752
- // Exits script depending on save status.
753
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
754
- return;
755
- }
756
-
757
- wcf()->options->save_checkout_fields( $post_id );
758
- }
759
-
760
- }
761
-
762
- /**
763
- * Kicking this off by calling 'get_instance()' method
764
- */
765
- Cartflows_Checkout_Meta::get_instance();
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Checkout post meta
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Checkout_Meta extends Cartflows_Meta {
12
+
13
+ /**
14
+ * Instance
15
+ *
16
+ * @var $instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Meta Option
22
+ *
23
+ * @var $meta_option
24
+ */
25
+ private static $meta_option = null;
26
+
27
+ /**
28
+ * Initiator
29
+ */
30
+ public static function get_instance() {
31
+ if ( ! isset( self::$instance ) ) {
32
+ self::$instance = new self;
33
+ }
34
+
35
+ return self::$instance;
36
+ }
37
+
38
+ /**
39
+ * Constructor
40
+ */
41
+ public function __construct() {
42
+
43
+ /* Init Metabox */
44
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
+ }
47
+
48
+ /**
49
+ * Init Metabox
50
+ */
51
+ public function init_metabox() {
52
+
53
+ add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
+ }
56
+
57
+ /**
58
+ * Setup Metabox
59
+ */
60
+ function setup_meta_box() {
61
+
62
+ // Get all posts.
63
+ $post_types = get_post_types();
64
+
65
+ if ( _is_wcf_checkout_type() ) {
66
+ add_meta_box(
67
+ 'wcf-checkout-settings', // Id.
68
+ __( 'Checkout Layout', 'cartflows' ), // Title.
69
+ array( $this, 'markup_meta_box' ), // Callback.
70
+ wcf()->utils->get_step_post_type(), // Post_type.
71
+ 'normal', // Context.
72
+ 'high' // Priority.
73
+ );
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Metabox Markup
79
+ *
80
+ * @param object $post Post object.
81
+ * @return void
82
+ */
83
+ function markup_meta_box( $post ) {
84
+
85
+ wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
86
+
87
+ $stored = get_post_meta( $post->ID );
88
+
89
+ $checkout_meta = self::get_meta_option( $post->ID );
90
+
91
+ // Set stored and override defaults.
92
+ foreach ( $stored as $key => $value ) {
93
+ if ( array_key_exists( $key, $checkout_meta ) ) {
94
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
95
+ } else {
96
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
97
+ }
98
+ }
99
+
100
+ // Get defaults.
101
+ $meta = self::get_meta_option( $post->ID );
102
+ $checkout_data = array();
103
+
104
+ foreach ( $meta as $key => $value ) {
105
+
106
+ $checkout_data[ $key ] = $meta[ $key ]['default'];
107
+ }
108
+
109
+ /*
110
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
111
+
112
+ foreach ( $billing_fields as $key => $value ) {
113
+
114
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
115
+ }
116
+
117
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
118
+
119
+ foreach ( $shipping_fields as $key => $value ) {
120
+
121
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
122
+ }
123
+
124
+ $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
125
+
126
+ foreach ( $additional_fields as $key => $value ) {
127
+
128
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
129
+ }
130
+ */
131
+
132
+ do_action( 'wcf_checkout_settings_markup_before' );
133
+ $this->tabs_markup( $checkout_data, $post->ID );
134
+ do_action( 'wcf_checkout_settings_markup_after' );
135
+ }
136
+
137
+ /**
138
+ * Page Header Tabs
139
+ *
140
+ * @param array $options options.
141
+ * @param int $post_id post ID.
142
+ */
143
+ function tabs_markup( $options, $post_id ) {
144
+
145
+ $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
146
+
147
+ if ( empty( $active_tab ) ) {
148
+ $active_tab = 'wcf-checkout-shortcodes';
149
+ }
150
+
151
+ $tabs = apply_filters(
152
+ 'cartflows_checkout_tabs',
153
+ array(
154
+ array(
155
+ 'title' => __( 'Shortcodes', 'cartflows' ),
156
+ 'id' => 'wcf-checkout-shortcodes',
157
+ 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
158
+ 'icon' => 'dashicons-editor-code',
159
+ ),
160
+ array(
161
+ 'title' => __( 'Select Product', 'cartflows' ),
162
+ 'id' => 'wcf-checkout-general',
163
+ 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
164
+ 'icon' => 'dashicons-info',
165
+ ),
166
+ array(
167
+ 'title' => __( 'Order Bump', 'cartflows' ),
168
+ 'id' => 'wcf-product-order-bump',
169
+ 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
170
+ 'icon' => 'dashicons-cart',
171
+ ),
172
+ array(
173
+ 'title' => __( 'Checkout Design', 'cartflows' ),
174
+ 'id' => 'wcf-checkout-style',
175
+ 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
176
+ 'icon' => 'dashicons-admin-customizer',
177
+ ),
178
+ array(
179
+ 'title' => __( 'Checkout Fields', 'cartflows' ),
180
+ 'id' => 'wcf-checkout-custom-fields',
181
+ 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
182
+ 'icon' => 'dashicons-welcome-widgets-menus',
183
+ ),
184
+ array(
185
+ 'title' => __( 'Logo (Optional)', 'cartflows' ),
186
+ 'id' => 'wcf-checkout-header',
187
+ 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
188
+ 'icon' => 'dashicons-format-image',
189
+ ),
190
+ array(
191
+ 'title' => __( 'Custom Script', 'cartflows' ),
192
+ 'id' => 'wcf-checkout-custom-script-header',
193
+ 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
194
+ 'icon' => 'dashicons-format-aside',
195
+ ),
196
+ ),
197
+ $active_tab
198
+ );
199
+
200
+ ?>
201
+ <div class="wcf-checkout-table wcf-metabox-wrap widefat">
202
+ <div class="wcf-table-container">
203
+ <div class="wcf-column-left">
204
+ <div class="wcf-tab-wrapper">
205
+
206
+ <?php foreach ( $tabs as $key => $tab ) { ?>
207
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
208
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
209
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
210
+ </div>
211
+ <?php } ?>
212
+
213
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
214
+ </div>
215
+ </div>
216
+ <div class="wcf-column-right">
217
+ <?php $this->tab_shortcodes( $options, $post_id ); ?>
218
+ <?php $this->tab_general( $options, $post_id ); ?>
219
+ <?php $this->tab_style( $options, $post_id ); ?>
220
+ <?php $this->tab_product_bump( $options, $post_id ); ?>
221
+ <?php $this->tab_custom_fields( $options, $post_id ); ?>
222
+ <?php $this->tab_header_content( $options, $post_id ); ?>
223
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
224
+ <?php do_action( 'cartflows_checkout_tabs_content', $options, $post_id ); ?>
225
+ <?php $this->right_column_footer( $options, $post_id ); ?>
226
+ </div>
227
+ </div>
228
+ </div>
229
+
230
+ <?php
231
+ }
232
+
233
+ /**
234
+ * Shortcodes tab
235
+ *
236
+ * @param array $options options.
237
+ * @param int $post_id post ID.
238
+ */
239
+ function tab_shortcodes( $options, $post_id ) {
240
+ ?>
241
+ <div class="wcf-checkout-shortcodes wcf-tab-content widefat">
242
+
243
+ <?php
244
+
245
+ echo wcf()->meta->get_shortcode_field(
246
+ array(
247
+ 'label' => 'Checkout Page',
248
+ 'name' => 'wcf-checkout-shortcode',
249
+ 'content' => '[cartflows_checkout]',
250
+ 'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
251
+ )
252
+ );
253
+ ?>
254
+ </div>
255
+ <?php
256
+ }
257
+
258
+
259
+ /**
260
+ * General tab
261
+ *
262
+ * @param array $options options.
263
+ * @param int $post_id post ID.
264
+ */
265
+ function tab_general( $options, $post_id ) {
266
+ ?>
267
+ <div class="wcf-checkout-general wcf-tab-content widefat">
268
+
269
+ <?php
270
+
271
+ echo wcf()->meta->get_product_selection_repeater(
272
+ array(
273
+ 'name' => 'wcf-checkout-products',
274
+ 'value' => $options['wcf-checkout-products'],
275
+ 'allow_clear' => true,
276
+ )
277
+ );
278
+
279
+ do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
280
+
281
+ ?>
282
+ </div>
283
+ <?php
284
+ }
285
+
286
+ /**
287
+ * Product bump tab
288
+ *
289
+ * @param array $options options.
290
+ * @param int $post_id post ID.
291
+ */
292
+ function tab_product_bump( $options, $post_id ) {
293
+ ?>
294
+ <div class="wcf-product-order-bump wcf-tab-content widefat">
295
+ <?php
296
+ if ( ! _is_cartflows_pro() ) {
297
+
298
+ echo wcf()->meta->get_description_field(
299
+ array(
300
+ 'name' => 'wcf-upgrade-to-pro',
301
+ /* translators: %s: link */
302
+ 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
303
+ )
304
+ );
305
+ }
306
+ ?>
307
+
308
+ <?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
309
+ </div>
310
+ <?php
311
+ }
312
+ /**
313
+ * Tab custom fields
314
+ *
315
+ * @param array $options options.
316
+ * @param int $post_id post ID.
317
+ */
318
+ function tab_custom_fields( $options, $post_id ) {
319
+ ?>
320
+ <div class="wcf-checkout-custom-fields wcf-tab-content widefat">
321
+ <?php
322
+ /* Custom Checkout Fields Section */
323
+
324
+ if ( ! _is_cartflows_pro() ) {
325
+
326
+ echo wcf()->meta->get_description_field(
327
+ array(
328
+ 'name' => 'wcf-upgrade-to-pro',
329
+ /* translators: %s: link */
330
+ 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
331
+ )
332
+ );
333
+ }
334
+ ?>
335
+ <?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
336
+ </div>
337
+ <?php
338
+ }
339
+
340
+ /**
341
+ * Tab style
342
+ *
343
+ * @param array $options options.
344
+ * @param int $post_id post ID.
345
+ */
346
+ function tab_style( $options, $post_id ) {
347
+ ?>
348
+
349
+ <div class="wcf-checkout-style wcf-tab-content widefat">
350
+ <div class="wcf-cs-fields">
351
+ <div class="wcf-cs-checkbox-field">
352
+ <?php
353
+
354
+ $layout_pro_option = array();
355
+
356
+ if ( ! _is_cartflows_pro() ) {
357
+ $layout_pro_option = array(
358
+ 'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
359
+ 'two-step' => __( 'Two Step (Available in CartFlows Pro) ', 'cartflows' ),
360
+ );
361
+ }
362
+
363
+ echo wcf()->meta->get_select_field(
364
+ array(
365
+ 'label' => __( 'Checkout Skin', 'cartflows' ),
366
+ 'name' => 'wcf-checkout-layout',
367
+ 'value' => $options['wcf-checkout-layout'],
368
+ 'options' => array(
369
+ 'one-column' => __( 'One Column', 'cartflows' ),
370
+ 'two-column' => __( 'Two Column', 'cartflows' ),
371
+ 'two-step' => __( 'Two Step', 'cartflows' ),
372
+ ),
373
+ 'pro-options' => $layout_pro_option,
374
+
375
+ )
376
+ );
377
+
378
+ echo wcf()->meta->get_color_picker_field(
379
+ array(
380
+ 'label' => __( 'Primary Color', 'cartflows' ),
381
+ 'name' => 'wcf-primary-color',
382
+ 'value' => $options['wcf-primary-color'],
383
+ )
384
+ );
385
+
386
+ echo wcf()->meta->get_font_family_field(
387
+ array(
388
+ 'for' => 'wcf-base',
389
+ 'label' => __( 'Font Family', 'cartflows' ),
390
+ 'name' => 'wcf-base-font-family',
391
+ 'value' => $options['wcf-base-font-family'],
392
+ )
393
+ );
394
+
395
+ echo wcf()->meta->get_checkbox_field(
396
+ array(
397
+ 'label' => __( 'Advance Options', 'cartflows' ),
398
+ 'name' => 'wcf-advance-options-fields',
399
+ 'value' => $options['wcf-advance-options-fields'],
400
+ 'after' => 'Enable',
401
+ )
402
+ );
403
+ ?>
404
+ </div>
405
+ <div class="wcf-cs-fields-options">
406
+ <?php
407
+ echo wcf()->meta->get_section(
408
+ array(
409
+ 'label' => __( 'Heading', 'cartflows' ),
410
+ )
411
+ );
412
+
413
+ echo wcf()->meta->get_color_picker_field(
414
+ array(
415
+ 'label' => __( 'Heading Color', 'cartflows' ),
416
+ 'name' => 'wcf-heading-color',
417
+ 'value' => $options['wcf-heading-color'],
418
+ )
419
+ );
420
+
421
+ echo wcf()->meta->get_font_family_field(
422
+ array(
423
+ 'for' => 'wcf-heading',
424
+ 'label' => __( 'Font Family', 'cartflows' ),
425
+ 'name' => 'wcf-heading-font-family',
426
+ 'value' => $options['wcf-heading-font-family'],
427
+ )
428
+ );
429
+
430
+ echo wcf()->meta->get_font_weight_field(
431
+ array(
432
+ 'for' => 'wcf-heading',
433
+ 'label' => __( 'Font Weight', 'cartflows' ),
434
+ 'name' => 'wcf-heading-font-weight',
435
+ 'value' => $options['wcf-heading-font-weight'],
436
+ )
437
+ );
438
+
439
+ echo wcf()->meta->get_section(
440
+ array(
441
+ 'label' => __( 'Input Fields', 'cartflows' ),
442
+ )
443
+ );
444
+
445
+ $fields_skin_pro_option = array();
446
+
447
+ if ( ! _is_cartflows_pro() ) {
448
+ $fields_skin_pro_option = array(
449
+ 'skin-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
450
+ );
451
+ }
452
+
453
+ echo wcf()->meta->get_select_field(
454
+ array(
455
+ 'label' => __( 'Style', 'cartflows' ),
456
+ 'name' => 'wcf-fields-skins',
457
+ 'value' => $options['wcf-fields-skins'],
458
+ 'options' => array(
459
+ 'default' => __( 'Default', 'cartflows' ),
460
+ 'style-one' => __( 'Floating Labels', 'cartflows' ),
461
+ ),
462
+ 'pro-options' => $fields_skin_pro_option,
463
+
464
+ )
465
+ );
466
+
467
+ echo wcf()->meta->get_font_family_field(
468
+ array(
469
+ 'for' => 'wcf-input',
470
+ 'label' => __( 'Font Family', 'cartflows' ),
471
+ 'name' => 'wcf-input-font-family',
472
+ 'value' => $options['wcf-input-font-family'],
473
+ )
474
+ );
475
+
476
+ echo wcf()->meta->get_font_weight_field(
477
+ array(
478
+ 'for' => 'wcf-input',
479
+ 'label' => __( 'Font Weight', 'cartflows' ),
480
+ 'name' => 'wcf-input-font-weight',
481
+ 'value' => $options['wcf-input-font-weight'],
482
+ )
483
+ );
484
+
485
+ echo wcf()->meta->get_select_field(
486
+ array(
487
+ 'label' => __( 'Size', 'cartflows' ),
488
+ 'name' => 'wcf-input-field-size',
489
+ 'value' => $options['wcf-input-field-size'],
490
+ 'options' => array(
491
+ '33px' => __( 'Extra Small', 'cartflows' ),
492
+ '38px' => __( 'Small', 'cartflows' ),
493
+ '44px' => __( 'Medium', 'cartflows' ),
494
+ '58px' => __( 'Large', 'cartflows' ),
495
+ '68px' => __( 'Extra Large', 'cartflows' ),
496
+ 'custom' => __( 'Custom', 'cartflows' ),
497
+ ),
498
+ )
499
+ );
500
+
501
+ echo wcf()->meta->get_number_field(
502
+ array(
503
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
504
+ 'name' => 'wcf-field-tb-padding',
505
+ 'value' => $options['wcf-field-tb-padding'],
506
+ )
507
+ );
508
+
509
+ echo wcf()->meta->get_number_field(
510
+ array(
511
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
512
+ 'name' => 'wcf-field-lr-padding',
513
+ 'value' => $options['wcf-field-lr-padding'],
514
+ )
515
+ );
516
+
517
+ echo wcf()->meta->get_color_picker_field(
518
+ array(
519
+ 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
520
+ 'name' => 'wcf-field-color',
521
+ 'value' => $options['wcf-field-color'],
522
+ )
523
+ );
524
+
525
+ echo wcf()->meta->get_color_picker_field(
526
+ array(
527
+ 'label' => __( 'Background Color', 'cartflows' ),
528
+ 'name' => 'wcf-field-bg-color',
529
+ 'value' => $options['wcf-field-bg-color'],
530
+ )
531
+ );
532
+
533
+ echo wcf()->meta->get_color_picker_field(
534
+ array(
535
+ 'label' => __( 'Border Color', 'cartflows' ),
536
+ 'name' => 'wcf-field-border-color',
537
+ 'value' => $options['wcf-field-border-color'],
538
+ )
539
+ );
540
+ echo wcf()->meta->get_color_picker_field(
541
+ array(
542
+ 'label' => __( 'Label Color', 'cartflows' ),
543
+ 'name' => 'wcf-field-label-color',
544
+ 'value' => $options['wcf-field-label-color'],
545
+ )
546
+ );
547
+
548
+ ?>
549
+ </div>
550
+ <div class="wcf-cs-button-options">
551
+ <?php
552
+
553
+ echo wcf()->meta->get_section(
554
+ array(
555
+ 'label' => __( 'Buttons', 'cartflows' ),
556
+ )
557
+ );
558
+
559
+ echo wcf()->meta->get_font_family_field(
560
+ array(
561
+ 'for' => 'wcf-button',
562
+ 'label' => __( 'Font Family', 'cartflows' ),
563
+ 'name' => 'wcf-button-font-family',
564
+ 'value' => $options['wcf-button-font-family'],
565
+ )
566
+ );
567
+
568
+ echo wcf()->meta->get_font_weight_field(
569
+ array(
570
+ 'for' => 'wcf-button',
571
+ 'label' => __( 'Font Weight', 'cartflows' ),
572
+ 'name' => 'wcf-button-font-weight',
573
+ 'value' => $options['wcf-button-font-weight'],
574
+ )
575
+ );
576
+
577
+ echo wcf()->meta->get_select_field(
578
+ array(
579
+ 'label' => __( 'Size', 'cartflows' ),
580
+ 'name' => 'wcf-input-button-size',
581
+ 'value' => $options['wcf-input-button-size'],
582
+ 'options' => array(
583
+ '33px' => __( 'Extra Small', 'cartflows' ),
584
+ '38px' => __( 'Small', 'cartflows' ),
585
+ '44px' => __( 'Medium', 'cartflows' ),
586
+ '58px' => __( 'Large', 'cartflows' ),
587
+ '68px' => __( 'Extra Large', 'cartflows' ),
588
+ 'custom' => __( 'Custom', 'cartflows' ),
589
+ ),
590
+ )
591
+ );
592
+
593
+ echo wcf()->meta->get_number_field(
594
+ array(
595
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
596
+ 'name' => 'wcf-submit-tb-padding',
597
+ 'value' => $options['wcf-submit-tb-padding'],
598
+ )
599
+ );
600
+
601
+ echo wcf()->meta->get_number_field(
602
+ array(
603
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
604
+ 'name' => 'wcf-submit-lr-padding',
605
+ 'value' => $options['wcf-submit-lr-padding'],
606
+ )
607
+ );
608
+
609
+ echo wcf()->meta->get_color_picker_field(
610
+ array(
611
+ 'label' => __( 'Text Color', 'cartflows' ),
612
+ 'name' => 'wcf-submit-color',
613
+ 'value' => $options['wcf-submit-color'],
614
+ )
615
+ );
616
+
617
+ echo wcf()->meta->get_color_picker_field(
618
+ array(
619
+ 'label' => __( 'Text Hover Color', 'cartflows' ),
620
+ 'name' => 'wcf-submit-hover-color',
621
+ 'value' => $options['wcf-submit-hover-color'],
622
+ )
623
+ );
624
+
625
+ echo wcf()->meta->get_color_picker_field(
626
+ array(
627
+ 'label' => __( 'Background Color', 'cartflows' ),
628
+ 'name' => 'wcf-submit-bg-color',
629
+ 'value' => $options['wcf-submit-bg-color'],
630
+ )
631
+ );
632
+
633
+ echo wcf()->meta->get_color_picker_field(
634
+ array(
635
+ 'label' => __( 'Background Hover Color', 'cartflows' ),
636
+ 'name' => 'wcf-submit-bg-hover-color',
637
+ 'value' => $options['wcf-submit-bg-hover-color'],
638
+ )
639
+ );
640
+
641
+ echo wcf()->meta->get_color_picker_field(
642
+ array(
643
+ 'label' => __( 'Border Color', 'cartflows' ),
644
+ 'name' => 'wcf-submit-border-color',
645
+ 'value' => $options['wcf-submit-border-color'],
646
+ )
647
+ );
648
+
649
+ echo wcf()->meta->get_color_picker_field(
650
+ array(
651
+ 'label' => __( 'Border Hover Color', 'cartflows' ),
652
+ 'name' => 'wcf-submit-border-hover-color',
653
+ 'value' => $options['wcf-submit-border-hover-color'],
654
+ )
655
+ );
656
+
657
+ ?>
658
+ </div>
659
+ <div class="wcf-cs-section-options">
660
+ <?php
661
+
662
+ echo wcf()->meta->get_section(
663
+ array(
664
+ 'label' => __( 'Sections', 'cartflows' ),
665
+ )
666
+ );
667
+
668
+ echo wcf()->meta->get_color_picker_field(
669
+ array(
670
+ 'label' => __( 'Highlight Area Background Color', 'cartflows' ),
671
+ 'name' => 'wcf-hl-bg-color',
672
+ 'value' => $options['wcf-hl-bg-color'],
673
+ )
674
+ );
675
+
676
+ echo wcf()->meta->get_hidden_field(
677
+ array(
678
+ 'name' => 'wcf-field-google-font-url',
679
+ 'value' => $options['wcf-field-google-font-url'],
680
+ )
681
+ );
682
+ ?>
683
+ </div>
684
+ <?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
685
+ </div>
686
+ </div>
687
+ <?php
688
+ }
689
+
690
+
691
+ /**
692
+ * Tab Header (Used for add logo into header)
693
+ *
694
+ * @param array $options options.
695
+ * @param int $post_id post ID.
696
+ */
697
+ function tab_header_content( $options, $post_id ) {
698
+ ?>
699
+
700
+ <div class="wcf-checkout-header wcf-tab-content widefat">
701
+ <?php
702
+
703
+ $layout_pro_option = array();
704
+
705
+ echo wcf()->meta->get_image_field(
706
+ array(
707
+ 'name' => 'wcf-header-logo-image',
708
+ 'value' => $options['wcf-header-logo-image'],
709
+ 'label' => __( 'Header Logo', 'cartflows' ),
710
+ )
711
+ );
712
+
713
+ echo wcf()->meta->get_number_field(
714
+ array(
715
+ 'name' => 'wcf-header-logo-width',
716
+ 'value' => $options['wcf-header-logo-width'],
717
+ 'label' => __( 'Logo Width (In px)', 'cartflows' ),
718
+ )
719
+ );
720
+ ?>
721
+ <?php do_action( 'cartflows_checkout_header_tab_content', $options, $post_id ); ?>
722
+ </div>
723
+ <?php
724
+ }
725
+ /**
726
+ * Get metabox options
727
+ *
728
+ * @param int $post_id post ID.
729
+ */
730
+ public static function get_meta_option( $post_id ) {
731
+
732
+ if ( null === self::$meta_option ) {
733
+
734
+ /**
735
+ * Set metabox options
736
+ *
737
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
738
+ */
739
+ self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
740
+ }
741
+
742
+ return self::$meta_option;
743
+ }
744
+
745
+ /**
746
+ * Metabox Save
747
+ *
748
+ * @param number $post_id Post ID.
749
+ * @return void
750
+ */
751
+ function save_meta_box( $post_id ) {
752
+
753
+ // Checks save status.
754
+ $is_autosave = wp_is_post_autosave( $post_id );
755
+ $is_revision = wp_is_post_revision( $post_id );
756
+
757
+ $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( $_POST['nonce-checkout-step-meta'], 'save-nonce-checkout-step-meta' ) ) ? true : false;
758
+
759
+ // Exits script depending on save status.
760
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
761
+ return;
762
+ }
763
+
764
+ wcf()->options->save_checkout_fields( $post_id );
765
+ }
766
+
767
+ }
768
+
769
+ /**
770
+ * Kicking this off by calling 'get_instance()' method
771
+ */
772
+ Cartflows_Checkout_Meta::get_instance();
modules/checkout/templates/embed/checkout-template-simple.php CHANGED
@@ -1,33 +1,33 @@
1
- <?php
2
- /**
3
- * Checkout template
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
9
- $fields_skins = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-fields-skins' );
10
- ?>
11
- <div id="wcf-embed-checkout-form" class="wcf-embed-checkout-form wcf-embed-checkout-form-<?php echo $checkout_layout; ?> wcf-field-<?php echo $fields_skins; ?>">
12
- <!-- CHECKOUT SHORTCODE -->
13
- <?php do_action( 'cartflows_add_before_main_section', $checkout_layout ); ?>
14
-
15
- <?php
16
- $checkout_html = do_shortcode( '[woocommerce_checkout]' );
17
-
18
- if (
19
- empty( $checkout_html ) ||
20
- trim( $checkout_html ) == '<div class="woocommerce"></div>'
21
- ) {
22
-
23
- do_action( 'cartflows_checkout_cart_empty', $checkout_id );
24
-
25
- echo __( 'Your cart is currently empty.', 'cartflows' );
26
- } else {
27
- echo $checkout_html;
28
- }
29
- ?>
30
-
31
- <?php do_action( 'cartflows_add_after_main_section', $arg = '' ); ?>
32
- <!-- END CHECKOUT SHORTCODE -->
33
- </div>
1
+ <?php
2
+ /**
3
+ * Checkout template
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
9
+ $fields_skins = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-fields-skins' );
10
+ ?>
11
+ <div id="wcf-embed-checkout-form" class="wcf-embed-checkout-form wcf-embed-checkout-form-<?php echo $checkout_layout; ?> wcf-field-<?php echo $fields_skins; ?>">
12
+ <!-- CHECKOUT SHORTCODE -->
13
+ <?php do_action( 'cartflows_add_before_main_section', $checkout_layout ); ?>
14
+
15
+ <?php
16
+ $checkout_html = do_shortcode( '[woocommerce_checkout]' );
17
+
18
+ if (
19
+ empty( $checkout_html ) ||
20
+ trim( $checkout_html ) == '<div class="woocommerce"></div>'
21
+ ) {
22
+
23
+ do_action( 'cartflows_checkout_cart_empty', $checkout_id );
24
+
25
+ echo __( 'Your cart is currently empty.', 'cartflows' );
26
+ } else {
27
+ echo $checkout_html;
28
+ }
29
+ ?>
30
+
31
+ <?php do_action( 'cartflows_add_after_main_section', $arg = '' ); ?>
32
+ <!-- END CHECKOUT SHORTCODE -->
33
+ </div>
modules/flow/class-cartflows-flow.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
- /**
3
- * Flow
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- define( 'CARTFLOWS_FLOW_DIR', CARTFLOWS_DIR . 'modules/flow/' );
9
- define( 'CARTFLOWS_FLOW_URL', CARTFLOWS_URL . 'modules/flow/' );
10
-
11
- /**
12
- * Initial Setup
13
- *
14
- * @since 1.0.0
15
- */
16
- class Cartflows_Flow {
17
-
18
-
19
- /**
20
- * Member Variable
21
- *
22
- * @var object instance
23
- */
24
- private static $instance;
25
-
26
- /**
27
- * Initiator
28
- */
29
- public static function get_instance() {
30
- if ( ! isset( self::$instance ) ) {
31
- self::$instance = new self;
32
- }
33
- return self::$instance;
34
- }
35
-
36
- /**
37
- * Constructor function that initializes required actions and hooks
38
- */
39
- public function __construct() {
40
- require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-loader.php';
41
- require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-meta.php';
42
- }
43
- }
44
-
45
- /**
46
- * Kicking this off by calling 'get_instance()' method
47
- */
48
- Cartflows_Flow::get_instance();
1
+ <?php
2
+ /**
3
+ * Flow
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ define( 'CARTFLOWS_FLOW_DIR', CARTFLOWS_DIR . 'modules/flow/' );
9
+ define( 'CARTFLOWS_FLOW_URL', CARTFLOWS_URL . 'modules/flow/' );
10
+
11
+ /**
12
+ * Initial Setup
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Cartflows_Flow {
17
+
18
+
19
+ /**
20
+ * Member Variable
21
+ *
22
+ * @var object instance
23
+ */
24
+ private static $instance;
25
+
26
+ /**
27
+ * Initiator
28
+ */
29
+ public static function get_instance() {
30
+ if ( ! isset( self::$instance ) ) {
31
+ self::$instance = new self;
32
+ }
33
+ return self::$instance;
34
+ }
35
+
36
+ /**
37
+ * Constructor function that initializes required actions and hooks
38
+ */
39
+ public function __construct() {
40
+ require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-loader.php';
41
+ require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-meta.php';
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Kicking this off by calling 'get_instance()' method
47
+ */
48
+ Cartflows_Flow::get_instance();
modules/flow/classes/class-cartflows-flow-meta.php CHANGED
@@ -1,743 +1,743 @@
1
- <?php
2
- /**
3
- * Flow meta
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Flow_Meta {
12
-
13
-
14
- /**
15
- * Instance
16
- *
17
- * @var $instance
18
- */
19
- private static $instance;
20
-
21
- /**
22
- * Meta Option
23
- *
24
- * @var $meta_option
25
- */
26
- private static $meta_option;
27
-
28
- /**
29
- * Initiator
30
- */
31
- public static function get_instance() {
32
- if ( ! isset( self::$instance ) ) {
33
- self::$instance = new self;
34
- }
35
-
36
- return self::$instance;
37
- }
38
-
39
- /**
40
- * Constructor
41
- */
42
- public function __construct() {
43
-
44
- add_action( 'admin_head', array( $this, 'menu_highlight' ) );
45
-
46
- add_action( 'admin_init', array( $this, 'admin_init_actions' ) );
47
-
48
- /* Init Metabox */
49
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
50
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
51
-
52
- /* Add Scripts */
53
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 20 );
54
-
55
- add_action( 'wp_ajax_cartflows_setup_default_steps', array( $this, 'cartflows_setup_default_steps' ) );
56
- add_action( 'wp_ajax_cartflows_delete_flow_step', array( $this, 'cartflows_delete_flow_step' ) );
57
-
58
- add_action( 'wp_ajax_cartflows_reorder_flow_steps', array( $this, 'cartflows_reorder_flow_steps' ) );
59
-
60
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
61
-
62
- add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
63
- }
64
-
65
- /**
66
- * Display admin notices.
67
- *
68
- * @since 1.0.0
69
- *
70
- * @return void
71
- */
72
- function admin_notices() {
73
-
74
- if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type() ) {
75
- return;
76
- }
77
-
78
- $flow_id = get_post_meta( get_the_id(), 'wcf-flow-id', true );
79
- if ( $flow_id ) { ?>
80
- <div class="wcf-notice-back-edit-flow">
81
- <p>
82
- <a href="<?php echo esc_url( get_edit_post_link( $flow_id ) ); ?>" class="button button-primary button-hero" style="text-decoration: none;">
83
- <i class="dashicons dashicons-arrow-left-alt"></i>
84
- <?php _e( 'Back to edit Flow', 'cartflows' ); ?>
85
- </a>
86
- </p>
87
- </div>
88
- <?php
89
- }
90
- }
91
-
92
- /**
93
- * Initialize admin actions.
94
- *
95
- * @since 1.0.0
96
- *
97
- * @return void
98
- */
99
- function admin_init_actions() {
100
- add_action( 'before_delete_post', array( $this, 'step_post_sync' ) );
101
- add_action( 'wp_trash_post', array( $this, 'step_post_trash_sync' ) );
102
- add_action( 'untrashed_post', array( $this, 'step_post_untrash_sync' ) );
103
- }
104
-
105
- /**
106
- * Delete term data and steps data after deleting flow.
107
- *
108
- * @since 1.0.0
109
- * @param int $pid post id.
110
- *
111
- * @return void
112
- */
113
- function step_post_sync( $pid ) {
114
-
115
- global $post_type;
116
-
117
- if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) {
118
-
119
- $steps = get_post_meta( $pid, 'wcf-steps', true );
120
-
121
- if ( $steps && is_array( $steps ) ) {
122
- foreach ( $steps as $i => $step ) {
123
- wp_delete_post( $step['id'], true );
124
- }
125
- }
126
-
127
- $term_data = term_exists( 'flow-' . $pid, CARTFLOWS_TAXONOMY_STEP_FLOW );
128
-
129
- if ( is_array( $term_data ) ) {
130
- wp_delete_term( $term_data['term_id'], CARTFLOWS_TAXONOMY_STEP_FLOW );
131
- }
132
- }
133
- }
134
-
135
- /**
136
- * Trash steps data after trashing flow.
137
- *
138
- * @since 1.0.0
139
- * @param int $pid post id.
140
- *
141
- * @return void
142
- */
143
- function step_post_trash_sync( $pid ) {
144
-
145
- global $post_type;
146
-
147
- if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) {
148
-
149
- $steps = get_post_meta( $pid, 'wcf-steps', true );
150
-
151
- if ( $steps && is_array( $steps ) ) {
152
- foreach ( $steps as $i => $step ) {
153
- wp_trash_post( $step['id'] );
154
- }
155
- }
156
- }
157
- }
158
-
159
- /**
160
- * Untrash steps data after restoring flow.
161
- *
162
- * @since 1.0.0
163
- * @param int $pid post id.
164
- *
165
- * @return void
166
- */
167
- function step_post_untrash_sync( $pid ) {
168
-
169
- global $post_type;
170
-
171
- if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) {
172
-
173
- $steps = get_post_meta( $pid, 'wcf-steps', true );
174
-
175
- if ( $steps && is_array( $steps ) ) {
176
- foreach ( $steps as $i => $step ) {
177
- wp_untrash_post( $step['id'] );
178
- }
179
- }
180
- }
181
- }
182
-
183
- /**
184
- * Setup default steps for flow
185
- *
186
- * @since 1.0.0
187
- *
188
- * @return void
189
- */
190
- public function cartflows_setup_default_steps() {
191
-
192
- check_ajax_referer( 'wcf-setup-default-steps', 'security' );
193
-
194
- $flow_id = intval( $_POST['post_id'] );
195
-
196
- $result = array(
197
- 'status' => false,
198
- /* translators: %s flow id */
199
- 'text' => sprintf( __( 'Steps not created for flow - %s', 'cartflows' ), $flow_id ),
200
- );
201
-
202
- if ( ! $flow_id ) {
203
- wp_send_json( $result );
204
- }
205
-
206
- $is_step_exists = get_post_meta( $flow_id, 'wcf-steps', true );
207
-
208
- if ( $is_step_exists ) {
209
-
210
- $result = array(
211
- 'status' => false,
212
- /* translators: %s flow id */
213
- 'text' => sprintf( __( 'Steps already exists. Flow - %s', 'cartflows' ), $flow_id ),
214
- );
215
-
216
- wp_send_json( $result );
217
- }
218
-
219
- /* Start Creating */
220
-
221
- $flow_steps = array();
222
-
223
- $steps_data = array(
224
- 'landing' => __( 'Landing Page', 'cartflows' ),
225
- 'checkout' => __( 'Checkout Page', 'cartflows' ),
226
- 'thankyou' => __( 'Thank You Page', 'cartflows' ),
227
- );
228
-
229
- foreach ( $steps_data as $slug => $title ) {
230
-
231
- $step_id = wp_insert_post(
232
- array(
233
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
234
- 'post_title' => $title,
235
- 'post_content' => '[cartflows_navigation]',
236
- 'post_status' => 'publish',
237
- )
238
- );
239
-
240
- if ( $step_id ) {
241
-
242
- $flow_steps[] = array(
243
- 'id' => $step_id,
244
- 'title' => $title,
245
- 'type' => $slug,
246
- );
247
-
248
- // insert post meta.
249
- update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
250
- update_post_meta( $step_id, 'wcf-step-type', $slug );
251
-
252
- wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
253
- wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
254
- }
255
- }
256
-
257
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
258
-
259
- $result = array(
260
- 'status' => true,
261
- /* translators: %s flow id */
262
- 'text' => sprintf( __( 'Steps created for flow - %s', 'cartflows' ), $flow_id ),
263
- 'redirect' => get_edit_post_link( $flow_id ),
264
- );
265
-
266
- wp_send_json( $result );
267
- }
268
-
269
- /**
270
- * Create step for given flow.
271
- *
272
- * @param int $flow_id flow ID.
273
- * @param int $step_type step type.
274
- * @param int $step_title step title.
275
- * @since 1.0.0
276
- *
277
- * @return int
278
- */
279
- public function create_step( $flow_id, $step_type, $step_title ) {
280
-
281
- $new_step_id = wp_insert_post(
282
- array(
283
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
284
- 'post_title' => $step_title,
285
- 'post_status' => 'publish',
286
- )
287
- );
288
-
289
- if ( $new_step_id ) {
290
-
291
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
292
-
293
- if ( ! is_array( $flow_steps ) ) {
294
- $flow_steps = array();
295
- }
296
-
297
- $flow_steps[] = array(
298
- 'id' => $new_step_id,
299
- 'title' => $step_title,
300
- 'type' => $step_type,
301
- );
302
-
303
- // insert post meta.
304
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
305
- update_post_meta( $new_step_id, 'wcf-step-type', $step_type );
306
-
307
- wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
308
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
309
- }
310
-
311
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
312
-
313
- return $new_step_id;
314
- }
315
-
316
- /**
317
- * Delete step for flow
318
- *
319
- * @since 1.0.0
320
- *
321
- * @return void
322
- */
323
- public function cartflows_delete_flow_step() {
324
-
325
- check_ajax_referer( 'wcf-delete-flow-step', 'security' );
326
-
327
- $flow_id = intval( $_POST['post_id'] );
328
- $step_id = intval( $_POST['step_id'] );
329
-
330
- $result = array(
331
- 'status' => false,
332
- /* translators: %s flow id */
333
- 'text' => sprintf( __( 'Step not deleted for flow - %s', 'cartflows' ), $flow_id ),
334
- );
335
-
336
- if ( ! $flow_id || ! $step_id ) {
337
- wp_send_json( $result );
338
- }
339
-
340
- wp_delete_post( $step_id, true );
341
-
342
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
343
-
344
- if ( ! is_array( $flow_steps ) ) {
345
- wp_send_json( $result );
346
- }
347
-
348
- foreach ( $flow_steps as $index => $data ) {
349
-
350
- if ( intval( $data['id'] ) === $step_id ) {
351
- unset( $flow_steps[ $index ] );
352
- break;
353
- }
354
- }
355
-
356
- /* Set index order properly */
357
- $flow_steps = array_merge( $flow_steps );
358
-
359
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
360
-
361
- $result = array(
362
- 'status' => true,
363
- /* translators: %s flow id */
364
- 'text' => sprintf( __( 'Step deleted for flow - %s', 'cartflows' ), $flow_id ),
365
- );
366
-
367
- wp_send_json( $result );
368
- }
369
-
370
- /**
371
- * Reorder step flow
372
- *
373
- * @since 1.0.0
374
- *
375
- * @return void
376
- */
377
- public function cartflows_reorder_flow_steps() {
378
-
379
- check_ajax_referer( 'wcf-reorder-flow-steps', 'security' );
380
-
381
- $flow_id = intval( $_POST['post_id'] );
382
- $step_ids = array_map( 'intval', $_POST['step_ids'] );
383
-
384
- $result = array(
385
- 'status' => false,
386
- /* translators: %s flow id */
387
- 'text' => sprintf( __( 'Steps not sorted for flow - %s', 'cartflows' ), $flow_id ),
388
- );
389
-
390
- if ( ! $flow_id || ! is_array( $step_ids ) ) {
391
- wp_send_json( $result );
392
- }
393
-
394
- $new_flow_steps = array();
395
-
396
- foreach ( $step_ids as $index => $step_id ) {
397
-
398
- $new_flow_steps[] = array(
399
- 'id' => intval( $step_id ),
400
- 'title' => get_the_title( $step_id ),
401
- 'type' => get_post_meta( $step_id, 'wcf-step-type', true ),
402
- );
403
- }
404
-
405
- update_post_meta( $flow_id, 'wcf-steps', $new_flow_steps );
406
-
407
- $result = array(
408
- 'status' => true,
409
- /* translators: %s flow id */
410
- 'text' => sprintf( __( 'Steps sorted for flow - %s', 'cartflows' ), $flow_id ),
411
- );
412
-
413
- wp_send_json( $result );
414
- }
415
-
416
-
417
- /**
418
- * Load admin scripts
419
- *
420
- * @since 1.0.0
421
- *
422
- * @return void
423
- */
424
- public function admin_scripts() {
425
-
426
- global $pagenow;
427
- global $post;
428
-
429
- $screen = get_current_screen();
430
-
431
- if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && CARTFLOWS_FLOW_POST_TYPE == $screen->post_type ) {
432
-
433
- wp_enqueue_script(
434
- 'wcf-flow-meta',
435
- CARTFLOWS_URL . 'admin/assets/js/flow-admin-edit.js',
436
- array( 'jquery', 'jquery-ui-sortable' ),
437
- CARTFLOWS_VER,
438
- true
439
- );
440
-
441
- wp_enqueue_style( 'wcf-flow-meta', CARTFLOWS_URL . 'admin/assets/css/flow-admin-edit.css', '', CARTFLOWS_VER );
442
- wp_style_add_data( 'wcf-flow-meta', 'rtl', 'replace' );
443
-
444
- $localize = array(
445
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
446
- );
447
-
448
- wp_localize_script( 'jquery', 'cartflows', apply_filters( 'wcf_js_localize', $localize ) );
449
- }
450
- }
451
-
452
- /**
453
- * Initialize meta box
454
- *
455
- * @since 1.0.0
456
- *
457
- * @return void
458
- */
459
- public function init_metabox() {
460
-
461
- /**
462
- * Fires after the title field.
463
- *
464
- * @param WP_Post $post Post object.
465
- */
466
- add_action( 'add_meta_boxes', array( $this, 'settings_meta_box' ) );
467
- add_action( 'edit_form_after_title', array( $this, 'setup_meta_box' ) );
468
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
469
- }
470
-
471
- /**
472
- * Is first time import?
473
- *
474
- * @param integer $post_id post ID.
475
- * @return bool
476
- */
477
- function is_flow_imported( $post_id = 0 ) {
478
-
479
- if ( 0 === $post_id ) {
480
- $post_id = get_the_ID();
481
- }
482
-
483
- $steps = get_post_meta( $post_id, 'wcf-steps', true );
484
- $choice = get_post_meta( $post_id, 'wcf-flow-choise', true );
485
-
486
- if ( empty( $steps ) && 'import' === $choice ) {
487
- return true;
488
- }
489
-
490
- return false;
491
- }
492
-
493
- /**
494
- * Setup meta box.
495
- *
496
- * @return void
497
- */
498
- function setup_meta_box() {
499
- if ( ! Cartflows_Admin::is_flow_edit_admin() ) {
500
- return;
501
- }
502
-
503
- /**
504
- * Adding Add new step button to the top*/
505
- echo $this->add_add_new_step_button();
506
-
507
- $this->markup_meta_box();
508
- }
509
-
510
- /**
511
- * Settings meta box.
512
- *
513
- * @return void
514
- */
515
- function settings_meta_box() {
516
-
517
- if ( CARTFLOWS_FLOW_POST_TYPE == get_post_type() ) {
518
-
519
- add_meta_box(
520
- 'wcf-sandbox-settings', // Id.
521
- __( 'Flow Settings', 'cartflows' ), // Title.
522
- array( $this, 'sandbox_meta_box' ), // Callback.
523
- CARTFLOWS_FLOW_POST_TYPE, // Post_type.
524
- 'side', // Context.
525
- 'high' // Priority.
526
- );
527
-
528
- do_action( 'cartflows_add_flow_metabox' );
529
- }
530
- }
531
-
532
- /**
533
- * Metabox Markup
534
- *
535
- * @return void
536
- */
537
- function markup_meta_box() {
538
- global $post;
539
-
540
- wp_nonce_field( 'save-nonce-flow-meta', 'nonce-flow-meta' );
541
-
542
- // Get defaults.
543
- $meta = self::get_current_post_meta( $post->ID );
544
-
545
- /**
546
- * Get options
547
- */
548
- $updated_data = array(
549
- 'steps' => $meta['wcf-steps']['default'],
550
- );
551
-
552
- do_action( 'wcf_flow_settings_markup_before', $meta );
553
- $this->page_header_tab( $updated_data );
554
- do_action( 'wcf_flow_settings_markup_after', $meta );
555
- }
556
-
557
- /**
558
- * Metabox Markup
559
- *
560
- * @param object $post Post object.
561
- * @return void
562
- */
563
- function sandbox_meta_box( $post ) {
564
-
565
- // Get defaults.
566
- $meta = self::get_current_post_meta( $post->ID );
567
-
568
- /**
569
- * Get options
570
- */
571
- foreach ( $meta as $key => $value ) {
572
- $updated_data[ $key ] = $meta[ $key ]['default'];
573
- }
574
-
575
- do_action( 'wcf_flow_sandbox_markup_before', $meta );
576
- $this->sandbox_markup( $updated_data );
577
- do_action( 'wcf_flow_sandbox_markup_after', $meta );
578
- }
579
-
580
- /**
581
- * Page Header Tabs
582
- *
583
- * @param array $options Post meta.
584
- * @return void
585
- */
586
- function page_header_tab( $options ) {
587
-
588
- include_once CARTFLOWS_FLOW_DIR . 'view/meta-flow-steps.php';
589
- }
590
-
591
- /**
592
- * Sandbox Markup
593
- *
594
- * @param array $options Post meta.
595
- * @return void
596
- */
597
- function sandbox_markup( $options ) {
598
- ?>
599
- <div class="wcf-flow-sandbox-table wcf-general-metabox-wrap widefat">
600
- <div class="wcf-flow-sandbox-table-container">
601
- <?php
602
- echo wcf()->meta->get_checkbox_field(
603
- array(
604
- 'name' => 'wcf-testing',
605
- 'value' => $options['wcf-testing'],
606
- 'after' => __( 'Enable Test Mode', 'cartflows' ),
607
- )
608
- );
609
-
610
- echo wcf()->meta->get_description_field(
611
- array(
612
- 'name' => 'wcf-testing-note',
613
- 'content' => __( 'Test mode adds random products in your flow, so you can preview it easily while testing.', 'cartflows' ),
614
- )
615
- );
616
-
617
- ?>
618
- </div>
619
- </div>
620
- <?php
621
- }
622
-
623
- /**
624
- * Keep the menu open when editing the flows.
625
- * Highlights the wanted admin (sub-) menu items for the CPT.
626
- *
627
- * @since 1.0.0
628
- */
629
- public function menu_highlight() {
630
- global $parent_file, $submenu_file, $post_type;
631
- if ( CARTFLOWS_FLOW_POST_TYPE == $post_type ) :
632
- $parent_file = CARTFLOWS_SLUG;
633
- $submenu_file = 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE;
634
- endif;
635
- }
636
-
637
- /**
638
- * Get metabox options
639
- *
640
- * @param int $post_id post id.
641
- * @return array
642
- */
643
- public static function get_meta_option( $post_id ) {
644
-
645
- if ( null === self::$meta_option ) {
646
- /**
647
- * Set metabox options
648
- */
649
- self::$meta_option = wcf()->options->get_flow_fields( $post_id );
650
- }
651
-
652
- return self::$meta_option;
653
- }
654
-
655
- /**
656
- * Get metabox options
657
- *
658
- * @param int $post_id post ID.
659
- * @return array
660
- */
661
- public static function get_current_post_meta( $post_id ) {
662
-
663
- $stored = get_post_meta( $post_id );
664
-
665
- $default_meta = self::get_meta_option( $post_id );
666
-
667
- // Set stored and override defaults.
668
- foreach ( $stored as $key => $value ) {
669
- if ( array_key_exists( $key, $default_meta ) ) {
670
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
671
- } else {
672
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
673
- }
674
- }
675
-
676
- return self::get_meta_option( $post_id );
677
- }
678
-
679
- /**
680
- * Metabox Save
681
- *
682
- * @param number $post_id Post ID.
683
- * @return void
684
- */
685
- function save_meta_box( $post_id ) {
686
-
687
- // Checks save status.
688
- $is_autosave = wp_is_post_autosave( $post_id );
689
- $is_revision = wp_is_post_revision( $post_id );
690
-
691
- $is_valid_nonce = ( isset( $_POST['nonce-flow-meta'] ) && wp_verify_nonce( $_POST['nonce-flow-meta'], 'save-nonce-flow-meta' ) ) ? true : false;
692
-
693
- // Exits script depending on save status.
694
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
695
- return;
696
- }
697
-
698
- wcf()->options->save_flow_fields( $post_id );
699
- }
700
-
701
- /**
702
- * Localize variables in admin
703
- *
704
- * @param array $vars variables.
705
- */
706
- function localize_vars( $vars ) {
707
-
708
- $ajax_actions = array(
709
- 'wcf_setup_default_steps',
710
- 'wcf_add_flow_step',
711
- 'wcf_delete_flow_step',
712
- 'wcf_reorder_flow_steps',
713
- );
714
-
715
- foreach ( $ajax_actions as $action ) {
716
-
717
- $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
718
- }
719
-
720
- return $vars;
721
- }
722
-
723
- /**
724
- * Add New Step Button
725
- *
726
- * @return string
727
- */
728
- function add_add_new_step_button() {
729
- $add_new_btn_markup = '<style>.wrap{ position:relative;}</style>';
730
- $add_new_btn_markup .= "<div class='wcf-button-wrap'>";
731
- $add_new_btn_markup .= "<button class='wcf-trigger-popup page-title-action'>";
732
- $add_new_btn_markup .= esc_html( 'Add New Step', 'cartflows' );
733
- $add_new_btn_markup .= '</button>';
734
- $add_new_btn_markup .= '</div>';
735
-
736
- return $add_new_btn_markup;
737
- }
738
- }
739
-
740
- /**
741
- * Kicking this off by calling 'get_instance()' method
742
- */
743
- Cartflows_Flow_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Flow meta
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Flow_Meta {
12
+
13
+
14
+ /**
15
+ * Instance
16
+ *
17
+ * @var $instance
18
+ */
19
+ private static $instance;
20
+
21
+ /**
22
+ * Meta Option
23
+ *
24
+ * @var $meta_option
25
+ */
26
+ private static $meta_option;
27
+
28
+ /**
29
+ * Initiator
30
+ */
31
+ public static function get_instance() {
32
+ if ( ! isset( self::$instance ) ) {
33
+ self::$instance = new self;
34
+ }
35
+
36
+ return self::$instance;
37
+ }
38
+
39
+ /**
40
+ * Constructor
41
+ */
42
+ public function __construct() {
43
+
44
+ add_action( 'admin_head', array( $this, 'menu_highlight' ) );
45
+
46
+ add_action( 'admin_init', array( $this, 'admin_init_actions' ) );
47
+
48
+ /* Init Metabox */
49
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
50
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
51
+
52
+ /* Add Scripts */
53
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 20 );
54
+
55
+ add_action( 'wp_ajax_cartflows_setup_default_steps', array( $this, 'cartflows_setup_default_steps' ) );
56
+ add_action( 'wp_ajax_cartflows_delete_flow_step', array( $this, 'cartflows_delete_flow_step' ) );
57
+
58
+ add_action( 'wp_ajax_cartflows_reorder_flow_steps', array( $this, 'cartflows_reorder_flow_steps' ) );
59
+
60
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
61
+
62
+ add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
63
+ }
64
+
65
+ /**
66
+ * Display admin notices.
67
+ *
68
+ * @since 1.0.0
69
+ *
70
+ * @return void
71
+ */
72
+ function admin_notices() {
73
+
74
+ if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type() ) {
75
+ return;
76
+ }
77
+
78
+ $flow_id = get_post_meta( get_the_id(), 'wcf-flow-id', true );
79
+ if ( $flow_id ) { ?>
80
+ <div class="wcf-notice-back-edit-flow">
81
+ <p>
82
+ <a href="<?php echo esc_url( get_edit_post_link( $flow_id ) ); ?>" class="button button-primary button-hero" style="text-decoration: none;">
83
+ <i class="dashicons dashicons-arrow-left-alt"></i>
84
+ <?php _e( 'Back to edit Flow', 'cartflows' ); ?>
85
+ </a>
86
+ </p>
87
+ </div>
88
+ <?php
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Initialize admin actions.
94
+ *
95
+ * @since 1.0.0
96
+ *
97
+ * @return void
98
+ */
99
+ function admin_init_actions() {
100
+ add_action( 'before_delete_post', array( $this, 'step_post_sync' ) );
101
+ add_action( 'wp_trash_post', array( $this, 'step_post_trash_sync' ) );
102
+ add_action( 'untrashed_post', array( $this, 'step_post_untrash_sync' ) );
103
+ }
104
+
105
+ /**
106
+ * Delete term data and steps data after deleting flow.
107
+ *
108
+ * @since 1.0.0
109
+ * @param int $pid post id.
110
+ *
111
+ * @return void
112
+ */
113
+ function step_post_sync( $pid ) {
114
+
115
+ global $post_type;
116
+
117
+ if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) {
118
+
119
+ $steps = get_post_meta( $pid, 'wcf-steps', true );
120
+
121
+ if ( $steps && is_array( $steps ) ) {
122
+ foreach ( $steps as $i => $step ) {
123
+ wp_delete_post( $step['id'], true );
124
+ }
125
+ }
126
+
127
+ $term_data = term_exists( 'flow-' . $pid, CARTFLOWS_TAXONOMY_STEP_FLOW );
128
+
129
+ if ( is_array( $term_data ) ) {
130
+ wp_delete_term( $term_data['term_id'], CARTFLOWS_TAXONOMY_STEP_FLOW );
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Trash steps data after trashing flow.
137
+ *
138
+ * @since 1.0.0
139
+ * @param int $pid post id.
140
+ *
141
+ * @return void
142
+ */
143
+ function step_post_trash_sync( $pid ) {
144
+
145
+ global $post_type;
146
+
147
+ if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) {
148
+
149
+ $steps = get_post_meta( $pid, 'wcf-steps', true );
150
+
151
+ if ( $steps && is_array( $steps ) ) {
152
+ foreach ( $steps as $i => $step ) {
153
+ wp_trash_post( $step['id'] );
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Untrash steps data after restoring flow.
161
+ *
162
+ * @since 1.0.0
163
+ * @param int $pid post id.
164
+ *
165
+ * @return void
166
+ */
167
+ function step_post_untrash_sync( $pid ) {
168
+
169
+ global $post_type;
170
+
171
+ if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) {
172
+
173
+ $steps = get_post_meta( $pid, 'wcf-steps', true );
174
+
175
+ if ( $steps && is_array( $steps ) ) {
176
+ foreach ( $steps as $i => $step ) {
177
+ wp_untrash_post( $step['id'] );
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Setup default steps for flow
185
+ *
186
+ * @since 1.0.0
187
+ *
188
+ * @return void
189
+ */
190
+ public function cartflows_setup_default_steps() {
191
+
192
+ check_ajax_referer( 'wcf-setup-default-steps', 'security' );
193
+
194
+ $flow_id = intval( $_POST['post_id'] );
195
+
196
+ $result = array(
197
+ 'status' => false,
198
+ /* translators: %s flow id */
199
+ 'text' => sprintf( __( 'Steps not created for flow - %s', 'cartflows' ), $flow_id ),
200
+ );
201
+
202
+ if ( ! $flow_id ) {
203
+ wp_send_json( $result );
204
+ }
205
+
206
+ $is_step_exists = get_post_meta( $flow_id, 'wcf-steps', true );
207
+
208
+ if ( $is_step_exists ) {
209
+
210
+ $result = array(
211
+ 'status' => false,
212
+ /* translators: %s flow id */
213
+ 'text' => sprintf( __( 'Steps already exists. Flow - %s', 'cartflows' ), $flow_id ),
214
+ );
215
+
216
+ wp_send_json( $result );
217
+ }
218
+
219
+ /* Start Creating */
220
+
221
+ $flow_steps = array();
222
+
223
+ $steps_data = array(
224
+ 'landing' => __( 'Landing Page', 'cartflows' ),
225
+ 'checkout' => __( 'Checkout Page', 'cartflows' ),
226
+ 'thankyou' => __( 'Thank You Page', 'cartflows' ),
227
+ );
228
+
229
+ foreach ( $steps_data as $slug => $title ) {
230
+
231
+ $step_id = wp_insert_post(
232
+ array(
233
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
234
+ 'post_title' => $title,
235
+ 'post_content' => '[cartflows_navigation]',
236
+ 'post_status' => 'publish',
237
+ )
238
+ );
239
+
240
+ if ( $step_id ) {
241
+
242
+ $flow_steps[] = array(
243
+ 'id' => $step_id,
244
+ 'title' => $title,
245
+ 'type' => $slug,
246
+ );
247
+
248
+ // insert post meta.
249
+ update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
250
+ update_post_meta( $step_id, 'wcf-step-type', $slug );
251
+
252
+ wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
253
+ wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
254
+ }
255
+ }
256
+
257
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
258
+
259
+ $result = array(
260
+ 'status' => true,
261
+ /* translators: %s flow id */
262
+ 'text' => sprintf( __( 'Steps created for flow - %s', 'cartflows' ), $flow_id ),
263
+ 'redirect' => get_edit_post_link( $flow_id ),
264
+ );
265
+
266
+ wp_send_json( $result );
267
+ }
268
+
269
+ /**
270
+ * Create step for given flow.
271
+ *
272
+ * @param int $flow_id flow ID.
273
+ * @param int $step_type step type.
274
+ * @param int $step_title step title.
275
+ * @since 1.0.0
276
+ *
277
+ * @return int
278
+ */
279
+ public function create_step( $flow_id, $step_type, $step_title ) {
280
+
281
+ $new_step_id = wp_insert_post(
282
+ array(
283
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
284
+ 'post_title' => $step_title,
285
+ 'post_status' => 'publish',
286
+ )
287
+ );
288
+
289
+ if ( $new_step_id ) {
290
+
291
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
292
+
293
+ if ( ! is_array( $flow_steps ) ) {
294
+ $flow_steps = array();
295
+ }
296
+
297
+ $flow_steps[] = array(
298
+ 'id' => $new_step_id,
299
+ 'title' => $step_title,
300
+ 'type' => $step_type,
301
+ );
302
+
303
+ // insert post meta.
304
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
305
+ update_post_meta( $new_step_id, 'wcf-step-type', $step_type );
306
+
307
+ wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
308
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
309
+ }
310
+
311
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
312
+
313
+ return $new_step_id;
314
+ }
315
+
316
+ /**
317
+ * Delete step for flow
318
+ *
319
+ * @since 1.0.0
320
+ *
321
+ * @return void
322
+ */
323
+ public function cartflows_delete_flow_step() {
324
+
325
+ check_ajax_referer( 'wcf-delete-flow-step', 'security' );
326
+
327
+ $flow_id = intval( $_POST['post_id'] );
328
+ $step_id = intval( $_POST['step_id'] );
329
+
330
+ $result = array(
331
+ 'status' => false,
332
+ /* translators: %s flow id */
333
+ 'text' => sprintf( __( 'Step not deleted for flow - %s', 'cartflows' ), $flow_id ),
334
+ );
335
+
336
+ if ( ! $flow_id || ! $step_id ) {
337
+ wp_send_json( $result );
338
+ }
339
+
340
+ wp_delete_post( $step_id, true );
341
+
342
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
343
+
344
+ if ( ! is_array( $flow_steps ) ) {
345
+ wp_send_json( $result );
346
+ }
347
+
348
+ foreach ( $flow_steps as $index => $data ) {
349
+
350
+ if ( intval( $data['id'] ) === $step_id ) {
351
+ unset( $flow_steps[ $index ] );
352
+ break;
353
+ }
354
+ }
355
+
356
+ /* Set index order properly */
357
+ $flow_steps = array_merge( $flow_steps );
358
+
359
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
360
+
361
+ $result = array(
362
+ 'status' => true,
363
+ /* translators: %s flow id */
364
+ 'text' => sprintf( __( 'Step deleted for flow - %s', 'cartflows' ), $flow_id ),
365
+ );
366
+
367
+ wp_send_json( $result );
368
+ }
369
+
370
+ /**
371
+ * Reorder step flow
372
+ *
373
+ * @since 1.0.0
374
+ *
375
+ * @return void
376
+ */
377
+ public function cartflows_reorder_flow_steps() {
378
+
379
+ check_ajax_referer( 'wcf-reorder-flow-steps', 'security' );
380
+
381
+ $flow_id = intval( $_POST['post_id'] );
382
+ $step_ids = array_map( 'intval', $_POST['step_ids'] );
383
+
384
+ $result = array(
385
+ 'status' => false,
386
+ /* translators: %s flow id */
387
+ 'text' => sprintf( __( 'Steps not sorted for flow - %s', 'cartflows' ), $flow_id ),
388
+ );
389
+
390
+ if ( ! $flow_id || ! is_array( $step_ids ) ) {
391
+ wp_send_json( $result );
392
+ }
393
+
394
+ $new_flow_steps = array();
395
+
396
+ foreach ( $step_ids as $index => $step_id ) {
397
+
398
+ $new_flow_steps[] = array(
399
+ 'id' => intval( $step_id ),
400
+ 'title' => get_the_title( $step_id ),
401
+ 'type' => get_post_meta( $step_id, 'wcf-step-type', true ),
402
+ );
403
+ }
404
+
405
+ update_post_meta( $flow_id, 'wcf-steps', $new_flow_steps );
406
+
407
+ $result = array(
408
+ 'status' => true,
409
+ /* translators: %s flow id */
410
+ 'text' => sprintf( __( 'Steps sorted for flow - %s', 'cartflows' ), $flow_id ),
411
+ );
412
+
413
+ wp_send_json( $result );
414
+ }
415
+
416
+
417
+ /**
418
+ * Load admin scripts
419
+ *
420
+ * @since 1.0.0
421
+ *
422
+ * @return void
423
+ */
424
+ public function admin_scripts() {
425
+
426
+ global $pagenow;
427
+ global $post;
428
+
429
+ $screen = get_current_screen();
430
+
431
+ if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && CARTFLOWS_FLOW_POST_TYPE == $screen->post_type ) {
432
+
433
+ wp_enqueue_script(
434
+ 'wcf-flow-meta',
435
+ CARTFLOWS_URL . 'admin/assets/js/flow-admin-edit.js',
436
+ array( 'jquery', 'jquery-ui-sortable' ),
437
+ CARTFLOWS_VER,
438
+ true
439
+ );
440
+
441
+ wp_enqueue_style( 'wcf-flow-meta', CARTFLOWS_URL . 'admin/assets/css/flow-admin-edit.css', '', CARTFLOWS_VER );
442
+ wp_style_add_data( 'wcf-flow-meta', 'rtl', 'replace' );
443
+
444
+ $localize = array(
445
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
446
+ );
447
+
448
+ wp_localize_script( 'jquery', 'cartflows', apply_filters( 'wcf_js_localize', $localize ) );
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Initialize meta box
454
+ *
455
+ * @since 1.0.0
456
+ *
457
+ * @return void
458
+ */
459
+ public function init_metabox() {
460
+
461
+ /**
462
+ * Fires after the title field.
463
+ *
464
+ * @param WP_Post $post Post object.
465
+ */
466
+ add_action( 'add_meta_boxes', array( $this, 'settings_meta_box' ) );
467
+ add_action( 'edit_form_after_title', array( $this, 'setup_meta_box' ) );
468
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
469
+ }
470
+
471
+ /**
472
+ * Is first time import?
473
+ *
474
+ * @param integer $post_id post ID.
475
+ * @return bool
476
+ */
477
+ function is_flow_imported( $post_id = 0 ) {
478
+
479
+ if ( 0 === $post_id ) {
480
+ $post_id = get_the_ID();
481
+ }
482
+
483
+ $steps = get_post_meta( $post_id, 'wcf-steps', true );
484
+ $choice = get_post_meta( $post_id, 'wcf-flow-choise', true );
485
+
486
+ if ( empty( $steps ) && 'import' === $choice ) {
487
+ return true;
488
+ }
489
+
490
+ return false;
491
+ }
492
+
493
+ /**
494
+ * Setup meta box.
495
+ *
496
+ * @return void
497
+ */
498
+ function setup_meta_box() {
499
+ if ( ! Cartflows_Admin::is_flow_edit_admin() ) {
500
+ return;
501
+ }
502
+
503
+ /**
504
+ * Adding Add new step button to the top*/
505
+ echo $this->add_add_new_step_button();
506
+
507
+ $this->markup_meta_box();
508
+ }
509
+
510
+ /**
511
+ * Settings meta box.
512
+ *
513
+ * @return void
514
+ */
515
+ function settings_meta_box() {
516
+
517
+ if ( CARTFLOWS_FLOW_POST_TYPE == get_post_type() ) {
518
+
519
+ add_meta_box(
520
+ 'wcf-sandbox-settings', // Id.
521
+ __( 'Flow Settings', 'cartflows' ), // Title.
522
+ array( $this, 'sandbox_meta_box' ), // Callback.
523
+ CARTFLOWS_FLOW_POST_TYPE, // Post_type.
524
+ 'side', // Context.
525
+ 'high' // Priority.
526
+ );
527
+
528
+ do_action( 'cartflows_add_flow_metabox' );
529
+ }
530
+ }
531
+
532
+ /**
533
+ * Metabox Markup
534
+ *
535
+ * @return void
536
+ */
537
+ function markup_meta_box() {
538
+ global $post;
539
+
540
+ wp_nonce_field( 'save-nonce-flow-meta', 'nonce-flow-meta' );
541
+
542
+ // Get defaults.
543
+ $meta = self::get_current_post_meta( $post->ID );
544
+
545
+ /**
546
+ * Get options
547
+ */
548
+ $updated_data = array(
549
+ 'steps' => $meta['wcf-steps']['default'],
550
+ );
551
+
552
+ do_action( 'wcf_flow_settings_markup_before', $meta );
553
+ $this->page_header_tab( $updated_data );
554
+ do_action( 'wcf_flow_settings_markup_after', $meta );
555
+ }
556
+
557
+ /**
558
+ * Metabox Markup
559
+ *
560
+ * @param object $post Post object.
561
+ * @return void
562
+ */
563
+ function sandbox_meta_box( $post ) {
564
+
565
+ // Get defaults.
566
+ $meta = self::get_current_post_meta( $post->ID );
567
+
568
+ /**
569
+ * Get options
570
+ */
571
+ foreach ( $meta as $key => $value ) {
572
+ $updated_data[ $key ] = $meta[ $key ]['default'];
573
+ }
574
+
575
+ do_action( 'wcf_flow_sandbox_markup_before', $meta );
576
+ $this->sandbox_markup( $updated_data );
577
+ do_action( 'wcf_flow_sandbox_markup_after', $meta );
578
+ }
579
+
580
+ /**
581
+ * Page Header Tabs
582
+ *
583
+ * @param array $options Post meta.
584
+ * @return void
585
+ */
586
+ function page_header_tab( $options ) {
587
+
588
+ include_once CARTFLOWS_FLOW_DIR . 'view/meta-flow-steps.php';
589
+ }
590
+
591
+ /**
592
+ * Sandbox Markup
593
+ *
594
+ * @param array $options Post meta.
595
+ * @return void
596
+ */
597
+ function sandbox_markup( $options ) {
598
+ ?>
599
+ <div class="wcf-flow-sandbox-table wcf-general-metabox-wrap widefat">
600
+ <div class="wcf-flow-sandbox-table-container">
601
+ <?php
602
+ echo wcf()->meta->get_checkbox_field(
603
+ array(
604
+ 'name' => 'wcf-testing',
605
+ 'value' => $options['wcf-testing'],
606
+ 'after' => __( 'Enable Test Mode', 'cartflows' ),
607
+ )
608
+ );
609
+
610
+ echo wcf()->meta->get_description_field(
611
+ array(
612
+ 'name' => 'wcf-testing-note',
613
+ 'content' => __( 'Test mode adds random products in your flow, so you can preview it easily while testing.', 'cartflows' ),
614
+ )
615
+ );
616
+
617
+ ?>
618
+ </div>
619
+ </div>
620
+ <?php
621
+ }
622
+
623
+ /**
624
+ * Keep the menu open when editing the flows.
625
+ * Highlights the wanted admin (sub-) menu items for the CPT.
626
+ *
627
+ * @since 1.0.0
628
+ */
629
+ public function menu_highlight() {
630
+ global $parent_file, $submenu_file, $post_type;
631
+ if ( CARTFLOWS_FLOW_POST_TYPE == $post_type ) :
632
+ $parent_file = CARTFLOWS_SLUG;
633
+ $submenu_file = 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE;
634
+ endif;
635
+ }
636
+
637
+ /**
638
+ * Get metabox options
639
+ *
640
+ * @param int $post_id post id.
641
+ * @return array
642
+ */
643
+ public static function get_meta_option( $post_id ) {
644
+
645
+ if ( null === self::$meta_option ) {
646
+ /**
647
+ * Set metabox options
648
+ */
649
+ self::$meta_option = wcf()->options->get_flow_fields( $post_id );
650
+ }
651
+
652
+ return self::$meta_option;
653
+ }
654
+
655
+ /**
656
+ * Get metabox options
657
+ *
658
+ * @param int $post_id post ID.
659
+ * @return array
660
+ */
661
+ public static function get_current_post_meta( $post_id ) {
662
+
663
+ $stored = get_post_meta( $post_id );
664
+
665
+ $default_meta = self::get_meta_option( $post_id );
666
+
667
+ // Set stored and override defaults.
668
+ foreach ( $stored as $key => $value ) {
669
+ if ( array_key_exists( $key, $default_meta ) ) {
670
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
671
+ } else {
672
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
673
+ }
674
+ }
675
+
676
+ return self::get_meta_option( $post_id );
677
+ }
678
+
679
+ /**
680
+ * Metabox Save
681
+ *
682
+ * @param number $post_id Post ID.
683
+ * @return void
684
+ */
685
+ function save_meta_box( $post_id ) {
686
+
687
+ // Checks save status.
688
+ $is_autosave = wp_is_post_autosave( $post_id );
689
+ $is_revision = wp_is_post_revision( $post_id );
690
+
691
+ $is_valid_nonce = ( isset( $_POST['nonce-flow-meta'] ) && wp_verify_nonce( $_POST['nonce-flow-meta'], 'save-nonce-flow-meta' ) ) ? true : false;
692
+
693
+ // Exits script depending on save status.
694
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
695
+ return;
696
+ }
697
+
698
+ wcf()->options->save_flow_fields( $post_id );
699
+ }
700
+
701
+ /**
702
+ * Localize variables in admin
703
+ *
704
+ * @param array $vars variables.
705
+ */
706
+ function localize_vars( $vars ) {
707
+
708
+ $ajax_actions = array(
709
+ 'wcf_setup_default_steps',
710
+ 'wcf_add_flow_step',
711
+ 'wcf_delete_flow_step',
712
+ 'wcf_reorder_flow_steps',
713
+ );
714
+
715
+ foreach ( $ajax_actions as $action ) {
716
+
717
+ $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
718
+ }
719
+
720
+ return $vars;
721
+ }
722
+
723
+ /**
724
+ * Add New Step Button
725
+ *
726
+ * @return string
727
+ */
728
+ function add_add_new_step_button() {
729
+ $add_new_btn_markup = '<style>.wrap{ position:relative;}</style>';
730
+ $add_new_btn_markup .= "<div class='wcf-button-wrap'>";
731
+ $add_new_btn_markup .= "<button class='wcf-trigger-popup page-title-action'>";
732
+ $add_new_btn_markup .= esc_html( 'Add New Step', 'cartflows' );
733
+ $add_new_btn_markup .= '</button>';
734
+ $add_new_btn_markup .= '</div>';
735
+
736
+ return $add_new_btn_markup;
737
+ }
738
+ }
739
+
740
+ /**
741
+ * Kicking this off by calling 'get_instance()' method
742
+ */
743
+ Cartflows_Flow_Meta::get_instance();
modules/flow/classes/class-cartflows-flow-post-type.php CHANGED
@@ -1,281 +1,281 @@
1
- <?php
2
- /**
3
- * Flow post type
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Flow_Post_Type {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Initiator
25
- */
26
- public static function get_instance() {
27
- if ( ! isset( self::$instance ) ) {
28
- self::$instance = new self;
29
- }
30
- return self::$instance;
31
- }
32
-
33
- /**
34
- * Constructor
35
- */
36
- public function __construct() {
37
-
38
- add_action( 'init', array( $this, 'flow_post_type' ) );
39
- add_action( 'admin_menu', array( $this, 'register_as_submenu' ), 100 );
40
-
41
- add_filter( 'post_updated_messages', array( $this, 'custom_post_type_post_update_messages' ) );
42
-
43
- /* View Post URL */
44
- add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 );
45
- add_filter( 'preview_post_link', array( $this, 'preview_post_link' ), 10, 2 );
46
- add_action( 'template_redirect', array( $this, 'redirect_to_step' ), 10 );
47
- }
48
-
49
- /**
50
- * Create custom post type
51
- */
52
- function flow_post_type() {
53
-
54
- $labels = array(
55
- 'name' => esc_html_x( 'Flows', 'flow general name', 'cartflows' ),
56
- 'singular_name' => esc_html_x( 'Flow', 'flow singular name', 'cartflows' ),
57
- 'search_items' => esc_html__( 'Search Flows', 'cartflows' ),
58
- 'all_items' => esc_html__( 'All Flows', 'cartflows' ),
59
- 'edit_item' => esc_html__( 'Edit Flow', 'cartflows' ),
60
- 'view_item' => esc_html__( 'View Flow', 'cartflows' ),
61
- 'add_new' => esc_html__( 'Add New', 'cartflows' ),
62
- 'update_item' => esc_html__( 'Update Flow', 'cartflows' ),
63
- 'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
64
- 'new_item_name' => esc_html__( 'New Flow Name', 'cartflows' ),
65
- );
66
-
67
- $args = array(
68
- 'labels' => $labels,
69
- 'show_in_menu' => false,
70
- 'public' => false, // it's not public, not own permalink.
71
- 'publicly_queryable' => true, // you should be able to query it.
72
- 'show_ui' => true,
73
- 'query_var' => true,
74
- 'can_export' => true,
75
- 'show_in_admin_bar' => true,
76
- 'exclude_from_search' => true,
77
- 'has_archive' => false, // it shouldn't have archive page.
78
- 'rewrite' => false, // it shouldn't have rewrite rules.
79
- 'supports' => array( 'title', 'thumbnail' ),
80
- 'capability_type' => 'post',
81
- );
82
-
83
- if ( false && ! _is_cartflows_pro() ) {
84
-
85
- $flow_posts = get_posts(
86
- array(
87
- 'posts_per_page' => 4,
88
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
89
- 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit', 'trash' ),
90
- )
91
- );
92
-
93
- if ( is_array( $flow_posts ) ) {
94
-
95
- $flow_count = count( $flow_posts );
96
-
97
- if ( $flow_count > 3 || 3 === $flow_count ) {
98
-
99
- $args['capabilities'] = array(
100
- 'create_posts' => 'do_not_allow',
101
- );
102
- $args['map_meta_cap'] = true;
103
- }
104
- }
105
- }
106
-
107
- register_post_type( CARTFLOWS_FLOW_POST_TYPE, $args );
108
- }
109
-
110
- /**
111
- * Add post raw actions
112
- *
113
- * @param array $actions actions.
114
- * @param array $post post data.
115
- * @return array
116
- */
117
- function post_row_actions( $actions, $post ) {
118
-
119
- $first_step = $this->get_first_step_url( $post );
120
-
121
- if ( $first_step && isset( $actions['view'] ) ) {
122
-
123
- $actions['view'] = '<a href="' . $first_step . '">' . __( 'View', 'cartflows' ) . '</a>';
124
- }
125
-
126
- return $actions;
127
- }
128
-
129
- /**
130
- * Returns previous post link
131
- *
132
- * @param string $prev_link previous link.
133
- * @param array $post post data.
134
- * @return string
135
- */
136
- function preview_post_link( $prev_link, $post ) {
137
-
138
- if ( $this->is_flow_post_type( $post ) ) {
139
-
140
- $first_step = $this->get_first_step_url( $post );
141
-
142
- if ( $first_step ) {
143
-
144
- return $first_step;
145
- }
146
-
147
- return '';
148
- }
149
-
150
- return $prev_link;
151
- }
152
-
153
- /**
154
- * Check if post type is flow
155
- *
156
- * @param array $post post data.
157
- * @return bool
158
- */
159
- function is_flow_post_type( $post ) {
160
-
161
- if ( isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
162
-
163
- return true;
164
- }
165
-
166
- return false;
167
- }
168
-
169
- /**
170
- * Redirect to first step
171
- *
172
- * @return void
173
- */
174
- function redirect_to_step() {
175
-
176
- global $post;
177
-
178
- $first_step = $this->get_first_step_url( $post );
179
-
180
- if ( $first_step ) {
181
-
182
- wp_redirect( $first_step );
183
- die;
184
- }
185
- }
186
-
187
- /**
188
- * Return first step URL
189
- *
190
- * @param array $post post data.
191
- * @return bool
192
- */
193
- function get_first_step_url( $post ) {
194
-
195
- if ( $this->is_flow_post_type( $post ) ) {
196
-
197
- $flow_id = $post->ID;
198
- $title = $post->post_title;
199
- $steps = get_post_meta( $flow_id, 'wcf-steps', true );
200
-
201
- if ( is_array( $steps ) && ! empty( $steps ) && isset( $steps[0]['id'] ) ) {
202
-
203
- return get_permalink( $steps[0]['id'] );
204
- }
205
- }
206
-
207
- return false;
208
- }
209
-
210
- /**
211
- * Register the admin menu for Custom Layouts
212
- *
213
- * @since 1.0.0
214
- * Moved the menu under Appearance -> Custom Layouts
215
- public function register_admin_menu() {
216
- add_submenu_page(
217
- CARTFLOWS_SLUG,
218
- __( 'Flows', 'wcf' ),
219
- __( 'Flows', 'wcf' ),
220
- 'edit_pages',
221
- 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE
222
- );
223
- }
224
- */
225
- public function register_as_submenu() {
226
-
227
- global $submenu;
228
-
229
- $submenu[ CARTFLOWS_SLUG ][0] = array(
230
- __( 'Flows', 'cartflows' ),
231
- 'edit_pages',
232
- 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE,
233
- );
234
- }
235
-
236
- /**
237
- * Add Update messages for any custom post type
238
- *
239
- * @param array $messages Array of default messages.
240
- */
241
- function custom_post_type_post_update_messages( $messages ) {
242
-
243
- $custom_post_type = get_post_type( get_the_ID() );
244
-
245
- if ( CARTFLOWS_FLOW_POST_TYPE == $custom_post_type ) {
246
-
247
- $obj = get_post_type_object( $custom_post_type );
248
- $singular_name = $obj->labels->singular_name;
249
- $messages[ $custom_post_type ] = array(
250
- 0 => '', // Unused. Messages start at index 1.
251
- /* translators: %s: singular custom post type name */
252
- 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
253
- /* translators: %s: singular custom post type name */
254
- 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
255
- /* translators: %s: singular custom post type name */
256
- 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
257
- /* translators: %s: singular custom post type name */
258
- 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
259
- /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
260
- 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
261
- /* translators: %s: singular custom post type name */
262
- 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
263
- /* translators: %s: singular custom post type name */
264
- 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
265
- /* translators: %s: singular custom post type name */
266
- 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
267
- /* translators: %s: singular custom post type name */
268
- 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
269
- /* translators: %s: singular custom post type name */
270
- 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
271
- );
272
- }
273
-
274
- return $messages;
275
- }
276
- }
277
-
278
- /**
279
- * Kicking this off by calling 'get_instance()' method
280
- */
281
- Cartflows_Flow_Post_Type::get_instance();
1
+ <?php
2
+ /**
3
+ * Flow post type
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Flow_Post_Type {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Initiator
25
+ */
26
+ public static function get_instance() {
27
+ if ( ! isset( self::$instance ) ) {
28
+ self::$instance = new self;
29
+ }
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Constructor
35
+ */
36
+ public function __construct() {
37
+
38
+ add_action( 'init', array( $this, 'flow_post_type' ) );
39
+ add_action( 'admin_menu', array( $this, 'register_as_submenu' ), 100 );
40
+
41
+ add_filter( 'post_updated_messages', array( $this, 'custom_post_type_post_update_messages' ) );
42
+
43
+ /* View Post URL */
44
+ add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 );
45
+ add_filter( 'preview_post_link', array( $this, 'preview_post_link' ), 10, 2 );
46
+ add_action( 'template_redirect', array( $this, 'redirect_to_step' ), 10 );
47
+ }
48
+
49
+ /**
50
+ * Create custom post type
51
+ */
52
+ function flow_post_type() {
53
+
54
+ $labels = array(
55
+ 'name' => esc_html_x( 'Flows', 'flow general name', 'cartflows' ),
56
+ 'singular_name' => esc_html_x( 'Flow', 'flow singular name', 'cartflows' ),
57
+ 'search_items' => esc_html__( 'Search Flows', 'cartflows' ),
58
+ 'all_items' => esc_html__( 'All Flows', 'cartflows' ),
59
+ 'edit_item' => esc_html__( 'Edit Flow', 'cartflows' ),
60
+ 'view_item' => esc_html__( 'View Flow', 'cartflows' ),
61
+ 'add_new' => esc_html__( 'Add New', 'cartflows' ),
62
+ 'update_item' => esc_html__( 'Update Flow', 'cartflows' ),
63
+ 'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
64
+ 'new_item_name' => esc_html__( 'New Flow Name', 'cartflows' ),
65
+ );
66
+
67
+ $args = array(
68
+ 'labels' => $labels,
69
+ 'show_in_menu' => false,
70
+ 'public' => false, // it's not public, not own permalink.
71
+ 'publicly_queryable' => true, // you should be able to query it.
72
+ 'show_ui' => true,
73
+ 'query_var' => true,
74
+ 'can_export' => true,
75
+ 'show_in_admin_bar' => true,
76
+ 'exclude_from_search' => true,
77
+ 'has_archive' => false, // it shouldn't have archive page.
78
+ 'rewrite' => false, // it shouldn't have rewrite rules.
79
+ 'supports' => array( 'title', 'thumbnail' ),
80
+ 'capability_type' => 'post',
81
+ );
82
+
83
+ if ( false && ! _is_cartflows_pro() ) {
84
+
85
+ $flow_posts = get_posts(
86
+ array(
87
+ 'posts_per_page' => 4,
88
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
89
+ 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit', 'trash' ),
90
+ )
91
+ );
92
+
93
+ if ( is_array( $flow_posts ) ) {
94
+
95
+ $flow_count = count( $flow_posts );
96
+
97
+ if ( $flow_count > 3 || 3 === $flow_count ) {
98
+
99
+ $args['capabilities'] = array(
100
+ 'create_posts' => 'do_not_allow',
101
+ );
102
+ $args['map_meta_cap'] = true;
103
+ }
104
+ }
105
+ }
106
+
107
+ register_post_type( CARTFLOWS_FLOW_POST_TYPE, $args );
108
+ }
109
+
110
+ /**
111
+ * Add post raw actions
112
+ *
113
+ * @param array $actions actions.
114
+ * @param array $post post data.
115
+ * @return array
116
+ */
117
+ function post_row_actions( $actions, $post ) {
118
+
119
+ $first_step = $this->get_first_step_url( $post );
120
+
121
+ if ( $first_step && isset( $actions['view'] ) ) {
122
+
123
+ $actions['view'] = '<a href="' . $first_step . '">' . __( 'View', 'cartflows' ) . '</a>';
124
+ }
125
+
126
+ return $actions;
127
+ }
128
+
129
+ /**
130
+ * Returns previous post link
131
+ *
132
+ * @param string $prev_link previous link.
133
+ * @param array $post post data.
134
+ * @return string
135
+ */
136
+ function preview_post_link( $prev_link, $post ) {
137
+
138
+ if ( $this->is_flow_post_type( $post ) ) {
139
+
140
+ $first_step = $this->get_first_step_url( $post );
141
+
142
+ if ( $first_step ) {
143
+
144
+ return $first_step;
145
+ }
146
+
147
+ return '';
148
+ }
149
+
150
+ return $prev_link;
151
+ }
152
+
153
+ /**
154
+ * Check if post type is flow
155
+ *
156
+ * @param array $post post data.
157
+ * @return bool
158
+ */
159
+ function is_flow_post_type( $post ) {
160
+
161
+ if ( isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
162
+
163
+ return true;
164
+ }
165
+
166
+ return false;
167
+ }
168
+
169
+ /**
170
+ * Redirect to first step
171
+ *
172
+ * @return void
173
+ */
174
+ function redirect_to_step() {
175
+
176
+ global $post;
177
+
178
+ $first_step = $this->get_first_step_url( $post );
179
+
180
+ if ( $first_step ) {
181
+
182
+ wp_redirect( $first_step );
183
+ die;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Return first step URL
189
+ *
190
+ * @param array $post post data.
191
+ * @return bool
192
+ */
193
+ function get_first_step_url( $post ) {
194
+
195
+ if ( $this->is_flow_post_type( $post ) ) {
196
+
197
+ $flow_id = $post->ID;
198
+ $title = $post->post_title;
199
+ $steps = get_post_meta( $flow_id, 'wcf-steps', true );
200
+
201
+ if ( is_array( $steps ) && ! empty( $steps ) && isset( $steps[0]['id'] ) ) {
202
+
203
+ return get_permalink( $steps[0]['id'] );
204
+ }
205
+ }
206
+
207
+ return false;
208
+ }
209
+
210
+ /**
211
+ * Register the admin menu for Custom Layouts
212
+ *
213
+ * @since 1.0.0
214
+ * Moved the menu under Appearance -> Custom Layouts
215
+ public function register_admin_menu() {
216
+ add_submenu_page(
217
+ CARTFLOWS_SLUG,
218
+ __( 'Flows', 'wcf' ),
219
+ __( 'Flows', 'wcf' ),
220
+ 'edit_pages',
221
+ 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE
222
+ );
223
+ }
224
+ */
225
+ public function register_as_submenu() {
226
+
227
+ global $submenu;
228
+
229
+ $submenu[ CARTFLOWS_SLUG ][0] = array(
230
+ __( 'Flows', 'cartflows' ),
231
+ 'edit_pages',
232
+ 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE,
233
+ );
234
+ }
235
+
236
+ /**
237
+ * Add Update messages for any custom post type
238
+ *
239
+ * @param array $messages Array of default messages.
240
+ */
241
+ function custom_post_type_post_update_messages( $messages ) {
242
+
243
+ $custom_post_type = get_post_type( get_the_ID() );
244
+
245
+ if ( CARTFLOWS_FLOW_POST_TYPE == $custom_post_type ) {
246
+
247
+ $obj = get_post_type_object( $custom_post_type );
248
+ $singular_name = $obj->labels->singular_name;
249
+ $messages[ $custom_post_type ] = array(
250
+ 0 => '', // Unused. Messages start at index 1.
251
+ /* translators: %s: singular custom post type name */
252
+ 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
253
+ /* translators: %s: singular custom post type name */
254
+ 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
255
+ /* translators: %s: singular custom post type name */
256
+ 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
257
+ /* translators: %s: singular custom post type name */
258
+ 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
259
+ /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
260
+ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
261
+ /* translators: %s: singular custom post type name */
262
+ 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
263
+ /* translators: %s: singular custom post type name */
264
+ 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
265
+ /* translators: %s: singular custom post type name */
266
+ 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
267
+ /* translators: %s: singular custom post type name */
268
+ 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
269
+ /* translators: %s: singular custom post type name */
270
+ 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
271
+ );
272
+ }
273
+
274
+ return $messages;
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Kicking this off by calling 'get_instance()' method
280
+ */
281
+ Cartflows_Flow_Post_Type::get_instance();
modules/flow/classes/class-cartflows-step-post-type.php CHANGED
@@ -1,470 +1,486 @@
1
- <?php
2
- /**
3
- * Step post type.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Step_Post_Type {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Member Variable
25
- *
26
- * @var body_classes
27
- */
28
- private $body_classes = array();
29
-
30
- /**
31
- * Initiator
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- */
43
- public function __construct() {
44
-
45
- add_action( 'init', array( $this, 'step_post_type' ) );
46
- add_action( 'init', array( $this, 'add_wp_templates_support' ) );
47
- add_filter( 'post_updated_messages', array( $this, 'post_update_messages' ) );
48
- add_filter( 'post_type_link', array( $this, 'post_type_permalinks' ), 10, 3 );
49
- add_filter( 'wp_unique_post_slug', array( $this, 'prevent_slug_duplicates' ), 10, 6 );
50
- add_action( 'pre_get_posts', array( $this, 'add_cpt_post_names_to_main_query' ), 20 );
51
-
52
- add_filter( 'template_include', array( $this, 'load_page_template' ), 99 );
53
- }
54
-
55
-
56
- /**
57
- * Trys to load page.php for a header, footer or part theme layout.
58
- *
59
- * @since 1.0.0
60
- * @param string $template The current template to be loaded.
61
- * @return string
62
- */
63
- function load_page_template( $template ) {
64
-
65
- global $post;
66
-
67
- if ( 'string' == gettype( $template ) && is_object( $post ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
68
-
69
- /**
70
- * Remove Next/Prev Navigation
71
- * add_filter('next_post_link', '__return_empty_string');
72
- * add_filter('previous_post_link', '__return_empty_string');
73
- *
74
- * $page = locate_template( array( 'page.php' ) );
75
- *
76
- * if ( ! empty( $page ) ) {
77
- * return $page;
78
- * }
79
- */
80
-
81
- /* Remove Next / Previous Rel Link */
82
- remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
83
- add_filter( 'next_post_rel_link', '__return_empty_string' );
84
- add_filter( 'previous_post_rel_link', '__return_empty_string' );
85
-
86
- $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
87
-
88
- $page_template = apply_filters( 'cartflows_page_template', $page_template );
89
-
90
- $file = '';
91
-
92
- switch ( $page_template ) {
93
-
94
- case 'cartflows-default':
95
- $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
96
- $this->body_classes[] = $page_template;
97
- break;
98
- case 'cartflows-canvas':
99
- $file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php';
100
- $this->body_classes[] = $page_template;
101
- break;
102
- default:
103
- $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
104
- $this->body_classes[] = 'cartflows-default';
105
- break;
106
- }
107
-
108
- // Just to be safe, we check if the file exist first.
109
- if ( file_exists( $file ) ) {
110
-
111
- /* Add Body Class */
112
- add_filter( 'body_class', [ $this, 'body_class' ] );
113
-
114
- return $file;
115
- } else {
116
- echo $file;
117
- }
118
- }
119
-
120
- return $template;
121
- }
122
-
123
- /**
124
- * Body classes.
125
- *
126
- * @since 1.0.0
127
- * @param array $classes Body classes.
128
- * @return array
129
- */
130
- function body_class( $classes = [] ) {
131
-
132
- $classes = array_merge( $classes, $this->body_classes );
133
-
134
- return $classes;
135
- }
136
-
137
- /**
138
- * Create custom post type
139
- */
140
- function step_post_type() {
141
-
142
- $labels = array(
143
- 'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ),
144
- 'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ),
145
- 'search_items' => esc_html__( 'Search Steps', 'cartflows' ),
146
- 'all_items' => esc_html__( 'All Steps', 'cartflows' ),
147
- 'edit_item' => esc_html__( 'Edit Step', 'cartflows' ),
148
- 'view_item' => esc_html__( 'View Step', 'cartflows' ),
149
- 'add_new' => esc_html__( 'Add New', 'cartflows' ),
150
- 'update_item' => esc_html__( 'Update Step', 'cartflows' ),
151
- 'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
152
- 'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ),
153
- );
154
-
155
- $args = array(
156
- 'labels' => $labels,
157
- 'public' => true,
158
- 'query_var' => true,
159
- 'can_export' => true,
160
- 'exclude_from_search' => true,
161
- 'show_ui' => true,
162
- 'show_in_menu' => false,
163
- 'show_in_admin_bar' => true,
164
- 'supports' => array( 'title', 'editor', 'elementor', 'revisions' ),
165
- 'capability_type' => 'post',
166
- 'capabilities' => array(
167
- 'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false.
168
- ),
169
- 'map_meta_cap' => true,
170
- );
171
-
172
- register_post_type( CARTFLOWS_STEP_POST_TYPE, $args );
173
-
174
- $args = array(
175
- 'label' => __( 'Step Type', 'cartflows' ),
176
- 'public' => false,
177
- 'rewrite' => false,
178
- 'hierarchical' => false,
179
- );
180
-
181
- register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args );
182
-
183
- $args = array(
184
- 'label' => __( 'Step Flow', 'cartflows' ),
185
- 'public' => false,
186
- 'rewrite' => false,
187
- 'hierarchical' => false,
188
- );
189
-
190
- register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args );
191
-
192
- /**
193
- * Register 'Elementor' & 'Beaver Builder' site types.
194
- *
195
- * @see self::add_terms();
196
- */
197
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
198
-
199
- $terms = array(
200
- array(
201
- 'name' => __( 'Landing', 'cartflows' ),
202
- 'args' => array(
203
- 'slug' => 'landing',
204
- ),
205
- ),
206
- array(
207
- 'name' => __( 'Checkout', 'cartflows' ),
208
- 'args' => array(
209
- 'slug' => 'checkout',
210
- ),
211
- ),
212
- array(
213
- 'name' => __( 'Thank You', 'cartflows' ),
214
- 'args' => array(
215
- 'slug' => 'thankyou',
216
- ),
217
- ),
218
- array(
219
- 'name' => __( 'Upsell', 'cartflows' ),
220
- 'args' => array(
221
- 'slug' => 'upsell',
222
- ),
223
- ),
224
- array(
225
- 'name' => __( 'Downsell', 'cartflows' ),
226
- 'args' => array(
227
- 'slug' => 'downsell',
228
- ),
229
- ),
230
- );
231
-
232
- $this->add_terms( $taxonomy, $terms );
233
- }
234
-
235
- /**
236
- * Add WordPress templates.
237
- *
238
- * Adds Cartflows templates to steps
239
- *
240
- * @since 1.0.0
241
- * @access public
242
- */
243
- function add_wp_templates_support() {
244
- add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 );
245
- }
246
-
247
- /**
248
- * Add page templates.
249
- *
250
- * @since 1.0.0
251
- * @access public
252
- *
253
- * @param array $page_templates Array of page templates.
254
- *
255
- * @param object $wp_theme wp theme.
256
- * @param object $post post.
257
- *
258
- * @return array Page templates.
259
- */
260
- function add_page_templates( $page_templates, $wp_theme, $post ) {
261
-
262
- $page_templates = array(
263
- 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ),
264
- );
265
-
266
- return $page_templates;
267
- }
268
-
269
- /**
270
- * Have WordPress match postname to any of our public post types.
271
- * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
272
- * By default, WordPress only accounts for posts and pages where the slug is /post-name/.
273
- *
274
- * @param string $query query statement.
275
- */
276
- function add_cpt_post_names_to_main_query( $query ) {
277
-
278
- // Bail if this is not the main query.
279
- if ( ! $query->is_main_query() ) {
280
- return;
281
- }
282
-
283
- // Bail if this query doesn't match our very specific rewrite rule.
284
- if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
285
- return;
286
- }
287
-
288
- // Bail if we're not querying based on the post name.
289
- if ( empty( $query->query['name'] ) ) {
290
- return;
291
- }
292
-
293
- // Add cartflows step post type to existing post type array.
294
- if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) {
295
-
296
- $post_types = $query->query_vars['post_type'];
297
-
298
- $post_types[] = CARTFLOWS_STEP_POST_TYPE;
299
-
300
- $query->set( 'post_type', $post_types );
301
-
302
- } else {
303
-
304
- // Add CPT to the list of post types WP will include when it queries based on the post name.
305
- $query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) );
306
- }
307
- }
308
-
309
- /**
310
- * Modify permalink
311
- *
312
- * @param string $post_link post link.
313
- * @param array $post post data.
314
- * @param string $leavename leave name.
315
- * @return string
316
- */
317
- function post_type_permalinks( $post_link, $post, $leavename ) {
318
-
319
- // If elementor page preview, return post link as it is.
320
- if ( isset( $_REQUEST['elementor-preview'] ) ) {
321
- return $post_link;
322
- }
323
-
324
- $structure = get_option( 'permalink_structure' );
325
-
326
- if ( '/%postname%/' === $structure ) {
327
-
328
- if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) {
329
-
330
- $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
331
- }
332
- }
333
-
334
- return $post_link;
335
- }
336
-
337
- /**
338
- * Prevent slug duplicated
339
- *
340
- * @param string $slug post slug.
341
- * @param int $post_ID post id.
342
- * @param string $post_status post status.
343
- * @param string $post_type post type.
344
- * @param int $post_parent post parent id.
345
- * @param string $original_slug original slug.
346
- * @return string
347
- */
348
- function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
349
-
350
- $check_post_types = array(
351
- 'post',
352
- 'page',
353
- CARTFLOWS_STEP_POST_TYPE,
354
- );
355
-
356
- if ( ! in_array( $post_type, $check_post_types ) ) {
357
- return $slug;
358
- }
359
-
360
- if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) {
361
- // Saving a post, check for duplicates in POST or PAGE post types.
362
- $post_match = get_page_by_path( $slug, 'OBJECT', 'post' );
363
- $page_match = get_page_by_path( $slug, 'OBJECT', 'page' );
364
-
365
- if ( $post_match || $page_match ) {
366
- $slug .= '-2';
367
- }
368
- } else {
369
-
370
- // Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type.
371
- $custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE );
372
-
373
- if ( $custom_post_type_match ) {
374
- $slug .= '-2';
375
- }
376
- }
377
-
378
- return $slug;
379
- }
380
-
381
- /**
382
- * Add Update messages for any custom post type
383
- *
384
- * @param array $messages Array of default messages.
385
- */
386
- function post_update_messages( $messages ) {
387
-
388
- $custom_post_type = get_post_type( get_the_ID() );
389
-
390
- if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) {
391
-
392
- $obj = get_post_type_object( $custom_post_type );
393
- $singular_name = $obj->labels->singular_name;
394
- $messages[ $custom_post_type ] = array(
395
- 0 => '', // Unused. Messages start at index 1.
396
- /* translators: %s: singular custom post type name */
397
- 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
398
- /* translators: %s: singular custom post type name */
399
- 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
400
- /* translators: %s: singular custom post type name */
401
- 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
402
- /* translators: %s: singular custom post type name */
403
- 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
404
- /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
405
- 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
406
- /* translators: %s: singular custom post type name */
407
- 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
408
- /* translators: %s: singular custom post type name */
409
- 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
410
- /* translators: %s: singular custom post type name */
411
- 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
412
- /* translators: %s: singular custom post type name */
413
- 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
414
- /* translators: %s: singular custom post type name */
415
- 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
416
- );
417
- }
418
-
419
- return $messages;
420
- }
421
-
422
- /**
423
- * Add Terms for Taxonomy.
424
- *
425
- * => Example.
426
- *
427
- * $taxonomy = '{taxonomy}';
428
- * $terms = array(
429
- * array(
430
- * 'name' => 'Free',
431
- * ),
432
- * array(
433
- * 'name' => 'Premium',
434
- * ),
435
- * );
436
- *
437
- * self::add_terms( $taxonomy, $terms );
438
- *
439
- * @since 1.0.0
440
- * @param string $taxonomy Taxonomy Name.
441
- * @param array $terms Terms list.
442
- * @return void
443
- */
444
- function add_terms( $taxonomy = '', $terms = array() ) {
445
-
446
- foreach ( $terms as $key => $term ) {
447
-
448
- $term_exist = term_exists( $term['name'], $taxonomy );
449
-
450
- if ( empty( $term_exist ) ) {
451
-
452
- /**
453
- * Add additional args if passed from request.
454
- *
455
- * @see https://codex.wordpress.org/Function_Reference/wp_insert_term
456
- */
457
- if ( array_key_exists( 'args', $term ) ) {
458
- wp_insert_term( $term['name'], $taxonomy, $term['args'] );
459
- } else {
460
- wp_insert_term( $term['name'], $taxonomy );
461
- }
462
- }
463
- }
464
- }
465
- }
466
-
467
- /**
468
- * Kicking this off by calling 'get_instance()' method
469
- */
470
- Cartflows_Step_Post_Type::get_instance();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Step post type.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Step_Post_Type {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var body_classes
27
+ */
28
+ private $body_classes = array();
29
+
30
+ /**
31
+ * Initiator
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ */
43
+ public function __construct() {
44
+
45
+ add_action( 'init', array( $this, 'step_post_type' ) );
46
+ add_action( 'init', array( $this, 'add_wp_templates_support' ) );
47
+ add_filter( 'post_updated_messages', array( $this, 'post_update_messages' ) );
48
+ add_filter( 'post_type_link', array( $this, 'post_type_permalinks' ), 10, 3 );
49
+ add_filter( 'wp_unique_post_slug', array( $this, 'prevent_slug_duplicates' ), 10, 6 );
50
+ add_action( 'pre_get_posts', array( $this, 'add_cpt_post_names_to_main_query' ), 20 );
51
+
52
+ add_filter( 'template_include', array( $this, 'load_page_template' ), 99 );
53
+ add_filter( 'template_redirect', array( $this, 'query_fix' ), 3 );
54
+ }
55
+
56
+
57
+ /**
58
+ * Trys to load page.php for a header, footer or part theme layout.
59
+ *
60
+ * @since 1.0.0
61
+ * @param string $template The current template to be loaded.
62
+ * @return string
63
+ */
64
+ function load_page_template( $template ) {
65
+
66
+ global $post;
67
+
68
+ if ( 'string' == gettype( $template ) && is_object( $post ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
69
+
70
+ /**
71
+ * Remove Next/Prev Navigation
72
+ * add_filter('next_post_link', '__return_empty_string');
73
+ * add_filter('previous_post_link', '__return_empty_string');
74
+ *
75
+ * $page = locate_template( array( 'page.php' ) );
76
+ *
77
+ * if ( ! empty( $page ) ) {
78
+ * return $page;
79
+ * }
80
+ */
81
+
82
+ /* Remove Next / Previous Rel Link */
83
+ remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
84
+ add_filter( 'next_post_rel_link', '__return_empty_string' );
85
+ add_filter( 'previous_post_rel_link', '__return_empty_string' );
86
+
87
+ $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
88
+
89
+ $page_template = apply_filters( 'cartflows_page_template', $page_template );
90
+
91
+ $file = '';
92
+
93
+ switch ( $page_template ) {
94
+
95
+ case 'cartflows-default':
96
+ $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
97
+ $this->body_classes[] = $page_template;
98
+ break;
99
+ case 'cartflows-canvas':
100
+ $file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php';
101
+ $this->body_classes[] = $page_template;
102
+ break;
103
+ default:
104
+ $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
105
+ $this->body_classes[] = 'cartflows-default';
106
+ break;
107
+ }
108
+
109
+ // Just to be safe, we check if the file exist first.
110
+ if ( file_exists( $file ) ) {
111
+
112
+ /* Add Body Class */
113
+ add_filter( 'body_class', [ $this, 'body_class' ] );
114
+
115
+ return $file;
116
+ } else {
117
+ echo $file;
118
+ }
119
+ }
120
+
121
+ return $template;
122
+ }
123
+
124
+ /**
125
+ * Body classes.
126
+ *
127
+ * @since 1.0.0
128
+ * @param array $classes Body classes.
129
+ * @return array
130
+ */
131
+ function body_class( $classes = [] ) {
132
+
133
+ $classes = array_merge( $classes, $this->body_classes );
134
+
135
+ return $classes;
136
+ }
137
+
138
+ /**
139
+ * Create custom post type
140
+ */
141
+ function step_post_type() {
142
+
143
+ $labels = array(
144
+ 'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ),
145
+ 'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ),
146
+ 'search_items' => esc_html__( 'Search Steps', 'cartflows' ),
147
+ 'all_items' => esc_html__( 'All Steps', 'cartflows' ),
148
+ 'edit_item' => esc_html__( 'Edit Step', 'cartflows' ),
149
+ 'view_item' => esc_html__( 'View Step', 'cartflows' ),
150
+ 'add_new' => esc_html__( 'Add New', 'cartflows' ),
151
+ 'update_item' => esc_html__( 'Update Step', 'cartflows' ),
152
+ 'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
153
+ 'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ),
154
+ );
155
+
156
+ $args = array(
157
+ 'labels' => $labels,
158
+ 'public' => true,
159
+ 'query_var' => true,
160
+ 'can_export' => true,
161
+ 'exclude_from_search' => true,
162
+ 'show_ui' => true,
163
+ 'show_in_menu' => false,
164
+ 'show_in_admin_bar' => true,
165
+ 'supports' => array( 'title', 'editor', 'elementor', 'revisions' ),
166
+ 'capability_type' => 'post',
167
+ 'capabilities' => array(
168
+ 'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false.
169
+ ),
170
+ 'map_meta_cap' => true,
171
+ );
172
+
173
+ register_post_type( CARTFLOWS_STEP_POST_TYPE, $args );
174
+
175
+ $args = array(
176
+ 'label' => __( 'Step Type', 'cartflows' ),
177
+ 'public' => false,
178
+ 'rewrite' => false,
179
+ 'hierarchical' => false,
180
+ );
181
+
182
+ register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args );
183
+
184
+ $args = array(
185
+ 'label' => __( 'Step Flow', 'cartflows' ),
186
+ 'public' => false,
187
+ 'rewrite' => false,
188
+ 'hierarchical' => false,
189
+ );
190
+
191
+ register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args );
192
+
193
+ /**
194
+ * Register 'Elementor' & 'Beaver Builder' site types.
195
+ *
196
+ * @see self::add_terms();
197
+ */
198
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
199
+
200
+ $terms = array(
201
+ array(
202
+ 'name' => __( 'Landing', 'cartflows' ),
203
+ 'args' => array(
204
+ 'slug' => 'landing',
205
+ ),
206
+ ),
207
+ array(
208
+ 'name' => __( 'Checkout', 'cartflows' ),
209
+ 'args' => array(
210
+ 'slug' => 'checkout',
211
+ ),
212
+ ),
213
+ array(
214
+ 'name' => __( 'Thank You', 'cartflows' ),
215
+ 'args' => array(
216
+ 'slug' => 'thankyou',
217
+ ),
218
+ ),
219
+ array(
220
+ 'name' => __( 'Upsell', 'cartflows' ),
221
+ 'args' => array(
222
+ 'slug' => 'upsell',
223
+ ),
224
+ ),
225
+ array(
226
+ 'name' => __( 'Downsell', 'cartflows' ),
227
+ 'args' => array(
228
+ 'slug' => 'downsell',
229
+ ),
230
+ ),
231
+ );
232
+
233
+ $this->add_terms( $taxonomy, $terms );
234
+ }
235
+
236
+ /**
237
+ * Add WordPress templates.
238
+ *
239
+ * Adds Cartflows templates to steps
240
+ *
241
+ * @since 1.0.0
242
+ * @access public
243
+ */
244
+ function add_wp_templates_support() {
245
+ add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 );
246
+ }
247
+
248
+ /**
249
+ * Add page templates.
250
+ *
251
+ * @since 1.0.0
252
+ * @access public
253
+ *
254
+ * @param array $page_templates Array of page templates.
255
+ *
256
+ * @param object $wp_theme wp theme.
257
+ * @param object $post post.
258
+ *
259
+ * @return array Page templates.
260
+ */
261
+ function add_page_templates( $page_templates, $wp_theme, $post ) {
262
+
263
+ $page_templates = array(
264
+ 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ),
265
+ );
266
+
267
+ return $page_templates;
268
+ }
269
+
270
+ /**
271
+ * Have WordPress match postname to any of our public post types.
272
+ * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
273
+ * By default, WordPress only accounts for posts and pages where the slug is /post-name/.
274
+ *
275
+ * @param string $query query statement.
276
+ */
277
+ function add_cpt_post_names_to_main_query( $query ) {
278
+
279
+ // Bail if this is not the main query.
280
+ if ( ! $query->is_main_query() ) {
281
+ return;
282
+ }
283
+
284
+ // Bail if this query doesn't match our very specific rewrite rule.
285
+ if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
286
+ return;
287
+ }
288
+
289
+ // Bail if we're not querying based on the post name.
290
+ if ( empty( $query->query['name'] ) ) {
291
+ return;
292
+ }
293
+
294
+ // Add cartflows step post type to existing post type array.
295
+ if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) {
296
+
297
+ $post_types = $query->query_vars['post_type'];
298
+
299
+ $post_types[] = CARTFLOWS_STEP_POST_TYPE;
300
+
301
+ $query->set( 'post_type', $post_types );
302
+
303
+ } else {
304
+
305
+ // Add CPT to the list of post types WP will include when it queries based on the post name.
306
+ $query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) );
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Query fixe throwing error on 404 page due our post type changes.
312
+ * We are setting post_type as empty array to fix the issue.
313
+ * Ther error was throwing due to redirect_canonical function
314
+ * This fix is apply for 404 page only
315
+ */
316
+ function query_fix() {
317
+
318
+ global $wp_query;
319
+
320
+ if ( $wp_query->is_404() ) {
321
+ $wp_query->set( 'post_type', array() );
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Modify permalink
327
+ *
328
+ * @param string $post_link post link.
329
+ * @param array $post post data.
330
+ * @param string $leavename leave name.
331
+ * @return string
332
+ */
333
+ function post_type_permalinks( $post_link, $post, $leavename ) {
334
+
335
+ // If elementor page preview, return post link as it is.
336
+ if ( isset( $_REQUEST['elementor-preview'] ) ) {
337
+ return $post_link;
338
+ }
339
+
340
+ $structure = get_option( 'permalink_structure' );
341
+
342
+ if ( '/%postname%/' === $structure ) {
343
+
344
+ if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) {
345
+
346
+ $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
347
+ }
348
+ }
349
+
350
+ return $post_link;
351
+ }
352
+
353
+ /**
354
+ * Prevent slug duplicated
355
+ *
356
+ * @param string $slug post slug.
357
+ * @param int $post_ID post id.
358
+ * @param string $post_status post status.
359
+ * @param string $post_type post type.
360
+ * @param int $post_parent post parent id.
361
+ * @param string $original_slug original slug.
362
+ * @return string
363
+ */
364
+ function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
365
+
366
+ $check_post_types = array(
367
+ 'post',
368
+ 'page',
369
+ CARTFLOWS_STEP_POST_TYPE,
370
+ );
371
+
372
+ if ( ! in_array( $post_type, $check_post_types ) ) {
373
+ return $slug;
374
+ }
375
+
376
+ if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) {
377
+ // Saving a post, check for duplicates in POST or PAGE post types.
378
+ $post_match = get_page_by_path( $slug, 'OBJECT', 'post' );
379
+ $page_match = get_page_by_path( $slug, 'OBJECT', 'page' );
380
+
381
+ if ( $post_match || $page_match ) {
382
+ $slug .= '-2';
383
+ }
384
+ } else {
385
+
386
+ // Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type.
387
+ $custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE );
388
+
389
+ if ( $custom_post_type_match ) {
390
+ $slug .= '-2';
391
+ }
392
+ }
393
+
394
+ return $slug;
395
+ }
396
+
397
+ /**
398
+ * Add Update messages for any custom post type
399
+ *
400
+ * @param array $messages Array of default messages.
401
+ */
402
+ function post_update_messages( $messages ) {
403
+
404
+ $custom_post_type = get_post_type( get_the_ID() );
405
+
406
+ if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) {
407
+
408
+ $obj = get_post_type_object( $custom_post_type );
409
+ $singular_name = $obj->labels->singular_name;
410
+ $messages[ $custom_post_type ] = array(
411
+ 0 => '', // Unused. Messages start at index 1.
412
+ /* translators: %s: singular custom post type name */
413
+ 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
414
+ /* translators: %s: singular custom post type name */
415
+ 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
416
+ /* translators: %s: singular custom post type name */
417
+ 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
418
+ /* translators: %s: singular custom post type name */
419
+ 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
420
+ /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
421
+ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
422
+ /* translators: %s: singular custom post type name */
423
+ 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
424
+ /* translators: %s: singular custom post type name */
425
+ 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
426
+ /* translators: %s: singular custom post type name */
427
+ 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
428
+ /* translators: %s: singular custom post type name */
429
+ 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
430
+ /* translators: %s: singular custom post type name */
431
+ 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
432
+ );
433
+ }
434
+
435
+ return $messages;
436
+ }
437
+
438
+ /**
439
+ * Add Terms for Taxonomy.
440
+ *
441
+ * => Example.
442
+ *
443
+ * $taxonomy = '{taxonomy}';
444
+ * $terms = array(
445
+ * array(
446
+ * 'name' => 'Free',
447
+ * ),
448
+ * array(
449
+ * 'name' => 'Premium',
450
+ * ),
451
+ * );
452
+ *
453
+ * self::add_terms( $taxonomy, $terms );
454
+ *
455
+ * @since 1.0.0
456
+ * @param string $taxonomy Taxonomy Name.
457
+ * @param array $terms Terms list.
458
+ * @return void
459
+ */
460
+ function add_terms( $taxonomy = '', $terms = array() ) {
461
+
462
+ foreach ( $terms as $key => $term ) {
463
+
464
+ $term_exist = term_exists( $term['name'], $taxonomy );
465
+
466
+ if ( empty( $term_exist ) ) {
467
+
468
+ /**
469
+ * Add additional args if passed from request.
470
+ *
471
+ * @see https://codex.wordpress.org/Function_Reference/wp_insert_term
472
+ */
473
+ if ( array_key_exists( 'args', $term ) ) {
474
+ wp_insert_term( $term['name'], $taxonomy, $term['args'] );
475
+ } else {
476
+ wp_insert_term( $term['name'], $taxonomy );
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+
483
+ /**
484
+ * Kicking this off by calling 'get_instance()' method
485
+ */
486
+ Cartflows_Step_Post_Type::get_instance();
modules/flow/templates/template-canvas.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- /**
3
- * Template Name: No Header Footer
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- ?>
9
-
10
- <!DOCTYPE html>
11
- <html <?php language_attributes(); ?> class="no-js">
12
- <head>
13
- <meta charset="<?php bloginfo( 'charset' ); ?>">
14
- <meta name="viewport" content="width=device-width, initial-scale=1">
15
- <link rel="profile" href="http://gmpg.org/xfn/11">
16
- <?php wp_head(); ?>
17
- </head>
18
-
19
- <body <?php body_class(); ?>>
20
-
21
- <?php do_action( 'cartflows_body_top' ); ?>
22
-
23
- <?php
24
-
25
- $atts_string = Cartflows_Helper::get_cartflows_container_atts();
26
-
27
- ?>
28
- <div class="cartflows-container" <?php echo trim( $atts_string ); ?>>
29
-
30
- <?php
31
- do_action( 'cartflows_container_top' );
32
- while ( have_posts() ) :
33
-
34
- the_post();
35
- the_content();
36
-
37
- endwhile;
38
- do_action( 'cartflows_container_bottom' );
39
- ?>
40
- </div>
41
-
42
- <?php do_action( 'cartflows_wp_footer' ); ?>
43
-
44
- <?php wp_footer(); ?>
45
- </body>
46
-
47
- </html>
48
-
49
- <?php
1
+ <?php
2
+ /**
3
+ * Template Name: No Header Footer
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ ?>
9
+
10
+ <!DOCTYPE html>
11
+ <html <?php language_attributes(); ?> class="no-js">
12
+ <head>
13
+ <meta charset="<?php bloginfo( 'charset' ); ?>">
14
+ <meta name="viewport" content="width=device-width, initial-scale=1">
15
+ <link rel="profile" href="http://gmpg.org/xfn/11">
16
+ <?php wp_head(); ?>
17
+ </head>
18
+
19
+ <body <?php body_class(); ?>>
20
+
21
+ <?php do_action( 'cartflows_body_top' ); ?>
22
+
23
+ <?php
24
+
25
+ $atts_string = Cartflows_Helper::get_cartflows_container_atts();
26
+
27
+ ?>
28
+ <div class="cartflows-container" <?php echo trim( $atts_string ); ?>>
29
+
30
+ <?php
31
+ do_action( 'cartflows_container_top' );
32
+ while ( have_posts() ) :
33
+
34
+ the_post();
35
+ the_content();
36
+
37
+ endwhile;
38
+ do_action( 'cartflows_container_bottom' );
39
+ ?>
40
+ </div>
41
+
42
+ <?php do_action( 'cartflows_wp_footer' ); ?>
43
+
44
+ <?php wp_footer(); ?>
45
+ </body>
46
+
47
+ </html>
48
+
49
+ <?php
modules/flow/templates/template-default.php CHANGED
@@ -1,54 +1,54 @@
1
- <?php
2
- /**
3
- * Template Name: No Header Footer
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- ?>
9
-
10
- <!DOCTYPE html>
11
- <html <?php language_attributes(); ?> class="no-js">
12
- <head>
13
- <meta charset="<?php bloginfo( 'charset' ); ?>">
14
- <meta name="viewport" content="width=device-width, initial-scale=1">
15
- <link rel="profile" href="http://gmpg.org/xfn/11">
16
- <?php wp_head(); ?>
17
- </head>
18
-
19
- <body <?php body_class(); ?>>
20
-
21
- <?php do_action( 'cartflows_body_top' ); ?>
22
-
23
- <?php
24
-
25
- $atts_string = Cartflows_Helper::get_cartflows_container_atts();
26
-
27
- ?>
28
- <div class="cartflows-container" <?php echo trim( $atts_string ); ?>>
29
- <?php
30
- do_action( 'cartflows_container_top' );
31
- ?>
32
- <div class="cartflows-primary">
33
- <?php
34
- while ( have_posts() ) :
35
-
36
- the_post();
37
- the_content();
38
-
39
- endwhile;
40
- ?>
41
- </div>
42
- <?php
43
- do_action( 'cartflows_container_bottom' );
44
- ?>
45
- </div>
46
-
47
- <?php do_action( 'cartflows_wp_footer' ); ?>
48
-
49
- <?php wp_footer(); ?>
50
- </body>
51
-
52
- </html>
53
-
54
- <?php
1
+ <?php
2
+ /**
3
+ * Template Name: No Header Footer
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ ?>
9
+
10
+ <!DOCTYPE html>
11
+ <html <?php language_attributes(); ?> class="no-js">
12
+ <head>
13
+ <meta charset="<?php bloginfo( 'charset' ); ?>">
14
+ <meta name="viewport" content="width=device-width, initial-scale=1">
15
+ <link rel="profile" href="http://gmpg.org/xfn/11">
16
+ <?php wp_head(); ?>
17
+ </head>
18
+
19
+ <body <?php body_class(); ?>>
20
+
21
+ <?php do_action( 'cartflows_body_top' ); ?>
22
+
23
+ <?php
24
+
25
+ $atts_string = Cartflows_Helper::get_cartflows_container_atts();
26
+
27
+ ?>
28
+ <div class="cartflows-container" <?php echo trim( $atts_string ); ?>>
29
+ <?php
30
+ do_action( 'cartflows_container_top' );
31
+ ?>
32
+ <div class="cartflows-primary">
33
+ <?php
34
+ while ( have_posts() ) :
35
+
36
+ the_post();
37
+ the_content();
38
+
39
+ endwhile;
40
+ ?>
41
+ </div>
42
+ <?php
43
+ do_action( 'cartflows_container_bottom' );
44
+ ?>
45
+ </div>
46
+
47
+ <?php do_action( 'cartflows_wp_footer' ); ?>
48
+
49
+ <?php wp_footer(); ?>
50
+ </body>
51
+
52
+ </html>
53
+
54
+ <?php
modules/flow/view/meta-flow-steps.php CHANGED
@@ -1,200 +1,200 @@
1
- <?php
2
- /**
3
- * View Flow steps
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
9
-
10
- $get_steps = array(
11
- 'landing' => __( 'Landing', 'cartflows' ),
12
- 'checkout' => __( 'Checkout', 'cartflows' ),
13
- 'thankyou' => __( 'Thank You', 'cartflows' ),
14
- 'upsell' => __( 'Upsell', 'cartflows' ),
15
- 'downsell' => __( 'Downsell', 'cartflows' ),
16
-
17
- );
18
-
19
- ?>
20
- <div class="wcf-flow-steps-meta-box">
21
- <div class="wcf-flow-settings">
22
- <?php do_action( 'cartflows_above_flow_steps' ); ?>
23
- <div class="wcf-flow-steps-wrap">
24
- <div class="wcf-flow-steps-container">
25
- <?php if ( is_array( $options['steps'] ) ) { ?>
26
- <?php foreach ( $options['steps'] as $index => $data ) { ?>
27
- <?php
28
- $term_slug = '';
29
- $term_name = '';
30
- $step_wrap_class = '';
31
- $has_product_assigned = true;
32
- $is_global_checkout = '';
33
- $common = '';
34
-
35
- if ( isset( $data['type'] ) ) {
36
- $term_slug = $data['type'];
37
- $term_name = $get_steps[ $data['type'] ];
38
- }
39
-
40
- if ( ! _is_cartflows_pro() && ( 'upsell' === $term_slug || 'downsell' === $term_slug ) ) {
41
- $step_wrap_class .= ' invalid-step';
42
- }
43
-
44
- if ( isset( $_GET['highlight-step-id'] ) && $_GET['highlight-step-id'] == $data['id'] ) {
45
- $step_wrap_class .= ' wcf-new-step-highlight';
46
- }
47
-
48
- if ( 'checkout' === $term_slug ) {
49
-
50
- $common = Cartflows_Helper::get_common_settings();
51
-
52
- $is_global_checkout = (int) $common['global_checkout'];
53
-
54
- if ( $data['id'] === $is_global_checkout ) {
55
- $step_wrap_class .= ' wcf-global-checkout';
56
- }
57
- }
58
-
59
- if ( 'upsell' === $term_slug || 'downsell' === $term_slug || 'checkout' === $term_slug ) {
60
-
61
- $has_product_assigned = Cartflows_Helper::has_product_assigned( $data['id'] );
62
-
63
- if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
64
- $step_wrap_class .= ' wcf-no-product-step';
65
- }
66
- }
67
-
68
- ?>
69
- <div class="wcf-step-wrap <?php echo $step_wrap_class; ?>" data-id="<?php echo $data['id']; ?>" data-term-slug="<?php echo esc_attr( $term_slug ); ?>">
70
- <div class="wcf-step">
71
- <div class="wcf-step-left-content">
72
- <span class="dashicons dashicons-menu"></span>
73
- <span><?php echo wp_trim_words( get_the_title( $data['id'] ), 3 ); ?></span>
74
- <span class="wcf-flow-badge"><?php echo esc_attr( $term_name ); ?></span>
75
-
76
- <?php
77
- if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
78
- ?>
79
- <span class="wcf-no-product-badge"><?php _e( 'No Product Assigned', 'cartflows' ); ?></span>
80
- <?php
81
- } elseif ( ( $has_product_assigned ) && ( $data['id'] === $is_global_checkout ) ) {
82
- ?>
83
- <span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout - Remove selected checkout product', 'cartflows' ); ?></span>
84
- <?php
85
- } elseif ( ( ! $has_product_assigned ) && $data['id'] === $is_global_checkout ) {
86
- ?>
87
- <span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout', 'cartflows' ); ?></span>
88
- <?php
89
- }
90
- ?>
91
-
92
- <input type="hidden" class="wcf-steps-hidden" name="wcf-steps[]" value="<?php echo $data['id']; ?>">
93
- </div>
94
- <div class="wcf-steps-action-buttons">
95
- <a href="<?php echo get_permalink( $data['id'] ); ?>" target="_blank" class="wcf-step-view wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'View Step', 'cartflows' ); ?>" >
96
- <span class="dashicons dashicons-visibility"></span>
97
- <span class="wcf-step-act-btn-text">View</span>
98
- </a>
99
- <a href="<?php echo get_edit_post_link( $data['id'] ); ?>" class="wcf-step-edit wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Edit Step', 'cartflows' ); ?>" >
100
- <span class="dashicons dashicons-edit"></span>
101
- <span class="wcf-step-act-btn-text">Edit</span>
102
- </a>
103
- <a href="<?php echo wp_nonce_url( 'admin.php?action=cartflows_clone_step&post=' . $data['id'], 'step_clone', 'step_clone_nonce' ); ?>" class="wcf-step-clone wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Clone Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
104
- <span class="dashicons dashicons-admin-page"></span>
105
- <span class="wcf-step-act-btn-text">Clone</span>
106
- </a>
107
- <a href="#" class="wcf-step-delete wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Delete Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
108
- <span class="dashicons dashicons-trash"></span>
109
- <span class="wcf-step-act-btn-text">Delete</span>
110
- </a>
111
- </div>
112
- </div>
113
- </div><!-- .wcf-step-wrap -->
114
- <?php } ?>
115
- <?php } ?>
116
- </div><!-- .wcf-flow-steps-container -->
117
- </div> <!-- .wcf-flow-steps-wrap -->
118
- <div class="wcf-flow-buttons-wrap"> <!-- .wcf-flow-buttons-wrap -->
119
- <?php do_action( 'cartflows_bellow_flow_steps' ); ?>
120
- <div class='wcf-add-new-step-btn-wrap'>
121
- <button class='wcf-trigger-popup button button-primary'>
122
- <?php echo __( 'Add New Step', 'cartflows' ); ?>
123
- </button>
124
- </div>
125
- </div><!-- .wcf-flow-buttons-wrap -->
126
- </div><!-- .wcf-flow-settings -->
127
-
128
- <div id="wcf-remote-step-importer" class="wcf-templates-popup-overlay">
129
- <div class="wcf-templates-popup-content">
130
- <div class="spinner"></div>
131
- <div class="wcf-templates-wrap wcf-templates-wrap-flows">
132
-
133
- <div id="wcf-remote-step-actions" class="wcf-template-header">
134
- <div class="wcf-template-logo-wrap">
135
- <span class="wcf-cartflows-logo-img">
136
- <span class="cartflows-logo-icon"></span>
137
- </span>
138
- <span class="wcf-cartflows-title"><?php _e( 'Steps Library', 'cartflows' ); ?></span>
139
- </div>
140
- <div class="wcf-tab-wrapper">
141
- <?php if ( 'other' !== $default_page_builder ) { ?>
142
- <div id="wcf-get-started-steps">
143
- <ul class="filter-links ">
144
- <li>
145
- <a href="#" class="current" data-slug="ready-templates" data-title="<?php _e( 'Ready Templates', 'cartflows' ); ?>"><?php _e( 'Ready Templates', 'cartflows' ); ?></a>
146
- </li>
147
- <li>
148
- <a href="#" data-slug="canvas" data-title="<?php _e( 'Create Your Own', 'cartflows' ); ?>"><?php _e( 'Create Your Own', 'cartflows' ); ?></a>
149
- </li>
150
- </ul>
151
- </div>
152
- <?php } ?>
153
- </div>
154
- <div class="wcf-popup-close-wrap">
155
- <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
156
- </div>
157
- </div>
158
-
159
- <!--<div class="wcf-search-form">
160
- <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
161
- <input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
162
- </div>-->
163
-
164
- <div id="wcf-remote-content">
165
- <?php if ( 'other' !== $default_page_builder ) { ?>
166
- <div id="wcf-ready-templates">
167
- <div id="wcf-remote-filters">
168
- <div id="wcf-page-builders"></div>
169
- <div id="wcf-categories"></div>
170
- </div>
171
- <div class="wcf-page-builder-notice"></div>
172
- <div id="wcf-remote-step-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
173
- <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
174
- </div>
175
- <?php } ?>
176
- <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
177
- <div class="inner">
178
- <div id="wcf-scratch-steps-categories">
179
- <select class="step-type-filter-links filter-links">
180
- <option value="" class="current"> Select Step Type </option>
181
- <option value="52" data-group="52" class="Landing" data-slug="landing" data-title="Landing">Landing</option>
182
- <option value="53" data-group="53" class="Checkout" data-slug="checkout" data-title="Checkout">Checkout</option>
183
- <option value="55" data-group="55" class="Upsell" data-slug="upsell" data-title="Upsell">Upsell</option>
184
- <option value="56" data-group="56" class="Downsell" data-slug="downsell" data-title="Downsell">Downsell</option>
185
- <option value="54" data-group="54" class="Thank You" data-slug="thankyou" data-title="Thank You">Thank You</option>
186
- </select>
187
- </div>
188
- <a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create Step', 'cartflows' ); ?></a>
189
- <?php if ( ! _is_cartflows_pro() ) { ?>
190
- <div class="wcf-template-notice"><p><?php echo __( 'You need a Cartflows Pro version to import Upsell / Downsell', 'cartflows' ); ?></p></div>
191
- <?php } ?>
192
- <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php _e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
193
- </div>
194
- </div>
195
- </div>
196
- </div>
197
- </div>
198
- </div><!-- .wcf-templates-popup-overlay -->
199
- </div>
200
- <?php
1
+ <?php
2
+ /**
3
+ * View Flow steps
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
9
+
10
+ $get_steps = array(
11
+ 'landing' => __( 'Landing', 'cartflows' ),
12
+ 'checkout' => __( 'Checkout', 'cartflows' ),
13
+ 'thankyou' => __( 'Thank You', 'cartflows' ),
14
+ 'upsell' => __( 'Upsell', 'cartflows' ),
15
+ 'downsell' => __( 'Downsell', 'cartflows' ),
16
+
17
+ );
18
+
19
+ ?>
20
+ <div class="wcf-flow-steps-meta-box">
21
+ <div class="wcf-flow-settings">
22
+ <?php do_action( 'cartflows_above_flow_steps' ); ?>
23
+ <div class="wcf-flow-steps-wrap">
24
+ <div class="wcf-flow-steps-container">
25
+ <?php if ( is_array( $options['steps'] ) ) { ?>
26
+ <?php foreach ( $options['steps'] as $index => $data ) { ?>
27
+ <?php
28
+ $term_slug = '';
29
+ $term_name = '';
30
+ $step_wrap_class = '';
31
+ $has_product_assigned = true;
32
+ $is_global_checkout = '';
33
+ $common = '';
34
+
35
+ if ( isset( $data['type'] ) ) {
36
+ $term_slug = $data['type'];
37
+ $term_name = $get_steps[ $data['type'] ];
38
+ }
39
+
40
+ if ( ! _is_cartflows_pro() && ( 'upsell' === $term_slug || 'downsell' === $term_slug ) ) {
41
+ $step_wrap_class .= ' invalid-step';
42
+ }
43
+
44
+ if ( isset( $_GET['highlight-step-id'] ) && $_GET['highlight-step-id'] == $data['id'] ) {
45
+ $step_wrap_class .= ' wcf-new-step-highlight';
46
+ }
47
+
48
+ if ( 'checkout' === $term_slug ) {
49
+
50
+ $common = Cartflows_Helper::get_common_settings();
51
+
52
+ $is_global_checkout = (int) $common['global_checkout'];
53
+
54
+ if ( $data['id'] === $is_global_checkout ) {
55
+ $step_wrap_class .= ' wcf-global-checkout';
56
+ }
57
+ }
58
+
59
+ if ( 'upsell' === $term_slug || 'downsell' === $term_slug || 'checkout' === $term_slug ) {
60
+
61
+ $has_product_assigned = Cartflows_Helper::has_product_assigned( $data['id'] );
62
+
63
+ if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
64
+ $step_wrap_class .= ' wcf-no-product-step';
65
+ }
66
+ }
67
+
68
+ ?>
69
+ <div class="wcf-step-wrap <?php echo $step_wrap_class; ?>" data-id="<?php echo $data['id']; ?>" data-term-slug="<?php echo esc_attr( $term_slug ); ?>">
70
+ <div class="wcf-step">
71
+ <div class="wcf-step-left-content">
72
+ <span class="dashicons dashicons-menu"></span>
73
+ <span><?php echo wp_trim_words( get_the_title( $data['id'] ), 3 ); ?></span>
74
+ <span class="wcf-flow-badge"><?php echo esc_attr( $term_name ); ?></span>
75
+
76
+ <?php
77
+ if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
78
+ ?>
79
+ <span class="wcf-no-product-badge"><?php _e( 'No Product Assigned', 'cartflows' ); ?></span>
80
+ <?php
81
+ } elseif ( ( $has_product_assigned ) && ( $data['id'] === $is_global_checkout ) ) {
82
+ ?>
83
+ <span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout - Remove selected checkout product', 'cartflows' ); ?></span>
84
+ <?php
85
+ } elseif ( ( ! $has_product_assigned ) && $data['id'] === $is_global_checkout ) {
86
+ ?>
87
+ <span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout', 'cartflows' ); ?></span>
88
+ <?php
89
+ }
90
+ ?>
91
+
92
+ <input type="hidden" class="wcf-steps-hidden" name="wcf-steps[]" value="<?php echo $data['id']; ?>">
93
+ </div>
94
+ <div class="wcf-steps-action-buttons">
95
+ <a href="<?php echo get_permalink( $data['id'] ); ?>" target="_blank" class="wcf-step-view wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'View Step', 'cartflows' ); ?>" >
96
+ <span class="dashicons dashicons-visibility"></span>
97
+ <span class="wcf-step-act-btn-text">View</span>
98
+ </a>
99
+ <a href="<?php echo get_edit_post_link( $data['id'] ); ?>" class="wcf-step-edit wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Edit Step', 'cartflows' ); ?>" >
100
+ <span class="dashicons dashicons-edit"></span>
101
+ <span class="wcf-step-act-btn-text">Edit</span>
102
+ </a>
103
+ <a href="<?php echo wp_nonce_url( 'admin.php?action=cartflows_clone_step&post=' . $data['id'], 'step_clone', 'step_clone_nonce' ); ?>" class="wcf-step-clone wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Clone Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
104
+ <span class="dashicons dashicons-admin-page"></span>
105
+ <span class="wcf-step-act-btn-text">Clone</span>
106
+ </a>
107
+ <a href="#" class="wcf-step-delete wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Delete Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
108
+ <span class="dashicons dashicons-trash"></span>
109
+ <span class="wcf-step-act-btn-text">Delete</span>
110
+ </a>
111
+ </div>
112
+ </div>
113
+ </div><!-- .wcf-step-wrap -->
114
+ <?php } ?>
115
+ <?php } ?>
116
+ </div><!-- .wcf-flow-steps-container -->
117
+ </div> <!-- .wcf-flow-steps-wrap -->
118
+ <div class="wcf-flow-buttons-wrap"> <!-- .wcf-flow-buttons-wrap -->
119
+ <?php do_action( 'cartflows_bellow_flow_steps' ); ?>
120
+ <div class='wcf-add-new-step-btn-wrap'>
121
+ <button class='wcf-trigger-popup button button-primary'>
122
+ <?php echo __( 'Add New Step', 'cartflows' ); ?>
123
+ </button>
124
+ </div>
125
+ </div><!-- .wcf-flow-buttons-wrap -->
126
+ </div><!-- .wcf-flow-settings -->
127
+
128
+ <div id="wcf-remote-step-importer" class="wcf-templates-popup-overlay">
129
+ <div class="wcf-templates-popup-content">
130
+ <div class="spinner"></div>
131
+ <div class="wcf-templates-wrap wcf-templates-wrap-flows">
132
+
133
+ <div id="wcf-remote-step-actions" class="wcf-template-header">
134
+ <div class="wcf-template-logo-wrap">
135
+ <span class="wcf-cartflows-logo-img">
136
+ <span class="cartflows-logo-icon"></span>
137
+ </span>
138
+ <span class="wcf-cartflows-title"><?php _e( 'Steps Library', 'cartflows' ); ?></span>
139
+ </div>
140
+ <div class="wcf-tab-wrapper">
141
+ <?php if ( 'other' !== $default_page_builder ) { ?>
142
+ <div id="wcf-get-started-steps">
143
+ <ul class="filter-links ">
144
+ <li>
145
+ <a href="#" class="current" data-slug="ready-templates" data-title="<?php _e( 'Ready Templates', 'cartflows' ); ?>"><?php _e( 'Ready Templates', 'cartflows' ); ?></a>
146
+ </li>
147
+ <li>
148
+ <a href="#" data-slug="canvas" data-title="<?php _e( 'Create Your Own', 'cartflows' ); ?>"><?php _e( 'Create Your Own', 'cartflows' ); ?></a>
149
+ </li>
150
+ </ul>
151
+ </div>
152
+ <?php } ?>
153
+ </div>
154
+ <div class="wcf-popup-close-wrap">
155
+ <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
156
+ </div>
157
+ </div>
158
+
159
+ <!--<div class="wcf-search-form">
160
+ <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
161
+ <input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
162
+ </div>-->
163
+
164
+ <div id="wcf-remote-content">
165
+ <?php if ( 'other' !== $default_page_builder ) { ?>
166
+ <div id="wcf-ready-templates">
167
+ <div id="wcf-remote-filters">
168
+ <div id="wcf-page-builders"></div>
169
+ <div id="wcf-categories"></div>
170
+ </div>
171
+ <div class="wcf-page-builder-notice"></div>
172
+ <div id="wcf-remote-step-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
173
+ <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
174
+ </div>
175
+ <?php } ?>
176
+ <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
177
+ <div class="inner">
178
+ <div id="wcf-scratch-steps-categories">
179
+ <select class="step-type-filter-links filter-links">
180
+ <option value="" class="current"> Select Step Type </option>
181
+ <option value="52" data-group="52" class="Landing" data-slug="landing" data-title="Landing">Landing</option>
182
+ <option value="53" data-group="53" class="Checkout" data-slug="checkout" data-title="Checkout">Checkout</option>
183
+ <option value="55" data-group="55" class="Upsell" data-slug="upsell" data-title="Upsell">Upsell</option>
184
+ <option value="56" data-group="56" class="Downsell" data-slug="downsell" data-title="Downsell">Downsell</option>
185
+ <option value="54" data-group="54" class="Thank You" data-slug="thankyou" data-title="Thank You">Thank You</option>
186
+ </select>
187
+ </div>
188
+ <a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create Step', 'cartflows' ); ?></a>
189
+ <?php if ( ! _is_cartflows_pro() ) { ?>
190
+ <div class="wcf-template-notice"><p><?php echo __( 'You need a Cartflows Pro version to import Upsell / Downsell', 'cartflows' ); ?></p></div>
191
+ <?php } ?>
192
+ <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php _e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
193
+ </div>
194
+ </div>
195
+ </div>
196
+ </div>
197
+ </div>
198
+ </div><!-- .wcf-templates-popup-overlay -->
199
+ </div>
200
+ <?php
modules/landing/classes/class-cartflows-landing-meta.php CHANGED
@@ -1,236 +1,236 @@
1
- <?php
2
- /**
3
- * Landing post meta box
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Landing_Meta extends Cartflows_Meta {
12
-
13
-
14
- /**
15
- * Instance
16
- *
17
- * @var $instance
18
- */
19
- private static $instance;
20
-
21
- /**
22
- * Meta Option
23
- *
24
- * @var $meta_option
25
- */
26
- private static $meta_option = null;
27
-
28
- /**
29
- * Initiator
30
- */
31
- public static function get_instance() {
32
- if ( ! isset( self::$instance ) ) {
33
- self::$instance = new self;
34
- }
35
-
36
- return self::$instance;
37
- }
38
-
39
- /**
40
- * Constructor
41
- */
42
- public function __construct() {
43
-
44
- /* Init Metabox */
45
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
46
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
47
- }
48
-
49
- /**
50
- * Init Metabox
51
- */
52
- public function init_metabox() {
53
-
54
- add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
55
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
56
- }
57
-
58
- /**
59
- * Setup Metabox
60
- */
61
- function setup_meta_box() {
62
-
63
- if ( _is_wcf_landing_type() ) {
64
- add_meta_box(
65
- 'wcf-ladning-settings', // Id.
66
- __( 'Landing Page Settings', 'cartflows' ), // Title.
67
- array( $this, 'landing_meta_box' ), // Callback.
68
- wcf()->utils->get_step_post_type(), // Post_type.
69
- 'normal', // Context.
70
- 'high' // Priority.
71
- );
72
- }
73
- }
74
-
75
- /**
76
- * Landing Metabox Markup
77
- *
78
- * @param object $post Post object.
79
- * @return void
80
- */
81
- function landing_meta_box( $post ) {
82
-
83
- wp_nonce_field( 'save-nonce-landing-step-meta', 'nonce-landing-step-meta' );
84
- $stored = get_post_meta( $post->ID );
85
-
86
- $checkout_meta = self::get_meta_option( $post->ID );
87
-
88
- // Set stored and override defaults.
89
- foreach ( $stored as $key => $value ) {
90
- if ( array_key_exists( $key, $checkout_meta ) ) {
91
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
92
- } else {
93
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
94
- }
95
- }
96
-
97
- // Get defaults.
98
- $meta = self::get_meta_option( $post->ID );
99
-
100
- /**
101
- * Get options
102
- */
103
- $landing_data = array();
104
- foreach ( $meta as $key => $value ) {
105
-
106
- $landing_data[ $key ] = $meta[ $key ]['default'];
107
- }
108
-
109
- do_action( 'wcf_landing_settings_markup_before', $meta );
110
- $this->page_header_tab( $landing_data, $post->ID );
111
- do_action( 'wcf_landing_settings_markup_after', $meta );
112
- }
113
-
114
- /**
115
- * Page Header Tabs
116
- *
117
- * @param array $options Post meta.
118
- * @param int $post_id Post ID.
119
- */
120
- function page_header_tab( $options, $post_id ) {
121
-
122
- $active_tab = get_post_meta( $post_id, 'wcf_active_tab', true );
123
-
124
- if ( empty( $active_tab ) ) {
125
- $active_tab = 'wcf-thankyou-shortcodes';
126
- }
127
-
128
- $tabs = array(
129
- array(
130
- 'title' => __( 'Shortcodes', 'cartflows' ),
131
- 'id' => 'wcf-thankyou-shortcodes',
132
- 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
- 'icon' => 'dashicons-info',
134
- ),
135
- array(
136
- 'title' => __( 'Custom Script', 'cartflows' ),
137
- 'id' => 'wcf-landing-custom-script-header',
138
- 'class' => 'wcf-landing-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
- 'icon' => 'dashicons-format-aside',
140
- ),
141
- );
142
-
143
- ?>
144
- <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
145
- <div class="wcf-table-container">
146
- <div class="wcf-column-left">
147
- <div class="wcf-tab-wrapper">
148
-
149
- <?php foreach ( $tabs as $key => $tab ) { ?>
150
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
151
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
152
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
153
- </div>
154
- <?php } ?>
155
- <input type="hidden" id="wcf_active_tab" name="wcf_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
156
-
157
- </div>
158
- </div>
159
- <div class="wcf-column-right">
160
- <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
161
- <?php
162
-
163
- $next_step_link = wcf()->utils->get_linking_url(
164
- array( 'class' => 'wcf-next-step' )
165
- );
166
-
167
- echo wcf()->meta->get_shortcode_field(
168
- array(
169
- 'label' => __( 'Next Step Link', 'cartflows' ),
170
- 'name' => 'wcf-next-step-link',
171
- 'content' => $next_step_link,
172
- )
173
- );
174
-
175
- ?>
176
- </div>
177
-
178
- <?php $this->tab_custom_script( $options, $post_id ); ?>
179
-
180
- <?php $this->right_column_footer( $options, $post_id ); ?>
181
- </div>
182
- </div>
183
- </div>
184
-
185
- <?php
186
-
187
- }
188
-
189
- /**
190
- * Get metabox options
191
- *
192
- * @param int $post_id post ID.
193
- * @return array
194
- */
195
- public static function get_meta_option( $post_id ) {
196
-
197
- if ( null === self::$meta_option ) {
198
- /**
199
- * Set metabox options
200
- *
201
- * @see http://php.net/manual/en/filter.filters.sanitize.php
202
- */
203
- // self::$meta_option = array(); .
204
- self::$meta_option = wcf()->options->get_landing_fields( $post_id );
205
- }
206
-
207
- return self::$meta_option;
208
- }
209
-
210
- /**
211
- * Metabox Save
212
- *
213
- * @param number $post_id Post ID.
214
- * @return void
215
- */
216
- function save_meta_box( $post_id ) {
217
-
218
- // Checks save status.
219
- $is_autosave = wp_is_post_autosave( $post_id );
220
- $is_revision = wp_is_post_revision( $post_id );
221
-
222
- $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( $_POST['nonce-landing-step-meta'], 'save-nonce-landing-step-meta' ) ) ? true : false;
223
-
224
- // Exits script depending on save status.
225
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
226
- return;
227
- }
228
-
229
- wcf()->options->save_landing_fields( $post_id );
230
- }
231
- }
232
-
233
- /**
234
- * Kicking this off by calling 'get_instance()' method
235
- */
236
- Cartflows_Landing_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Landing post meta box
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Landing_Meta extends Cartflows_Meta {
12
+
13
+
14
+ /**
15
+ * Instance
16
+ *
17
+ * @var $instance
18
+ */
19
+ private static $instance;
20
+
21
+ /**
22
+ * Meta Option
23
+ *
24
+ * @var $meta_option
25
+ */
26
+ private static $meta_option = null;
27
+
28
+ /**
29
+ * Initiator
30
+ */
31
+ public static function get_instance() {
32
+ if ( ! isset( self::$instance ) ) {
33
+ self::$instance = new self;
34
+ }
35
+
36
+ return self::$instance;
37
+ }
38
+
39
+ /**
40
+ * Constructor
41
+ */
42
+ public function __construct() {
43
+
44
+ /* Init Metabox */
45
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
46
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
47
+ }
48
+
49
+ /**
50
+ * Init Metabox
51
+ */
52
+ public function init_metabox() {
53
+
54
+ add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
55
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
56
+ }
57
+
58
+ /**
59
+ * Setup Metabox
60
+ */
61
+ function setup_meta_box() {
62
+
63
+ if ( _is_wcf_landing_type() ) {
64
+ add_meta_box(
65
+ 'wcf-ladning-settings', // Id.
66
+ __( 'Landing Page Settings', 'cartflows' ), // Title.
67
+ array( $this, 'landing_meta_box' ), // Callback.
68
+ wcf()->utils->get_step_post_type(), // Post_type.
69
+ 'normal', // Context.
70
+ 'high' // Priority.
71
+ );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Landing Metabox Markup
77
+ *
78
+ * @param object $post Post object.
79
+ * @return void
80
+ */
81
+ function landing_meta_box( $post ) {
82
+
83
+ wp_nonce_field( 'save-nonce-landing-step-meta', 'nonce-landing-step-meta' );
84
+ $stored = get_post_meta( $post->ID );
85
+
86
+ $checkout_meta = self::get_meta_option( $post->ID );
87
+
88
+ // Set stored and override defaults.
89
+ foreach ( $stored as $key => $value ) {
90
+ if ( array_key_exists( $key, $checkout_meta ) ) {
91
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
92
+ } else {
93
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
94
+ }
95
+ }
96
+
97
+ // Get defaults.
98
+ $meta = self::get_meta_option( $post->ID );
99
+
100
+ /**
101
+ * Get options
102
+ */
103
+ $landing_data = array();
104
+ foreach ( $meta as $key => $value ) {
105
+
106
+ $landing_data[ $key ] = $meta[ $key ]['default'];
107
+ }
108
+
109
+ do_action( 'wcf_landing_settings_markup_before', $meta );
110
+ $this->page_header_tab( $landing_data, $post->ID );
111
+ do_action( 'wcf_landing_settings_markup_after', $meta );
112
+ }
113
+
114
+ /**
115
+ * Page Header Tabs
116
+ *
117
+ * @param array $options Post meta.
118
+ * @param int $post_id Post ID.
119
+ */
120
+ function page_header_tab( $options, $post_id ) {
121
+
122
+ $active_tab = get_post_meta( $post_id, 'wcf_active_tab', true );
123
+
124
+ if ( empty( $active_tab ) ) {
125
+ $active_tab = 'wcf-thankyou-shortcodes';
126
+ }
127
+
128
+ $tabs = array(
129
+ array(
130
+ 'title' => __( 'Shortcodes', 'cartflows' ),
131
+ 'id' => 'wcf-thankyou-shortcodes',
132
+ 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
+ 'icon' => 'dashicons-info',
134
+ ),
135
+ array(
136
+ 'title' => __( 'Custom Script', 'cartflows' ),
137
+ 'id' => 'wcf-landing-custom-script-header',
138
+ 'class' => 'wcf-landing-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
+ 'icon' => 'dashicons-format-aside',
140
+ ),
141
+ );
142
+
143
+ ?>
144
+ <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
145
+ <div class="wcf-table-container">
146
+ <div class="wcf-column-left">
147
+ <div class="wcf-tab-wrapper">
148
+
149
+ <?php foreach ( $tabs as $key => $tab ) { ?>
150
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
151
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
152
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
153
+ </div>
154
+ <?php } ?>
155
+ <input type="hidden" id="wcf_active_tab" name="wcf_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
156
+
157
+ </div>
158
+ </div>
159
+ <div class="wcf-column-right">
160
+ <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
161
+ <?php
162
+
163
+ $next_step_link = wcf()->utils->get_linking_url(
164
+ array( 'class' => 'wcf-next-step' )
165
+ );
166
+
167
+ echo wcf()->meta->get_shortcode_field(
168
+ array(
169
+ 'label' => __( 'Next Step Link', 'cartflows' ),
170
+ 'name' => 'wcf-next-step-link',
171
+ 'content' => $next_step_link,
172
+ )
173
+ );
174
+
175
+ ?>
176
+ </div>
177
+
178
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
179
+
180
+ <?php $this->right_column_footer( $options, $post_id ); ?>
181
+ </div>
182
+ </div>
183
+ </div>
184
+
185
+ <?php
186
+
187
+ }
188
+
189
+ /**
190
+ * Get metabox options
191
+ *
192
+ * @param int $post_id post ID.
193
+ * @return array
194
+ */
195
+ public static function get_meta_option( $post_id ) {
196
+
197
+ if ( null === self::$meta_option ) {
198
+ /**
199
+ * Set metabox options
200
+ *
201
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
202
+ */
203
+ // self::$meta_option = array(); .
204
+ self::$meta_option = wcf()->options->get_landing_fields( $post_id );
205
+ }
206
+
207
+ return self::$meta_option;
208
+ }
209
+
210
+ /**
211
+ * Metabox Save
212
+ *
213
+ * @param number $post_id Post ID.
214
+ * @return void
215
+ */
216
+ function save_meta_box( $post_id ) {
217
+
218
+ // Checks save status.
219
+ $is_autosave = wp_is_post_autosave( $post_id );
220
+ $is_revision = wp_is_post_revision( $post_id );
221
+
222
+ $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( $_POST['nonce-landing-step-meta'], 'save-nonce-landing-step-meta' ) ) ? true : false;
223
+
224
+ // Exits script depending on save status.
225
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
226
+ return;
227
+ }
228
+
229
+ wcf()->options->save_landing_fields( $post_id );
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Kicking this off by calling 'get_instance()' method
235
+ */
236
+ Cartflows_Landing_Meta::get_instance();
modules/thankyou/classes/class-cartflows-thankyou-meta.php CHANGED
@@ -1,371 +1,371 @@
1
- <?php
2
- /**
3
- * Checkout post meta box
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Thankyou_Meta extends Cartflows_Meta {
12
-
13
- /**
14
- * Instance
15
- *
16
- * @var $instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Meta Option
22
- *
23
- * @var $meta_option
24
- */
25
- private static $meta_option = null;
26
-
27
- /**
28
- * Initiator
29
- */
30
- public static function get_instance() {
31
- if ( ! isset( self::$instance ) ) {
32
- self::$instance = new self;
33
- }
34
-
35
- return self::$instance;
36
- }
37
-
38
- /**
39
- * Constructor
40
- */
41
- public function __construct() {
42
-
43
- /* Init Metabox */
44
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
- }
47
-
48
- /**
49
- * Init Metabox
50
- */
51
- public function init_metabox() {
52
-
53
- add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
- }
56
-
57
- /**
58
- * Setup Metabox
59
- */
60
- function setup_meta_box() {
61
-
62
- if ( _is_wcf_thankyou_type() ) {
63
- add_meta_box(
64
- 'wcf-thankyou-settings', // Id.
65
- __( 'Thank You Page Settings', 'cartflows' ), // Title.
66
- array( $this, 'markup_meta_box' ), // Callback.
67
- wcf()->utils->get_step_post_type(), // Post_type.
68
- 'normal', // Context.
69
- 'high' // Priority.
70
- );
71
- }
72
- }
73
-
74
- /**
75
- * Metabox Markup
76
- *
77
- * @param object $post Post object.
78
- * @return void
79
- */
80
- function markup_meta_box( $post ) {
81
-
82
- wp_nonce_field( 'save-nonce-thankyou-step-meta', 'nonce-thankyou-step-meta' );
83
- $stored = get_post_meta( $post->ID );
84
-
85
- $checkout_meta = self::get_meta_option( $post->ID );
86
-
87
- // Set stored and override defaults.
88
- foreach ( $stored as $key => $value ) {
89
- if ( array_key_exists( $key, $checkout_meta ) ) {
90
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
91
- } else {
92
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
93
- }
94
- }
95
-
96
- // Get defaults.
97
- $meta = self::get_meta_option( $post->ID );
98
-
99
- /**
100
- * Get options
101
- */
102
- $thankyou_data = array();
103
-
104
- foreach ( $meta as $key => $value ) {
105
-
106
- $thankyou_data[ $key ] = $meta[ $key ]['default'];
107
- }
108
-
109
- do_action( 'wcf_thankyou_settings_markup_before', $meta );
110
- $this->page_header_tab( $thankyou_data, $post->ID );
111
- do_action( 'wcf_thankyou_settings_markup_after', $meta );
112
- }
113
-
114
- /**
115
- * Page Header Tabs
116
- *
117
- * @param array $options Post meta.
118
- * @param int $post_id Post ID.
119
- */
120
- function page_header_tab( $options, $post_id ) {
121
-
122
- $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
123
-
124
- if ( empty( $active_tab ) ) {
125
- $active_tab = 'wcf-thankyou-shortcodes';
126
- }
127
-
128
- $tabs = array(
129
- array(
130
- 'title' => __( 'Shortcodes', 'cartflows' ),
131
- 'id' => 'wcf-thankyou-shortcodes',
132
- 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
- 'icon' => 'dashicons-editor-code',
134
- ),
135
- array(
136
- 'title' => __( 'Thank You Design', 'cartflows' ),
137
- 'id' => 'wcf-thankyou-design',
138
- 'class' => 'wcf-thankyou-design' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
- 'icon' => 'dashicons-admin-customizer',
140
- ),
141
- array(
142
- 'title' => __( 'Thank You Fields', 'cartflows' ),
143
- 'id' => 'wcf-thankyou-fields',
144
- 'class' => 'wcf-thankyou-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
145
- 'icon' => 'dashicons-welcome-widgets-menus',
146
- ),
147
- array(
148
- 'title' => __( 'Custom Script', 'cartflows' ),
149
- 'id' => 'wcf-thankyou-custom-script-header',
150
- 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
151
- 'icon' => 'dashicons-format-aside',
152
- ),
153
- );
154
-
155
- ?>
156
- <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
157
- <div class="wcf-table-container">
158
- <div class="wcf-column-left">
159
- <div class="wcf-tab-wrapper">
160
-
161
- <?php foreach ( $tabs as $key => $tab ) { ?>
162
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
163
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
164
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
165
- </div>
166
- <?php } ?>
167
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
168
-
169
- </div>
170
- </div>
171
- <div class="wcf-column-right">
172
- <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
173
- <?php
174
- echo wcf()->meta->get_shortcode_field(
175
- array(
176
- 'label' => __( 'Order Details', 'cartflows' ),
177
- 'name' => 'wcf-order-details',
178
- 'content' => esc_html( '[cartflows_order_details]' ),
179
- )
180
- );
181
- ?>
182
- </div>
183
- <div class="wcf-thankyou-design wcf-tab-content widefat">
184
- <?php
185
-
186
- echo wcf()->meta->get_section(
187
- array(
188
- 'label' => __( 'Text', 'cartflows' ),
189
- )
190
- );
191
-
192
- echo wcf()->meta->get_color_picker_field(
193
- array(
194
- 'label' => __( 'Color', 'cartflows' ),
195
- 'name' => 'wcf-tq-text-color',
196
- 'value' => $options['wcf-tq-text-color'],
197
- )
198
- );
199
-
200
- echo wcf()->meta->get_font_family_field(
201
- array(
202
- 'for' => 'wcf-tq-font-family',
203
- 'label' => __( 'Font Family', 'cartflows' ),
204
- 'name' => 'wcf-tq-font-family',
205
- 'value' => $options['wcf-tq-font-family'],
206
- )
207
- );
208
-
209
- echo wcf()->meta->get_section(
210
- array(
211
- 'label' => __( 'Heading', 'cartflows' ),
212
- )
213
- );
214
-
215
- echo wcf()->meta->get_color_picker_field(
216
- array(
217
- 'label' => __( 'Color', 'cartflows' ),
218
- 'name' => 'wcf-tq-heading-color',
219
- 'value' => $options['wcf-tq-heading-color'],
220
- )
221
- );
222
-
223
- echo wcf()->meta->get_font_family_field(
224
- array(
225
- 'for' => 'wcf-tq-heading-font-family',
226
- 'label' => __( 'Font Family', 'cartflows' ),
227
- 'name' => 'wcf-tq-heading-font-family',
228
- 'value' => $options['wcf-tq-heading-font-family'],
229
- )
230
- );
231
-
232
- echo wcf()->meta->get_font_weight_field(
233
- array(
234
- 'for' => 'wcf-tq-heading-font-family',
235
- 'label' => __( 'Font Weight', 'cartflows' ),
236
- 'name' => 'wcf-tq-heading-font-wt',
237
- 'value' => $options['wcf-tq-heading-font-wt'],
238
- )
239
- );
240
-
241
- echo wcf()->meta->get_checkbox_field(
242
- array(
243
- 'label' => __( 'Advanced Options', 'cartflows' ),
244
- 'name' => 'wcf-tq-advance-options-fields',
245
- 'value' => $options['wcf-tq-advance-options-fields'],
246
- 'after' => 'Enable',
247
- )
248
- );
249
-
250
- echo wcf()->meta->get_number_field(
251
- array(
252
- 'for' => 'wcf-heading',
253
- 'label' => __( 'Container Width (In px)', 'cartflows' ),
254
- 'name' => 'wcf-tq-container-width',
255
- 'value' => $options['wcf-tq-container-width'],
256
- )
257
- );
258
-
259
- echo wcf()->meta->get_color_picker_field(
260
- array(
261
- 'label' => __( 'Section Background Color', 'cartflows' ),
262
- 'name' => 'wcf-tq-section-bg-color',
263
- 'value' => $options['wcf-tq-section-bg-color'],
264
- )
265
- );
266
-
267
- ?>
268
- </div>
269
- <div class="wcf-thankyou-fields wcf-tab-content widefat">
270
- <?php
271
- echo wcf()->meta->get_checkbox_field(
272
- array(
273
- 'name' => 'wcf-show-overview-section',
274
- 'value' => $options['wcf-show-overview-section'],
275
- 'after' => __( 'Enable Order Overview ', 'cartflows' ),
276
- )
277
- );
278
-
279
- echo wcf()->meta->get_checkbox_field(
280
- array(
281
- 'name' => 'wcf-show-details-section',
282
- 'value' => $options['wcf-show-details-section'],
283
- 'after' => __( 'Enable Order Details ', 'cartflows' ),
284
- )
285
- );
286
-
287
- echo wcf()->meta->get_checkbox_field(
288
- array(
289
- 'name' => 'wcf-show-billing-section',
290
- 'value' => $options['wcf-show-billing-section'],
291
- 'after' => __( 'Enable Billing Details ', 'cartflows' ),
292
- )
293
- );
294
-
295
- echo wcf()->meta->get_checkbox_field(
296
- array(
297
- 'name' => 'wcf-show-shipping-section',
298
- 'value' => $options['wcf-show-shipping-section'],
299
- 'after' => __( 'Enable Shipping Details ', 'cartflows' ),
300
- )
301
- );
302
-
303
- echo wcf()->meta->get_hidden_field(
304
- array(
305
- 'name' => 'wcf-field-google-font-url',
306
- 'value' => $options['wcf-field-google-font-url'],
307
- )
308
- );
309
- ?>
310
- </div>
311
-
312
- <?php $this->tab_custom_script( $options, $post_id ); ?>
313
-
314
- <?php $this->right_column_footer( $options, $post_id ); ?>
315
- </div>
316
- </div>
317
- </div>
318
-
319
- <?php
320
-
321
- }
322
-
323
- /**
324
- * Get metabox options
325
- *
326
- * @param int $post_id post ID.
327
- * @return array
328
- */
329
- public static function get_meta_option( $post_id ) {
330
-
331
- if ( null === self::$meta_option ) {
332
-
333
- /**
334
- * Set metabox options
335
- *
336
- * @see http://php.net/manual/en/filter.filters.sanitize.php
337
- */
338
- self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
339
- }
340
-
341
- return self::$meta_option;
342
-
343
- }
344
-
345
- /**
346
- * Metabox Save
347
- *
348
- * @param number $post_id Post ID.
349
- * @return void
350
- */
351
- function save_meta_box( $post_id ) {
352
-
353
- // Checks save status.
354
- $is_autosave = wp_is_post_autosave( $post_id );
355
- $is_revision = wp_is_post_revision( $post_id );
356
-
357
- $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( $_POST['nonce-thankyou-step-meta'], 'save-nonce-thankyou-step-meta' ) ) ? true : false;
358
-
359
- // Exits script depending on save status.
360
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
361
- return;
362
- }
363
-
364
- wcf()->options->save_thankyou_fields( $post_id );
365
- }
366
- }
367
-
368
- /**
369
- * Kicking this off by calling 'get_instance()' method
370
- */
371
- Cartflows_Thankyou_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Checkout post meta box
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Thankyou_Meta extends Cartflows_Meta {
12
+
13
+ /**
14
+ * Instance
15
+ *
16
+ * @var $instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Meta Option
22
+ *
23
+ * @var $meta_option
24
+ */
25
+ private static $meta_option = null;
26
+
27
+ /**
28
+ * Initiator
29
+ */
30
+ public static function get_instance() {
31
+ if ( ! isset( self::$instance ) ) {
32
+ self::$instance = new self;
33
+ }
34
+
35
+ return self::$instance;
36
+ }
37
+
38
+ /**
39
+ * Constructor
40
+ */
41
+ public function __construct() {
42
+
43
+ /* Init Metabox */
44
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
+ }
47
+
48
+ /**
49
+ * Init Metabox
50
+ */
51
+ public function init_metabox() {
52
+
53
+ add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
+ }
56
+
57
+ /**
58
+ * Setup Metabox
59
+ */
60
+ function setup_meta_box() {
61
+
62
+ if ( _is_wcf_thankyou_type() ) {
63
+ add_meta_box(
64
+ 'wcf-thankyou-settings', // Id.
65
+ __( 'Thank You Page Settings', 'cartflows' ), // Title.
66
+ array( $this, 'markup_meta_box' ), // Callback.
67
+ wcf()->utils->get_step_post_type(), // Post_type.
68
+ 'normal', // Context.
69
+ 'high' // Priority.
70
+ );
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Metabox Markup
76
+ *
77
+ * @param object $post Post object.
78
+ * @return void
79
+ */
80
+ function markup_meta_box( $post ) {
81
+
82
+ wp_nonce_field( 'save-nonce-thankyou-step-meta', 'nonce-thankyou-step-meta' );
83
+ $stored = get_post_meta( $post->ID );
84
+
85
+ $checkout_meta = self::get_meta_option( $post->ID );
86
+
87
+ // Set stored and override defaults.
88
+ foreach ( $stored as $key => $value ) {
89
+ if ( array_key_exists( $key, $checkout_meta ) ) {
90
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
91
+ } else {
92
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
93
+ }
94
+ }
95
+
96
+ // Get defaults.
97
+ $meta = self::get_meta_option( $post->ID );
98
+
99
+ /**
100
+ * Get options
101
+ */
102
+ $thankyou_data = array();
103
+
104
+ foreach ( $meta as $key => $value ) {
105
+
106
+ $thankyou_data[ $key ] = $meta[ $key ]['default'];
107
+ }
108
+
109
+ do_action( 'wcf_thankyou_settings_markup_before', $meta );
110
+ $this->page_header_tab( $thankyou_data, $post->ID );
111
+ do_action( 'wcf_thankyou_settings_markup_after', $meta );
112
+ }
113
+
114
+ /**
115
+ * Page Header Tabs
116
+ *
117
+ * @param array $options Post meta.
118
+ * @param int $post_id Post ID.
119
+ */
120
+ function page_header_tab( $options, $post_id ) {
121
+
122
+ $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
123
+
124
+ if ( empty( $active_tab ) ) {
125
+ $active_tab = 'wcf-thankyou-shortcodes';
126
+ }
127
+
128
+ $tabs = array(
129
+ array(
130
+ 'title' => __( 'Shortcodes', 'cartflows' ),
131
+ 'id' => 'wcf-thankyou-shortcodes',
132
+ 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
+ 'icon' => 'dashicons-editor-code',
134
+ ),
135
+ array(
136
+ 'title' => __( 'Thank You Design', 'cartflows' ),
137
+ 'id' => 'wcf-thankyou-design',
138
+ 'class' => 'wcf-thankyou-design' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
+ 'icon' => 'dashicons-admin-customizer',
140
+ ),
141
+ array(
142
+ 'title' => __( 'Thank You Fields', 'cartflows' ),
143
+ 'id' => 'wcf-thankyou-fields',
144
+ 'class' => 'wcf-thankyou-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
145
+ 'icon' => 'dashicons-welcome-widgets-menus',
146
+ ),
147
+ array(
148
+ 'title' => __( 'Custom Script', 'cartflows' ),
149
+ 'id' => 'wcf-thankyou-custom-script-header',
150
+ 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
151
+ 'icon' => 'dashicons-format-aside',
152
+ ),
153
+ );
154
+
155
+ ?>
156
+ <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
157
+ <div class="wcf-table-container">
158
+ <div class="wcf-column-left">
159
+ <div class="wcf-tab-wrapper">
160
+
161
+ <?php foreach ( $tabs as $key => $tab ) { ?>
162
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
163
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
164
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
165
+ </div>
166
+ <?php } ?>
167
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
168
+
169
+ </div>
170
+ </div>
171
+ <div class="wcf-column-right">
172
+ <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
173
+ <?php
174
+ echo wcf()->meta->get_shortcode_field(
175
+ array(
176
+ 'label' => __( 'Order Details', 'cartflows' ),
177
+ 'name' => 'wcf-order-details',
178
+ 'content' => esc_html( '[cartflows_order_details]' ),
179
+ )
180
+ );
181
+ ?>
182
+ </div>
183
+ <div class="wcf-thankyou-design wcf-tab-content widefat">
184
+ <?php
185
+
186
+ echo wcf()->meta->get_section(
187
+ array(
188
+ 'label' => __( 'Text', 'cartflows' ),
189
+ )
190
+ );
191
+
192
+ echo wcf()->meta->get_color_picker_field(
193
+ array(
194
+ 'label' => __( 'Color', 'cartflows' ),
195
+ 'name' => 'wcf-tq-text-color',
196
+ 'value' => $options['wcf-tq-text-color'],
197
+ )
198
+ );
199
+
200
+ echo wcf()->meta->get_font_family_field(
201
+ array(
202
+ 'for' => 'wcf-tq-font-family',
203
+ 'label' => __( 'Font Family', 'cartflows' ),
204
+ 'name' => 'wcf-tq-font-family',
205
+ 'value' => $options['wcf-tq-font-family'],
206
+ )
207
+ );
208
+
209
+ echo wcf()->meta->get_section(
210
+ array(
211
+ 'label' => __( 'Heading', 'cartflows' ),
212
+ )
213
+ );
214
+
215
+ echo wcf()->meta->get_color_picker_field(
216
+ array(
217
+ 'label' => __( 'Color', 'cartflows' ),
218
+ 'name' => 'wcf-tq-heading-color',
219
+ 'value' => $options['wcf-tq-heading-color'],
220
+ )
221
+ );
222
+
223
+ echo wcf()->meta->get_font_family_field(
224
+ array(
225
+ 'for' => 'wcf-tq-heading-font-family',
226
+ 'label' => __( 'Font Family', 'cartflows' ),
227
+ 'name' => 'wcf-tq-heading-font-family',
228
+ 'value' => $options['wcf-tq-heading-font-family'],
229
+ )
230
+ );
231
+
232
+ echo wcf()->meta->get_font_weight_field(
233
+ array(
234
+ 'for' => 'wcf-tq-heading-font-family',
235
+ 'label' => __( 'Font Weight', 'cartflows' ),
236
+ 'name' => 'wcf-tq-heading-font-wt',
237
+ 'value' => $options['wcf-tq-heading-font-wt'],
238
+ )
239
+ );
240
+
241
+ echo wcf()->meta->get_checkbox_field(
242
+ array(
243
+ 'label' => __( 'Advanced Options', 'cartflows' ),
244
+ 'name' => 'wcf-tq-advance-options-fields',
245
+ 'value' => $options['wcf-tq-advance-options-fields'],
246
+ 'after' => 'Enable',
247
+ )
248
+ );
249
+
250
+ echo wcf()->meta->get_number_field(
251
+ array(
252
+ 'for' => 'wcf-heading',
253
+ 'label' => __( 'Container Width (In px)', 'cartflows' ),
254
+ 'name' => 'wcf-tq-container-width',
255
+ 'value' => $options['wcf-tq-container-width'],
256
+ )
257
+ );
258
+
259
+ echo wcf()->meta->get_color_picker_field(
260
+ array(
261
+ 'label' => __( 'Section Background Color', 'cartflows' ),
262
+ 'name' => 'wcf-tq-section-bg-color',
263
+ 'value' => $options['wcf-tq-section-bg-color'],
264
+ )
265
+ );
266
+
267
+ ?>
268
+ </div>
269
+ <div class="wcf-thankyou-fields wcf-tab-content widefat">
270
+ <?php
271
+ echo wcf()->meta->get_checkbox_field(
272
+ array(
273
+ 'name' => 'wcf-show-overview-section',
274
+ 'value' => $options['wcf-show-overview-section'],
275
+ 'after' => __( 'Enable Order Overview ', 'cartflows' ),
276
+ )
277
+ );
278
+
279
+ echo wcf()->meta->get_checkbox_field(
280
+ array(
281
+ 'name' => 'wcf-show-details-section',
282
+ 'value' => $options['wcf-show-details-section'],
283
+ 'after' => __( 'Enable Order Details ', 'cartflows' ),
284
+ )
285
+ );
286
+
287
+ echo wcf()->meta->get_checkbox_field(
288
+ array(
289
+ 'name' => 'wcf-show-billing-section',
290
+ 'value' => $options['wcf-show-billing-section'],
291
+ 'after' => __( 'Enable Billing Details ', 'cartflows' ),
292
+ )
293
+ );
294
+
295
+ echo wcf()->meta->get_checkbox_field(
296
+ array(
297
+ 'name' => 'wcf-show-shipping-section',
298
+ 'value' => $options['wcf-show-shipping-section'],
299
+ 'after' => __( 'Enable Shipping Details ', 'cartflows' ),
300
+ )
301
+ );
302
+
303
+ echo wcf()->meta->get_hidden_field(
304
+ array(
305
+ 'name' => 'wcf-field-google-font-url',
306
+ 'value' => $options['wcf-field-google-font-url'],
307
+ )
308
+ );
309
+ ?>
310
+ </div>
311
+
312
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
313
+
314
+ <?php $this->right_column_footer( $options, $post_id ); ?>
315
+ </div>
316
+ </div>
317
+ </div>
318
+
319
+ <?php
320
+
321
+ }
322
+
323
+ /**
324
+ * Get metabox options
325
+ *
326
+ * @param int $post_id post ID.
327
+ * @return array
328
+ */
329
+ public static function get_meta_option( $post_id ) {
330
+
331
+ if ( null === self::$meta_option ) {
332
+
333
+ /**
334
+ * Set metabox options
335
+ *
336
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
337
+ */
338
+ self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
339
+ }
340
+
341
+ return self::$meta_option;
342
+
343
+ }
344
+
345
+ /**
346
+ * Metabox Save
347
+ *
348
+ * @param number $post_id Post ID.
349
+ * @return void
350
+ */
351
+ function save_meta_box( $post_id ) {
352
+
353
+ // Checks save status.
354
+ $is_autosave = wp_is_post_autosave( $post_id );
355
+ $is_revision = wp_is_post_revision( $post_id );
356
+
357
+ $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( $_POST['nonce-thankyou-step-meta'], 'save-nonce-thankyou-step-meta' ) ) ? true : false;
358
+
359
+ // Exits script depending on save status.
360
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
361
+ return;
362
+ }
363
+
364
+ wcf()->options->save_thankyou_fields( $post_id );
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Kicking this off by calling 'get_instance()' method
370
+ */
371
+ Cartflows_Thankyou_Meta::get_instance();
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
- === Funnel Builder by CartFlows - Create High Converting Sales Funnels For WordPress ===
2
  Contributors: brainstormforce, wpcrafter
3
  Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: woocommerce, cart
5
  Requires at least: 4.4
6
  Requires PHP: 5.6
7
  Tested up to: 5.1
8
- Stable tag: 1.1.12
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -93,6 +93,13 @@ Say goodby to using the same ridgid checkout page that everyone else is using. C
93
 
94
  == Changelog ==
95
 
 
 
 
 
 
 
 
96
  = Version 1.1.12 - Friday, 22nd March 2019 =
97
  * New: Added ability to set checkout page as a home page.
98
  * Fix: Thrive Architect CSS conflict.
1
+ === Funnel Builder by CartFlows - Create High Converting Sales Funnels For WordPress ===
2
  Contributors: brainstormforce, wpcrafter
3
  Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: woocommerce, cart
5
  Requires at least: 4.4
6
  Requires PHP: 5.6
7
  Tested up to: 5.1
8
+ Stable tag: 1.1.13
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
93
 
94
  == Changelog ==
95
 
96
+ = Version 1.1.13 - Tuesday, 9th April 2019 =
97
+ * Improvement: Added compatibility for a Two-Step checkout style of CartFlows Pro.
98
+ * Fix: CSS conflict with the Divi theme.
99
+ * Fix: Checkout field validation issue.
100
+ * Fix: Conflict with the Norebro theme.
101
+ * Fix: Redirection issue while paying through a Swish payment gateway.
102
+
103
  = Version 1.1.12 - Friday, 22nd March 2019 =
104
  * New: Added ability to set checkout page as a home page.
105
  * Fix: Thrive Architect CSS conflict.
woocommerce/template/cart/cart-shipping.php CHANGED
@@ -1,79 +1,79 @@
1
- <?php
2
- /**
3
- * Shipping Methods Display
4
- *
5
- * In 2.1 we show methods per package. This allows for multiple methods per order if so desired.
6
- *
7
- * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-shipping.php.
8
- *
9
- * HOWEVER, on occasion WooCommerce will need to update template files and you
10
- * (the theme developer) will need to copy the new files to your theme to
11
- * maintain compatibility. We try to do this as little as possible, but it does
12
- * happen. When this occurs the version of the template file will be bumped and
13
- * the readme will list any important changes.
14
- *
15
- * @see https://docs.woocommerce.com/document/template-structure/
16
- * @package WooCommerce/Templates
17
- * @version 3.5.0
18
- */
19
-
20
- defined( 'ABSPATH' ) || exit;
21
-
22
- $formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' );
23
- $has_calculated_shipping = ! empty( $has_calculated_shipping );
24
- $show_shipping_calculator = ! empty( $show_shipping_calculator );
25
- $calculator_text = '';
26
- ?>
27
- <tr class="woocommerce-shipping-totals shipping">
28
- <th><?php echo wp_kses_post( $package_name ); ?></th>
29
- <td data-title="<?php echo esc_attr( $package_name ); ?>">
30
- <?php if ( $available_methods ) : ?>
31
- <ul id="shipping_method" class="woocommerce-shipping-methods">
32
- <?php foreach ( $available_methods as $method ) : ?>
33
- <li>
34
- <?php
35
- if ( 1 < count( $available_methods ) ) {
36
- printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ), checked( $method->id, $chosen_method, false ) ); // WPCS: XSS ok.
37
- } else {
38
- printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ) ); // WPCS: XSS ok.
39
- }
40
- printf( '<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr( sanitize_title( $method->id ) ), wc_cart_totals_shipping_method_label( $method ) ); // WPCS: XSS ok.
41
- do_action( 'woocommerce_after_shipping_rate', $method, $index );
42
- ?>
43
- </li>
44
- <?php endforeach; ?>
45
- </ul>
46
- <?php if ( is_cart() ) : ?>
47
- <p class="woocommerce-shipping-destination">
48
- <?php
49
- if ( $formatted_destination ) {
50
- // Translators: $s shipping destination.
51
- printf( esc_html__( 'Estimate for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
52
- $calculator_text = __( 'Change address', 'woocommerce' );
53
- } else {
54
- echo esc_html__( 'This is only an estimate. Prices will be updated during checkout.', 'woocommerce' );
55
- }
56
- ?>
57
- </p>
58
- <?php endif; ?>
59
- <?php
60
- elseif ( ! $has_calculated_shipping || ! $formatted_destination ) :
61
- esc_html_e( 'Enter your address to view shipping options.', 'woocommerce' );
62
- elseif ( ! is_cart() ) :
63
- echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
64
- else :
65
- // Translators: $s shipping destination.
66
- echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html', sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
67
- $calculator_text = __( 'Enter a different address', 'woocommerce' );
68
- endif;
69
- ?>
70
-
71
- <?php if ( $show_package_details ) : ?>
72
- <?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
73
- <?php endif; ?>
74
-
75
- <?php if ( $show_shipping_calculator ) : ?>
76
- <?php woocommerce_shipping_calculator( $calculator_text ); ?>
77
- <?php endif; ?>
78
- </td>
79
- </tr>
1
+ <?php
2
+ /**
3
+ * Shipping Methods Display
4
+ *
5
+ * In 2.1 we show methods per package. This allows for multiple methods per order if so desired.
6
+ *
7
+ * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-shipping.php.
8
+ *
9
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
10
+ * (the theme developer) will need to copy the new files to your theme to
11
+ * maintain compatibility. We try to do this as little as possible, but it does
12
+ * happen. When this occurs the version of the template file will be bumped and
13
+ * the readme will list any important changes.
14
+ *
15
+ * @see https://docs.woocommerce.com/document/template-structure/
16
+ * @package WooCommerce/Templates
17
+ * @version 3.5.0
18
+ */
19
+
20
+ defined( 'ABSPATH' ) || exit;
21
+
22
+ $formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' );
23
+ $has_calculated_shipping = ! empty( $has_calculated_shipping );
24
+ $show_shipping_calculator = ! empty( $show_shipping_calculator );
25
+ $calculator_text = '';
26
+ ?>
27
+ <tr class="woocommerce-shipping-totals shipping">
28
+ <th><?php echo wp_kses_post( $package_name ); ?></th>
29
+ <td data-title="<?php echo esc_attr( $package_name ); ?>">
30
+ <?php if ( $available_methods ) : ?>
31
+ <ul id="shipping_method" class="woocommerce-shipping-methods">
32
+ <?php foreach ( $available_methods as $method ) : ?>
33
+ <li>
34
+ <?php
35
+ if ( 1 < count( $available_methods ) ) {
36
+ printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ), checked( $method->id, $chosen_method, false ) ); // WPCS: XSS ok.
37
+ } else {
38
+ printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ) ); // WPCS: XSS ok.
39
+ }
40
+ printf( '<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr( sanitize_title( $method->id ) ), wc_cart_totals_shipping_method_label( $method ) ); // WPCS: XSS ok.
41
+ do_action( 'woocommerce_after_shipping_rate', $method, $index );
42
+ ?>
43
+ </li>
44
+ <?php endforeach; ?>
45
+ </ul>
46
+ <?php if ( is_cart() ) : ?>
47
+ <p class="woocommerce-shipping-destination">
48
+ <?php
49
+ if ( $formatted_destination ) {
50
+ // Translators: $s shipping destination.
51
+ printf( esc_html__( 'Estimate for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
52
+ $calculator_text = __( 'Change address', 'woocommerce' );
53
+ } else {
54
+ echo esc_html__( 'This is only an estimate. Prices will be updated during checkout.', 'woocommerce' );
55
+ }
56
+ ?>
57
+ </p>
58
+ <?php endif; ?>
59
+ <?php
60
+ elseif ( ! $has_calculated_shipping || ! $formatted_destination ) :
61
+ esc_html_e( 'Enter your address to view shipping options.', 'woocommerce' );
62
+ elseif ( ! is_cart() ) :
63
+ echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
64
+ else :
65
+ // Translators: $s shipping destination.
66
+ echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html', sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
67
+ $calculator_text = __( 'Enter a different address', 'woocommerce' );
68
+ endif;
69
+ ?>
70
+
71
+ <?php if ( $show_package_details ) : ?>
72
+ <?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
73
+ <?php endif; ?>
74
+
75
+ <?php if ( $show_shipping_calculator ) : ?>
76
+ <?php woocommerce_shipping_calculator( $calculator_text ); ?>
77
+ <?php endif; ?>
78
+ </td>
79
+ </tr>
woocommerce/template/checkout/form-billing.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * Checkout billing information form
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-billing.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @author WooThemes
15
- * @package WooCommerce/Templates
16
- * @version 3.0.9
17
- */
18
-
19
- if ( ! defined( 'ABSPATH' ) ) {
20
- exit; // Exit if accessed directly.
21
- }
22
-
23
- ?>
24
- <div class="woocommerce-billing-fields">
25
- <?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>
26
-
27
- <h3><?php _e( 'Billing &amp; Shipping', 'woocommerce' ); ?></h3>
28
-
29
- <?php else : ?>
30
-
31
- <h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>
32
-
33
- <?php endif; ?>
34
-
35
- <?php do_action( 'woocommerce_before_checkout_billing_form', $checkout ); ?>
36
-
37
- <div class="woocommerce-billing-fields__field-wrapper">
38
- <?php
39
- $fields = $checkout->get_checkout_fields( 'billing' );
40
-
41
- foreach ( $fields as $key => $field ) {
42
- if ( isset( $field['country_field'], $fields[ $field['country_field'] ] ) ) {
43
- $field['country'] = $checkout->get_value( $field['country_field'] );
44
- }
45
- woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
46
- }
47
- ?>
48
- </div>
49
-
50
- <?php do_action( 'woocommerce_after_checkout_billing_form', $checkout ); ?>
51
- </div>
52
-
53
- <?php if ( ! is_user_logged_in() && $checkout->is_registration_enabled() ) : ?>
54
- <div class="woocommerce-account-fields">
55
- <?php if ( ! $checkout->is_registration_required() ) : ?>
56
-
57
- <p class="form-row form-row-wide create-account">
58
- <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
59
- <input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ); ?> type="checkbox" name="createaccount" value="1" /> <span><?php _e( 'Create an account?', 'woocommerce' ); ?></span>
60
- </label>
61
- </p>
62
-
63
- <?php endif; ?>
64
-
65
- <?php do_action( 'woocommerce_before_checkout_registration_form', $checkout ); ?>
66
-
67
- <?php if ( $checkout->get_checkout_fields( 'account' ) ) : ?>
68
-
69
- <div class="create-account">
70
- <?php foreach ( $checkout->get_checkout_fields( 'account' ) as $key => $field ) : ?>
71
- <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
72
- <?php endforeach; ?>
73
- <div class="clear"></div>
74
- </div>
75
-
76
- <?php endif; ?>
77
-
78
- <?php do_action( 'woocommerce_after_checkout_registration_form', $checkout ); ?>
79
- </div>
80
- <?php endif; ?>
1
+ <?php
2
+ /**
3
+ * Checkout billing information form
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-billing.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @author WooThemes
15
+ * @package WooCommerce/Templates
16
+ * @version 3.0.9
17
+ */
18
+
19
+ if ( ! defined( 'ABSPATH' ) ) {
20
+ exit; // Exit if accessed directly.
21
+ }
22
+
23
+ ?>
24
+ <div class="woocommerce-billing-fields">
25
+ <?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>
26
+
27
+ <h3><?php _e( 'Billing &amp; Shipping', 'woocommerce' ); ?></h3>
28
+
29
+ <?php else : ?>
30
+
31
+ <h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>
32
+
33
+ <?php endif; ?>
34
+
35
+ <?php do_action( 'woocommerce_before_checkout_billing_form', $checkout ); ?>
36
+
37
+ <div class="woocommerce-billing-fields__field-wrapper">
38
+ <?php
39
+ $fields = $checkout->get_checkout_fields( 'billing' );
40
+
41
+ foreach ( $fields as $key => $field ) {
42
+ if ( isset( $field['country_field'], $fields[ $field['country_field'] ] ) ) {
43
+ $field['country'] = $checkout->get_value( $field['country_field'] );
44
+ }
45
+ woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
46
+ }
47
+ ?>
48
+ </div>
49
+
50
+ <?php do_action( 'woocommerce_after_checkout_billing_form', $checkout ); ?>
51
+ </div>
52
+
53
+ <?php if ( ! is_user_logged_in() && $checkout->is_registration_enabled() ) : ?>
54
+ <div class="woocommerce-account-fields">
55
+ <?php if ( ! $checkout->is_registration_required() ) : ?>
56
+
57
+ <p class="form-row form-row-wide create-account">
58
+ <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
59
+ <input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ); ?> type="checkbox" name="createaccount" value="1" /> <span><?php _e( 'Create an account?', 'woocommerce' ); ?></span>
60
+ </label>
61
+ </p>
62
+
63
+ <?php endif; ?>
64
+
65
+ <?php do_action( 'woocommerce_before_checkout_registration_form', $checkout ); ?>
66
+
67
+ <?php if ( $checkout->get_checkout_fields( 'account' ) ) : ?>
68
+
69
+ <div class="create-account">
70
+ <?php foreach ( $checkout->get_checkout_fields( 'account' ) as $key => $field ) : ?>
71
+ <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
72
+ <?php endforeach; ?>
73
+ <div class="clear"></div>
74
+ </div>
75
+
76
+ <?php endif; ?>
77
+
78
+ <?php do_action( 'woocommerce_after_checkout_registration_form', $checkout ); ?>
79
+ </div>
80
+ <?php endif; ?>
woocommerce/template/checkout/form-checkout.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Checkout Form
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @package WooCommerce/Templates
15
- * @version 3.5.0
16
- */
17
-
18
- if ( ! defined( 'ABSPATH' ) ) {
19
- exit;
20
- }
21
-
22
- do_action( 'woocommerce_before_checkout_form', $checkout );
23
-
24
- // If checkout registration is disabled and not logged in, the user cannot checkout.
25
- if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
26
- echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
27
- return;
28
- }
29
-
30
- ?>
31
-
32
- <form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
33
-
34
- <?php if ( $checkout->get_checkout_fields() ) : ?>
35
-
36
- <?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>
37
-
38
- <div class="col2-set" id="customer_details">
39
- <div class="col-1">
40
- <?php do_action( 'woocommerce_checkout_billing' ); ?>
41
- </div>
42
-
43
- <div class="col-2">
44
- <?php do_action( 'woocommerce_checkout_shipping' ); ?>
45
- </div>
46
- </div>
47
-
48
- <?php do_action( 'woocommerce_checkout_after_customer_details' ); ?>
49
-
50
- <?php endif; ?>
51
-
52
- <h3 id="order_review_heading"><?php esc_html_e( 'Your order', 'woocommerce' ); ?></h3>
53
-
54
- <?php do_action( 'woocommerce_checkout_before_order_review' ); ?>
55
-
56
- <div id="order_review" class="woocommerce-checkout-review-order">
57
- <?php do_action( 'woocommerce_checkout_order_review' ); ?>
58
- </div>
59
-
60
- <?php do_action( 'woocommerce_checkout_after_order_review' ); ?>
61
-
62
- </form>
63
-
64
- <?php do_action( 'woocommerce_after_checkout_form', $checkout ); ?>
1
+ <?php
2
+ /**
3
+ * Checkout Form
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.5.0
16
+ */
17
+
18
+ if ( ! defined( 'ABSPATH' ) ) {
19
+ exit;
20
+ }
21
+
22
+ do_action( 'woocommerce_before_checkout_form', $checkout );
23
+
24
+ // If checkout registration is disabled and not logged in, the user cannot checkout.
25
+ if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
26
+ echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
27
+ return;
28
+ }
29
+
30
+ ?>
31
+
32
+ <form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
33
+
34
+ <?php if ( $checkout->get_checkout_fields() ) : ?>
35
+
36
+ <?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>
37
+
38
+ <div class="col2-set" id="customer_details">
39
+ <div class="col-1">
40
+ <?php do_action( 'woocommerce_checkout_billing' ); ?>
41
+ </div>
42
+
43
+ <div class="col-2">
44
+ <?php do_action( 'woocommerce_checkout_shipping' ); ?>
45
+ </div>
46
+ </div>
47
+
48
+ <?php do_action( 'woocommerce_checkout_after_customer_details' ); ?>
49
+
50
+ <?php endif; ?>
51
+
52
+ <h3 id="order_review_heading"><?php esc_html_e( 'Your order', 'woocommerce' ); ?></h3>
53
+
54
+ <?php do_action( 'woocommerce_checkout_before_order_review' ); ?>
55
+
56
+ <div id="order_review" class="woocommerce-checkout-review-order">
57
+ <?php do_action( 'woocommerce_checkout_order_review' ); ?>
58
+ </div>
59
+
60
+ <?php do_action( 'woocommerce_checkout_after_order_review' ); ?>
61
+
62
+ </form>
63
+
64
+ <?php do_action( 'woocommerce_after_checkout_form', $checkout ); ?>
woocommerce/template/checkout/form-coupon.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /**
3
- * Checkout coupon form
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-coupon.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @package WooCommerce/Templates
15
- * @version 3.4.4
16
- */
17
-
18
- defined( 'ABSPATH' ) || exit;
19
-
20
- if ( ! wc_coupons_enabled() ) { // @codingStandardsIgnoreLine.
21
- return;
22
- }
23
-
24
- ?>
25
- <div class="woocommerce-form-coupon-toggle">
26
- <?php wc_print_notice( apply_filters( 'woocommerce_checkout_coupon_message', __( 'Have a coupon?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>' ), 'notice' ); ?>
27
- </div>
28
-
29
- <form class="checkout_coupon woocommerce-form-coupon" method="post" style="display:none">
30
-
31
- <p><?php esc_html_e( 'If you have a coupon code, please apply it below.', 'woocommerce' ); ?></p>
32
-
33
- <p class="form-row form-row-first">
34
- <input type="text" name="coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="coupon_code" value="" />
35
- </p>
36
-
37
- <p class="form-row form-row-last">
38
- <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?></button>
39
- </p>
40
-
41
- <div class="clear"></div>
42
- </form>
1
+ <?php
2
+ /**
3
+ * Checkout coupon form
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-coupon.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.4.4
16
+ */
17
+
18
+ defined( 'ABSPATH' ) || exit;
19
+
20
+ if ( ! wc_coupons_enabled() ) { // @codingStandardsIgnoreLine.
21
+ return;
22
+ }
23
+
24
+ ?>
25
+ <div class="woocommerce-form-coupon-toggle">
26
+ <?php wc_print_notice( apply_filters( 'woocommerce_checkout_coupon_message', __( 'Have a coupon?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>' ), 'notice' ); ?>
27
+ </div>
28
+
29
+ <form class="checkout_coupon woocommerce-form-coupon" method="post" style="display:none">
30
+
31
+ <p><?php esc_html_e( 'If you have a coupon code, please apply it below.', 'woocommerce' ); ?></p>
32
+
33
+ <p class="form-row form-row-first">
34
+ <input type="text" name="coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="coupon_code" value="" />
35
+ </p>
36
+
37
+ <p class="form-row form-row-last">
38
+ <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?></button>
39
+ </p>
40
+
41
+ <div class="clear"></div>
42
+ </form>
woocommerce/template/checkout/form-login.php CHANGED
@@ -1,36 +1,36 @@
1
- <?php
2
- /**
3
- * Checkout login form
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-login.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @package WooCommerce/Templates
15
- * @version 3.4.0
16
- */
17
-
18
- defined( 'ABSPATH' ) || exit;
19
-
20
- if ( is_user_logged_in() || 'no' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) {
21
- return;
22
- }
23
-
24
- ?>
25
- <div class="woocommerce-form-login-toggle">
26
- <?php wc_print_notice( apply_filters( 'woocommerce_checkout_login_message', __( 'Returning customer?', 'woocommerce' ) ) . ' <a href="#" class="showlogin">' . __( 'Click here to login', 'woocommerce' ) . '</a>', 'notice' ); ?>
27
- </div>
28
- <?php
29
-
30
- woocommerce_login_form(
31
- array(
32
- 'message' => __( 'If you have shopped with us before, please enter your details below. If you are a new customer, please proceed to the Billing &amp; Shipping section.', 'woocommerce' ),
33
- 'redirect' => wc_get_page_permalink( 'checkout' ),
34
- 'hidden' => true,
35
- )
36
- );
1
+ <?php
2
+ /**
3
+ * Checkout login form
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-login.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.4.0
16
+ */
17
+
18
+ defined( 'ABSPATH' ) || exit;
19
+
20
+ if ( is_user_logged_in() || 'no' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) {
21
+ return;
22
+ }
23
+
24
+ ?>
25
+ <div class="woocommerce-form-login-toggle">
26
+ <?php wc_print_notice( apply_filters( 'woocommerce_checkout_login_message', __( 'Returning customer?', 'woocommerce' ) ) . ' <a href="#" class="showlogin">' . __( 'Click here to login', 'woocommerce' ) . '</a>', 'notice' ); ?>
27
+ </div>
28
+ <?php
29
+
30
+ woocommerce_login_form(
31
+ array(
32
+ 'message' => __( 'If you have shopped with us before, please enter your details below. If you are a new customer, please proceed to the Billing &amp; Shipping section.', 'woocommerce' ),
33
+ 'redirect' => wc_get_page_permalink( 'checkout' ),
34
+ 'hidden' => true,
35
+ )
36
+ );
woocommerce/template/checkout/payment.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Checkout Payment Section
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/payment.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.5.3
16
+ */
17
+
18
+ defined( 'ABSPATH' ) || exit;
19
+
20
+ if ( ! is_ajax() ) {
21
+ do_action( 'woocommerce_review_order_before_payment' );
22
+ }
23
+ ?>
24
+ <div id="payment" class="woocommerce-checkout-payment">
25
+ <?php if ( WC()->cart->needs_payment() ) : ?>
26
+ <ul class="wc_payment_methods payment_methods methods">
27
+ <?php
28
+ if ( ! empty( $available_gateways ) ) {
29
+ foreach ( $available_gateways as $gateway ) {
30
+ wc_get_template( 'checkout/payment-method.php', array( 'gateway' => $gateway ) );
31
+ }
32
+ } else {
33
+ echo '<li class="woocommerce-notice woocommerce-notice--info woocommerce-info">' . apply_filters( 'woocommerce_no_available_payment_methods_message', WC()->customer->get_billing_country() ? esc_html__( 'Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' ) : esc_html__( 'Please fill in your details above to see available payment methods.', 'woocommerce' ) ) . '</li>'; // @codingStandardsIgnoreLine
34
+ }
35
+ ?>
36
+ </ul>
37
+ <?php endif; ?>
38
+ <div class="form-row place-order">
39
+ <noscript>
40
+ <?php
41
+ /* translators: $1 and $2 opening and closing emphasis tags respectively */
42
+ printf( esc_html__( 'Since your browser does not support JavaScript, or it is disabled, please ensure you click the %1$sUpdate Totals%2$s button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce' ), '<em>', '</em>' );
43
+ ?>
44
+ <br/><button type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php esc_attr_e( 'Update totals', 'woocommerce' ); ?>"><?php esc_html_e( 'Update totals', 'woocommerce' ); ?></button>
45
+ </noscript>
46
+
47
+ <?php wc_get_template( 'checkout/terms.php' ); ?>
48
+
49
+ <?php do_action( 'woocommerce_review_order_before_submit' ); ?>
50
+
51
+ <?php echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '">' . esc_html( $order_button_text ) . '</button>' ); // @codingStandardsIgnoreLine ?>
52
+
53
+ <?php do_action( 'woocommerce_review_order_after_submit' ); ?>
54
+
55
+ <?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
56
+ </div>
57
+ </div>
58
+ <?php
59
+ if ( ! is_ajax() ) {
60
+ do_action( 'woocommerce_review_order_after_payment' );
61
+ }
woocommerce/template/checkout/review-order.php CHANGED
@@ -1,113 +1,113 @@
1
- <?php
2
- /**
3
- * Review order table
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/checkout/review-order.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @author WooThemes
15
- * @package WooCommerce/Templates
16
- * @version 3.3.0
17
- */
18
-
19
- if ( ! defined( 'ABSPATH' ) ) {
20
- exit;
21
- }
22
- ?>
23
- <table class="shop_table woocommerce-checkout-review-order-table">
24
- <thead>
25
- <tr>
26
- <th class="product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
27
- <th class="product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
28
- </tr>
29
- </thead>
30
- <tbody>
31
- <?php
32
- do_action( 'woocommerce_review_order_before_cart_contents' );
33
-
34
- foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
35
- $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
36
-
37
- if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
38
- ?>
39
- <tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
40
- <td class="product-name">
41
- <?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;'; ?>
42
- <?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '&times; %s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); ?>
43
- <?php echo wc_get_formatted_cart_item_data( $cart_item ); ?>
44
- </td>
45
- <td class="product-total">
46
- <?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); ?>
47
- </td>
48
- </tr>
49
- <?php
50
- }
51
- }
52
-
53
- do_action( 'woocommerce_review_order_after_cart_contents' );
54
- ?>
55
- </tbody>
56
- <tfoot>
57
-
58
- <tr class="cart-subtotal">
59
- <th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
60
- <td><?php wc_cart_totals_subtotal_html(); ?></td>
61
- </tr>
62
-
63
- <?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
64
- <tr class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
65
- <th><?php wc_cart_totals_coupon_label( $coupon ); ?></th>
66
- <td><?php wc_cart_totals_coupon_html( $coupon ); ?></td>
67
- </tr>
68
- <?php endforeach; ?>
69
-
70
- <?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?>
71
-
72
- <?php do_action( 'woocommerce_review_order_before_shipping' ); ?>
73
-
74
- <?php wc_cart_totals_shipping_html(); ?>
75
-
76
- <?php do_action( 'woocommerce_review_order_after_shipping' ); ?>
77
-
78
- <?php endif; ?>
79
-
80
- <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
81
- <tr class="fee">
82
- <th><?php echo esc_html( $fee->name ); ?></th>
83
- <td><?php wc_cart_totals_fee_html( $fee ); ?></td>
84
- </tr>
85
- <?php endforeach; ?>
86
-
87
- <?php if ( wc_tax_enabled() && ! WC()->cart->display_prices_including_tax() ) : ?>
88
- <?php if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) : ?>
89
- <?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : ?>
90
- <tr class="tax-rate tax-rate-<?php echo sanitize_title( $code ); ?>">
91
- <th><?php echo esc_html( $tax->label ); ?></th>
92
- <td><?php echo wp_kses_post( $tax->formatted_amount ); ?></td>
93
- </tr>
94
- <?php endforeach; ?>
95
- <?php else : ?>
96
- <tr class="tax-total">
97
- <th><?php echo esc_html( WC()->countries->tax_or_vat() ); ?></th>
98
- <td><?php wc_cart_totals_taxes_total_html(); ?></td>
99
- </tr>
100
- <?php endif; ?>
101
- <?php endif; ?>
102
-
103
- <?php do_action( 'woocommerce_review_order_before_order_total' ); ?>
104
-
105
- <tr class="order-total">
106
- <th><?php _e( 'Total', 'woocommerce' ); ?></th>
107
- <td><?php wc_cart_totals_order_total_html(); ?></td>
108
- </tr>
109
-
110
- <?php do_action( 'woocommerce_review_order_after_order_total' ); ?>
111
-
112
- </tfoot>
113
- </table>
1
+ <?php
2
+ /**
3
+ * Review order table
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/review-order.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @author WooThemes
15
+ * @package WooCommerce/Templates
16
+ * @version 3.3.0
17
+ */
18
+
19
+ if ( ! defined( 'ABSPATH' ) ) {
20
+ exit;
21
+ }
22
+ ?>
23
+ <table class="shop_table woocommerce-checkout-review-order-table">
24
+ <thead>
25
+ <tr>
26
+ <th class="product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
27
+ <th class="product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
28
+ </tr>
29
+ </thead>
30
+ <tbody>
31
+ <?php
32
+ do_action( 'woocommerce_review_order_before_cart_contents' );
33
+
34
+ foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
35
+ $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
36
+
37
+ if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
38
+ ?>
39
+ <tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
40
+ <td class="product-name">
41
+ <?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;'; ?>
42
+ <?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '&times; %s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); ?>
43
+ <?php echo wc_get_formatted_cart_item_data( $cart_item ); ?>
44
+ </td>
45
+ <td class="product-total">
46
+ <?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); ?>
47
+ </td>
48
+ </tr>
49
+ <?php
50
+ }
51
+ }
52
+
53
+ do_action( 'woocommerce_review_order_after_cart_contents' );
54
+ ?>
55
+ </tbody>
56
+ <tfoot>
57
+
58
+ <tr class="cart-subtotal">
59
+ <th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
60
+ <td><?php wc_cart_totals_subtotal_html(); ?></td>
61
+ </tr>
62
+
63
+ <?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
64
+ <tr class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
65
+ <th><?php wc_cart_totals_coupon_label( $coupon ); ?></th>
66
+ <td><?php wc_cart_totals_coupon_html( $coupon ); ?></td>
67
+ </tr>
68
+ <?php endforeach; ?>
69
+
70
+ <?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?>
71
+
72
+ <?php do_action( 'woocommerce_review_order_before_shipping' ); ?>
73
+
74
+ <?php wc_cart_totals_shipping_html(); ?>
75
+
76
+ <?php do_action( 'woocommerce_review_order_after_shipping' ); ?>
77
+
78
+ <?php endif; ?>
79
+
80
+ <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
81
+ <tr class="fee">
82
+ <th><?php echo esc_html( $fee->name ); ?></th>
83
+ <td><?php wc_cart_totals_fee_html( $fee ); ?></td>
84
+ </tr>
85
+ <?php endforeach; ?>
86
+
87
+ <?php if ( wc_tax_enabled() && ! WC()->cart->display_prices_including_tax() ) : ?>
88
+ <?php if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) : ?>
89
+ <?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : ?>
90
+ <tr class="tax-rate tax-rate-<?php echo sanitize_title( $code ); ?>">
91
+ <th><?php echo esc_html( $tax->label ); ?></th>
92
+ <td><?php echo wp_kses_post( $tax->formatted_amount ); ?></td>
93
+ </tr>
94
+ <?php endforeach; ?>
95
+ <?php else : ?>
96
+ <tr class="tax-total">
97
+ <th><?php echo esc_html( WC()->countries->tax_or_vat() ); ?></th>
98
+ <td><?php wc_cart_totals_taxes_total_html(); ?></td>
99
+ </tr>
100
+ <?php endif; ?>
101
+ <?php endif; ?>
102
+
103
+ <?php do_action( 'woocommerce_review_order_before_order_total' ); ?>
104
+
105
+ <tr class="order-total">
106
+ <th><?php _e( 'Total', 'woocommerce' ); ?></th>
107
+ <td><?php wc_cart_totals_order_total_html(); ?></td>
108
+ </tr>
109
+
110
+ <?php do_action( 'woocommerce_review_order_after_order_total' ); ?>
111
+
112
+ </tfoot>
113
+ </table>
woocommerce/template/checkout/thankyou.php CHANGED
@@ -1,87 +1,87 @@
1
- <?php
2
- /**
3
- * Thankyou page
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/checkout/thankyou.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @author WooThemes
15
- * @package WooCommerce/Templates
16
- * @version 3.2.0
17
- */
18
-
19
- if ( ! defined( 'ABSPATH' ) ) {
20
- exit;
21
- }
22
- ?>
23
-
24
- <div class="woocommerce-order">
25
-
26
- <?php if ( $order ) : ?>
27
-
28
- <?php if ( $order->has_status( 'failed' ) ) : ?>
29
-
30
- <p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
31
-
32
- <p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions">
33
- <a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button pay"><?php _e( 'Pay', 'woocommerce' ); ?></a>
34
- <?php if ( is_user_logged_in() ) : ?>
35
- <a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="button pay"><?php _e( 'My account', 'woocommerce' ); ?></a>
36
- <?php endif; ?>
37
- </p>
38
-
39
- <?php else : ?>
40
-
41
- <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
42
-
43
- <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
44
-
45
- <li class="woocommerce-order-overview__order order">
46
- <?php _e( 'Order number:', 'woocommerce' ); ?>
47
- <strong><?php echo $order->get_order_number(); ?></strong>
48
- </li>
49
-
50
- <li class="woocommerce-order-overview__date date">
51
- <?php _e( 'Date:', 'woocommerce' ); ?>
52
- <strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
53
- </li>
54
-
55
- <?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
56
- <li class="woocommerce-order-overview__email email">
57
- <?php _e( 'Email:', 'woocommerce' ); ?>
58
- <strong><?php echo $order->get_billing_email(); ?></strong>
59
- </li>
60
- <?php endif; ?>
61
-
62
- <li class="woocommerce-order-overview__total total">
63
- <?php _e( 'Total:', 'woocommerce' ); ?>
64
- <strong><?php echo $order->get_formatted_order_total(); ?></strong>
65
- </li>
66
-
67
- <?php if ( $order->get_payment_method_title() ) : ?>
68
- <li class="woocommerce-order-overview__payment-method method">
69
- <?php _e( 'Payment method:', 'woocommerce' ); ?>
70
- <strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
71
- </li>
72
- <?php endif; ?>
73
-
74
- </ul>
75
-
76
- <?php endif; ?>
77
-
78
- <?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
79
- <?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
80
-
81
- <?php else : ?>
82
-
83
- <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
84
-
85
- <?php endif; ?>
86
-
87
- </div>
1
+ <?php
2
+ /**
3
+ * Thankyou page
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/checkout/thankyou.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @author WooThemes
15
+ * @package WooCommerce/Templates
16
+ * @version 3.2.0
17
+ */
18
+
19
+ if ( ! defined( 'ABSPATH' ) ) {
20
+ exit;
21
+ }
22
+ ?>
23
+
24
+ <div class="woocommerce-order">
25
+
26
+ <?php if ( $order ) : ?>
27
+
28
+ <?php if ( $order->has_status( 'failed' ) ) : ?>
29
+
30
+ <p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
31
+
32
+ <p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions">
33
+ <a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button pay"><?php _e( 'Pay', 'woocommerce' ); ?></a>
34
+ <?php if ( is_user_logged_in() ) : ?>
35
+ <a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="button pay"><?php _e( 'My account', 'woocommerce' ); ?></a>
36
+ <?php endif; ?>
37
+ </p>
38
+
39
+ <?php else : ?>
40
+
41
+ <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
42
+
43
+ <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
44
+
45
+ <li class="woocommerce-order-overview__order order">
46
+ <?php _e( 'Order number:', 'woocommerce' ); ?>
47
+ <strong><?php echo $order->get_order_number(); ?></strong>
48
+ </li>
49
+
50
+ <li class="woocommerce-order-overview__date date">
51
+ <?php _e( 'Date:', 'woocommerce' ); ?>
52
+ <strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
53
+ </li>
54
+
55
+ <?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
56
+ <li class="woocommerce-order-overview__email email">
57
+ <?php _e( 'Email:', 'woocommerce' ); ?>
58
+ <strong><?php echo $order->get_billing_email(); ?></strong>
59
+ </li>
60
+ <?php endif; ?>
61
+
62
+ <li class="woocommerce-order-overview__total total">
63
+ <?php _e( 'Total:', 'woocommerce' ); ?>
64
+ <strong><?php echo $order->get_formatted_order_total(); ?></strong>
65
+ </li>
66
+
67
+ <?php if ( $order->get_payment_method_title() ) : ?>
68
+ <li class="woocommerce-order-overview__payment-method method">
69
+ <?php _e( 'Payment method:', 'woocommerce' ); ?>
70
+ <strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
71
+ </li>
72
+ <?php endif; ?>
73
+
74
+ </ul>
75
+
76
+ <?php endif; ?>
77
+
78
+ <?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
79
+ <?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
80
+
81
+ <?php else : ?>
82
+
83
+ <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
84
+
85
+ <?php endif; ?>
86
+
87
+ </div>
woocommerce/template/notices/error.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- /**
3
- * Show error messages
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/notices/error.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @package WooCommerce/Templates
15
- * @version 3.5.0
16
- */
17
-
18
- if ( ! defined( 'ABSPATH' ) ) {
19
- exit;
20
- }
21
-
22
- if ( ! $messages ) {
23
- return;
24
- }
25
-
26
- ?>
27
- <ul class="woocommerce-error" role="alert">
28
- <?php foreach ( $messages as $message ) : ?>
29
- <li>
30
- <?php
31
- echo wc_kses_notice( $message );
32
- ?>
33
- </li>
34
- <?php endforeach; ?>
35
- </ul>
1
+ <?php
2
+ /**
3
+ * Show error messages
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/notices/error.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.5.0
16
+ */
17
+
18
+ if ( ! defined( 'ABSPATH' ) ) {
19
+ exit;
20
+ }
21
+
22
+ if ( ! $messages ) {
23
+ return;
24
+ }
25
+
26
+ ?>
27
+ <ul class="woocommerce-error" role="alert">
28
+ <?php foreach ( $messages as $message ) : ?>
29
+ <li>
30
+ <?php
31
+ echo wc_kses_notice( $message );
32
+ ?>
33
+ </li>
34
+ <?php endforeach; ?>
35
+ </ul>
woocommerce/template/notices/notice.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
- /**
3
- * Show messages
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/notices/notice.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @package WooCommerce/Templates
15
- * @version 3.5.0
16
- */
17
-
18
- if ( ! defined( 'ABSPATH' ) ) {
19
- exit; // Exit if accessed directly.
20
- }
21
-
22
- if ( ! $messages ) {
23
- return;
24
- }
25
-
26
- ?>
27
-
28
- <?php foreach ( $messages as $message ) : ?>
29
- <div class="woocommerce-info">
30
- <?php
31
- echo wc_kses_notice( $message );
32
- ?>
33
- </div>
34
- <?php endforeach; ?>
1
+ <?php
2
+ /**
3
+ * Show messages
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/notices/notice.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.5.0
16
+ */
17
+
18
+ if ( ! defined( 'ABSPATH' ) ) {
19
+ exit; // Exit if accessed directly.
20
+ }
21
+
22
+ if ( ! $messages ) {
23
+ return;
24
+ }
25
+
26
+ ?>
27
+
28
+ <?php foreach ( $messages as $message ) : ?>
29
+ <div class="woocommerce-info">
30
+ <?php
31
+ echo wc_kses_notice( $message );
32
+ ?>
33
+ </div>
34
+ <?php endforeach; ?>
woocommerce/template/notices/success.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
- /**
3
- * Show messages
4
- *
5
- * This template can be overridden by copying it to yourtheme/woocommerce/notices/success.php.
6
- *
7
- * HOWEVER, on occasion WooCommerce will need to update template files and you
8
- * (the theme developer) will need to copy the new files to your theme to
9
- * maintain compatibility. We try to do this as little as possible, but it does
10
- * happen. When this occurs the version of the template file will be bumped and
11
- * the readme will list any important changes.
12
- *
13
- * @see https://docs.woocommerce.com/document/template-structure/
14
- * @package WooCommerce/Templates
15
- * @version 3.5.0
16
- */
17
-
18
- if ( ! defined( 'ABSPATH' ) ) {
19
- exit;
20
- }
21
-
22
- if ( ! $messages ) {
23
- return;
24
- }
25
-
26
- ?>
27
-
28
- <?php foreach ( $messages as $message ) : ?>
29
- <div class="woocommerce-message" role="alert">
30
- <?php
31
- echo wc_kses_notice( $message );
32
- ?>
33
- </div>
34
- <?php endforeach; ?>
1
+ <?php
2
+ /**
3
+ * Show messages
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/notices/success.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @package WooCommerce/Templates
15
+ * @version 3.5.0
16
+ */
17
+
18
+ if ( ! defined( 'ABSPATH' ) ) {
19
+ exit;
20
+ }
21
+
22
+ if ( ! $messages ) {
23
+ return;
24
+ }
25
+
26
+ ?>
27
+
28
+ <?php foreach ( $messages as $message ) : ?>
29
+ <div class="woocommerce-message" role="alert">
30
+ <?php
31
+ echo wc_kses_notice( $message );
32
+ ?>
33
+ </div>
34
+ <?php endforeach; ?>