PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.0
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.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 / includes / core / classes / class-wpfnl-admin-menus.php

class-wpfnl-admin-menus.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.0, at includes/core/classes/class-wpfnl-admin-menus.php

627 lines 17.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin menus
4 *
5 * @package
6 */
7 namespace WPFunnels\Menu;
8
9 use WPFunnels\Admin\SetupWizard;
10 use WPFunnels\Wpfnl;
11 use WPFunnels\Wpfnl_functions;
12
13 /**
14 * Class Wpfnl_Menus
15 *
16 * @package Wpfnl
17 */
18 class Wpfnl_Menus
19 {
20 public function __construct()
21 {
22 add_action('admin_menu', [$this, 'register_plugin_menus']);
23 add_filter('admin_head', [$this, 'remove_submenu'], 10, 2);
24 add_filter('admin_head', [$this, 'remove_notices_from_funnel_window'], 10, 2);
25 add_action('admin_init', [$this, 'disallow_all_step_view']);
26 add_action('admin_footer', [$this, 'doc_link_with_new_page']);
27 add_filter('wpfnl_dashboard_nav_lists', [$this, 'add_store_checkout_nav'], 15, 1);
28 add_action('admin_bar_menu', [$this, 'register_admin_bar_menu'], 100);
29
30 if( isset($_GET['page']) && 'edit_funnel' === $_GET['page'] ) {
31 $funnel_id = isset($_GET['id']) ? absint($_GET['id']) : 0;
32 $funnel_type = $funnel_id ? get_post_meta($funnel_id, '_wpfnl_funnel_type', true) : '';
33 if ( 'store_checkout' === $funnel_type ) {
34 add_filter( 'parent_file', function( $parent_file ) {
35 return WPFNL_MAIN_PAGE_SLUG;
36 });
37 add_filter( 'submenu_file', function( $submenu_file ) {
38 return WPFNL_STORE_CHECKOUT_SLUG;
39 });
40 } else {
41 add_filter( "admin_body_class", array($this, 'add_folded_menu_class') );
42 }
43 }
44 }
45
46
47 /**
48 * Register plugin menus and submenus
49 *
50 * @since 1.0.0
51 */
52 public function register_plugin_menus()
53 {
54 $role_permission = Wpfnl_functions::get_general_settings();
55
56 add_menu_page(
57 'WPFunnels',
58 'WPFunnels',
59 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
60 WPFNL_MAIN_PAGE_SLUG,
61 '',
62 WPFNL_DIR_URL . 'admin/assets/images/funnel.svg',
63 6
64 );
65
66
67 // Register dashboard page for WPF
68 add_submenu_page(
69 WPFNL_MAIN_PAGE_SLUG,
70 __('Dashboard', 'wpfnl'),
71 __('Dashboard', 'wpfnl'),
72 'wpf_manage_funnels',
73 WPFNL_MAIN_PAGE_SLUG,
74 [$this, 'render']
75 );
76
77 add_submenu_page(
78 WPFNL_MAIN_PAGE_SLUG,
79 __('Funnels', 'wpfnl'),
80 __('Funnels', 'wpfnl'),
81 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
82 WPFNL_FUNNEL_PAGE_SLUG,
83 [$this, 'render_funnels_page']
84 );
85
86 add_submenu_page(
87 WPFNL_MAIN_PAGE_SLUG,
88 __('Store Checkout', 'wpfnl'),
89 __('Store Checkout', 'wpfnl'),
90 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
91 WPFNL_STORE_CHECKOUT_SLUG,
92 [$this, 'render_store_checkout_page']
93 );
94
95 add_submenu_page(
96 WPFNL_MAIN_PAGE_SLUG,
97 __('Automations', 'wpfnl'),
98 __('Automations', 'wpfnl'),
99 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
100 WPFNL_AUTOMATIONS_SLUG,
101 [$this, 'render_automations_page']
102 );
103
104 $integrations_in_pro = defined( 'WPFNL_PRO_VERSION' ) && version_compare( WPFNL_PRO_VERSION, '2.9.0', '>=' );
105 $legacy_addon_active = is_plugin_active( 'wpfunnels-pro-integrations/wpfunnels-pro-integrations.php' );
106
107 if ( $integrations_in_pro || ! $legacy_addon_active ) {
108 // Pro owns the integrations menu; access is controlled by plan check inside the page renderer.
109 add_submenu_page(
110 WPFNL_MAIN_PAGE_SLUG,
111 __('Integrations', 'wpfnl'),
112 __('Integrations', 'wpfnl'),
113 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
114 WPFNL_INTEGRATIONS_MAIN_PAGE_SLUG,
115 [$this, 'render_integration_page']
116 );
117 } else {
118 /**
119 * After setup menu of WPFunnels.
120 * Legacy fallback for users still running the old addon.
121 *
122 * @since 1.0.0
123 */
124 do_action( 'wpfunnels/after_setup_menu');
125 }
126
127 add_submenu_page(
128 WPFNL_MAIN_PAGE_SLUG,
129 __('Templates', 'wpfnl'),
130 __('Templates', 'wpfnl'),
131 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
132 WPFNL_TEMPLATE_PAGE_SLUG,
133 [$this, 'render_funnel_template_page']
134 );
135
136 // add_submenu_page(
137 // WPFNL_MAIN_PAGE_SLUG,
138 // __('Add-ons', 'wpfnl'),
139 // __('Add-ons', 'wpfnl'),
140 // Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
141 // WPFNL_ADDONS_SLUG,
142 // [$this, 'render_addons_page']
143 // );
144
145
146 // Show Integrations menu if WPFunnels Pro Integrations is deactivated
147 if ( ! function_exists( 'is_plugin_active' ) ) {
148 require_once ABSPATH . 'wp-admin/includes/plugin.php';
149 }
150
151 add_submenu_page(
152 WPFNL_MAIN_PAGE_SLUG,
153 __('Settings', 'wpfnl'),
154 __('Settings', 'wpfnl'),
155 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
156 WPFNL_GLOBAL_SETTINGS_SLUG,
157 [$this, 'render_settings_page']
158 );
159
160 add_submenu_page(
161 WPFNL_MAIN_PAGE_SLUG,
162 __('AI Assistant', 'wpfnl'),
163 __('AI Assistant', 'wpfnl'),
164 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
165 WPFNL_AI_FUNNEL_PAGE_SLUG,
166 [$this, 'render_ai_funnel_page']
167 );
168
169 // add_submenu_page(
170 // WPFNL_MAIN_PAGE_SLUG,
171 // __('Documentation', 'wpfnl'),
172 // '<span id="wpfnl-documentation">'. __('Documentation', 'wpfnl').'</span>',
173 // Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
174 // 'https://getwpfunnels.com/resources/'
175 // );
176
177 add_submenu_page(
178 WPFNL_MAIN_PAGE_SLUG,
179 __('Edit Funnel', 'wpfnl'),
180 __('Edit Funnel', 'wpfnl'),
181 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
182 WPFNL_EDIT_FUNNEL_SLUG,
183 [$this, 'render_edit_funnel_page']
184 );
185
186 add_submenu_page(
187 WPFNL_MAIN_PAGE_SLUG,
188 __('Trash', 'wpfnl'),
189 __('Trash', 'wpfnl'),
190 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
191 WPFNL_TRASH_FUNNEL_SLUG,
192 [$this, 'render_trash_funnel_page']
193 );
194
195 add_submenu_page(
196 WPFNL_MAIN_PAGE_SLUG,
197 __('Request a Feature', 'wpfnl'),
198 '<span id="wpfnl-request-feature">'. __('Request a Feature', 'wpfnl').'</span>',
199 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
200 'https://getwpfunnels.com/ideas/'
201 );
202
203 add_submenu_page(
204 WPFNL_MAIN_PAGE_SLUG,
205 __('Email Builder', 'wpfnl'),
206 __('Email Builder', 'wpfnl'),
207 Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
208 'email-builder',
209 [$this, 'render_email_builder_page']
210 );
211
212 // if ( !Wpfnl_functions::is_wpfnl_pro_activated() ) {
213
214 // add_submenu_page(
215 // WPFNL_MAIN_PAGE_SLUG,
216 // __('Free vs Pro', 'wpfnl'),
217 // __('Free vs Pro', 'wpfnl'),
218 // Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
219 // 'wpf_feature_comparison',
220 // [$this, 'render_feature_comparison_page']
221 // );
222
223
224 // add_submenu_page(
225 // WPFNL_MAIN_PAGE_SLUG,
226 // __('Go Pro', 'wpfnl'),
227 // '<span id="wpfnl-go-pro" class="dashicons dashicons-star-filled" style="font-size: 17px; color:#1fb3fb;"></span> ' . __('Go Pro', 'wpfnl'),
228 // Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ),
229 // 'https://getwpfunnels.com/pricing/'
230 // );
231 // }
232 }
233
234
235 /**
236 * Render the admin view of WPFunnels
237 *
238 * @since 3.1.7
239 */
240 public function render() {
241 include_once WPFNL_ADMIN_DIR . 'views/base.php';
242 }
243
244
245
246 public function render_email_builder_page() { ?>
247 <div id="email-builder"></div>
248 <?php }
249
250
251
252 /**
253 * Render funnel page
254 *
255 * @since 1.0.0
256 */
257 public function render_funnels_page()
258 {
259 Wpfnl::$instance->module_manager->get_admin_modules('funnels')->get_view();
260 }
261
262
263 /**
264 * Render AI funnel page.
265 *
266 * @since 3.10.0
267 */
268 public function render_ai_funnel_page()
269 {
270 require WPFNL_DIR . '/admin/views/ai-funnel.php';
271 }
272
273
274 /**
275 * Render funnel template page
276 *
277 * @since 1.0.0
278 */
279 public function render_funnel_template_page()
280 {
281 require WPFNL_DIR . '/admin/partials/templates.php';
282 }
283
284
285 /**
286 * Render feature comparison page
287 *
288 * @return void
289 * @since 3.4.13
290 */
291 public function render_feature_comparison_page() {
292 require WPFNL_DIR . '/admin/partials/feature-comparison.php';
293 }
294
295
296 /**
297 * Render edit funnel page.
298 *
299 * @since 1.0.0
300 */
301 public function render_edit_funnel_page()
302 {
303 $funnel_id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_SPECIAL_CHARS);
304 Wpfnl::$instance->module_manager->get_admin_modules('funnel')->init($funnel_id);
305 Wpfnl::$instance->module_manager->get_admin_modules('funnel')->get_view();
306 }
307
308
309 /**
310 * Render trash funnel page.
311 *
312 * @since 3.1.8
313 */
314 public function render_trash_funnel_page()
315 {
316 Wpfnl::$instance->module_manager->get_admin_modules('funnels')->get_view();
317 }
318
319 /**
320 * Render create funnel page
321 *
322 * @since 1.0.0
323 */
324 public function render_create_funnel_page()
325 {
326 Wpfnl::$instance->module_manager->get_admin_modules('create-funnel')->get_view();
327 }
328
329
330 /**
331 * Render settings page
332 *
333 * @since 1.0.0
334 */
335 public function render_settings_page()
336 {
337 Wpfnl::$instance->module_manager->get_admin_modules('settings')->get_view();
338 }
339
340 public function render_automations_page()
341 {
342 Wpfnl::$instance->module_manager->get_admin_modules('automations')->get_view();
343 }
344
345
346 /**
347 * Render addons page
348 *
349 * @since 1.0.0
350 */
351 public function render_addons_page()
352 {
353 require_once WPFNL_DIR . 'admin/modules/addons/view.php';
354 }
355
356
357 /**
358 * Render Store Checkout page
359 *
360 * Since 3.6.0 multiple store checkouts are allowed, so this page always
361 * shows the listing rather than redirecting to a single canvas.
362 *
363 * @since 3.5.0
364 */
365 public function render_store_checkout_page()
366 {
367 require WPFNL_DIR . '/admin/modules/store-checkout/views/store-checkout-listing.php';
368 }
369
370 /**
371 * Render Integration page
372 *
373 * @since 1.0.0
374 */
375 public function render_integration_page()
376 {
377 // Show Integrations page only if WPFunnels Pro Integrations is deactivated
378 if ( ! function_exists( 'is_plugin_active' ) ) {
379 require_once ABSPATH . 'wp-admin/includes/plugin.php';
380 }
381
382 if ( has_action( 'wpfunnels/render_integrations_page' ) ) {
383 // Pro plugin has registered its renderer — delegate (plan gate applied inside).
384 do_action( 'wpfunnels/render_integrations_page' );
385 } elseif ( ! is_plugin_active( 'wpfunnels-pro-integrations/wpfunnels-pro-integrations.php' ) ) {
386 require_once WPFNL_DIR . 'admin/modules/integration/view.php';
387 }
388 }
389
390 /**
391 * Get Store Checkout funnel if exists
392 *
393 * @return WP_Post|false
394 * @since 3.5.0
395 */
396 private function get_store_checkout_funnel()
397 {
398 $args = [
399 'post_type' => WPFNL_FUNNELS_POST_TYPE,
400 'posts_per_page' => 1,
401 'post_status' => ['publish', 'draft'],
402 'meta_query' => [
403 [
404 'key' => '_wpfnl_funnel_type',
405 'value' => 'store_checkout',
406 ],
407 ],
408 ];
409
410 $funnels = get_posts($args);
411 return !empty($funnels) ? $funnels[0] : false;
412 }
413
414
415
416
417 /**
418 * Render license page for funnel
419 *
420 * @since 2.0.0
421 */
422 public function render_license() {
423 require WPFNL_DIR . '/admin/partials/license.php';
424 }
425
426 /**
427 * Remove submenu from plugin menu
428 *
429 * @since 1.0.0
430 */
431 public function remove_submenu()
432 {
433 remove_submenu_page(WPFNL_MAIN_PAGE_SLUG, 'edit_funnel');
434 remove_submenu_page(WPFNL_MAIN_PAGE_SLUG, 'trash_funnels');
435 // The AI Assistant page stays in the menu: it is a destination in its own
436 // right, not an internal screen like the funnel canvas above.
437 }
438
439
440 /**
441 * Remove all notices from funnel window
442 *
443 * @since 2.0.0
444 */
445 public function remove_notices_from_funnel_window() {
446 if (empty($_GET['page'])) {
447 return;
448 }
449 if (('edit_funnel' == sanitize_text_field( $_GET['page'] ) )) {
450 remove_all_actions( 'admin_notices' );
451 }
452 if ( 'wp_funnels' == sanitize_text_field( $_GET['page'] ) || 'wpf_templates' == sanitize_text_field( $_GET['page'] ) || 'trash_funnels' == sanitize_text_field( $_GET['page'] ) || 'wpfnl_settings' == sanitize_text_field( $_GET['page'] ) || 'wpf-license' == sanitize_text_field( $_GET['page'] ) || WPFNL_AI_FUNNEL_PAGE_SLUG == sanitize_text_field( $_GET['page'] ) ) {
453 add_action('admin_footer', array( $this, 'remove_admin_notices' ));
454 }
455
456 }
457
458
459
460 /**
461 * Force user to visit all steps page
462 *
463 * @since 1.0.0
464 */
465 public function disallow_all_step_view()
466 {
467 global $pagenow;
468 if ('edit.php' === $pagenow && isset($_GET['post_type']) && WPFNL_STEPS_POST_TYPE === sanitize_text_field($_GET['post_type'])) {
469 $funnel_link = add_query_arg(
470 [
471 'page' => WPFNL_MAIN_PAGE_SLUG,
472 ],
473 admin_url('admin.php')
474 );
475 wp_safe_redirect( wp_sanitize_redirect( esc_url_raw( $funnel_link ) ) );
476 exit;
477 }
478 }
479
480 /**
481 * Redirect user to pro url
482 */
483 public function redirect_to_pro()
484 {
485 $url = 'https://getwpfunnels.com/pricing/';
486 wp_safe_redirect( wp_sanitize_redirect( esc_url_raw( $url ) ) );
487 exit();
488 }
489
490
491 /**
492 * Open with new page when documenation is clicked
493 */
494 public function doc_link_with_new_page(){
495 ?>
496 <script type="text/javascript">
497 jQuery(document).ready(function($) {
498 $('#wpfnl-documentation').parent().attr('target','_blank');
499 $('#wpfnl-request-feature').parent().attr('target','_blank');
500 $('#wpfnl-go-pro').parent().attr('target','_blank');
501 });
502 </script>
503 <?php
504 }
505
506
507 public function add_folded_menu_class($classes) {
508 return $classes." folded";
509 }
510
511
512 /**
513 * Remove admin notices
514 */
515 public function remove_admin_notices() {
516 echo '<style>.update-nag, .updated, .error, .is-dismissible, .notice { display: none; } .wpfnl-import-notice {display: block!important; margin: 15px 15px 15px 0px;} .wpfunnels-notice {display: block; margin-left: 0px; margin-right: 25px;}</style>';
517 }
518
519
520 /**
521 * Add Store Checkout to dashboard navigation
522 *
523 * @param array $list Navigation list
524 * @return array Modified navigation list
525 * @since 3.5.0
526 */
527 public function add_store_checkout_nav( $list ) {
528 if ( ! is_array( $list ) ) {
529 return $list;
530 }
531
532 // Insert Store Checkout before settings
533 $new_list = array();
534
535 foreach ( $list as $key => $item ) {
536 // Insert Store Checkout before settings
537 if ( $key === 'settings' ) {
538 $new_list['store_checkout'] = array(
539 'title' => __('Store Checkout', 'wpfnl'),
540 'icon' => 'storewide-checkout-icon',
541 'page' => 'store_checkout',
542 );
543 }
544
545 $new_list[$key] = $item;
546 }
547
548 return $new_list;
549 }
550
551
552 /**
553 * Register WPFunnels nodes in the WordPress admin bar.
554 *
555 * @param WP_Admin_Bar $wp_admin_bar
556 * @since 3.10.9
557 */
558 public function register_admin_bar_menu( $wp_admin_bar ) {
559 $role_permission = Wpfnl_functions::get_general_settings();
560 $capability = Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission );
561
562 if ( ! current_user_can( $capability ) ) {
563 return;
564 }
565
566 $wp_admin_bar->add_node([
567 'id' => 'wpfunnels',
568 'title' => __('WPFunnels', 'wpfnl'),
569 'href' => admin_url('admin.php?page=' . WPFNL_MAIN_PAGE_SLUG),
570 ]);
571
572 $subnodes = [
573 [
574 'id' => 'wpfunnels-dashboard',
575 'title' => __('Dashboard', 'wpfnl'),
576 'href' => admin_url('admin.php?page=' . WPFNL_MAIN_PAGE_SLUG),
577 ],
578 [
579 'id' => 'wpfunnels-funnels',
580 'title' => __('Funnels', 'wpfnl'),
581 'href' => admin_url('admin.php?page=' . WPFNL_FUNNEL_PAGE_SLUG),
582 ],
583 [
584 'id' => 'wpfunnels-store-checkout',
585 'title' => __('Store Checkout', 'wpfnl'),
586 'href' => admin_url('admin.php?page=' . WPFNL_STORE_CHECKOUT_SLUG),
587 ],
588 [
589 'id' => 'wpfunnels-automations',
590 'title' => __('Automations', 'wpfnl'),
591 'href' => admin_url('admin.php?page=' . WPFNL_AUTOMATIONS_SLUG),
592 ],
593 ];
594
595 if ( ! function_exists( 'is_plugin_active' ) ) {
596 require_once ABSPATH . 'wp-admin/includes/plugin.php';
597 }
598
599 $integrations_in_pro = defined('WPFNL_PRO_VERSION') && version_compare(WPFNL_PRO_VERSION, '2.9.0', '>=');
600 $legacy_addon_active = is_plugin_active('wpfunnels-pro-integrations/wpfunnels-pro-integrations.php');
601
602 if ( $integrations_in_pro || ! $legacy_addon_active ) {
603 $subnodes[] = [
604 'id' => 'wpfunnels-integrations',
605 'title' => __('Integrations', 'wpfnl'),
606 'href' => admin_url('admin.php?page=' . WPFNL_INTEGRATIONS_MAIN_PAGE_SLUG),
607 ];
608 }
609
610 $subnodes[] = [
611 'id' => 'wpfunnels-templates',
612 'title' => __('Templates', 'wpfnl'),
613 'href' => admin_url('admin.php?page=' . WPFNL_TEMPLATE_PAGE_SLUG),
614 ];
615
616 $subnodes[] = [
617 'id' => 'wpfunnels-settings',
618 'title' => __('Settings', 'wpfnl'),
619 'href' => admin_url('admin.php?page=' . WPFNL_GLOBAL_SETTINGS_SLUG),
620 ];
621
622 foreach ( $subnodes as $node ) {
623 $wp_admin_bar->add_node( array_merge( $node, ['parent' => 'wpfunnels'] ) );
624 }
625 }
626 }
627