PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.10.6
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.10.6
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.10.6, at admin/class-wpfnl-admin.php

1,888 lines 60.3 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
983 /**
984 * This code snippet will check if pro addons is activated or not. if not activated
985 * Total number of funnels will be maximum 3, otherwise customer can add as more funnels
986 * As they want
987 */
988 $is_pro_active = apply_filters('wpfunnels/is_pro_license_activated', false);
989 $count_funnels = Wpfnl_functions::count_non_store_checkout_funnels( array( 'publish', 'draft', 'trash' ) );
990 $count_active_funnels = Wpfnl_functions::count_non_store_checkout_funnels();
991 $total_allowed_funnels = 3;
992 if ($is_pro_active) {
993 $total_allowed_funnels = -1;
994 }
995 $count_store_checkouts = Wpfnl_functions::count_store_checkout_funnels();
996 $total_allowed_store_checkouts = $is_pro_active ? -1 : 3;
997
998 $wc_currency_symbol = '$';
999 if (function_exists('get_woocommerce_currency_symbol')) {
1000 $wc_currency_symbol = html_entity_decode(get_woocommerce_currency_symbol());
1001 }
1002 $ld_currency_symbol = '$';
1003 if (function_exists('learndash_get_currency_symbol')) {
1004 $ld_currency_symbol = html_entity_decode(learndash_get_currency_symbol());
1005 }
1006
1007 $product_url = esc_url_raw(
1008 add_query_arg(
1009 array(
1010 'post_type' => 'product',
1011 'wpfunnels' => 'yes',
1012 ),
1013 admin_url('post-new.php')
1014 )
1015 );
1016
1017 wp_localize_script($this->plugin_name, 'WPFunnelVars', array(
1018 'ajaxurl' => admin_url('admin-ajax.php'),
1019 'rest_api_url' => get_rest_url(),
1020 'security' => wp_create_nonce('wpfnl-admin'),
1021 'import_nonce' => wp_create_nonce('wpfnl_import_funnels_nonce'),
1022 'admin_url' => admin_url(),
1023 'edit_funnel_url' => admin_url('admin.php?page=edit_funnel'),
1024 'i18n' => array('wpfnl' => $this->get_jed_locale_data('wpfnl')),
1025 'current_user_id' => get_current_user_id(),
1026 'is_wc_installed' => $is_wc_installed,
1027 'is_wpfunnels_installed' => $is_wpfunnels_installed,
1028 'products' => $products,
1029 'funnel_id' => $funnel_id,
1030 'step_id' => $step_id,
1031 'funnel_title' => $funnel_title,
1032 'funnel_preview_link' => $funnel_preview_link,
1033 'site_url' => site_url(),
1034 'image_path' => WPFNL_URL . 'admin/assets/images',
1035 'placeholder_image_path' => WPFNL_URL . 'admin/assets/images/ob_placeholder.png',
1036 'nonce' => wp_create_nonce('wp_rest'),
1037 'isNewFunnel' => \Wpfnl_Activator::is_new_install() ? true : false,
1038 'isProActivated' => $is_pro_active,
1039 'totalFunnels' => $count_funnels,
1040 'count_active_funnels' => $count_active_funnels,
1041 'totalStoreCheckouts' => $count_store_checkouts,
1042 'totalAllowedStoreCheckouts' => $total_allowed_store_checkouts,
1043 'product_url' => $product_url,
1044 'totalAllowedFunnels' => $total_allowed_funnels,
1045 'builder' => $builder,
1046 'dependencyPlugins' => Wpfnl_functions::get_dependency_plugins_status(),
1047 'isAnyPluginMissing' => Wpfnl_functions::is_any_plugin_missing(),
1048 'isGlobalFunnelActivated' => Wpfnl_functions::is_global_funnel_activated(),
1049 'isGlobalFunnel' => Wpfnl_functions::is_global_funnel($funnel_id),
1050 'GBFVersion' => defined('WPFNL_PRO_GBF_VERSION') ? WPFNL_PRO_GBF_VERSION : ( defined('WPFNL_PRO_GB_VERSION') ? WPFNL_PRO_GB_VERSION : '' ),
1051 'isSkipOffer' => $this->is_skip_offer(),
1052 'paymentMethod' => $this->get_payment_method(),
1053 'shippingMethod' => $this->get_shipping_method(),
1054 'isGbf' => $this->maybe_gbf($funnel_id),
1055 'isLms' => $this->maybe_lms($funnel_id),
1056 'lmsProvider' => $this->get_lms_provider(),
1057 'isLmsActivated' => Wpfnl_functions::is_lms_addon_active(),
1058 'isAnyLmsPluginActive' => Wpfnl_functions::is_any_lms_plugin_active(),
1059 'isLmsSettings' => Wpfnl_functions::is_enable_lms_settings(),
1060 'isLmsDisbaled' => $this->maybe_lms_settings_disbaled(),
1061 'lmsVersion' => (defined('WPFNL_PRO_LMS_VERSION') || defined('WPFUNNELS_PRO_LMS_VERSION')) && defined('LEARNDASH_VERSION') ? version_compare(LEARNDASH_VERSION, '4.2.1.1', '>=') : false,
1062 'global_funnel_type' => Wpfnl_functions::get_global_funnel_type(),
1063 'individual_funnel_type' => get_post_meta($funnel_id, '_wpfnl_funnel_type', true),
1064 'isStoreCheckout' => get_post_meta($funnel_id, '_wpfnl_funnel_type', true) === 'store_checkout',
1065 'gbf_set_condition_steps' => $this->get_gbf_steps($funnel_id),
1066 'reconfigurable_condition_data' => $this->get_reconfigurable_condition_data($funnel_id),
1067 'mint_steps' => $this->mint_step_settings($funnel_id),
1068 'mint_tags' => Wpfnl_functions::get_mint_contact_groups('tags'),
1069 'mint_lists' => Wpfnl_functions::get_mint_contact_groups('lists'),
1070 'mint_sequences' => Wpfnl_functions::get_sequences(),
1071 'obList' => Wpfnl_functions::get_all_ob($funnel_id),
1072 'upsellSteps' => Wpfnl_functions::get_selected_steps('upsell', $funnel_id),
1073 'downsellSteps' => Wpfnl_functions::get_selected_steps('downsell', $funnel_id),
1074 'landingAndCustomSteps' => Wpfnl_functions::get_selected_steps('landing', $funnel_id),
1075 'customSteps' => Wpfnl_functions::get_selected_steps('custom', $funnel_id),
1076 'onlySettingsSteps' => Wpfnl_functions::get_only_settings_steps(),
1077 'isWCML' => defined('WCML_VERSION'),
1078 'cfeDefault' => Wpfnl_functions::get_cfe_default_fields(),
1079 'adminEmail' => get_bloginfo('admin_email'),
1080 'siteName' => get_option('blogname'),
1081 'mailMintEmail' => Wpfnl_functions::get_mailmint_email(),
1082 'email_settings' => Wpfnl_functions::get_mailmint_email_settings(),
1083 'mint_twillo_settings' => Wpfnl_functions::get_mailmint_twillo_settings(),
1084 'emailBuilderUrl' => admin_url() . 'admin.php?page=email-builder',
1085 'currentUrl' => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
1086 'wc_currency' => $wc_currency_symbol,
1087 'ld_currency' => $ld_currency_symbol,
1088 'getText' => Wpfnl_functions::get_text(),
1089 'user_role_manager_data' => Wpfnl_functions::get_user_role_settings(),
1090 'availableGateways' => Wpfnl_functions::get_enabled_payment_gateways(),
1091 'guidedTour' => Wpfnl_functions::get_guided_tour(),
1092 'isWPFIntegrationActive' => apply_filters( 'wpfunnels/is_integration_license_active', false ),
1093 ));
1094 wp_localize_script(
1095 $this->plugin_name,
1096 'template_library_object',
1097 array(
1098 'ajaxurl' => esc_url_raw(admin_url('admin-ajax.php')),
1099 'rest_api_url' => esc_url_raw(get_rest_url()),
1100 'dashboard_url' => ( $funnel_id && get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ) === 'store_checkout' )
1101 ? esc_url_raw(admin_url('admin.php?page=store_checkout'))
1102 : esc_url_raw(admin_url('admin.php?page=' . WPFNL_FUNNEL_PAGE_SLUG)),
1103 'settings_url' => esc_url_raw(admin_url('admin.php?page=settings')),
1104 'home_url' => esc_url_raw(home_url()),
1105 'funnel_id' => $funnel_id,
1106 'isTemplatePage' => 'wpfunnels_page_wpf_templates' === $hook,
1107 'is_pro' => Wpfnl_functions::is_pro_license_activated(),
1108 'is_ab_tesing_available' => defined('WPFNL_PRO_VERSION') ? version_compare(WPFNL_PRO_VERSION, "1.7.3", ">=") : false,
1109 'is_webhook_licensed' => Wpfnl_functions::is_webhook_license_activated(),
1110 'pro_url' => add_query_arg('wpfnl-dashboard', '1', GETWPFUNNEL_PRICING_URL),
1111 'nonce' => wp_create_nonce('wp_rest'),
1112 'image_path' => WPFNL_URL . 'admin/assets/images',
1113 'template_type' => Wpfnl_functions::get_template_types(),
1114 'countries' => Wpfnl_functions::get_countries(),
1115 'supported_steps' => Wpfnl_functions::get_supported_step_type(),
1116 'is_mint_active' => Wpfnl_functions::is_mint_mrm_active(),
1117 'settingsSteps' => Wpfnl_functions::get_settings_steps(),
1118 'isRemote' => Wpfnl_functions::maybe_remote_funnel(),
1119 'isStoreCheckout' => 'wpfunnels_page_store_checkout' === $hook,
1120 )
1121 );
1122
1123 wp_localize_script(
1124 $this->plugin_name,
1125 'CheckoutStep',
1126 array(
1127 'ajaxurl' => esc_url_raw(admin_url('admin-ajax.php')),
1128 'rest_api_url' => esc_url_raw(get_rest_url()),
1129 'wc_currency' => $wc_currency_symbol,
1130 'nonce' => wp_create_nonce('wp_rest'),
1131 'security' => wp_create_nonce('wpfnl-admin'),
1132 'image_path' => WPFNL_URL . 'admin/assets/images',
1133 'tooltipIcon' => WPFNL_URL . 'admin/partials/icons/question-tooltip-icon.php',
1134 'imageUploadIcon' => WPFNL_URL . 'admin/partials/icons/image-upload-icon.php',
1135 'step_id' => $step_id,
1136 'back' => add_query_arg(
1137 array(
1138 'page' => WPFNL_EDIT_FUNNEL_SLUG,
1139 'id' => filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT),
1140 'step_id' => $step_id,
1141 ),
1142 admin_url('admin.php')
1143 ),
1144 'priceConfig' => Wpfnl_functions::get_wc_price_config(),
1145 )
1146 );
1147
1148 wp_localize_script(
1149 $this->plugin_name,
1150 'wpfnl_addons_vars',
1151 array(
1152 'addons' => Wpfnl_functions::get_supported_addons(),
1153 'gbf_conditions' => Wpfnl_functions::get_supported_gbf_offer_condition(),
1154 'categories' => Wpfnl_functions::get_categories_gbf_offer_condition(),
1155 'role' => Wpfnl_functions::get_all_user_roles(),
1156 'tags' => Wpfnl_functions::get_all_tags(),
1157 'shippingClasses' => Wpfnl_functions::get_shipping_classes(),
1158 )
1159 );
1160
1161 // Enqueue the admin dashboard script only on WPFunnels Main Page
1162
1163 if ($this->is_current_page('wpfunnels')) {
1164 wp_enqueue_script('wpfnl-admin-app', plugin_dir_url(__FILE__) . 'assets/dist/js/wpfnl-admin-app.min.js', array(), $this->version, true);
1165 wp_localize_script('wpfnl-admin-app', 'WPFAdminObj', array(
1166 'rest_api_url' => get_rest_url(),
1167 'security' => wp_create_nonce('wpfnl-admin'),
1168 'nonce' => wp_create_nonce('wp_rest'),
1169 'priceConfig' => Wpfnl_functions::get_wc_price_config(),
1170 'isProActivated' => apply_filters('wpfunnels/is_wpfnl_pro_active', false),
1171 'isWPFIntegrationActive' => apply_filters( 'wpfunnels/is_integration_license_active', false ),
1172 'getText' => Wpfnl_functions::get_text(),
1173 'admin_url' => admin_url(),
1174 ));
1175 }
1176
1177
1178 /**
1179 * Localize scripts for funnel window
1180 *
1181 * @var $localize
1182 */
1183
1184 $notices = $this->get_builder_notice();
1185
1186 $localize = apply_filters('wpfunnels/funnel_window_admin_localize', array());
1187 wp_localize_script($this->plugin_name . '-funnel-window', 'wpfunnels_funnel_localize', array($localize));
1188
1189
1190 do_action('wpfunnels_after_scripts_loaded');
1191 }
1192 }
1193
1194
1195 public function get_lms_provider()
1196 {
1197 $lms_settings = get_option('_wpfunnels_lms_settings', array());
1198 $provider_id = isset($lms_settings['lms_provider']) ? $lms_settings['lms_provider'] : 'learndash';
1199 return $provider_id;
1200 }
1201
1202
1203 /**
1204 * Get the reconfigurable condition data for a funnel
1205 */
1206 public function get_reconfigurable_condition_data($funnel_id)
1207 {
1208 if (!$funnel_id) {
1209 return [];
1210 }
1211 $data = get_post_meta($funnel_id, '_wpfnl_reconfigurable_condition_data', true);
1212 if (!is_array($data) || empty($data)) {
1213 return [];
1214 }
1215 return $data;
1216 }
1217
1218
1219 /**
1220 * Get all setps where GBF conditions is already set
1221 *
1222 * @param Integer $funnel_id
1223 *
1224 * @since 2.6.1
1225 */
1226 private function get_gbf_steps($funnel_id)
1227 {
1228 $gbf_steps = [];
1229 if ($funnel_id) {
1230 $is_gbf = get_post_meta($funnel_id, 'is_global_funnel', true);
1231 if ('yes' === $is_gbf) {
1232 $steps = Wpfnl_functions::get_steps($funnel_id);
1233 if (is_array($steps)) {
1234 foreach ($steps as $step) {
1235 if (isset($step['id'], $step['step_type'])) {
1236 if ('checkout' === $step['step_type']) {
1237 $conditions = get_post_meta($funnel_id, 'global_funnel_start_condition', true);
1238 if (is_array($conditions)) {
1239 array_push($gbf_steps, $step['id']);
1240 }
1241 }
1242 elseif ('upsell' === $step['step_type'] || 'downsell' === $step['step_type']) {
1243
1244 $conditions = get_post_meta($step['id'], 'global_funnel_' . $step['step_type'] . '_rules', true);
1245 if (is_array($conditions)) {
1246 array_push($gbf_steps, $step['id']);
1247 }
1248 }
1249 }
1250 }
1251 }
1252 }
1253 }
1254
1255 return $gbf_steps;
1256 }
1257
1258
1259 /**
1260 * Returns Jed-formatted localization data.
1261 *
1262 * @param string $domain Translation domain.
1263 *
1264 * @return array
1265 */
1266 public function get_jed_locale_data($domain, $language_dir = null)
1267 {
1268 $plugin_translations = $this->get_translations_for_plugin_domain($domain, $language_dir);
1269 $translations = get_translations_for_domain($domain);
1270
1271 $locale = array(
1272 'domain' => $domain,
1273 'locale_data' => array(
1274 $domain => array(
1275 '' => array(
1276 'domain' => $domain,
1277 'lang' => is_admin() ? get_user_locale() : get_locale(),
1278 ),
1279 ),
1280 ),
1281 );
1282
1283 if (!empty($translations->headers['Plural-Forms'])) {
1284 $locale['locale_data'][$domain]['']['plural_forms'] = $translations->headers['Plural-Forms'];
1285 }
1286 else if (!empty($plugin_translations['header'])) {
1287 $locale['locale_data'][$domain]['']['plural_forms'] = $plugin_translations['header']['Plural-Forms'];
1288 }
1289
1290 $entries = array_merge($plugin_translations['translations'], $translations->entries);
1291
1292 foreach ($entries as $msgid => $entry) {
1293 $locale['locale_data'][$domain][$msgid] = $entry->translations;
1294 }
1295
1296 return $locale;
1297 }
1298
1299
1300 /**
1301 * Get translactions for WePos plugin
1302 *
1303 * @param string $domain
1304 * @param string $language_dir
1305 *
1306 * @return array
1307 */
1308 public function get_translations_for_plugin_domain($domain, $language_dir = null)
1309 {
1310 if ($language_dir == null) {
1311 $language_dir = WPFNL_PATH . '/languages/';
1312 }
1313 $languages = get_available_languages($language_dir);
1314 $get_site_lang = is_admin() ? get_user_locale() : get_locale();
1315 $mo_file_name = $domain . '-' . $get_site_lang;
1316 $translations = [];
1317
1318 if (in_array($mo_file_name, $languages) && file_exists($language_dir . $mo_file_name . '.mo')) {
1319 $mo = new \MO();
1320 if ($mo->import_from_file($language_dir . $mo_file_name . '.mo')) {
1321 $translations = $mo->entries;
1322 }
1323 }
1324
1325 return [
1326 'header' => isset($mo) ? $mo->headers : '',
1327 'translations' => $translations,
1328 ];
1329 }
1330
1331
1332 /**
1333 * Check GBF version for skip offer
1334 */
1335 public function is_skip_offer()
1336 {
1337 // GBF is now built into WPFunnels Pro — always available when GBF is activated.
1338 if ( Wpfnl_functions::is_global_funnel_activated() ) {
1339 return true;
1340 }
1341 // Legacy: standalone addon still active.
1342 if ( defined('WPFNL_PRO_GB_VERSION') ) {
1343 return version_compare( WPFNL_PRO_GB_VERSION, '1.0.9', '>=' );
1344 }
1345 return false;
1346 }
1347
1348 public function mint_step_settings($funnel_id)
1349 {
1350 $steps = get_post_meta($funnel_id, '_steps', true);
1351 $mint_steps = [];
1352 if (is_array($steps)) {
1353 foreach ($steps as $step) {
1354 $mint_settings['stepID'] = $step['id'];
1355 $value = get_post_meta($step['id'], '_wpfnl_automation_steps', true);
1356 $mint_settings['value'] = is_array($value) ? $value : [];
1357 array_push($mint_steps, $mint_settings);
1358 }
1359 }
1360 return $mint_steps;
1361 }
1362
1363
1364 /**
1365 * Define w2cloud routes
1366 *
1367 * @return array
1368 */
1369 public function get_wpfnl_routes()
1370 {
1371 $routes = array(
1372 array(
1373 'path' => '/',
1374 'name' => 'home',
1375 'component' => 'Home'
1376 )
1377 );
1378 return apply_filters('wpfnl_routes', $routes);
1379 }
1380
1381 /**
1382 * Get all active Payment Method
1383 *
1384 * @return array
1385 */
1386 public function get_payment_method()
1387 {
1388 if (Wpfnl_functions::is_wc_active()) {
1389 $gateways = WC()->payment_gateways->get_available_payment_gateways();
1390 $enabled_gateways = [];
1391
1392 if ($gateways) {
1393 foreach ($gateways as $key => $gateway) {
1394 if ($gateway->enabled == 'yes') {
1395 $enabled_gateways[$key] = $gateway->method_title;
1396 }
1397 }
1398 }
1399 return $enabled_gateways;
1400 }
1401 return [];
1402 }
1403
1404 /**
1405 * Get all shipping methods
1406 *
1407 * @return array
1408 */
1409 public function get_shipping_method()
1410 {
1411 if (Wpfnl_functions::is_wc_active()) {
1412 $available_shipping = WC()->shipping()->get_shipping_methods();
1413 $enabled_shipping = [];
1414 if ($available_shipping) {
1415 foreach ($available_shipping as $key => $shipping) {
1416 $enabled_shipping[$key] = $shipping->method_title;
1417 }
1418 }
1419 return $enabled_shipping;
1420 }
1421 return [];
1422 }
1423
1424
1425 /**
1426 * Show funnel steps on reading
1427 *
1428 * @param $output
1429 *
1430 * @return mixed
1431 */
1432 public function show_funnel_steps_on_reading($output)
1433 {
1434 global $pagenow;
1435 if (('options-reading.php' === $pagenow || 'customize.php' === $pagenow) && preg_match('#page_on_front#', $output)) {
1436 $output = $this->show_steps_options($output);
1437 }
1438 return $output;
1439 }
1440
1441
1442 /**
1443 * Show steps pages on reading
1444 *
1445 * @param $output
1446 *
1447 * @return string
1448 */
1449 private function show_steps_options($output)
1450 {
1451 $options = '';
1452
1453 $steps = get_posts(
1454 array(
1455 'post_type' => WPFNL_STEPS_POST_TYPE,
1456 'posts_per_page' => -1,
1457 'numberposts' => 100,
1458 'orderby' => 'title',
1459 'order' => 'ASC',
1460 'post_status' => 'publish',
1461 'meta_query' => array(
1462 'relation' => 'OR',
1463 array(
1464 'key' => '_step_type',
1465 'value' => 'landing',
1466 ),
1467 array(
1468 'key' => '_step_type',
1469 'value' => 'checkout',
1470 )
1471 ),
1472 )
1473 );
1474
1475 if ($steps && is_array($steps)) {
1476 $front_page_id = get_option('page_on_front');
1477 foreach ($steps as $step) {
1478 $selected = selected($front_page_id, $step->ID, false);
1479 $post_type_obj = get_post_type_object($step->post_type);
1480 $options .= "<option value=\"{$step->ID}\"{$selected}>{$step->post_title} (WPFunnels {$post_type_obj->labels->singular_name})</option>";
1481 }
1482 $options .= '</select>';
1483 $output = str_replace('</select>', $options, $output);
1484 }
1485 return $output;
1486 }
1487
1488
1489 /**
1490 * Get notice for builder
1491 *
1492 * @return array
1493 */
1494 public function get_builder_notice()
1495 {
1496 $builder = Wpfnl_functions::get_builder_type();
1497 $notices = array();
1498 if ('divi-builder' === $builder) {
1499 $notices['notices'][] = array();
1500 }
1501 return $notices;
1502 }
1503
1504
1505 /**
1506 * Change text in order details page
1507 */
1508 public function wpfnl_customizing_checkout_text($translated_text, $untranslated_text, $domain)
1509 {
1510
1511 if (is_admin()) {
1512 if ($translated_text == 'Coupon(s):') {
1513 $translated_text = __('Discount:', 'wpfnl');
1514 }
1515 }
1516
1517 return $translated_text;
1518 }
1519
1520
1521 /**
1522 * Change local for if this is funnel canvas window
1523 *
1524 * @param $local
1525 *
1526 * @return string
1527 *
1528 * @since 2.3.8
1529 */
1530 public function change_local_for_funnel_canvas($local)
1531 {
1532 if (Wpfnl_functions::is_funnel_canvas_window()) {
1533 return 'en_US';
1534 }
1535 return $local;
1536 }
1537
1538
1539 /**
1540 * Add type meta
1541 *
1542 * @since 2.4.4
1543 */
1544 public function wpfnl_add_type_meta()
1545 {
1546 Wpfnl_functions::add_type_meta();
1547 }
1548
1549
1550 /**
1551 * Maybe Global funnel
1552 *
1553 * @param String
1554 *
1555 * @return Bool
1556 * @since 2.4.11
1557 */
1558 public function maybe_gbf($funnel_id)
1559 {
1560
1561 if ( Wpfnl_functions::is_global_funnel_activated() ) {
1562 if ($funnel_id) {
1563 $is_gbf = get_post_meta($funnel_id, 'is_global_funnel', true);
1564 if ('yes' == $is_gbf) {
1565 return true;
1566 }
1567 }
1568 }
1569
1570 return false;
1571 }
1572
1573 /**
1574 * Check funnel type is lms or not by funnel_id
1575 *
1576 * @return Bool
1577 */
1578 public function maybe_lms($funnel_id)
1579 {
1580
1581 $type = get_post_meta($funnel_id, '_wpfnl_funnel_type', true);
1582 if ('lms' === $type) {
1583 return true;
1584 }
1585 return false;
1586 }
1587
1588 /**
1589 * May be lms settings is disbaled
1590 */
1591 public function maybe_lms_settings_disbaled()
1592 {
1593 return Wpfnl_functions::is_wc_active() && Wpfnl_functions::is_lms_addon_active();
1594 }
1595
1596
1597 /**
1598 * Trigger when any plugin is deactivated
1599 *
1600 * @param $filename
1601 *
1602 * @since 2.5.1
1603 */
1604 public function wpfnl_deactivated_plugin($filename)
1605 {
1606 if ('woocommerce/woocommerce.php' === $filename) {
1607 if (!Wpfnl_functions::is_lms_addon_active()) {
1608 Wpfnl_functions::update_funnel_type_to_lead();
1609 }
1610 Wpfnl_functions::wpfnl_delete_transient();
1611 }
1612 elseif ('sfwd-lms/sfwd_lms.php' === $filename) {
1613 if (!Wpfnl_functions::is_wc_active()) {
1614 Wpfnl_functions::update_funnel_type_to_lead();
1615 }
1616 Wpfnl_functions::wpfnl_delete_transient();
1617 }
1618 elseif ('wpfunnels-pro-lms/wpfunnels-pro-lms.php' === $filename) {
1619 Wpfnl_functions::wpfnl_delete_transient();
1620 }
1621 elseif ('qubely/qubely.php' === $filename) {
1622 Wpfnl_functions::wpfnl_delete_transient();
1623 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_wc');
1624 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_lms');
1625 delete_transient('wpfunnels_remote_template_data_wc_' . WPFNL_VERSION);
1626 delete_transient('wpfunnels_remote_template_data_lms_' . WPFNL_VERSION);
1627 delete_transient('wpfunnels_remote_template_data_lead_' . WPFNL_VERSION);
1628 delete_transient('wpfunnels_remote_template_data_store_checkout_' . WPFNL_VERSION);
1629 }
1630 }
1631
1632
1633 /**
1634 * Trigger when any plugin is activated
1635 *
1636 * @param $filename
1637 *
1638 * @since 2.5.1
1639 */
1640 public function wpfnl_activated_plugin($filename)
1641 {
1642 if ('woocommerce/woocommerce.php' === $filename) {
1643 Wpfnl_functions::wpfnl_delete_transient();
1644 }
1645 elseif ('sfwd-lms/sfwd_lms.php' === $filename) {
1646 if (Wpfnl_functions::is_lms_addon_active()) {
1647 Wpfnl_functions::wpfnl_delete_transient();
1648 }
1649 }
1650 elseif ('wpfunnels-pro-lms/wpfunnels-pro-lms.php' === $filename) {
1651 Wpfnl_functions::wpfnl_delete_transient();
1652 }
1653 elseif ('qubely/qubely.php' === $filename) {
1654 Wpfnl_functions::wpfnl_delete_transient();
1655 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_wc');
1656 delete_option(WPFNL_TEMPLATES_OPTION_KEY . '_lms');
1657 delete_transient('wpfunnels_remote_template_data_wc_' . WPFNL_VERSION);
1658 delete_transient('wpfunnels_remote_template_data_lms_' . WPFNL_VERSION);
1659 delete_transient('wpfunnels_remote_template_data_lead_' . WPFNL_VERSION);
1660 delete_transient('wpfunnels_remote_template_data_store_checkout_' . WPFNL_VERSION);
1661 }
1662 }
1663
1664
1665
1666 /**
1667 * Get editor source data
1668 *
1669 * @return array
1670 * @since 1.0.0
1671 */
1672 private function get_editor_source()
1673 {
1674 // get product categories for email builder.
1675 $wc_categories = $this->get_formatted_wc_categories();
1676 $wp_categories = $this->get_formatted_wp_post_categories();
1677
1678 return apply_filters(
1679 'plugin_hook_name',
1680 array(
1681 'product_categories' => $wc_categories,
1682 'post_categories' => $wp_categories,
1683 'placeholder_image' => ''
1684 )
1685 );
1686 }
1687
1688
1689
1690 /**
1691 * Get the WooCommerce product categories
1692 *
1693 * @return array
1694 * @since 1.0.0
1695 */
1696 private function get_formatted_wc_categories()
1697 {
1698 $taxonomy = 'product_cat';
1699 $orderby = 'name';
1700 $show_count = 0;
1701 $pad_counts = 0;
1702 $hierarchical = 1;
1703 $title = '';
1704 $empty = 0;
1705
1706 $args = array(
1707 'taxonomy' => $taxonomy,
1708 'orderby' => $orderby,
1709 'show_count' => $show_count,
1710 'pad_counts' => $pad_counts,
1711 'hierarchical' => $hierarchical,
1712 'title_li' => $title,
1713 'hide_empty' => $empty,
1714 );
1715 $product_categories = get_categories($args);
1716 $wc_categories = array();
1717 foreach ($product_categories as $product_cat) {
1718 $wc_categories[] = array(
1719 'value' => $product_cat->term_id,
1720 'label' => $product_cat->name,
1721 );
1722 }
1723
1724 return $wc_categories;
1725 }
1726
1727
1728 /**
1729 * Get the WordPress post categories
1730 *
1731 * @return array
1732 * @since 1.0.0
1733 */
1734 private function get_formatted_wp_post_categories()
1735 {
1736 $taxonomy = 'category';
1737 $orderby = 'name';
1738 $show_count = 0;
1739 $pad_counts = 0;
1740 $hierarchical = 1;
1741 $title = '';
1742 $empty = 0;
1743
1744 $args = array(
1745 'taxonomy' => $taxonomy,
1746 'orderby' => $orderby,
1747 'show_count' => $show_count,
1748 'pad_counts' => $pad_counts,
1749 'hierarchical' => $hierarchical,
1750 'title_li' => $title,
1751 'hide_empty' => $empty,
1752 );
1753 $post_categories = get_categories($args);
1754 $categories = array();
1755 foreach ($post_categories as $post_cat) {
1756 $categories[] = array(
1757 'value' => $post_cat->term_id,
1758 'label' => $post_cat->name,
1759 );
1760 }
1761 return $categories;
1762 }
1763
1764
1765 /**
1766 * Add custom capabilities to administrator role
1767 *
1768 * @since 3.1.3
1769 */
1770 public function attach_admin_capabilities()
1771 {
1772 global $wp_roles;
1773 $capabilities = array(
1774 'wpf_manage_funnels',
1775 );
1776 foreach ($capabilities as $cap) {
1777 $wp_roles->add_cap('administrator', $cap);
1778 }
1779 }
1780
1781 /**
1782 * Checks if the current page slug matches the provided slug.
1783 *
1784 * @param $slug
1785 * @return bool
1786 * @since 3.5.0
1787 */
1788 public function is_current_page($slug)
1789 {
1790 if (empty($slug)) {
1791 return false;
1792 }
1793 $current_page_slug = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
1794 if ($slug === $current_page_slug) {
1795 return true;
1796 }
1797 return false;
1798 }
1799
1800 /**
1801 * Add body class for WPFunnels admin pages.
1802 *
1803 * @param string $classes Current body classes.
1804 * @return string Modified body classes.
1805 * @since 3.9.5
1806 */
1807 public function add_wpfunnels_admin_body_class($classes)
1808 {
1809 // Check if we're on a WPFunnels admin page.
1810 $screen = get_current_screen();
1811
1812 if ($screen && in_array($screen->id, $this->page_hooks)) {
1813 $classes .= ' wpfunnels-body';
1814 }
1815
1816 return $classes;
1817 }
1818
1819
1820 /**
1821 * Create contact on mailmint when user allows to track data
1822 *
1823 * @param array $data
1824 *
1825 * @since 3.3.1
1826 */
1827 public function wpfunnels_tracker_optin($data)
1828 {
1829 if (isset($data['admin_email'], $data['first_name'], $data['last_name'])) {
1830 $json_body_data = json_encode([
1831 'email' => $data['admin_email'],
1832 'first_name' => $data['first_name'],
1833 'last_name' => $data['last_name'],
1834 ]);
1835
1836 $webHookUrl = [
1837 'https://staging-useraccount.kinsta.cloud/?mailmint=1&route=webhook&topic=contact&hash=b258136d-6759-4e91-bbab-0b7397af6dc7'
1838 ];
1839
1840 try {
1841 if (!empty($webHookUrl)) {
1842 foreach ($webHookUrl as $url) {
1843 wp_remote_request($url, [
1844 'method' => 'POST',
1845 'headers' => [
1846 'Content-Type' => 'application/json',
1847 ],
1848 'body' => $json_body_data
1849 ]);
1850 }
1851 }
1852 }
1853 catch (\Exception $e) {
1854 }
1855 }
1856 }
1857
1858 /**
1859 * Creates a new MRM contact.
1860 *
1861 * @param array $data The data for the contact.
1862 * @return void
1863 */
1864 public function create_mrm_contact($data)
1865 {
1866 if (!isset($data['data']['user_email'])) {
1867 return;
1868 }
1869 // Get double opt-in settings.
1870 $default = \MRM\Common\MrmCommon::double_optin_default_configuration();
1871 $settings = get_option('_mrm_optin_settings', $default);
1872 $enable = isset($settings['enable']) ? $settings['enable'] : false;
1873
1874 $user_data = array(
1875 'email' => $data['data']['user_email'],
1876 'first_name' => isset($data['data']['first_name']) ? $data['data']['first_name'] : '',
1877 'last_name' => isset($data['data']['last_name']) ? $data['data']['last_name'] : '',
1878 'meta_fields' => array(
1879 'phone_number' => isset($data['data']['phone_number']) ? $data['data']['phone_number'] : '',
1880 ),
1881 'status' => $enable ? 'pending' : 'subscribed',
1882 'source' => 'WPFunnels',
1883 );
1884
1885 $mail_mint_object = new \WPFunnels\Integrations\MailMint($user_data);
1886 $mail_mint_object->create_or_update_contact();
1887 }
1888 }