← All changes
|
includes/widget-load/bricks/class-wdkit-bricks-files-load.php
+4
-55
2.6.2
→
2.7.0
View file →
| @@ -66,66 +66,15 @@ | ||
| 66 | 66 | * |
| 67 | 67 | * @since 1.0.1 |
| 68 | 68 | */ |
| 69 | 69 | public function wdkit_init() { |
| 70 | - $dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/bricks/'; | |
| 71 | - | |
| 72 | - if ( ! is_dir( $dir ) ) { | |
| 70 | + if ( ! defined( 'WDKIT_BUILDER_PATH' ) || ! function_exists( 'wdesignkit_get_widget_registry' ) || ! class_exists( 'Bricks\Elements' ) ) { | |
| 73 | 71 | return false; |
| 74 | 72 | } |
| 75 | 73 | |
| 76 | - $list = ! empty( $dir ) ? scandir( $dir ) : array(); | |
| 77 | - if ( empty( $list ) || count( $list ) <= 2 ) { | |
| 78 | - return false; | |
| 79 | - } | |
| 80 | - | |
| 81 | - $get_db_widget = get_option( 'wkit_deactivate_widgets', [] ); | |
| 82 | - $server_w_unique = array_column($get_db_widget, 'w_unique'); | |
| 83 | - | |
| 84 | - foreach ( $list as $key => $value ) { | |
| 85 | - if ( in_array( $value, array( '..', '.' ), true ) ) { | |
| 86 | - continue; | |
| 87 | - } | |
| 88 | - | |
| 89 | - if (! is_dir( trailingslashit( $dir ) . $value ) ){ | |
| 90 | - continue; | |
| 91 | - } | |
| 92 | - | |
| 93 | - if ( ! strpos( $value, '.' ) ) { | |
| 94 | - $sub_dir = scandir( trailingslashit( $dir ) . $value ); | |
| 95 | - | |
| 96 | - foreach ( $sub_dir as $sub_dir_value ) { | |
| 97 | - if ( in_array( $sub_dir_value, array( '..', '.' ), true ) ) { | |
| 98 | - continue; | |
| 99 | - } | |
| 100 | - | |
| 101 | - $file = new SplFileInfo( $sub_dir_value ); | |
| 102 | - $check_ext = $file->getExtension(); | |
| 103 | - $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); | |
| 104 | - | |
| 105 | - if ( 'php' === $ext ) { | |
| 106 | - $json_file = str_replace( '.php', '.json', $sub_dir_value ); | |
| 107 | - $str_replace = str_replace( '.php', '', $sub_dir_value ); | |
| 108 | - $str_replace = str_replace( '-', '_', $str_replace ); | |
| 109 | - | |
| 110 | - $json_path = trailingslashit( WDKIT_BUILDER_PATH ) . "bricks/{$value}/{$json_file}"; | |
| 111 | - $json_data = wp_json_file_decode( $json_path ); | |
| 112 | - $w_type = ! empty( $json_data->widget_data->widgetdata->publish_type ) ? $json_data->widget_data->widgetdata->publish_type : ''; | |
| 113 | - $widget_id = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? $json_data->widget_data->widgetdata->widget_id : ''; | |
| 114 | - | |
| 115 | - if ( ! empty( $w_type ) && 'Publish' === $w_type ) { | |
| 116 | - | |
| 117 | - if( ! in_array( $widget_id , $server_w_unique ) ){ | |
| 118 | - | |
| 119 | - $file = trailingslashit( WDKIT_BUILDER_PATH ) . "/bricks/{$value}/{$sub_dir_value}"; | |
| 120 | - | |
| 121 | - if ( class_exists( 'Bricks\Elements' ) ) { | |
| 122 | - Bricks\Elements::register_element( $file ); | |
| 123 | - } | |
| 124 | - } | |
| 125 | - } | |
| 126 | - } | |
| 127 | - } | |
| 74 | + foreach ( wdesignkit_get_widget_registry( 'bricks' ) as $entry ) { | |
| 75 | + if ( file_exists( $entry['file'] ) ) { | |
| 76 | + Bricks\Elements::register_element( $entry['file'] ); | |
| 128 | 77 | } |
| 129 | 78 | } |
| 130 | 79 | } |
| 131 | 80 | |