| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is used to load widget builder files and the builder. |
| 4 |
* |
| 5 |
* @link https://posimyth.com/ |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Wdesignkit |
| 9 |
*/ |
| 10 |
|
| 11 |
/** |
| 12 |
* Exit if accessed directly. |
| 13 |
* */ |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
use wdkit\Wdkit_Wdesignkit; |
| 19 |
|
| 20 |
if ( ! class_exists( 'Wdkit_Widget_Load_Files' ) ) { |
| 21 |
|
| 22 |
/** |
| 23 |
* This class used for widget load |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
*/ |
| 27 |
class Wdkit_Widget_Load_Files { |
| 28 |
|
| 29 |
/** |
| 30 |
* |
| 31 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 32 |
* |
| 33 |
* @var instance |
| 34 |
* @since 1.0.0 |
| 35 |
*/ |
| 36 |
private static $instance = null; |
| 37 |
|
| 38 |
/** |
| 39 |
* This instance is used to load class |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
*/ |
| 43 |
public static function instance() { |
| 44 |
|
| 45 |
if ( is_null( self::$instance ) ) { |
| 46 |
self::$instance = new self(); |
| 47 |
} |
| 48 |
|
| 49 |
return self::$instance; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* This constructor is used to load builder files. |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
*/ |
| 57 |
public function __construct() { |
| 58 |
|
| 59 |
$this->wdkit_default_category(); |
| 60 |
$this->wdkit_db_widgetlist(); |
| 61 |
|
| 62 |
$this->wdkit_elementor_load(); |
| 63 |
$this->wdkit_gutenberg_load(); |
| 64 |
$this->wdkit_bricks_load(); |
| 65 |
$this->wdkit_gutenberg_core_load(); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* This function is called to load Elementor files, categories, and everything needed for WDesignKit to build with Elementor. |
| 70 |
* |
| 71 |
* @since 1.0.0 |
| 72 |
*/ |
| 73 |
public function wdkit_elementor_load() { |
| 74 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor', 'widget' ) ) { |
| 75 |
require_once WDKIT_INCLUDES . 'widget-load/elementor/class-wdkit-elementor-files-load.php'; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* This function is called to load Gutenberg files, categories, and everything needed for WDesignKit to build with Gutenberg. |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
*/ |
| 84 |
public function wdkit_gutenberg_load() { |
| 85 |
if ( ! Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) { |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
// Frontend: always load so register_block_type() runs and the style/script |
| 90 |
// handles attached to each widget (wp_register_style, render_callback) are |
| 91 |
// enqueued correctly on public pages. |
| 92 |
if ( ! is_admin() ) { |
| 93 |
require_once WDKIT_INCLUDES . 'widget-load/gutenberg/class-wdkit-gutenberg-files-load.php'; |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
// Skip Elementor editor — $_GET['action'] is set before plugins_loaded |
| 98 |
// and is the most reliable way to detect the Elementor edit screen. |
| 99 |
if ( isset( $_GET['action'] ) && 'elementor' === sanitize_key( wp_unslash( $_GET['action'] ) ) ) { |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
// Admin: whitelist pages where the block editor can be active. |
| 104 |
// $pagenow is set by WordPress before plugins_loaded — no timing issues, |
| 105 |
// no dependency on post-type registration. Covers all CPTs including |
| 106 |
// ACF-registered ones. Bricks and other builders are excluded automatically |
| 107 |
// because they do not use these pages. |
| 108 |
global $pagenow; |
| 109 |
$block_editor_pages = array( 'post.php', 'post-new.php', 'widgets.php', 'customize.php' ); |
| 110 |
|
| 111 |
if ( in_array( $pagenow, $block_editor_pages, true ) ) { |
| 112 |
require_once WDKIT_INCLUDES . 'widget-load/gutenberg/class-wdkit-gutenberg-files-load.php'; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* This function is called to load Gutenberg Core files, categories, and everything needed for WDesignKit to build with Gutenberg. |
| 118 |
* |
| 119 |
* @since 1.2.5 |
| 120 |
*/ |
| 121 |
public function wdkit_gutenberg_core_load() { |
| 122 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_core', 'widget' ) ) { |
| 123 |
require_once WDKIT_INCLUDES . 'widget-load/gutenberg_core/class-wdkit-gutenberg-core-files-load.php'; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* This function is called to load Bricks files, categories, and everything needed for WDesignKit to build with bricks. |
| 129 |
* |
| 130 |
* @since 1.0.0 |
| 131 |
*/ |
| 132 |
public function wdkit_bricks_load() { |
| 133 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks', 'widget' ) ) { |
| 134 |
require_once WDKIT_INCLUDES . 'widget-load/bricks/class-wdkit-bricks-files-load.php'; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Set widget Default Category as WDesignKit |
| 140 |
* |
| 141 |
* @since 1.0.0 |
| 142 |
*/ |
| 143 |
public function wdkit_default_category() { |
| 144 |
$category_list = get_option( 'wkit_builder' ); |
| 145 |
|
| 146 |
$final_category = array( 'WDesignKit' ); |
| 147 |
if ( ! empty( $category_list ) && ! in_array( 'WDesignKit', $category_list, true ) ) { |
| 148 |
$final_category = array_merge( $final_category, $category_list ); |
| 149 |
|
| 150 |
update_option( 'wkit_builder', $final_category ); |
| 151 |
} elseif ( ! is_array( $category_list ) && empty( $category_list ) ) { |
| 152 |
do_action( 'wdkit_admin_create_default' ); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Store default widget list |
| 158 |
* |
| 159 |
* @since 1.0.19 |
| 160 |
*/ |
| 161 |
public function wdkit_db_widgetlist(){ |
| 162 |
|
| 163 |
$get_db_widget = get_option( 'wkit_deactivate_widgets', [] ); |
| 164 |
|
| 165 |
if ( empty( $get_db_widget ) ) { |
| 166 |
|
| 167 |
add_option( 'wkit_deactivate_widgets', [], '', 'yes' ); |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
Wdkit_Widget_Load_Files::instance(); |
| 173 |
} |
| 174 |
|