| 1 |
<?php |
| 2 |
/** |
| 3 |
* Exit if accessed directly. |
| 4 |
* |
| 5 |
* @link https://posimyth.com/ |
| 6 |
* @since 1.0.1 |
| 7 |
* |
| 8 |
* @package Wdesignkit |
| 9 |
* @subpackage Wdesignkit/includes/bricks |
| 10 |
* */ |
| 11 |
|
| 12 |
/** |
| 13 |
* Exit if accessed directly. |
| 14 |
*/ |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
if ( ! class_exists( 'Wdkit_Bricks_Files_Load' ) ) { |
| 20 |
|
| 21 |
/** |
| 22 |
* This class used for only bricks widget load |
| 23 |
* |
| 24 |
* @since 1.0.1 |
| 25 |
*/ |
| 26 |
class Wdkit_Bricks_Files_Load { |
| 27 |
|
| 28 |
/** |
| 29 |
* Instance |
| 30 |
* |
| 31 |
* @since 1.0.1 |
| 32 |
* @var \Bricks\Plugin The single instance of the class. |
| 33 |
*/ |
| 34 |
private static $instance = null; |
| 35 |
|
| 36 |
/** |
| 37 |
* Instance |
| 38 |
* |
| 39 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 40 |
* |
| 41 |
* @since 1.0.1 |
| 42 |
* @return \Bricks\Plugin An instance of the class. |
| 43 |
*/ |
| 44 |
public static function instance() { |
| 45 |
if ( is_null( self::$instance ) ) { |
| 46 |
self::$instance = new self(); |
| 47 |
} |
| 48 |
return self::$instance; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Perform some compatibility checks to make sure basic requirements are meet. |
| 53 |
* |
| 54 |
* @since 1.0.1 |
| 55 |
*/ |
| 56 |
public function __construct() { |
| 57 |
add_action( 'init', array( $this, 'wdkit_init' ), 99 ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Initialize |
| 62 |
* |
| 63 |
* Load the addons functionality only after bricks is initialized. |
| 64 |
* |
| 65 |
* Fired by `bricks/init` action hook. |
| 66 |
* |
| 67 |
* @since 1.0.1 |
| 68 |
*/ |
| 69 |
public function wdkit_init() { |
| 70 |
$dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/bricks/'; |
| 71 |
|
| 72 |
if ( ! is_dir( $dir ) ) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
$list = ! empty( $dir ) ? scandir( $dir ) : array(); |
| 77 |
if ( empty( $list ) || count( $list ) <= 2 ) { |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
foreach ( $list as $key => $value ) { |
| 82 |
if ( in_array( $value, array( '..', '.' ), true ) ) { |
| 83 |
continue; |
| 84 |
} |
| 85 |
|
| 86 |
if ( ! strpos( $value, '.' ) ) { |
| 87 |
$sub_dir = scandir( trailingslashit( $dir ) . $value ); |
| 88 |
|
| 89 |
foreach ( $sub_dir as $sub_dir_value ) { |
| 90 |
if ( in_array( $sub_dir_value, array( '..', '.' ), true ) ) { |
| 91 |
continue; |
| 92 |
} |
| 93 |
|
| 94 |
$file = new SplFileInfo( $sub_dir_value ); |
| 95 |
$check_ext = $file->getExtension(); |
| 96 |
$ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 97 |
|
| 98 |
if ( 'php' === $ext ) { |
| 99 |
$json_file = str_replace( '.php', '.json', $sub_dir_value ); |
| 100 |
$str_replace = str_replace( '.php', '', $sub_dir_value ); |
| 101 |
$str_replace = str_replace( '-', '_', $str_replace ); |
| 102 |
|
| 103 |
$json_path = trailingslashit( WDKIT_BUILDER_PATH ) . "bricks/{$value}/{$json_file}"; |
| 104 |
$json_data = wp_json_file_decode( $json_path ); |
| 105 |
$w_type = ! empty( $json_data->widget_data->widgetdata->publish_type ) ? $json_data->widget_data->widgetdata->publish_type : ''; |
| 106 |
|
| 107 |
if ( ! empty( $w_type ) && 'Publish' === $w_type ) { |
| 108 |
|
| 109 |
$file = trailingslashit( WDKIT_BUILDER_PATH ) . "/bricks/{$value}/{$sub_dir_value}"; |
| 110 |
|
| 111 |
if ( class_exists( 'Bricks\Elements' ) ) { |
| 112 |
Bricks\Elements::register_element( $file ); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
Wdkit_Bricks_Files_Load::instance(); |
| 124 |
} |
| 125 |
|