PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.13
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.13
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / class-wpfnl-admin.php

class-wpfnl-admin.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.13, at admin/class-wpfnl-admin.php

1,906 lines 61.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Admin class
5 *
6 * @package
7 */
8
9 namespace WPFunnels\Admin;
10
11 use WPFunnels\Admin\BatchProcessing\BatchProcessingController;
12 use WPFunnels\Admin\Migrations\MigrationManager;
13 use WPFunnels\Wpfnl;
14 use WPFunnels\Wpfnl_functions;
15 use MRM\Common\MrmCommon;
16
17
18 /**
19 * The admin-specific functionality of the plugin.
20 *
21 * @link https://rextheme.com
22 * @since 1.0.0
23 *
24 * @package WPFunnels
25 * @subpackage WPFunnels/Admin
26 */
27
28 /**
29 * The admin-specific functionality of the plugin.
30 *
31 * Defines the plugin name, version, and two examples hooks for how to
32 * enqueue the admin-specific stylesheet and JavaScript.
33 *
34 * @package Wpfnl
35 * @subpackage Wpfnl/admin
36 * @author RexTheme <[email protected]>
37 */
38 class Wpfnl_Admin
39 {
40 /**
41 * Wpfunnels feed option key.
42 */
43 const WPFNL_FEED_OPTION_KEY = 'wpfnl_remote_info_feed_data';
44
45 /**
46 * The ID of this plugin.
47 *
48 * @since 1.0.0
49 * @access private
50 * @var string $plugin_name The ID of this plugin.
51 */
52 private $plugin_name;
53
54 /**
55 * The version of this plugin.
56 *
57 * @since 1.0.0
58 * @access private
59 * @var string $version The current version of this plugin.
60 */
61 private $version;
62
63
64 private $dependency_plugins;
65
66
67 /**
68 * Page hooks
69 *
70 * @var array
71 */
72 private $page_hooks = [
73 'toplevel_page_wpf_templates',
74 'toplevel_page_wpfunnels',
75 'wpfunnels_page_wpf_templates',
76 'wpfunnels_page_trash_funnels',
77 'wpfunnels_page_wpf_feature_comparison',
78 'wpfunnels_page_wp_funnel_settings',
79 'wpfunnels_page_wpfnl_settings',
80 'wpfunnels_page_wp_global_store',
81 'wpfunnels_page_edit_funnel',
82 'wpfunnels_page_create_funnel',
83 'wpfunnels_page_wpfnl_settings',
84 'wpfunnels_page_wpfnl_automations',
85 'wpfunnels_page_wpfnl_addons',
86 'wpfunnels_page_store_checkout',
87 'wpfunnels_page_wpfunnels_integrations',
88 'wpfunnels_page_wpf-license',
89 'wpfunnels_page_email-builder',
90 'wpfunnels_page_wp_funnels',
91 'wpfunnels_page_wpf_templates'
92 ];
93
94 /**
95 * Initialize the class and set its properties.
96 *
97 * @param string $plugin_name The name of this plugin.
98 * @param string $version The version of this plugin.
99 *
100 * @since 1.0.0
101 */
102 public function __construct($plugin_name, $version)
103 {
104 $this->plugin_name = $plugin_name;
105 $this->version = $version;
106
107 add_action('admin_enqueue_scripts', [$this, 'enqueue_styles']);
108 add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']);
109 add_filter('plugin_action_links_' . WPFNL_BASE, [$this, 'add_funnel_action_links']);
110 add_filter('locale', array($this, 'change_local_for_funnel_canvas'));
111 if (is_admin()) {
112 add_filter('admin_body_class', [$this, 'add_wpfunnels_admin_body_class']);
113 add_filter('wp_dropdown_pages', array($this, 'show_funnel_steps_on_reading'));
114 add_filter('gettext', [$this, 'wpfnl_customizing_checkout_text'], 10, 3);
115 add_action('admin_init', [$this, 'wpfnl_add_type_meta']);
116 add_action('admin_init', array($this, 'init_actions'));
117 add_action('deactivated_plugin', [$this, 'wpfnl_deactivated_plugin']);
118 add_action('activated_plugin', [$this, 'wpfnl_activated_plugin']);
119
120 // Register Dashboard Widgets.
121 add_action('wp_dashboard_setup', [$this, 'wpfnl_register_dashboard_widgets']);
122
123 if (isset($_GET['page']) && 'edit_funnel' === $_GET['page']) {
124 wp_cache_flush();
125 }
126 }
127
128 add_action('admin_head', function () {
129 remove_submenu_page(WPFNL_MAIN_PAGE_SLUG, 'email-builder');
130 });
131
132
133 // Remove all admin notices from WPFunnels Dashboard
134 if ($this->is_current_page('wpfunnels')) {
135 remove_all_actions('admin_notices');
136 }
137
138
139 /**
140 * @todo This piece of code will be removed after releasing 3.2.0. We need to introduced this because we have changed the funnel template creation strategy.
141 *
142 */
143 add_action('admin_init', function () {
144 $current_version = get_option('wpfunnels_version');
145 $is_already_synced = get_option('_is_wpfunnels_new_templates_synced', 'no');
146 if (version_compare($current_version, '3.1.2', '>') && 'yes' != $is_already_synced) {
147 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_wc');
148 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_lms');
149 delete_transient('wpfunnels_remote_template_data_wc_' . WPFNL_VERSION);
150 delete_transient('wpfunnels_remote_template_data_lms_' . WPFNL_VERSION);
151 delete_transient('wpfunnels_remote_template_data_lead_' . WPFNL_VERSION);
152 delete_transient('wpfunnels_remote_template_data_store_checkout_' . WPFNL_VERSION);
153 update_option('_is_wpfunnels_new_templates_synced', 'yes');
154 }
155 });
156
157 add_action('admin_init', array($this, 'attach_admin_capabilities'));
158
159 add_action('wpfunnels_tracker_optin', array($this, 'wpfunnels_tracker_optin'), 10);
160 add_action('mint_before_sending_sms', array($this, 'create_mrm_contact'), 10);
161 }
162
163
164 public function init_actions()
165 {
166 $batch_processor = new BatchProcessingController();
167 new MigrationManager($batch_processor);
168
169 // Run stat status sync migration directly (independent of Action Scheduler).
170 $stat_sync = new \WPFunnels\Admin\Migrations\StatStatusSyncMigration();
171 $stat_sync->run();
172 }
173
174 /**
175 * Register dashboard widgets.
176 *
177 * Adds a new WPFunnels widgets to WordPress dashboard.
178 *
179 * Fired by `wp_dashboard_setup` action.
180 *
181 * @since 2.6.2
182 */
183 public function wpfnl_register_dashboard_widgets()
184 {
185 wp_add_dashboard_widget('wpfnl-dashboard-overview', esc_html__('WPFunnels Overview', 'wpfnl'), [$this, 'wpfnl_dashboard_overview_widget']);
186 global $wp_meta_boxes;
187
188 $dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
189 $ours = [
190 'wpfnl-dashboard-overview' => $dashboard['wpfnl-dashboard-overview'],
191 ];
192
193 $wp_meta_boxes['dashboard']['normal']['core'] = array_merge($ours, $dashboard);
194 }
195
196
197 /**
198 * WPFunnels dashboard widget.
199 *
200 * Displays the wpfunnels dashboard widget.
201 *
202 * @since 2.6.2
203 */
204 public function wpfnl_dashboard_overview_widget()
205 {
206 $upgrade_to_pro = __('Upgrade to Pro', 'wpfnl');
207 $install_activate = __('Install & Activate', 'wpfnl');
208 $is_mail_mint_active = WPFnl_functions::is_mail_mint_free_active();
209
210 $response = $this->get_wpfnl_feed_data();
211
212 $icons = [
213 'Total Orders' => '<svg width="16" height="17" fill="none" viewBox="0 0 16 17" xmlns="http://www.w3.org/2000/svg"><path fill="#B7A6E9" d="M12.061 8.04a4.015 4.015 0 01-3.478-6.03h-5.74l-.029-.236A2.01 2.01 0 00.82 0H.67a.67.67 0 000 1.34h.15a.67.67 0 01.665.592l.922 7.84a3.35 3.35 0 003.328 2.96h6.997a.67.67 0 000-1.341H5.734a2.01 2.01 0 01-1.89-1.34h7.987a3.35 3.35 0 003.298-2.756l.16-.884a4.01 4.01 0 01-3.228 1.63z"/><path fill="#B7A6E9" d="M10.542 5.994a1.254 1.254 0 00.901.402h.023a1.255 1.255 0 00.894-.37l2.863-2.863a.672.672 0 10-.95-.952l-2.806 2.81-.827-.887a.67.67 0 00-.98.915l.882.945zM4.69 16.082a1.34 1.34 0 100-2.68 1.34 1.34 0 000 2.68zm6.701 0a1.34 1.34 0 100-2.68 1.34 1.34 0 000 2.68z"/></svg>',
214 'Total Revenue' => '<svg width="15" height="15" fill="none" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg"><path fill="#B7A6E9" d="M9.75 15h-4.5C1.5 15 0 13.5 0 9.75v-4.5C0 1.5 1.5 0 5.25 0h4.5C13.5 0 15 1.5 15 5.25v4.5C15 13.5 13.5 15 9.75 15z"/><path fill="#B7A6E9" d="M5.004 9.247c0 .968.742 1.748 1.665 1.748H8.55c.803 0 1.455-.683 1.455-1.523 0-.915-.397-1.237-.99-1.447l-3.022-1.05c-.593-.21-.99-.533-.99-1.448 0-.84.652-1.522 1.455-1.522H8.34c.923 0 1.665.78 1.665 1.747"/><path stroke="#fff" stroke-linecap="round" stroke-linejoin="round" d="M5.004 9.247c0 .968.742 1.748 1.665 1.748H8.55c.803 0 1.455-.683 1.455-1.523 0-.915-.397-1.237-.99-1.447l-3.022-1.05c-.593-.21-.99-.533-.99-1.448 0-.84.652-1.522 1.455-1.522H8.34c.923 0 1.665.78 1.665 1.747"/><path fill="#B7A6E9" d="M7.5 3v9-9z"/><path stroke="#fff" stroke-linecap="round" stroke-linejoin="round" d="M7.5 3v9"/></svg>',
215 'Order Bump Revenue' => '<svg width="15" height="15" fill="none" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg"><path stroke="#B7A6E9" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="1.5" d="M5.376 1L3.05 3.333M9.475 1l2.327 2.333"/><path fill="#fff" stroke="#B7A6E9" stroke-width="1.5" d="M1 4.76c0-1.19.636-1.286 1.427-1.286h10c.791 0 1.428.097 1.428 1.286 0 1.382-.637 1.285-1.427 1.285H2.427C1.637 6.045 1 6.142 1 4.76z"/><path fill="#B7A6E9" d="M3.273 13.064L1.79 5.944h10.975l-.89 6.526c0 .712-1.582 1.286-2.373 1.484H5.35c-.237.237-1.483-.495-2.076-.89z"/><path stroke="#B7A6E9" stroke-linecap="round" stroke-width="1.5" d="M1.964 6.142l.906 5.553c.206 1.247.7 2.16 2.54 2.16h3.875c1.999 0 2.294-.874 2.526-2.082l1.08-5.63"/><path stroke="#fff" stroke-linecap="round" stroke-linejoin="round" d="M8.91 9.504L7.425 8.021 5.943 9.504M7.426 8.02v3.56"/></svg>',
216 'Upsell/Downsell Revenue' => '<svg width="15" height="15" fill="none" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg"><path fill="#B7A6E9" d="M5.25 15h4.5C13.5 15 15 13.5 15 9.75v-4.5C15 1.5 13.5 0 9.75 0h-4.5C1.5 0 0 1.5 0 5.25v4.5C0 13.5 1.5 15 5.25 15z"/><path fill="#B7A6E9" d="M6.379 5.25h3.37v3.371"/><path stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6.379 5.25h3.37v3.371M9.75 5.25l-4.5 4.5"/></svg>',
217 'Total Leads' => '<svg width="13" height="13" fill="none" viewBox="0 0 13 13" xmlns="http://www.w3.org/2000/svg"><path fill="#B7A6E9" d="M8.45 0h-3.9C1.3 0 0 1.3 0 4.55v3.9c0 2.457.741 3.803 2.509 4.303.143-1.69 1.879-3.023 3.991-3.023 2.113 0 3.848 1.333 3.991 3.023C12.259 12.253 13 10.907 13 8.45v-3.9C13 1.3 11.7 0 8.45 0zM6.5 7.91a2.33 2.33 0 010-4.66 2.33 2.33 0 010 4.66z"/></svg>',
218 ];
219
220
221 $pro_icon_svg = '<div class="pro-icon"><svg width="14" height="14" fill="none" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"><circle cx="7" cy="7" r="7" fill="#66CB64"/><path fill="#fff" fill-rule="evenodd" d="M7.623 4.465a.69.69 0 00-1.15 0l-1.36 2.08-1.04-.59c-.52-.294-1.146.168-1.005.743l.706 2.88c.032.13.15.222.285.222h5.977a.292.292 0 00.285-.221l.706-2.88c.141-.576-.485-1.038-1.005-.743l-1.04.588-1.36-2.08zm-.493.312a.098.098 0 00-.165 0l-1.51 2.311a.296.296 0 01-.393.094l-1.28-.725a.097.097 0 00-.144.106l.652 2.659h5.515l.652-2.66a.096.096 0 00-.143-.105l-1.281.725a.296.296 0 01-.393-.094l-1.51-2.31z" clip-rule="evenodd"/><path fill="#fff" d="M4.312 10.377a.291.291 0 00-.293.29.29.29 0 00.293.288h5.472c.161 0 .293-.13.293-.289a.291.291 0 00-.293-.289H4.312z"/><circle cx="10.739" cy="4.987" r=".514" fill="#fff"/><circle cx="3.139" cy="4.987" r=".514" fill="#fff"/><circle cx="7.042" cy="3.139" r=".514" fill="#fff"/><path fill="#fff" d="M9.918 9.404h-5.65L3.241 6.22l1.952.616 1.849-2.465L8.993 6.94l1.746-.822-.821 3.287z"/></svg></div>';
222
223 ?>
224 <div class="wpfnl-dashboard-widget">
225 <div class="wpfnl-overview__header">
226 <div class="wpfnl-overview__logo">
227 <div class="wpfnl-logo-wrapper">
228 <svg width="38" height="28" viewBox="0 0 38 28" fill="none" xmlns="http://www.w3.org/2000/svg">
229 <path d="M7.01532 18H31.9847L34 11H5L7.01532 18Z" fill="#EE8134"></path>
230 <path
231 d="M11.9621 27.2975C12.0923 27.7154 12.4792 28 12.9169 28H26.0831C26.5208 28 26.9077 27.7154 27.0379 27.2975L29 21H10L11.9621 27.2975Z"
232 fill="#6E42D3"></path>
233 <path
234 d="M37.8161 0.65986C37.61 0.247888 37.2609 0 36.8867 0H1.11326C0.739128 0 0.390003 0.247888 0.183972 0.65986C-0.0220592 1.07193 -0.0573873 1.59277 0.0898627 2.04655L1.69781 7H36.3022L37.9102 2.04655C38.0574 1.59287 38.022 1.07193 37.8161 0.65986Z"
235 fill="#6E42D3"></path>
236 </svg>
237 </div>
238 </div>
239
240 <div class="wpfnl-overview__upgrade">
241 <span><?php echo !Wpfnl_functions::is_pro_license_activated() ? __('Upgrade to Pro to get premium features such as one-click upsells, A/B testing and more!', 'wpfnl') : __('Start creating high converting landing pages, sales funnels, and checkout flows in minutes!', 'wpfnl'); ?></span>
242 </div>
243
244 <?php if (!Wpfnl_functions::is_pro_license_activated()) { ?>
245 <div class="wpfnl-overview__create">
246 <a href="https://getwpfunnels.com/pricing/" target="_blank" class="button"><span aria-hidden="true"></span>
247 <?php echo esc_html($upgrade_to_pro); ?></a>
248 </div>
249 <?php
250 }?>
251
252 </div>
253
254 <!-- overview report -->
255 <div class="wpfnl-overview__report">
256 <?php foreach ($response as $report):
257 $icon_html = $icons[$report['title']] ?? '';
258 ?>
259 <div class="report-item">
260 <div class="icon"><?php echo $icon_html; ?></div>
261 <div class="text-wrapper">
262 <p class="title"><?php echo esc_html($report['title']); ?></p>
263 <p class="amount"><?php echo $report['amount']; ?></p>
264 </div>
265
266 <?php if ($report['show_pro'] && !Wpfnl_functions::is_pro_license_activated()): ?>
267 <?php echo $pro_icon_svg; ?>
268 <?php
269 endif; ?>
270
271 </div>
272 <?php
273 endforeach; ?>
274 </div>
275
276 <?php if (!Wpfnl_functions::is_mint_mrm_active()): ?>
277 <!-- install mail mint -->
278 <div
279 class="wpfnl-overview__mailmint <?php echo Wpfnl_functions::is_mint_mrm_active() ? 'is-active' : 'is-disabled'; ?>">
280 <div class="icon-wrapper">
281 <div class="icon">
282 <svg width="34" height="34" fill="none" viewBox="0 0 34 34" xmlns="http://www.w3.org/2000/svg">
283 <circle cx="17" cy="17" r="16.5" fill="#fff" stroke="#573BFF" />
284 <path fill="#573BFF"
285 d="M24.084 14.876l-.634 8.778.905-1.267.996-10.225-9.23 6.153-2.082-2.172-5.972-5.067 7.601 8.868c.272.271.634.362.996.09l7.42-5.158z" />
286 <path fill="#02C4FB"
287 d="M21.822 11.62c-3.891.814-7.24.904-8.416.814l.995 1.086c4.525-.272 6.697-.905 7.24-1.267.362-.272.271-.543.18-.634z" />
288 <path fill="#573BFF"
289 d="M20.374 13.61c-2.444.724-4.525.905-5.249.905l.724.633c2.805-.362 4.163-.905 4.434-1.176.272-.181.181-.362.09-.362z" />
290 <path fill="#573BFF"
291 d="M25.947 11.345c-.212-.033-.418.064-.596.184l-9.05 6.153-4.162-4.525-.749-.793-.79-.835c1.72.18 8.778-.09 12.67-.996 1.81-.452 1.447-1.267 1.266-1.176-8.415 1.176-15.745.452-15.745.452-.403-.034-.617.066-.815.362-.18.272-.09.634.09.905l.453.453 2.082 2.08 5.158 5.43c.271.272.633.272.995.09l8.054-5.52c-.453 4.073-.996 8.145-1.267 9.14-1.81.363-12.397.453-13.845.091-.453-.724-.996-4.253-1.358-7.963-.09-.543-.633-.905-1.176-.634 0 0-.362.177-.362.724.905 8.597 1.81 9.05 2.081 9.23.543.272 4.163.453 7.873.453s7.33-.181 7.873-.634c.18-.18.814-.723 1.9-11.401v-.091c.074-.736-.152-1.113-.58-1.18z" />
292 <path fill="url(#paint0_linear_129_34)" d="M8.474 11.538h2.135l1.687 1.79H9.984l-1.51-1.79z" />
293 <defs>
294 <linearGradient id="paint0_linear_129_34" x1="9.613" x2="10.654" y1="11.538" y2="13.37"
295 gradientUnits="userSpaceOnUse">
296 <stop stop-color="#0C0632" />
297 <stop offset="1" stop-color="#573BFF" />
298 </linearGradient>
299 </defs>
300 </svg>
301 </div>
302 <div class="text-wrapper">
303 <p class="description">
304 <?php echo $is_mail_mint_active ? __('Use email marketing automation for your funnels easily with <b>Mail Mint</b>!', 'wpfnl') : __('Use email marketing automation for your funnels easily with <b>Mail Mint</b>!', 'wpfnl'); ?>
305 </p>
306 </div>
307 </div>
308 <div class="wpfnl-overview__install-mailmint">
309 <?php if (Wpfnl_functions::is_mail_mint_free_active()): ?>
310 <a href="https://getwpfunnels.com/pricing/#mail-mint" target="_blank" class="button">
311 <?php echo $upgrade_to_pro; ?>
312 </a>
313 <?php
314 else: ?>
315 <button id="pro-modal-dropdown-btn" class="button">
316 <span class="loader" style="display:none;"></span>
317 <span class="btn-text"><?php echo $install_activate; ?></span>
318 </button>
319 <?php
320 endif; ?>
321 </div>
322
323 </div>
324 <?php
325 endif; ?>
326
327 <div class="wpfnl-overview__footer wpfnl-divider_top">
328 <ul>
329 <?php foreach ($this->get_wpfunnels_dashboard_overview_widget_footer_actions() as $action_id => $action): ?>
330 <li class="wpfnl-overview__<?php echo esc_attr($action_id); ?>"><a
331 href="<?php echo esc_attr($action['link']); ?>"
332 target="_blank"><?php echo esc_html($action['title']); ?> <span
333 class="screen-reader-text"><?php echo esc_html__('(opens in a new window)', 'wpfnl'); ?></span></a>
334 </li>
335 <?php
336 endforeach; ?>
337 </ul>
338 </div>
339
340 <script>
341 (function ($) {
342
343 const apiService = (path = "", method = "GET", data, content_type = "text/plain") => {
344 return new Promise((resolve, reject) => {
345 jQuery.ajax({
346 url: wpApiSettings.root + path,
347 type: method,
348 data: data,
349 beforeSend: function (xhr) {
350 xhr.setRequestHeader("X-WP-Nonce", wpApiSettings.nonce);
351 },
352 dataType: "json",
353 contentType: content_type,
354 success: resolve,
355 error: reject
356 });
357 });
358 };
359
360 $(document).ready(function () {
361 jQuery("#pro-modal-dropdown-btn").click((e) => {
362 e.preventDefault();
363 var btn = $('#pro-modal-dropdown-btn');
364 var loader = btn.find('.loader');
365 var btnText = btn.find('.btn-text');
366 loader.show();
367 btn.prop('disabled', true);
368 btnText.text('Processing...');
369 apiService("wpfunnels/v1/activate-plugin", 'POST', JSON.stringify({
370 basename: 'mail-mint/mail-mint.php',
371 slug: 'mail-mint',
372 }), 'application/json').then((res) => {
373 var upgradeBtn = $(
374 '<a href="https://getwpfunnels.com/pricing/#mail-mint" target="_blank" class="button" style="margin-left:0;">' +
375 'Upgrade to Pro' +
376 '</a>'
377 );
378 btn.closest('.wpfnl-overview__install-mailmint').html(upgradeBtn);
379 $('.text-wrapper .title').text('Get Mail Mint Pro');
380 $('.text-wrapper .description').html('Use email marketing automation for your funnels easily with <b>Mail Mint</b>!');
381 }).catch((e) => {
382 btn.replaceWith(btnPrevState);
383 addClickEvent();
384 })
385 });
386 });
387 })(jQuery);
388 </script>
389
390 <style>
391 .wpfnl-dashboard-widget {
392 margin-top: -11px;
393 }
394
395 .wpfnl-dashboard-widget .wpfnl-overview__mailmint {
396 display: flex;
397 align-items: center;
398 justify-content: space-between;
399 padding: 16px 20px;
400 border: 1px solid #EEEAF8;
401 margin-bottom: 15px;
402 }
403
404 .wpfnl-dashboard-widget .wpfnl-overview__mailmint.is-active .wpfnl-overview__install-mailmint button {
405 pointer-events: none;
406 cursor: not-allowed;
407 }
408
409 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .icon-wrapper {
410 display: flex;
411 gap: 12px;
412 align-items: center;
413 }
414
415 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .wpfnl-overview__install-mailmint .button {
416 border-radius: 7px;
417 background: #573BFF;
418 color: #FFF;
419 text-align: center;
420 font-family: Inter;
421 font-size: 12px;
422 font-style: normal;
423 font-weight: 500;
424 line-height: 2.6;
425 border: none;
426 }
427
428 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .wpfnl-overview__install-mailmint .button:focus {
429 box-shadow: unset;
430 }
431
432 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .wpfnl-overview__install-mailmint .loader {
433 border: 2px solid #f3f3f3;
434 border-top: 2px solid #573BFF;
435 border-radius: 50%;
436 width: 12px;
437 height: 12px;
438 animation: spin 0.8s linear infinite;
439 display: inline-block;
440 vertical-align: middle;
441 margin-right: 4px;
442 }
443
444 @keyframes spin {
445 0% {
446 transform: rotate(0deg);
447 }
448
449 100% {
450 transform: rotate(360deg);
451 }
452 }
453
454 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .wpfnl-overview__install-mailmint .button:disabled {
455 cursor: not-allowed;
456 opacity: 0.7;
457 background: #573BFF !important;
458 color: #FFF !important;
459 }
460
461
462 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .icon-wrapper .text-wrapper .title {
463 color: #2E3148;
464 font-size: 16px;
465 font-weight: 600;
466 line-height: 1;
467 letter-spacing: -0.32px;
468 margin: 0 0 8px;
469 }
470
471 .wpfnl-dashboard-widget .wpfnl-overview__mailmint .icon-wrapper .text-wrapper .description {
472 margin: 0;
473 line-height: 1;
474 }
475
476 .wpfnl-dashboard-widget .wpfnl-overview__report {
477 display: grid;
478 grid-template-columns: repeat(2, 1fr);
479 border: 1px solid #EEEAF8;
480 margin: 15px 0;
481 }
482
483 .wpfnl-dashboard-widget .wpfnl-overview__report .report-item {
484 display: flex;
485 gap: 15px;
486 padding: 20px;
487 position: relative;
488
489 }
490
491 .wpfnl-dashboard-widget .wpfnl-overview__report .report-item:nth-child(odd)::before {
492 content: "";
493 position: absolute;
494 right: 15%;
495 height: 36px;
496 width: 1px;
497 background: linear-gradient(180deg, rgba(238, 234, 248, 0.00) -2.78%, #EEEAF8 47.1%, rgba(238, 234, 248, 0.00) 104.17%);
498 }
499
500 .wpfnl-dashboard-widget .wpfnl-overview__report .report-item .text-wrapper p {
501 margin: 0;
502 line-height: 1;
503 }
504
505 .wpfnl-dashboard-widget .wpfnl-overview__report .report-item .text-wrapper p.title {
506 color: #2E3148;
507 font-size: 12px;
508 font-weight: 400;
509 margin-bottom: 8px;
510 }
511
512 .wpfnl-dashboard-widget .wpfnl-overview__report .report-item .text-wrapper p.amount {
513 color: #2E3148;
514 font-size: 15px;
515 font-weight: 600;
516 line-height: normal;
517 }
518
519 .wpfnl-dashboard-widget .wpfnl-overview__header {
520 display: flex;
521 align-items: center;
522 justify-content: space-between;
523 border-bottom: 1px solid #eee;
524 gap: 15px;
525 padding: 15px 15px;
526 margin: 0 -12px;
527
528 }
529
530 .wpfnl-dashboard-widget .wpfnl-overview__header .wpfnl-overview__upgrade {
531 padding: 0px 15px;
532 }
533
534 .wpfnl-dashboard-widget .wpfnl-overview__versions {
535 font-size: 0.9em;
536 line-height: 1.5;
537 }
538
539 .wpfnl-dashboard-widget .wpfnl-overview__version {
540 display: block;
541 }
542
543 .wpfnl-dashboard-widget .wpfnl-overview__create a {
544 border-radius: 7px;
545 background: #6E42D3;
546 border: 1px solid #6E42D3;
547 font-style: normal;
548 line-height: 2.28;
549 color: #FFF;
550 text-align: center;
551 font-family: Inter;
552 font-size: 14px;
553 font-weight: 500;
554 }
555
556 .wpfnl-dashboard-widget .wpfnl-overview__create a:hover {
557 background: #6E42D3;
558 color: #FFF;
559 box-shadow: unset;
560 border-color: transparent;
561 }
562
563 .wpfnl-dashboard-widget .wpfnl-overview__create a:focus {
564 background: #6E42D3;
565 color: #FFF;
566 outline: none;
567 box-shadow: unset;
568 border-color: transparent;
569 }
570
571 .wpfnl-dashboard-widget .wpfnl-overview__create .dashicons {
572 font-size: 15px;
573 line-height: 1;
574 position: relative;
575 top: 8px;
576 }
577
578 .wpfnl-dashboard-widget .wpfnl-overview__recently-edited .wpfnl-heading {
579 font-weight: 600 !important;
580 border-bottom: 1px solid #eee;
581 margin: 0 -12px !important;
582 padding: 6px 12px !important;
583 margin-bottom: 13px !important;
584 }
585
586 .wpfnl-dashboard-widget .wpfnl-overview__post {
587 margin-top: 10px;
588 font-weight: 500;
589 }
590
591 .wpfnl-dashboard-widget .wpfnl-overview__post-link {
592 display: inline-block;
593 }
594
595 .wpfnl-dashboard-widget .wpfnl-overview__post-description {
596 margin: 0 0 1.5em;
597 }
598
599 .wpfnl-dashboard-widget .wpfnl-overview__footer {
600 border-top: 1px solid #eee;
601 margin: 0 -12px;
602 padding: 6px 12px;
603 padding-top: 12px;
604 padding-bottom: 0;
605 }
606
607 .wpfnl-dashboard-widget .wpfnl-overview__footer ul {
608 display: -webkit-box;
609 display: -ms-flexbox;
610 display: flex;
611 list-style: none;
612 margin: 0;
613 padding: 0;
614 }
615
616 .wpfnl-dashboard-widget .wpfnl-overview__footer ul li {
617 padding: 0 10px;
618 margin: 0;
619 position: relative;
620 }
621
622 .wpfnl-dashboard-widget .wpfnl-overview__footer .wpfnl-overview__blog a,
623 .wpfnl-dashboard-widget .wpfnl-overview__footer .wpfnl-overview__changelog a,
624 .wpfnl-dashboard-widget .wpfnl-overview__footer .wpfnl-overview__help a {
625 color: #667085;
626 font-size: 12px;
627 font-weight: 400;
628 position: relative;
629 }
630
631 .wpfnl-dashboard-widget .wpfnl-overview__footer .wpfnl-overview__blog a:hover,
632 .wpfnl-dashboard-widget .wpfnl-overview__footer .wpfnl-overview__changelog a:hover,
633 .wpfnl-dashboard-widget .wpfnl-overview__footer .wpfnl-overview__help a:hover {
634 color: #6846CE;
635 }
636
637 .wpfnl-dashboard-widget .wpfnl-overview__footer ul li:not(:last-child)::before {
638 content: "";
639 position: absolute;
640 right: 0;
641 top: 3px;
642 height: 16px;
643 width: 1px;
644 background: linear-gradient(180deg, rgba(238, 234, 248, 0.00) -2.78%, #EEEAF8 47.1%, rgba(238, 234, 248, 0.00) 104.17%);
645 }
646
647 .wpfnl-dashboard-widget .wpfnl-overview__footer ul li:first-child {
648 padding-left: 0;
649 border: none;
650 }
651
652 .wpfnl-dashboard-widget .wpfnl-overview__footer ul li.wpfnl-overview__go-pro a {
653 color: #DF8740;
654 font-size: 12px;
655 font-weight: 400;
656 line-height: normal;
657 }
658 </style>
659 </div>
660 <?php
661 }
662
663 /**
664 * Get wpfunnels feed data.
665 *
666 * Retrieve the feed info data from remote wpfunnels server.
667 *
668 * @access public
669 *
670 * @param bool $force_update Optional. Whether to force the data update or
671 * not. Default is false.
672 *
673 * @return array Feed data.
674 * @since 2.7.16
675 */
676 public function get_wpfnl_feed_data($force_update = false)
677 {
678 return $this->get_wpfnl_info_data($force_update);
679 }
680
681 /**
682 * Get wpfunnles info data.
683 *
684 * This function retrieves post from wpfunnels remote API.
685 *
686 * @access private
687 *
688 * @param bool $force_update Optional. Whether to force the data retrieval or
689 * not. Default is false.
690 *
691 * @return array|false Info data, or false.
692 * @since 2.7.16
693 */
694 private function get_wpfnl_info_data($force_update)
695 {
696 global $wpdb;
697 $response = [
698 [
699 'title' => 'Total Orders',
700 'amount' => $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$wpdb->prefix}wpfnl_stats WHERE status = %s", 'completed')),
701 'show_pro' => false
702 ],
703 [
704 'title' => 'Total Revenue',
705 'amount' => Wpfnl_functions::is_wc_active() ? wc_price((int)$wpdb->get_var($wpdb->prepare("SELECT SUM(total_sales) FROM {$wpdb->prefix}wpfnl_stats WHERE status = %s", 'completed'))) : number_format(0, 2),
706 'show_pro' => false
707 ],
708 [
709 'title' => 'Order Bump Revenue',
710 'amount' => Wpfnl_functions::is_wc_active() ? wc_price((int)$wpdb->get_var($wpdb->prepare("SELECT SUM(orderbump_sales) FROM {$wpdb->prefix}wpfnl_stats WHERE status = %s", 'completed'))) : number_format(0, 2),
711 'show_pro' => false
712 ],
713 [
714 'title' => 'Upsell/Downsell Revenue',
715 'amount' => (Wpfnl_functions::is_pro_license_activated() && Wpfnl_functions::is_wc_active()) ? wc_price((int)$wpdb->get_var($wpdb->prepare("SELECT SUM(upsell_sales + downsell_sales) FROM {$wpdb->prefix}wpfnl_stats WHERE status = %s", 'completed'))) : number_format(0, 2),
716 'show_pro' => true
717 ],
718 [
719 'title' => 'Total Leads',
720 'amount' => $wpdb->get_var("SELECT COUNT(id) FROM {$wpdb->prefix}wpfnl_optin_entries"),
721 'show_pro' => false
722 ],
723 ];
724
725 return $response;
726 }
727
728 /**
729 * Get all post from url
730 *
731 * @param $url
732 * @param $args
733 *
734 * @return array
735 */
736 private function remote_get($url, $args = [])
737 {
738 $response = wp_remote_get($url, $args);
739
740 if (is_wp_error($response) || !is_array($response) || !isset($response['body'])) {
741 return [
742 'success' => false,
743 'message' => $response->get_error_message(),
744 'data' => $response,
745 ];
746 }
747
748 // Decode the results.
749 $results = json_decode($response['body'], true);
750
751 if (!is_array($results)) {
752 return new \WP_Error('unexpected_data_format', 'Data was not returned in the expected format.');
753 }
754
755 return [
756 'success' => true,
757 'message' => 'Data successfully retrieved',
758 'data' => json_decode(wp_remote_retrieve_body($response), true),
759 ];
760 }
761
762
763 /**
764 * Get wpfunnels dashboard overview widget footer actions.
765 *
766 * Retrieves the footer action links displayed in wpfunnels dashboard widget.
767 *
768 * @since 1.9.0
769 * @access private
770 */
771 private function get_wpfunnels_dashboard_overview_widget_footer_actions()
772 {
773 $actions = [
774 'go-pro' => [
775 'title' => esc_html__('Upgrade to Pro', 'wpfnl'),
776 'link' => 'https://getwpfunnels.com/pricing/',
777 ],
778 'blog' => [
779 'title' => esc_html__('Blogs', 'wpfnl'),
780 'link' => 'https://getwpfunnels.com/blog/',
781 ],
782 'changelog' => [
783 'title' => esc_html__('Changelogs', 'wpfnl'),
784 'link' => 'https://getwpfunnels.com/changelog/',
785 ],
786 'help' => [
787 'title' => esc_html__('Get Help', 'wpfnl'),
788 'link' => 'https://getwpfunnels.com/docs/getting-started-with-wpfunnels/',
789 ],
790
791 ];
792
793 if (Wpfnl_functions::is_pro_license_activated()) {
794 unset($actions['go-pro']);
795 }
796
797 return $actions;
798 }
799
800
801
802 /**
803 * Funnel action links
804 *
805 * @since 1.0.0
806 */
807 public function add_funnel_action_links($actions)
808 {
809 $documentation = array(
810 '<a href="https://getwpfunnels.com/docs/wpfunnels-wordpress-funnel-builder/" target="_blank" >Documentation</a>',
811 );
812 $is_pro_installed = Wpfnl_functions::is_plugin_installed('wpfunnels-pro/wpfnl-pro.php');
813 if (!defined('WPFNL_PRO_VERSION') && !$is_pro_installed) {
814 $documentation[] = '<a href="https://getwpfunnels.com/pricing/" target="_blank" style="color:#6E42D3;font-weight:bold" >Upgrade to Pro</a>';
815 }
816 $actions = array_merge($actions, $documentation);
817 return $actions;
818 }
819
820 /**
821 * Register the stylesheets for the admin area.
822 *
823 * @since 1.0.0
824 */
825 public function enqueue_styles($hook)
826 {
827
828 /**
829 * This function is provided for demonstration purposes only.
830 *
831 * An instance of this class should be passed to the run() function
832 * defined in Wpfnl_Loader as all of the hooks are defined
833 * in that particular class.
834 *
835 * The Wpfnl_Loader will then create the relationship
836 * between the defined hooks and the functions defined in this
837 * class.
838 */
839 if ('wpfunnels_page_email-builder' === $hook) {
840 wp_enqueue_style($this->plugin_name . '-email-builder', plugin_dir_url(__FILE__) . 'assets/dist/email-builder/email-builder.css', [], $this->version, 'all');
841 }
842
843 if ($this->is_current_page('wpfunnels')) {
844 wp_enqueue_style('wpfnl-admin-app', plugin_dir_url(__FILE__) . 'assets/css/admin-app.css', [], $this->version, 'all');
845 }
846
847
848 if (in_array($hook, $this->page_hooks)) {
849 wp_enqueue_style('wp-color-picker');
850 wp_enqueue_style($this->plugin_name . '-jquery-ui', plugin_dir_url(__FILE__) . 'assets/css/jquery-ui.min.css', [], $this->version, 'all');
851
852 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'assets/css/wpfnl-admin.css', [], $this->version, 'all');
853
854 do_action('wpfunnels_after_styles_loaded');
855 }
856 }
857
858 /**
859 * Register the JavaScript for the admin area.
860 *
861 * @since 1.0.0
862 */
863 public function enqueue_scripts($hook)
864 {
865 /**
866 * This function is provided for demonstration purposes only.
867 *
868 * An instance of this class should be passed to the run() function
869 * defined in Wpfnl_Loader as all of the hooks are defined
870 * in that particular class.
871 *
872 * The Wpfnl_Loader will then create the relationship
873 * between the defined hooks and the functions defined in this
874 * class.
875 */
876
877
878 $screen = get_current_screen();
879
880
881 if ('dashboard' === $screen->id || 'plugins' === $screen->id) {
882 wp_enqueue_script($this->plugin_name . '-global', plugin_dir_url(__FILE__) . 'assets/js/wpfnl-global.js', ['jquery', 'jquery-ui-sortable'], $this->version, true);
883 }
884
885 if ('wpfunnels_page_email-builder' === $hook) {
886 $is_wc_installed = 'no';
887 $is_wpfunnels_installed = 'no';
888 if (is_plugin_active('woocommerce/woocommerce.php')) {
889 $is_wc_installed = 'yes';
890 }
891 if (is_plugin_active('wpfunnels/wpfunnels.php')) {
892 $is_wpfunnels_installed = 'yes';
893 }
894 $dependency = require_once WPFNL_PATH . '/admin/assets/dist/email-builder/main.min.asset.php';
895 wp_enqueue_script(
896 $this->plugin_name . '-email-builder',
897 plugin_dir_url(__FILE__) . 'assets/dist/email-builder/main.min.js',
898 $dependency['dependencies'],
899 $this->version,
900 true
901 );
902 wp_localize_script(
903 $this->plugin_name . '-email-builder',
904 'WPFEmailBuilderVars',
905 array(
906 'editor_data_source' => $this->get_editor_source(),
907 'post_types' => MrmCommon::get_all_post_types(),
908 'is_wc_installed' => $is_wc_installed,
909 'is_mint_active' => Wpfnl_functions::is_mint_mrm_active(),
910 )
911 );
912 }
913
914 if (in_array($hook, $this->page_hooks)) {
915
916 $is_wc_installed = 'no';
917 $is_wpfunnels_installed = 'no';
918 if (is_plugin_active('woocommerce/woocommerce.php')) {
919 $is_wc_installed = 'yes';
920 }
921 if (is_plugin_active('wpfunnels/wpfunnels.php')) {
922 $is_wpfunnels_installed = 'yes';
923 }
924
925 wp_enqueue_script($this->plugin_name . '-select2', plugin_dir_url(__FILE__) . 'assets/js/select2.min.js', ['jquery'], $this->version, true);
926 $products = array();
927 if (isset($_GET['step_id'])) {
928 $step_id = sanitize_text_field($_GET['step_id']);
929 if ($step_id) {
930 if (Wpfnl_functions::check_if_this_is_step_type_by_id($step_id, 'checkout')) {
931 $products = get_post_meta($step_id, '_wpfnl_checkout_products', true);
932 if (empty($products)) {
933 $products = [];
934 }
935 }
936 }
937 }
938
939 $funnel_id = '';
940 $funnel_title = '';
941 $step_id = '';
942 if (isset($_GET['id'])) {
943 $funnel_id = $_GET['id'];
944 $funnel_title = html_entity_decode(get_the_title($funnel_id));
945 if (isset($_GET['step_id'])) {
946 $step_id = filter_input(INPUT_GET, 'step_id', FILTER_VALIDATE_INT);
947 }
948
949 // For store checkout funnels, resolve the checkout step ID when not in URL.
950 if ( empty( $step_id ) && 'store_checkout' === get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ) ) {
951 $step_id = \WPFunnels\WooCommerce\Wpfnl_Store_Checkout_Conditions::get_checkout_step_id_for_funnel( $funnel_id );
952 }
953 }
954
955 /**
956 * Get funnel preview link
957 */
958 $steps = get_post_meta($funnel_id, '_steps_order', true);
959 $funnel_preview_link = '#';
960 $response['success'] = false;
961 if ($steps) {
962 if (isset($steps[0]) && $steps[0]['id']) {
963 $funnel_preview_link = get_post_permalink($steps[0]['id']);
964 }
965 }
966
967
968 wp_enqueue_script('jquery-ui-datepicker');
969 wp_enqueue_editor();
970 wp_enqueue_script('wp-color-picker');
971 wp_enqueue_media();
972
973 wp_enqueue_script($this->plugin_name . '-jed', plugin_dir_url(__FILE__) . 'assets/js/jed.js', ['jquery'], $this->version, true);
974 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'assets/js/wpfnl-admin.js', ['jquery', 'jquery-ui-sortable'], $this->version, true);
975 wp_enqueue_script($this->plugin_name . '-runtime', plugin_dir_url(__FILE__) . 'assets/dist/runtime/index.min.js', ['jquery', 'wp-i18n', 'wp-util', 'updates', 'wp-color-picker', $this->plugin_name . '-jed'], $this->version, true);
976 wp_enqueue_script($this->plugin_name . '-funnel-window', plugin_dir_url(__FILE__) . 'assets/dist/js/funnel-components.min.js', ['jquery', 'wp-i18n', 'wp-util', 'updates', 'wp-color-picker', $this->plugin_name . '-jed', $this->plugin_name . '-runtime'], $this->version, true);
977 wp_enqueue_script($this->plugin_name . '-backbone-marionette', plugin_dir_url(__FILE__) . 'assets/lib/backbone/backbone.marionette.min.js', ['backbone'], $this->version, true);
978 wp_enqueue_script($this->plugin_name . '-backbone-radio', plugin_dir_url(__FILE__) . 'assets/lib/backbone/backbone.radio.min.js', ['backbone'], $this->version, true);
979
980 $general_settings = Wpfnl_functions::get_general_settings();
981 $builder = $general_settings['builder'];
982 $funnel_builder_mode = Wpfnl_functions::get_default_funnel_builder_mode();
983 $canvas_view_mode = Wpfnl_functions::get_canvas_view_mode();
984
985 /**
986 * This code snippet will check if pro addons is activated or not. if not activated
987 * Total number of funnels will be maximum 3, otherwise customer can add as more funnels
988 * As they want
989 */
990 $is_pro_active = apply_filters('wpfunnels/is_pro_license_activated', false);
991 $count_funnels = Wpfnl_functions::count_non_store_checkout_funnels( array( 'publish', 'draft', 'trash' ) );
992 $count_active_funnels = Wpfnl_functions::count_non_store_checkout_funnels();
993 $total_allowed_funnels = 3;
994 if ($is_pro_active) {
995 $total_allowed_funnels = -1;
996 }
997 $count_store_checkouts = Wpfnl_functions::count_store_checkout_funnels();
998 $total_allowed_store_checkouts = $is_pro_active ? -1 : 3;
999
1000 $wc_currency_symbol = '$';
1001 if (function_exists('get_woocommerce_currency_symbol')) {
1002 $wc_currency_symbol = html_entity_decode(get_woocommerce_currency_symbol());
1003 }
1004 $ld_currency_symbol = '$';
1005 if (function_exists('learndash_get_currency_symbol')) {
1006 $ld_currency_symbol = html_entity_decode(learndash_get_currency_symbol());
1007 }
1008
1009 $product_url = esc_url_raw(
1010 add_query_arg(
1011 array(
1012 'post_type' => 'product',
1013 'wpfunnels' => 'yes',
1014 ),
1015 admin_url('post-new.php')
1016 )
1017 );
1018
1019 wp_localize_script($this->plugin_name, 'WPFunnelVars', array(
1020 'ajaxurl' => admin_url('admin-ajax.php'),
1021 'rest_api_url' => get_rest_url(),
1022 'security' => wp_create_nonce('wpfnl-admin'),
1023 'import_nonce' => wp_create_nonce('wpfnl_import_funnels_nonce'),
1024 'admin_url' => admin_url(),
1025 'edit_funnel_url' => admin_url('admin.php?page=edit_funnel'),
1026 'i18n' => array('wpfnl' => $this->get_jed_locale_data('wpfnl')),
1027 'current_user_id' => get_current_user_id(),
1028 'is_wc_installed' => $is_wc_installed,
1029 'is_wpfunnels_installed' => $is_wpfunnels_installed,
1030 'products' => $products,
1031 'funnel_id' => $funnel_id,
1032 'step_id' => $step_id,
1033 'funnel_title' => $funnel_title,
1034 'funnel_preview_link' => $funnel_preview_link,
1035 'site_url' => site_url(),
1036 'image_path' => WPFNL_URL . 'admin/assets/images',
1037 'placeholder_image_path' => WPFNL_URL . 'admin/assets/images/ob_placeholder.png',
1038 'nonce' => wp_create_nonce('wp_rest'),
1039 'isNewFunnel' => \Wpfnl_Activator::is_new_install() ? true : false,
1040 'isProActivated' => $is_pro_active,
1041 'totalFunnels' => $count_funnels,
1042 'count_active_funnels' => $count_active_funnels,
1043 'totalStoreCheckouts' => $count_store_checkouts,
1044 'totalAllowedStoreCheckouts' => $total_allowed_store_checkouts,
1045 'product_url' => $product_url,
1046 'totalAllowedFunnels' => $total_allowed_funnels,
1047 'builder' => $builder,
1048 'funnel_builder_mode' => $funnel_builder_mode,
1049 'canvas_view_mode' => $canvas_view_mode,
1050 'dependencyPlugins' => Wpfnl_functions::get_dependency_plugins_status(),
1051 'isAnyPluginMissing' => Wpfnl_functions::is_any_plugin_missing(),
1052 'isGlobalFunnelActivated' => Wpfnl_functions::is_global_funnel_activated(),
1053 'isGlobalFunnel' => Wpfnl_functions::is_global_funnel($funnel_id),
1054 'GBFVersion' => defined('WPFNL_PRO_GBF_VERSION') ? WPFNL_PRO_GBF_VERSION : ( defined('WPFNL_PRO_GB_VERSION') ? WPFNL_PRO_GB_VERSION : '' ),
1055 'isSkipOffer' => $this->is_skip_offer(),
1056 'paymentMethod' => $this->get_payment_method(),
1057 'shippingMethod' => $this->get_shipping_method(),
1058 'isGbf' => $this->maybe_gbf($funnel_id),
1059 'isLms' => $this->maybe_lms($funnel_id),
1060 'lmsProvider' => $this->get_lms_provider(),
1061 'isLmsActivated' => Wpfnl_functions::is_lms_addon_active(),
1062 'isAnyLmsPluginActive' => Wpfnl_functions::is_any_lms_plugin_active(),
1063 'isLmsSettings' => Wpfnl_functions::is_enable_lms_settings(),
1064 'isLmsDisbaled' => $this->maybe_lms_settings_disbaled(),
1065 'lmsVersion' => (defined('WPFNL_PRO_LMS_VERSION') || defined('WPFUNNELS_PRO_LMS_VERSION')) && defined('LEARNDASH_VERSION') ? version_compare(LEARNDASH_VERSION, '4.2.1.1', '>=') : false,
1066 'global_funnel_type' => Wpfnl_functions::get_global_funnel_type(),
1067 'individual_funnel_type' => get_post_meta($funnel_id, '_wpfnl_funnel_type', true),
1068 'isStoreCheckout' => get_post_meta($funnel_id, '_wpfnl_funnel_type', true) === 'store_checkout',
1069 'gbf_set_condition_steps' => $this->get_gbf_steps($funnel_id),
1070 'reconfigurable_condition_data' => $this->get_reconfigurable_condition_data($funnel_id),
1071 'mint_steps' => $this->mint_step_settings($funnel_id),
1072 'mint_tags' => Wpfnl_functions::get_mint_contact_groups('tags'),
1073 'mint_lists' => Wpfnl_functions::get_mint_contact_groups('lists'),
1074 'mint_sequences' => Wpfnl_functions::get_sequences(),
1075 'obList' => Wpfnl_functions::get_all_ob($funnel_id),
1076 'upsellSteps' => Wpfnl_functions::get_selected_steps('upsell', $funnel_id),
1077 'downsellSteps' => Wpfnl_functions::get_selected_steps('downsell', $funnel_id),
1078 'landingAndCustomSteps' => Wpfnl_functions::get_selected_steps('landing', $funnel_id),
1079 'customSteps' => Wpfnl_functions::get_selected_steps('custom', $funnel_id),
1080 'onlySettingsSteps' => Wpfnl_functions::get_only_settings_steps(),
1081 'isWCML' => defined('WCML_VERSION'),
1082 'cfeDefault' => Wpfnl_functions::get_cfe_default_fields(),
1083 'adminEmail' => get_bloginfo('admin_email'),
1084 'siteName' => get_option('blogname'),
1085 'mailMintEmail' => Wpfnl_functions::get_mailmint_email(),
1086 'email_settings' => Wpfnl_functions::get_mailmint_email_settings(),
1087 'mint_twillo_settings' => Wpfnl_functions::get_mailmint_twillo_settings(),
1088 'emailBuilderUrl' => admin_url() . 'admin.php?page=email-builder',
1089 'currentUrl' => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
1090 'wc_currency' => $wc_currency_symbol,
1091 'ld_currency' => $ld_currency_symbol,
1092 'getText' => Wpfnl_functions::get_text(),
1093 'user_role_manager_data' => Wpfnl_functions::get_user_role_settings(),
1094 'availableGateways' => Wpfnl_functions::get_enabled_payment_gateways(),
1095 'guidedTour' => Wpfnl_functions::get_guided_tour(),
1096 'isWPFIntegrationActive' => apply_filters( 'wpfunnels/is_integration_license_active', false ),
1097 ));
1098 wp_localize_script(
1099 $this->plugin_name,
1100 'template_library_object',
1101 array(
1102 'ajaxurl' => esc_url_raw(admin_url('admin-ajax.php')),
1103 'rest_api_url' => esc_url_raw(get_rest_url()),
1104 'dashboard_url' => ( $funnel_id && get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ) === 'store_checkout' )
1105 ? esc_url_raw(admin_url('admin.php?page=store_checkout'))
1106 : esc_url_raw(admin_url('admin.php?page=' . WPFNL_FUNNEL_PAGE_SLUG)),
1107 'settings_url' => esc_url_raw(admin_url('admin.php?page=settings')),
1108 'home_url' => esc_url_raw(home_url()),
1109 'funnel_id' => $funnel_id,
1110 'isTemplatePage' => 'wpfunnels_page_wpf_templates' === $hook,
1111 'is_pro' => Wpfnl_functions::is_pro_license_activated(),
1112 'is_ab_tesing_available' => defined('WPFNL_PRO_VERSION') ? version_compare(WPFNL_PRO_VERSION, "1.7.3", ">=") : false,
1113 'is_webhook_licensed' => Wpfnl_functions::is_webhook_license_activated(),
1114 'pro_url' => add_query_arg('wpfnl-dashboard', '1', GETWPFUNNEL_PRICING_URL),
1115 'nonce' => wp_create_nonce('wp_rest'),
1116 'image_path' => WPFNL_URL . 'admin/assets/images',
1117 'template_type' => Wpfnl_functions::get_template_types(),
1118 'countries' => Wpfnl_functions::get_countries(),
1119 'supported_steps' => Wpfnl_functions::get_supported_step_type(),
1120 'is_mint_active' => Wpfnl_functions::is_mint_mrm_active(),
1121 'settingsSteps' => Wpfnl_functions::get_settings_steps(),
1122 'isRemote' => Wpfnl_functions::maybe_remote_funnel(),
1123 'isStoreCheckout' => 'wpfunnels_page_store_checkout' === $hook,
1124 )
1125 );
1126
1127 wp_localize_script(
1128 $this->plugin_name,
1129 'CheckoutStep',
1130 array(
1131 'ajaxurl' => esc_url_raw(admin_url('admin-ajax.php')),
1132 'rest_api_url' => esc_url_raw(get_rest_url()),
1133 'wc_currency' => $wc_currency_symbol,
1134 'nonce' => wp_create_nonce('wp_rest'),
1135 'security' => wp_create_nonce('wpfnl-admin'),
1136 'image_path' => WPFNL_URL . 'admin/assets/images',
1137 'tooltipIcon' => WPFNL_URL . 'admin/partials/icons/question-tooltip-icon.php',
1138 'imageUploadIcon' => WPFNL_URL . 'admin/partials/icons/image-upload-icon.php',
1139 'step_id' => $step_id,
1140 'back' => add_query_arg(
1141 array(
1142 'page' => WPFNL_EDIT_FUNNEL_SLUG,
1143 'id' => filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT),
1144 'step_id' => $step_id,
1145 ),
1146 admin_url('admin.php')
1147 ),
1148 'priceConfig' => Wpfnl_functions::get_wc_price_config(),
1149 )
1150 );
1151
1152 wp_localize_script(
1153 $this->plugin_name,
1154 'wpfnl_addons_vars',
1155 array(
1156 'addons' => Wpfnl_functions::get_supported_addons(),
1157 'gbf_conditions' => Wpfnl_functions::get_supported_gbf_offer_condition(),
1158 'categories' => Wpfnl_functions::get_categories_gbf_offer_condition(),
1159 'role' => Wpfnl_functions::get_all_user_roles(),
1160 'tags' => Wpfnl_functions::get_all_tags(),
1161 'shippingClasses' => Wpfnl_functions::get_shipping_classes(),
1162 )
1163 );
1164
1165 // Enqueue the admin dashboard script only on WPFunnels Main Page
1166
1167 if ($this->is_current_page('wpfunnels')) {
1168 wp_enqueue_script('wpfnl-admin-app', plugin_dir_url(__FILE__) . 'assets/dist/js/wpfnl-admin-app.min.js', array(), $this->version, true);
1169 wp_localize_script('wpfnl-admin-app', 'WPFAdminObj', array(
1170 'rest_api_url' => get_rest_url(),
1171 'security' => wp_create_nonce('wpfnl-admin'),
1172 'nonce' => wp_create_nonce('wp_rest'),
1173 'priceConfig' => Wpfnl_functions::get_wc_price_config(),
1174 'isProActivated' => apply_filters('wpfunnels/is_wpfnl_pro_active', false),
1175 'isWPFIntegrationActive' => apply_filters( 'wpfunnels/is_integration_license_active', false ),
1176 'getText' => Wpfnl_functions::get_text(),
1177 'admin_url' => admin_url(),
1178 ));
1179 }
1180
1181
1182 /**
1183 * Localize scripts for funnel window
1184 *
1185 * @var $localize
1186 */
1187
1188 $notices = $this->get_builder_notice();
1189
1190 $localize = apply_filters('wpfunnels/funnel_window_admin_localize', array());
1191 wp_localize_script($this->plugin_name . '-funnel-window', 'wpfunnels_funnel_localize', array($localize));
1192
1193
1194 do_action('wpfunnels_after_scripts_loaded');
1195 }
1196 }
1197
1198
1199 public function get_lms_provider()
1200 {
1201 $lms_settings = get_option('_wpfunnels_lms_settings', array());
1202 $provider_id = isset($lms_settings['lms_provider']) ? $lms_settings['lms_provider'] : 'learndash';
1203 return $provider_id;
1204 }
1205
1206
1207 /**
1208 * Get the reconfigurable condition data for a funnel
1209 */
1210 public function get_reconfigurable_condition_data($funnel_id)
1211 {
1212 if (!$funnel_id) {
1213 return [];
1214 }
1215 $data = get_post_meta($funnel_id, '_wpfnl_reconfigurable_condition_data', true);
1216 if (!is_array($data) || empty($data)) {
1217 return [];
1218 }
1219 return $data;
1220 }
1221
1222
1223 /**
1224 * Get all setps where GBF conditions is already set
1225 *
1226 * @param Integer $funnel_id
1227 *
1228 * @since 2.6.1
1229 */
1230 private function get_gbf_steps($funnel_id)
1231 {
1232 $gbf_steps = [];
1233 if ($funnel_id) {
1234 $funnel_type = get_post_meta($funnel_id, '_wpfnl_funnel_type', true);
1235 $is_gbf = get_post_meta($funnel_id, 'is_global_funnel', true);
1236
1237 if ('yes' === $is_gbf) {
1238 $steps = Wpfnl_functions::get_steps($funnel_id);
1239 if (is_array($steps)) {
1240 foreach ($steps as $step) {
1241 if (isset($step['id'], $step['step_type'])) {
1242 if ('checkout' === $step['step_type']) {
1243 $conditions = get_post_meta($funnel_id, 'global_funnel_start_condition', true);
1244 if (is_array($conditions)) {
1245 array_push($gbf_steps, $step['id']);
1246 }
1247 }
1248 elseif ('upsell' === $step['step_type'] || 'downsell' === $step['step_type']) {
1249 $conditions = get_post_meta($step['id'], 'global_funnel_' . $step['step_type'] . '_rules', true);
1250 if (is_array($conditions)) {
1251 array_push($gbf_steps, $step['id']);
1252 }
1253 }
1254 }
1255 }
1256 }
1257 } elseif ('store_checkout' === $funnel_type) {
1258 $steps = Wpfnl_functions::get_steps($funnel_id);
1259 if (is_array($steps)) {
1260 foreach ($steps as $step) {
1261 if (isset($step['id'], $step['step_type']) && 'checkout' === $step['step_type']) {
1262 $raw = get_post_meta($step['id'], '_wpfnl_store_checkout_condition', true);
1263 $condition = is_string($raw) ? json_decode($raw, true) : $raw;
1264 if (is_array($condition) && isset($condition['condition_type']) && 'rules' === $condition['condition_type']) {
1265 array_push($gbf_steps, $step['id']);
1266 }
1267 }
1268 }
1269 }
1270 }
1271 }
1272
1273 return $gbf_steps;
1274 }
1275
1276
1277 /**
1278 * Returns Jed-formatted localization data.
1279 *
1280 * @param string $domain Translation domain.
1281 *
1282 * @return array
1283 */
1284 public function get_jed_locale_data($domain, $language_dir = null)
1285 {
1286 $plugin_translations = $this->get_translations_for_plugin_domain($domain, $language_dir);
1287 $translations = get_translations_for_domain($domain);
1288
1289 $locale = array(
1290 'domain' => $domain,
1291 'locale_data' => array(
1292 $domain => array(
1293 '' => array(
1294 'domain' => $domain,
1295 'lang' => is_admin() ? get_user_locale() : get_locale(),
1296 ),
1297 ),
1298 ),
1299 );
1300
1301 if (!empty($translations->headers['Plural-Forms'])) {
1302 $locale['locale_data'][$domain]['']['plural_forms'] = $translations->headers['Plural-Forms'];
1303 }
1304 else if (!empty($plugin_translations['header'])) {
1305 $locale['locale_data'][$domain]['']['plural_forms'] = $plugin_translations['header']['Plural-Forms'];
1306 }
1307
1308 $entries = array_merge($plugin_translations['translations'], $translations->entries);
1309
1310 foreach ($entries as $msgid => $entry) {
1311 $locale['locale_data'][$domain][$msgid] = $entry->translations;
1312 }
1313
1314 return $locale;
1315 }
1316
1317
1318 /**
1319 * Get translactions for WePos plugin
1320 *
1321 * @param string $domain
1322 * @param string $language_dir
1323 *
1324 * @return array
1325 */
1326 public function get_translations_for_plugin_domain($domain, $language_dir = null)
1327 {
1328 if ($language_dir == null) {
1329 $language_dir = WPFNL_PATH . '/languages/';
1330 }
1331 $languages = get_available_languages($language_dir);
1332 $get_site_lang = is_admin() ? get_user_locale() : get_locale();
1333 $mo_file_name = $domain . '-' . $get_site_lang;
1334 $translations = [];
1335
1336 if (in_array($mo_file_name, $languages) && file_exists($language_dir . $mo_file_name . '.mo')) {
1337 $mo = new \MO();
1338 if ($mo->import_from_file($language_dir . $mo_file_name . '.mo')) {
1339 $translations = $mo->entries;
1340 }
1341 }
1342
1343 return [
1344 'header' => isset($mo) ? $mo->headers : '',
1345 'translations' => $translations,
1346 ];
1347 }
1348
1349
1350 /**
1351 * Check GBF version for skip offer
1352 */
1353 public function is_skip_offer()
1354 {
1355 // GBF is now built into WPFunnels Pro — always available when GBF is activated.
1356 if ( Wpfnl_functions::is_global_funnel_activated() ) {
1357 return true;
1358 }
1359 // Legacy: standalone addon still active.
1360 if ( defined('WPFNL_PRO_GB_VERSION') ) {
1361 return version_compare( WPFNL_PRO_GB_VERSION, '1.0.9', '>=' );
1362 }
1363 return false;
1364 }
1365
1366 public function mint_step_settings($funnel_id)
1367 {
1368 $steps = get_post_meta($funnel_id, '_steps', true);
1369 $mint_steps = [];
1370 if (is_array($steps)) {
1371 foreach ($steps as $step) {
1372 $mint_settings['stepID'] = $step['id'];
1373 $value = get_post_meta($step['id'], '_wpfnl_automation_steps', true);
1374 $mint_settings['value'] = is_array($value) ? $value : [];
1375 array_push($mint_steps, $mint_settings);
1376 }
1377 }
1378 return $mint_steps;
1379 }
1380
1381
1382 /**
1383 * Define w2cloud routes
1384 *
1385 * @return array
1386 */
1387 public function get_wpfnl_routes()
1388 {
1389 $routes = array(
1390 array(
1391 'path' => '/',
1392 'name' => 'home',
1393 'component' => 'Home'
1394 )
1395 );
1396 return apply_filters('wpfnl_routes', $routes);
1397 }
1398
1399 /**
1400 * Get all active Payment Method
1401 *
1402 * @return array
1403 */
1404 public function get_payment_method()
1405 {
1406 if (Wpfnl_functions::is_wc_active()) {
1407 $gateways = WC()->payment_gateways->get_available_payment_gateways();
1408 $enabled_gateways = [];
1409
1410 if ($gateways) {
1411 foreach ($gateways as $key => $gateway) {
1412 if ($gateway->enabled == 'yes') {
1413 $enabled_gateways[$key] = $gateway->method_title;
1414 }
1415 }
1416 }
1417 return $enabled_gateways;
1418 }
1419 return [];
1420 }
1421
1422 /**
1423 * Get all shipping methods
1424 *
1425 * @return array
1426 */
1427 public function get_shipping_method()
1428 {
1429 if (Wpfnl_functions::is_wc_active()) {
1430 $available_shipping = WC()->shipping()->get_shipping_methods();
1431 $enabled_shipping = [];
1432 if ($available_shipping) {
1433 foreach ($available_shipping as $key => $shipping) {
1434 $enabled_shipping[$key] = $shipping->method_title;
1435 }
1436 }
1437 return $enabled_shipping;
1438 }
1439 return [];
1440 }
1441
1442
1443 /**
1444 * Show funnel steps on reading
1445 *
1446 * @param $output
1447 *
1448 * @return mixed
1449 */
1450 public function show_funnel_steps_on_reading($output)
1451 {
1452 global $pagenow;
1453 if (('options-reading.php' === $pagenow || 'customize.php' === $pagenow) && preg_match('#page_on_front#', $output)) {
1454 $output = $this->show_steps_options($output);
1455 }
1456 return $output;
1457 }
1458
1459
1460 /**
1461 * Show steps pages on reading
1462 *
1463 * @param $output
1464 *
1465 * @return string
1466 */
1467 private function show_steps_options($output)
1468 {
1469 $options = '';
1470
1471 $steps = get_posts(
1472 array(
1473 'post_type' => WPFNL_STEPS_POST_TYPE,
1474 'posts_per_page' => -1,
1475 'numberposts' => 100,
1476 'orderby' => 'title',
1477 'order' => 'ASC',
1478 'post_status' => 'publish',
1479 'meta_query' => array(
1480 'relation' => 'OR',
1481 array(
1482 'key' => '_step_type',
1483 'value' => 'landing',
1484 ),
1485 array(
1486 'key' => '_step_type',
1487 'value' => 'checkout',
1488 )
1489 ),
1490 )
1491 );
1492
1493 if ($steps && is_array($steps)) {
1494 $front_page_id = get_option('page_on_front');
1495 foreach ($steps as $step) {
1496 $selected = selected($front_page_id, $step->ID, false);
1497 $post_type_obj = get_post_type_object($step->post_type);
1498 $options .= "<option value=\"{$step->ID}\"{$selected}>{$step->post_title} (WPFunnels {$post_type_obj->labels->singular_name})</option>";
1499 }
1500 $options .= '</select>';
1501 $output = str_replace('</select>', $options, $output);
1502 }
1503 return $output;
1504 }
1505
1506
1507 /**
1508 * Get notice for builder
1509 *
1510 * @return array
1511 */
1512 public function get_builder_notice()
1513 {
1514 $builder = Wpfnl_functions::get_builder_type();
1515 $notices = array();
1516 if ('divi-builder' === $builder) {
1517 $notices['notices'][] = array();
1518 }
1519 return $notices;
1520 }
1521
1522
1523 /**
1524 * Change text in order details page
1525 */
1526 public function wpfnl_customizing_checkout_text($translated_text, $untranslated_text, $domain)
1527 {
1528
1529 if (is_admin()) {
1530 if ($translated_text == 'Coupon(s):') {
1531 $translated_text = __('Discount:', 'wpfnl');
1532 }
1533 }
1534
1535 return $translated_text;
1536 }
1537
1538
1539 /**
1540 * Change local for if this is funnel canvas window
1541 *
1542 * @param $local
1543 *
1544 * @return string
1545 *
1546 * @since 2.3.8
1547 */
1548 public function change_local_for_funnel_canvas($local)
1549 {
1550 if (Wpfnl_functions::is_funnel_canvas_window()) {
1551 return 'en_US';
1552 }
1553 return $local;
1554 }
1555
1556
1557 /**
1558 * Add type meta
1559 *
1560 * @since 2.4.4
1561 */
1562 public function wpfnl_add_type_meta()
1563 {
1564 Wpfnl_functions::add_type_meta();
1565 }
1566
1567
1568 /**
1569 * Maybe Global funnel
1570 *
1571 * @param String
1572 *
1573 * @return Bool
1574 * @since 2.4.11
1575 */
1576 public function maybe_gbf($funnel_id)
1577 {
1578
1579 if ( Wpfnl_functions::is_global_funnel_activated() ) {
1580 if ($funnel_id) {
1581 $is_gbf = get_post_meta($funnel_id, 'is_global_funnel', true);
1582 if ('yes' == $is_gbf) {
1583 return true;
1584 }
1585 }
1586 }
1587
1588 return false;
1589 }
1590
1591 /**
1592 * Check funnel type is lms or not by funnel_id
1593 *
1594 * @return Bool
1595 */
1596 public function maybe_lms($funnel_id)
1597 {
1598
1599 $type = get_post_meta($funnel_id, '_wpfnl_funnel_type', true);
1600 if ('lms' === $type) {
1601 return true;
1602 }
1603 return false;
1604 }
1605
1606 /**
1607 * May be lms settings is disbaled
1608 */
1609 public function maybe_lms_settings_disbaled()
1610 {
1611 return Wpfnl_functions::is_wc_active() && Wpfnl_functions::is_lms_addon_active();
1612 }
1613
1614
1615 /**
1616 * Trigger when any plugin is deactivated
1617 *
1618 * @param $filename
1619 *
1620 * @since 2.5.1
1621 */
1622 public function wpfnl_deactivated_plugin($filename)
1623 {
1624 if ('woocommerce/woocommerce.php' === $filename) {
1625 if (!Wpfnl_functions::is_lms_addon_active()) {
1626 Wpfnl_functions::update_funnel_type_to_lead();
1627 }
1628 Wpfnl_functions::wpfnl_delete_transient();
1629 }
1630 elseif ('sfwd-lms/sfwd_lms.php' === $filename) {
1631 if (!Wpfnl_functions::is_wc_active()) {
1632 Wpfnl_functions::update_funnel_type_to_lead();
1633 }
1634 Wpfnl_functions::wpfnl_delete_transient();
1635 }
1636 elseif ('wpfunnels-pro-lms/wpfunnels-pro-lms.php' === $filename) {
1637 Wpfnl_functions::wpfnl_delete_transient();
1638 }
1639 elseif ('qubely/qubely.php' === $filename) {
1640 Wpfnl_functions::wpfnl_delete_transient();
1641 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_wc');
1642 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_lms');
1643 delete_transient('wpfunnels_remote_template_data_wc_' . WPFNL_VERSION);
1644 delete_transient('wpfunnels_remote_template_data_lms_' . WPFNL_VERSION);
1645 delete_transient('wpfunnels_remote_template_data_lead_' . WPFNL_VERSION);
1646 delete_transient('wpfunnels_remote_template_data_store_checkout_' . WPFNL_VERSION);
1647 }
1648 }
1649
1650
1651 /**
1652 * Trigger when any plugin is activated
1653 *
1654 * @param $filename
1655 *
1656 * @since 2.5.1
1657 */
1658 public function wpfnl_activated_plugin($filename)
1659 {
1660 if ('woocommerce/woocommerce.php' === $filename) {
1661 Wpfnl_functions::wpfnl_delete_transient();
1662 }
1663 elseif ('sfwd-lms/sfwd_lms.php' === $filename) {
1664 if (Wpfnl_functions::is_lms_addon_active()) {
1665 Wpfnl_functions::wpfnl_delete_transient();
1666 }
1667 }
1668 elseif ('wpfunnels-pro-lms/wpfunnels-pro-lms.php' === $filename) {
1669 Wpfnl_functions::wpfnl_delete_transient();
1670 }
1671 elseif ('qubely/qubely.php' === $filename) {
1672 Wpfnl_functions::wpfnl_delete_transient();
1673 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_wc');
1674 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_lms');
1675 delete_transient('wpfunnels_remote_template_data_wc_' . WPFNL_VERSION);
1676 delete_transient('wpfunnels_remote_template_data_lms_' . WPFNL_VERSION);
1677 delete_transient('wpfunnels_remote_template_data_lead_' . WPFNL_VERSION);
1678 delete_transient('wpfunnels_remote_template_data_store_checkout_' . WPFNL_VERSION);
1679 }
1680 }
1681
1682
1683
1684 /**
1685 * Get editor source data
1686 *
1687 * @return array
1688 * @since 1.0.0
1689 */
1690 private function get_editor_source()
1691 {
1692 // get product categories for email builder.
1693 $wc_categories = $this->get_formatted_wc_categories();
1694 $wp_categories = $this->get_formatted_wp_post_categories();
1695
1696 return apply_filters(
1697 'plugin_hook_name',
1698 array(
1699 'product_categories' => $wc_categories,
1700 'post_categories' => $wp_categories,
1701 'placeholder_image' => ''
1702 )
1703 );
1704 }
1705
1706
1707
1708 /**
1709 * Get the WooCommerce product categories
1710 *
1711 * @return array
1712 * @since 1.0.0
1713 */
1714 private function get_formatted_wc_categories()
1715 {
1716 $taxonomy = 'product_cat';
1717 $orderby = 'name';
1718 $show_count = 0;
1719 $pad_counts = 0;
1720 $hierarchical = 1;
1721 $title = '';
1722 $empty = 0;
1723
1724 $args = array(
1725 'taxonomy' => $taxonomy,
1726 'orderby' => $orderby,
1727 'show_count' => $show_count,
1728 'pad_counts' => $pad_counts,
1729 'hierarchical' => $hierarchical,
1730 'title_li' => $title,
1731 'hide_empty' => $empty,
1732 );
1733 $product_categories = get_categories($args);
1734 $wc_categories = array();
1735 foreach ($product_categories as $product_cat) {
1736 $wc_categories[] = array(
1737 'value' => $product_cat->term_id,
1738 'label' => $product_cat->name,
1739 );
1740 }
1741
1742 return $wc_categories;
1743 }
1744
1745
1746 /**
1747 * Get the WordPress post categories
1748 *
1749 * @return array
1750 * @since 1.0.0
1751 */
1752 private function get_formatted_wp_post_categories()
1753 {
1754 $taxonomy = 'category';
1755 $orderby = 'name';
1756 $show_count = 0;
1757 $pad_counts = 0;
1758 $hierarchical = 1;
1759 $title = '';
1760 $empty = 0;
1761
1762 $args = array(
1763 'taxonomy' => $taxonomy,
1764 'orderby' => $orderby,
1765 'show_count' => $show_count,
1766 'pad_counts' => $pad_counts,
1767 'hierarchical' => $hierarchical,
1768 'title_li' => $title,
1769 'hide_empty' => $empty,
1770 );
1771 $post_categories = get_categories($args);
1772 $categories = array();
1773 foreach ($post_categories as $post_cat) {
1774 $categories[] = array(
1775 'value' => $post_cat->term_id,
1776 'label' => $post_cat->name,
1777 );
1778 }
1779 return $categories;
1780 }
1781
1782
1783 /**
1784 * Add custom capabilities to administrator role
1785 *
1786 * @since 3.1.3
1787 */
1788 public function attach_admin_capabilities()
1789 {
1790 global $wp_roles;
1791 $capabilities = array(
1792 'wpf_manage_funnels',
1793 );
1794 foreach ($capabilities as $cap) {
1795 $wp_roles->add_cap('administrator', $cap);
1796 }
1797 }
1798
1799 /**
1800 * Checks if the current page slug matches the provided slug.
1801 *
1802 * @param $slug
1803 * @return bool
1804 * @since 3.5.0
1805 */
1806 public function is_current_page($slug)
1807 {
1808 if (empty($slug)) {
1809 return false;
1810 }
1811 $current_page_slug = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
1812 if ($slug === $current_page_slug) {
1813 return true;
1814 }
1815 return false;
1816 }
1817
1818 /**
1819 * Add body class for WPFunnels admin pages.
1820 *
1821 * @param string $classes Current body classes.
1822 * @return string Modified body classes.
1823 * @since 3.9.5
1824 */
1825 public function add_wpfunnels_admin_body_class($classes)
1826 {
1827 // Check if we're on a WPFunnels admin page.
1828 $screen = get_current_screen();
1829
1830 if ($screen && in_array($screen->id, $this->page_hooks)) {
1831 $classes .= ' wpfunnels-body';
1832 }
1833
1834 return $classes;
1835 }
1836
1837
1838 /**
1839 * Create contact on mailmint when user allows to track data
1840 *
1841 * @param array $data
1842 *
1843 * @since 3.3.1
1844 */
1845 public function wpfunnels_tracker_optin($data)
1846 {
1847 if (isset($data['admin_email'], $data['first_name'], $data['last_name'])) {
1848 $json_body_data = json_encode([
1849 'email' => $data['admin_email'],
1850 'first_name' => $data['first_name'],
1851 'last_name' => $data['last_name'],
1852 ]);
1853
1854 $webHookUrl = [
1855 'https://staging-useraccount.kinsta.cloud/?mailmint=1&route=webhook&topic=contact&hash=b258136d-6759-4e91-bbab-0b7397af6dc7'
1856 ];
1857
1858 try {
1859 if (!empty($webHookUrl)) {
1860 foreach ($webHookUrl as $url) {
1861 wp_remote_request($url, [
1862 'method' => 'POST',
1863 'headers' => [
1864 'Content-Type' => 'application/json',
1865 ],
1866 'body' => $json_body_data
1867 ]);
1868 }
1869 }
1870 }
1871 catch (\Exception $e) {
1872 }
1873 }
1874 }
1875
1876 /**
1877 * Creates a new MRM contact.
1878 *
1879 * @param array $data The data for the contact.
1880 * @return void
1881 */
1882 public function create_mrm_contact($data)
1883 {
1884 if (!isset($data['data']['user_email'])) {
1885 return;
1886 }
1887 // Get double opt-in settings.
1888 $default = \MRM\Common\MrmCommon::double_optin_default_configuration();
1889 $settings = get_option('_mrm_optin_settings', $default);
1890 $enable = isset($settings['enable']) ? $settings['enable'] : false;
1891
1892 $user_data = array(
1893 'email' => $data['data']['user_email'],
1894 'first_name' => isset($data['data']['first_name']) ? $data['data']['first_name'] : '',
1895 'last_name' => isset($data['data']['last_name']) ? $data['data']['last_name'] : '',
1896 'meta_fields' => array(
1897 'phone_number' => isset($data['data']['phone_number']) ? $data['data']['phone_number'] : '',
1898 ),
1899 'status' => $enable ? 'pending' : 'subscribed',
1900 'source' => 'WPFunnels',
1901 );
1902
1903 $mail_mint_object = new \WPFunnels\Integrations\MailMint($user_data);
1904 $mail_mint_object->create_or_update_contact();
1905 }
1906 }