| 1 |
<?php |
| 2 |
/** |
| 3 |
* Exit if accessed directly. |
| 4 |
* |
| 5 |
* @link https://posimyth.com/ |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Wdesignkit |
| 9 |
* @subpackage Wdesignkit/includes/elementor |
| 10 |
* */ |
| 11 |
|
| 12 |
/** |
| 13 |
* Exit if accessed directly. |
| 14 |
* */ |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
if ( ! class_exists( 'Wdkit_Elementor_Files_Load' ) ) { |
| 20 |
|
| 21 |
/** |
| 22 |
* This class used for only elementor widget load |
| 23 |
* |
| 24 |
* @since 1.0.0 |
| 25 |
*/ |
| 26 |
class Wdkit_Elementor_Files_Load { |
| 27 |
/** |
| 28 |
* Instance |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @access private |
| 32 |
* @static |
| 33 |
* @var \Elementor_Test_Addon\Plugin The single instance of the class. |
| 34 |
*/ |
| 35 |
private static $instance = null; |
| 36 |
|
| 37 |
/** |
| 38 |
* Instance |
| 39 |
* |
| 40 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* @access public |
| 44 |
* @static |
| 45 |
* @return \Elementor_Test_Addon\Plugin An instance of the class. |
| 46 |
*/ |
| 47 |
public static function instance() { |
| 48 |
if ( is_null( self::$instance ) ) { |
| 49 |
self::$instance = new self(); |
| 50 |
} |
| 51 |
|
| 52 |
return self::$instance; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Constructor |
| 57 |
* |
| 58 |
* Perform some compatibility checks to make sure basic requirements are meet. |
| 59 |
* If all compatibility checks pass, initialize the functionality. |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* @access public |
| 63 |
*/ |
| 64 |
public function __construct() { |
| 65 |
add_action( 'elementor/init', array( $this, 'wdkit_init' ) ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Initialize |
| 70 |
* |
| 71 |
* Load the addons functionality only after Elementor is initialized. |
| 72 |
* |
| 73 |
* Fired by `elementor/init` action hook. |
| 74 |
* |
| 75 |
* @since 1.0.0 |
| 76 |
* @access public |
| 77 |
*/ |
| 78 |
public function wdkit_init() { |
| 79 |
require_once WDKIT_INCLUDES . 'widget-load/elementor/wb-controller.php'; |
| 80 |
|
| 81 |
$this->wdkit_register_categories(); |
| 82 |
add_action( 'elementor/widgets/register', array( $this, 'wdkit_register_widgets' ) ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* |
| 87 |
* Add elementor widgets list |
| 88 |
* |
| 89 |
* @since 1.0.0 |
| 90 |
* |
| 91 |
* @param string $widgets_manager elementor widget structure. |
| 92 |
*/ |
| 93 |
public function wdkit_register_widgets( $widgets_manager ) { |
| 94 |
$dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/elementor/'; |
| 95 |
|
| 96 |
if ( ! is_dir( $dir ) ) { |
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 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 ) ) { |
| 107 |
continue; |
| 108 |
} |
| 109 |
|
| 110 |
if ( ! strpos( $value, '.' ) ) { |
| 111 |
$sub_dir = scandir( trailingslashit( $dir ) . $value ); |
| 112 |
|
| 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 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* |
| 146 |
* Add elementor categories list |
| 147 |
* |
| 148 |
* @since 1.0.0 |
| 149 |
*/ |
| 150 |
public function wdkit_register_categories() { |
| 151 |
$elementor = \Elementor\Plugin::$instance; |
| 152 |
|
| 153 |
$category_list = get_option( 'wkit_builder' ); |
| 154 |
|
| 155 |
if ( ! empty( $category_list ) ) { |
| 156 |
foreach ( $category_list as $value ) { |
| 157 |
$elementor->elements_manager->add_category( |
| 158 |
$value, |
| 159 |
array( |
| 160 |
'title' => esc_html( $value ), |
| 161 |
'icon' => 'fa fa-plug', |
| 162 |
) |
| 163 |
); |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
Wdkit_Elementor_Files_Load::instance(); |
| 170 |
} |
| 171 |
|