← All changes
|
includes/widget-load/elementor/class-wdkit-elementor-files-load.php
+6
-42
1.0.13
→
2.7.0
View file →
| @@ -39,9 +39,8 @@ | ||
| 39 | 39 | * |
| 40 | 40 | * Ensures only one instance of the class is loaded or can be loaded. |
| 41 | 41 | * |
| 42 | 42 | * @since 1.0.0 |
| 43 | - * @access public | |
| 44 | 43 | * @static |
| 45 | 44 | * @return \Elementor_Test_Addon\Plugin An instance of the class. |
| 46 | 45 | */ |
| 47 | 46 | public static function instance() { |
| @@ -58,9 +57,8 @@ | ||
| 58 | 57 | * Perform some compatibility checks to make sure basic requirements are meet. |
| 59 | 58 | * If all compatibility checks pass, initialize the functionality. |
| 60 | 59 | * |
| 61 | 60 | * @since 1.0.0 |
| 62 | - * @access public | |
| 63 | 61 | */ |
| 64 | 62 | public function __construct() { |
| 65 | 63 | add_action( 'elementor/init', array( $this, 'wdkit_init' ) ); |
| 66 | 64 | } |
| @@ -72,9 +70,8 @@ | ||
| 72 | 70 | * |
| 73 | 71 | * Fired by `elementor/init` action hook. |
| 74 | 72 | * |
| 75 | 73 | * @since 1.0.0 |
| 76 | - * @access public | |
| 77 | 74 | */ |
| 78 | 75 | public function wdkit_init() { |
| 79 | 76 | require_once WDKIT_INCLUDES . 'widget-load/elementor/wb-controller.php'; |
| 80 | 77 | |
| @@ -90,54 +87,21 @@ | ||
| 90 | 87 | * |
| 91 | 88 | * @param string $widgets_manager elementor widget structure. |
| 92 | 89 | */ |
| 93 | 90 | public function wdkit_register_widgets( $widgets_manager ) { |
| 94 | - $dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/elementor/'; | |
| 95 | - | |
| 96 | - if ( ! is_dir( $dir ) ) { | |
| 91 | + if ( ! defined( 'WDKIT_BUILDER_PATH' ) || ! function_exists( 'wdesignkit_get_widget_registry' ) ) { | |
| 97 | 92 | return false; |
| 98 | 93 | } |
| 99 | 94 | |
| 100 | - $list = ! empty( $dir ) ? scandir( $dir ) : array(); | |
| 101 | - if ( empty( $list ) || count( $list ) <= 2 ) { | |
| 102 | - return false; | |
| 103 | - } | |
| 104 | - | |
| 105 | - foreach ( $list as $key => $value ) { | |
| 106 | - if ( in_array( $value, array( '..', '.' ), true ) ) { | |
| 95 | + foreach ( wdesignkit_get_widget_registry( 'elementor' ) as $entry ) { | |
| 96 | + if ( ! file_exists( $entry['file'] ) ) { | |
| 107 | 97 | continue; |
| 108 | 98 | } |
| 109 | 99 | |
| 110 | - if ( ! strpos( $value, '.' ) ) { | |
| 111 | - $sub_dir = scandir( trailingslashit( $dir ) . $value ); | |
| 100 | + require_once $entry['file']; | |
| 112 | 101 | |
| 113 | - foreach ( $sub_dir as $sub_dir_value ) { | |
| 114 | - if ( in_array( $sub_dir_value, array( '..', '.' ), true ) ) { | |
| 115 | - continue; | |
| 116 | - } | |
| 117 | - | |
| 118 | - $file = new SplFileInfo( $sub_dir_value ); | |
| 119 | - $check_ext = $file->getExtension(); | |
| 120 | - $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); | |
| 121 | - | |
| 122 | - if ( 'php' === $ext ) { | |
| 123 | - $json_file = str_replace( '.php', '.json', $sub_dir_value ); | |
| 124 | - $str_replace = str_replace( '.php', '', $sub_dir_value ); | |
| 125 | - $str_replace = str_replace( '-', '_', $str_replace ); | |
| 126 | - | |
| 127 | - $json_path = trailingslashit( WDKIT_BUILDER_PATH ) . "elementor/{$value}/{$json_file}"; | |
| 128 | - $json_data = wp_json_file_decode( $json_path ); | |
| 129 | - | |
| 130 | - $w_type = ! empty( $json_data->widget_data->widgetdata->publish_type ) ? $json_data->widget_data->widgetdata->publish_type : ''; | |
| 131 | - | |
| 132 | - if ( ! empty( $w_type ) && 'Publish' === $w_type ) { | |
| 133 | - $class = 'Wdkit_' . sanitize_text_field( $str_replace ); | |
| 134 | - require_once trailingslashit( WDKIT_BUILDER_PATH ) . "/elementor/{$value}/{$sub_dir_value}"; | |
| 135 | - | |
| 136 | - $widgets_manager->register( new $class() ); | |
| 137 | - } | |
| 138 | - } | |
| 139 | - } | |
| 102 | + if ( class_exists( $entry['class'] ) ) { | |
| 103 | + $widgets_manager->register( new $entry['class']() ); | |
| 140 | 104 | } |
| 141 | 105 | } |
| 142 | 106 | } |
| 143 | 107 | |