]> _ Git - physioassist-wordpress.git/blob
3243608636ddcac4d64cd055c77308814daadbd5
[physioassist-wordpress.git] /
1 <?php
2
3 use WPML\PB\Container\Config;
4 use function WPML\Container\make;
5 use function WPML\Container\share;
6
7 class WPML_PB_Loader {
8
9         public function __construct(
10                 SitePress $sitepress,
11                 WPDB $wpdb,
12                 WPML_ST_Settings $st_settings,
13                 $pb_integration = null // Only needed for testing
14         ) {
15                 share( Config::getSharedClasses() );
16
17                 do_action( 'wpml_load_page_builders_integration' );
18
19                 $page_builder_strategies = array();
20
21                 /**
22                  * This filter hook provide the API page builders names that need to be supported.
23                  *
24                  * For each PB name, we will create a dedicated strategy and a proper string package namespace.
25                  *
26                  * It's called in 2 places:
27                  * - `WPML_Page_Builders_Integration` for external plugins
28                  * - `WPML_Gutenberg_Integration` for WordPress Core block editor
29                  *
30                  * @param string[] Required plugin names (e.g. `Beaver Builder`, `Gutenberg`)
31                  */
32                 $required = apply_filters( 'wpml_page_builder_support_required', array() );
33                 foreach ( $required as $plugin ) {
34                         $page_builder_strategies[] = new WPML_PB_API_Hooks_Strategy( $plugin );
35                 }
36
37                 $page_builder_config_import = new WPML_PB_Config_Import_Shortcode( $st_settings );
38                 $page_builder_config_import->add_hooks();
39                 if ( $page_builder_config_import->has_settings() ) {
40                         $strategy = new WPML_PB_Shortcode_Strategy( new WPML_Page_Builder_Settings() );
41                         $strategy->add_shortcodes( $page_builder_config_import->get_settings() );
42                         $page_builder_strategies[] = $strategy;
43
44                         if ( defined( 'WPML_MEDIA_VERSION' ) && $page_builder_config_import->get_media_settings() ) {
45                                 $shortcodes_media_hooks = new WPML_Page_Builders_Media_Hooks(
46                                         new WPML_Page_Builders_Media_Shortcodes_Update_Factory( $page_builder_config_import ),
47                                         'shortcodes'
48                                 );
49                                 $shortcodes_media_hooks->add_hooks();
50                         }
51                 }
52
53                 self::load_hooks( (bool) $page_builder_strategies );
54
55                 if ( $page_builder_strategies ) {
56                         if ( $pb_integration ) {
57                                 $factory = $pb_integration->get_factory();
58                         } else {
59                                 $factory        = make( 'WPML_PB_Factory' );
60                                 $pb_integration = make( 'WPML_PB_Integration' );
61                         }
62                         $pb_integration->add_hooks();
63                         foreach ( $page_builder_strategies as $strategy ) {
64                                 $strategy->set_factory( $factory );
65                                 $pb_integration->add_strategy( $strategy );
66                         }
67                 }
68
69         }
70
71         /**
72          * @param bool $has_page_builder_strategy
73          */
74         private static function load_hooks( $has_page_builder_strategy ) {
75                 $hooks = [
76                         WPML\PB\Compatibility\Toolset\Layouts\HooksFactory::class,
77                 ];
78
79                 if ( $has_page_builder_strategy ) {
80                         $hooks = array_merge(
81                                 $hooks,
82                                 [
83                                         WPML_PB_Handle_Post_Body::class,
84 //                                      WPML\PB\AutoUpdate\Hooks::class, // see wpmlcore-7428
85                                         WPML\PB\Shutdown\Hooks::class,
86                                 ]
87                         );
88                 }
89
90                 make( WPML_Action_Filter_Loader::class )->load( $hooks );
91         }
92 }