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

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