PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.2
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.2
3.13.4 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 All 262 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.12.2, at includes/core/widgets/divi-modules/divi-5/modules/Modules.php

130 lines 3.9 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 shortcode conversion map ────────────────────────────────────
87 add_filter(
88 'divi.moduleLibrary.conversion.moduleConversionOutline',
89 static function ( $outline ) {
90 $outline['wpfnl_checkout'] = 'wpfnl/checkout';
91 $outline['wpfnl_optin'] = 'wpfnl/opt-in';
92 $outline['wpfnl_next_step_button'] = 'wpfnl/next-step-button';
93 $outline['wpfnl_order_details'] = 'wpfnl/order-details';
94 $outline['wpfnl_offer_button'] = 'wpfnl/offer-button';
95 $outline['wpfnl_lms_checkout'] = 'wpfnl/lms-checkout';
96 $outline['wpfnl_lms_order_details'] = 'wpfnl/lms-order-details';
97 return $outline;
98 }
99 );
100
101 // ── Prevent D4 shortcode content from being corrupted when Divi 5 ────────
102 // is active and the post is saved via the Gutenberg editor.
103 add_filter(
104 'wp_insert_post_data',
105 static function ( $data, $postarr ) {
106 if ( empty( $data['post_content'] ) ) {
107 return $data;
108 }
109
110 $new_content = $data['post_content'];
111 $has_d5_wrap = false !== strpos( $new_content, '<!-- wp:divi/placeholder' );
112 $has_d4_sc = false !== strpos( $new_content, '[et_pb_' );
113
114 if ( $has_d5_wrap && $has_d4_sc ) {
115 // Restore original DB content to preserve the D4 shortcode layout
116 $original = get_post_field( 'post_content', $postarr['ID'] ?? 0 );
117 if ( ! empty( $original ) ) {
118 $data['post_content'] = $original;
119 }
120 }
121
122 return $data;
123 },
124 10,
125 2
126 );
127
128 define( 'WPFNL_DIVI5_MODULES_LOADED', true );
129 }
130