PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.1
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 / widgets / diviModulesV5 / class-manager.php

class-manager.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.1, at includes/core/widgets/diviModulesV5/class-manager.php

158 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Divi 5 Widgets Manager entry point.
4 *
5 * Loaded by Wpfnl_Widgets_Manager when Divi 5 is detected.
6 * Mirrors the diviModules Manager interface so the widget system can
7 * instantiate it via the same naming convention.
8 *
9 * @package WPFunnels\Widgets\DiviModulesV5
10 * @since 2.9.1
11 */
12
13 namespace WPFunnels\Widgets\DiviModulesV5;
14
15 final class Manager {
16
17 private static $_instance = null;
18
19 public static function instance() {
20 if ( is_null( self::$_instance ) ) {
21 self::$_instance = new self();
22 }
23 return self::$_instance;
24 }
25
26 /** @var string Path to the divi-5 modules directory */
27 private string $d5_dir;
28
29 public function __construct() {
30 $this->d5_dir = plugin_dir_path( __FILE__ )
31 . '../divi-modules/divi-5/';
32
33 $this->init();
34 }
35
36 private function init(): void {
37 $modules_file = $this->d5_dir . 'modules/Modules.php';
38 if ( file_exists( $modules_file ) ) {
39 require_once $modules_file;
40 }
41
42 $this->enqueue_vb_bundle();
43 }
44
45 /**
46 * Enqueue the Visual Builder JS bundle when the Divi 5 VB is active.
47 */
48 private function enqueue_vb_bundle(): void {
49 // Fires inside PackageBuildManager::enqueue_scripts() — app-window only,
50 // before divi-module-library is queued, so our addAction listener is
51 // registered before Divi fires divi.moduleLibrary.registerModuleLibraryStore.after.
52 add_action( 'divi_visual_builder_assets_before_enqueue_app_window_scripts', function () {
53 $build_dir = $this->d5_dir . 'visual-builder/build/';
54 $build_url = plugins_url(
55 'includes/core/widgets/divi-modules/divi-5/visual-builder/build/',
56 \WPFNL_FILE
57 );
58
59 $js_file = $build_dir . 'wpfnl-divi5-vb.js';
60 if ( ! file_exists( $js_file ) ) {
61 return;
62 }
63
64 wp_enqueue_script(
65 'wpfnl-divi5-vb',
66 $build_url . 'wpfnl-divi5-vb.js',
67 [ 'divi-vendor-react', 'divi-vendor-wp-hooks', 'divi-module', 'divi-rest' ],
68 \WPFNL_VERSION . '.' . (string) filemtime( $js_file ),
69 true
70 );
71
72 // Load WPFunnels public CSS in the VB canvas so checkout/optin layouts render correctly.
73 $public_css = \WPFNL_DIR_URL . 'public/assets/css/wpfnl-public.css';
74 wp_enqueue_style( 'wpfnl-public', $public_css, [], \WPFNL_VERSION );
75
76 wp_localize_script(
77 'wpfnl-divi5-vb',
78 'wpfnlDiviVBData',
79 [
80 'postId' => get_the_ID(),
81 'restUrl' => rest_url( 'wpfnl/v1' ),
82 'nonce' => wp_create_nonce( 'wp_rest' ),
83 'funnels' => $this->get_funnel_options(),
84 'mailmintForms' => $this->get_mailmint_forms_options(),
85 'mmEnabled' => $this->is_mailmint_enabled(),
86 'mmLists' => $this->get_mm_lists_options(),
87 'mmTags' => $this->get_mm_tags_options(),
88 ]
89 );
90 } );
91 }
92
93 /**
94 * Mail Mint forms map for the OptIn module's "Mail Mint Form" select.
95 *
96 * @return array<string,string>
97 */
98 private function get_mailmint_forms_options(): array {
99 $options = [ '' => __( 'Select a form', 'wpfnl' ) ];
100 if ( class_exists( '\\WPFunnels\\Widgets\\Wpfnl_Widgets_Manager' ) ) {
101 $forms = \WPFunnels\Widgets\Wpfnl_Widgets_Manager::get_mailmint_forms();
102 if ( is_array( $forms ) ) {
103 foreach ( $forms as $id => $title ) {
104 $options[ (string) $id ] = (string) $title;
105 }
106 }
107 }
108 return $options;
109 }
110
111 private function is_mailmint_enabled(): bool {
112 return class_exists( '\\WPFunnels\\Integrations\\Helper' )
113 && \WPFunnels\Integrations\Helper::maybe_enabled();
114 }
115
116 /**
117 * @return array<string,string>
118 */
119 private function get_mm_lists_options(): array {
120 if ( ! $this->is_mailmint_enabled() ) {
121 return [ '' => __( 'Select list', 'wpfnl' ) ];
122 }
123 $lists = \WPFunnels\Integrations\Helper::get_lists();
124 return is_array( $lists ) ? array_map( 'strval', $lists ) : [ '' => __( 'Select list', 'wpfnl' ) ];
125 }
126
127 /**
128 * @return array<string,string>
129 */
130 private function get_mm_tags_options(): array {
131 if ( ! $this->is_mailmint_enabled() ) {
132 return [ '' => __( 'Select tag', 'wpfnl' ) ];
133 }
134 $tags = \WPFunnels\Integrations\Helper::get_tags();
135 return is_array( $tags ) ? array_map( 'strval', $tags ) : [ '' => __( 'Select tag', 'wpfnl' ) ];
136 }
137
138 /**
139 * Build the funnel options map used by the Next Step Button "Another Funnel"
140 * dropdown in the Divi 5 Visual Builder.
141 *
142 * @return array<string,string> URL => Title (first entry is the empty placeholder).
143 */
144 private function get_funnel_options(): array {
145 if ( ! class_exists( '\\WPFunnels\\Wpfnl_functions' ) ) {
146 return [ '' => __( 'Select funnel', 'wpfnl' ) ];
147 }
148 $raw = \WPFunnels\Wpfnl_functions::get_funnel_list();
149 $options = [];
150 foreach ( $raw as $url => $title ) {
151 $options[ trim( (string) $url ) ] = (string) $title;
152 }
153 if ( ! isset( $options[''] ) ) {
154 $options = array_merge( [ '' => __( 'Select funnel', 'wpfnl' ) ], $options );
155 }
156 return $options;
157 }
158 }