PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
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 / divi-modules / divi-5 / modules / Modules.php

Modules.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at includes/core/widgets/divi-modules/divi-5/modules/Modules.php

142 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Divi 5 module registration orchestrator.
4 *
5 * Loaded once by the DiviModulesV5 Manager. Registers three hooks:
6 *
7 * 1. divi_module_library_modules_dependency_tree (init:0)
8 * — Primary registration path used by Divi 5's module library.
9 *
10 * 2. rest_api_init
11 * — Registers REST routes so the Visual Builder can fetch live previews
12 * even when the dependency-tree hook already fired.
13 *
14 * 3. init:20 (fallback)
15 * — Catches cases where this file is required after init:0 has already
16 * fired (e.g. on certain admin-ajax requests).
17 *
18 * Also registers the D4 → D5 shortcode conversion map so Divi can migrate
19 * existing pages built with the old ET_Builder_Module modules.
20 *
21 * @package WPFunnels\Widgets\DiviModules\D5
22 * @since 2.9.1
23 */
24
25 namespace WPFunnels\Widgets\DiviModules\D5;
26
27 if ( ! defined( 'ABSPATH' ) ) {
28 die( 'Direct access forbidden.' );
29 }
30
31 if ( ! defined( 'WPFNL_DIVI5_MODULES_LOADED' ) ) {
32
33 require_once __DIR__ . '/ModuleRegistry.php';
34
35 // ── Primary: Divi 5 dependency tree (fires at init priority 0) ──────────
36 add_action(
37 'divi_module_library_modules_dependency_tree',
38 static function ( $dependency_tree ) {
39 if ( ! is_object( $dependency_tree ) ) {
40 return;
41 }
42 ModuleRegistry::register_modules( $dependency_tree );
43 },
44 10,
45 1
46 );
47
48 // ── REST API: register routes independently of the dependency tree ───────
49 // The dependency tree hook only fires during Divi page rendering.
50 // REST requests to /wp-json/wpfnl/v1/* need routes registered here.
51 add_action(
52 'rest_api_init',
53 static function () {
54 if ( ! interface_exists( 'ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface' ) ) {
55 return;
56 }
57 ModuleRegistry::register_rest_routes();
58 }
59 );
60
61 // ── Fallback: if this file was loaded after init:0 already fired ─────────
62 add_action(
63 'init',
64 static function () {
65 static $done = false;
66 if ( $done ) {
67 return;
68 }
69 // Use the same detection logic as is_divi5_active()
70 $is_divi5 = false;
71 if ( function_exists( 'et_builder_d5_enabled' ) ) {
72 $is_divi5 = et_builder_d5_enabled();
73 } elseif ( interface_exists( 'ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface' ) ) {
74 $is_divi5 = true;
75 }
76
77 if ( ! $is_divi5 ) {
78 return;
79 }
80 ModuleRegistry::register_modules( null );
81 $done = true;
82 },
83 20
84 );
85
86 // ── D4 → D5 frontend shortcode compatibility ─────────────────────────────
87 // Imported templates built with Divi 4 still store `[wpfnl_*]` shortcodes.
88 // Register frontend handlers so they render under Divi 5 instead of printing
89 // the raw shortcode as plain text. Hooked on `wp` so step context is ready.
90 require_once __DIR__ . '/../compat/D4ShortcodeCompat.php';
91 add_action(
92 'wp',
93 static function () {
94 \WPFunnels\Widgets\DiviModules\D5\Compat\D4ShortcodeCompat::register();
95 }
96 );
97
98 // ── D4 → D5 shortcode conversion map ────────────────────────────────────
99 add_filter(
100 'divi.moduleLibrary.conversion.moduleConversionOutline',
101 static function ( $outline ) {
102 $outline['wpfnl_checkout'] = 'wpfnl/checkout';
103 $outline['wpfnl_optin'] = 'wpfnl/opt-in';
104 $outline['wpfnl_next_step_button'] = 'wpfnl/next-step-button';
105 $outline['wpfnl_order_details'] = 'wpfnl/order-details';
106 $outline['wpfnl_offer_button'] = 'wpfnl/offer-button';
107 $outline['wpfnl_lms_checkout'] = 'wpfnl/lms-checkout';
108 $outline['wpfnl_lms_order_details'] = 'wpfnl/lms-order-details';
109 return $outline;
110 }
111 );
112
113 // ── Prevent D4 shortcode content from being corrupted when Divi 5 ────────
114 // is active and the post is saved via the Gutenberg editor.
115 add_filter(
116 'wp_insert_post_data',
117 static function ( $data, $postarr ) {
118 if ( empty( $data['post_content'] ) ) {
119 return $data;
120 }
121
122 $new_content = $data['post_content'];
123 $has_d5_wrap = false !== strpos( $new_content, '<!-- wp:divi/placeholder' );
124 $has_d4_sc = false !== strpos( $new_content, '[et_pb_' );
125
126 if ( $has_d5_wrap && $has_d4_sc ) {
127 // Restore original DB content to preserve the D4 shortcode layout
128 $original = get_post_field( 'post_content', $postarr['ID'] ?? 0 );
129 if ( ! empty( $original ) ) {
130 $data['post_content'] = $original;
131 }
132 }
133
134 return $data;
135 },
136 10,
137 2
138 );
139
140 define( 'WPFNL_DIVI5_MODULES_LOADED', true );
141 }
142