PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.7.1
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.7.1
2.7.1 2.7.0 2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 All 130 releases
wdesignkit / includes / widget-load / gutenberg / class-wdkit-gutenberg-files-load.php

class-wdkit-gutenberg-files-load.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.7.1, at includes/widget-load/gutenberg/class-wdkit-gutenberg-files-load.php

131 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Exit if accessed directly.
4 *
5 * @link https://posimyth.com/
6 * @since 1.0.2
7 *
8 * @package Wdesignkit
9 * @subpackage Wdesignkit/includes/gutenberg
10 * */
11
12 /**
13 * Exit if accessed directly.
14 */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'Wdkit_Gutenberg_Files_Load' ) ) {
20
21 /**
22 * This class used for only gutenberg widget load
23 *
24 * @since 1.0.2
25 */
26 class Wdkit_Gutenberg_Files_Load {
27
28 /**
29 * Instance
30 *
31 * @since 1.0.2
32 * @var 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.2
42 * @return 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.2
55 */
56 public function __construct() {
57 add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) );
58 $this->wdkit_register_gutenberg_widgets();
59 }
60
61 /**
62 * Load Gutenburg Builder js and css for controller.
63 *
64 * @since 1.0.2
65 */
66 public function editor_assets() {
67
68 $wp_localize_tpgb = array(
69 'category' => 'tpgb',
70 'admin_url' => esc_url( admin_url() ),
71 'home_url' => home_url(),
72 'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
73 );
74
75 global $pagenow;
76 $scripts_dep = array( 'wp-blocks', 'wp-i18n', 'wp-plugins', 'wp-element', 'wp-components', 'wp-api-fetch', 'media-upload', 'media-editor' );
77 if ( 'widgets.php' !== $pagenow && 'customize.php' !== $pagenow ) {
78 $scripts_dep = array_merge( $scripts_dep, array( 'wp-editor', 'wp-edit-post' ) );
79 wp_enqueue_script( 'wkit-editor-block-pmgc', WDKIT_URL . '/assets/js/main/gutenberg/wkit_g_pmgc.js', $scripts_dep, WDKIT_VERSION, false );
80 wp_localize_script( 'wkit-editor-block-pmgc', 'wdkit_blocks_load', $wp_localize_tpgb );
81 }
82 }
83
84 /**
85 * Here is Register Gutenberg Widgets
86 *
87 * @since 1.0.2
88 */
89 public function wdkit_register_gutenberg_widgets() {
90 if ( ! defined( 'WDKIT_BUILDER_PATH' ) || ! function_exists( 'wdesignkit_get_widget_registry' ) ) {
91 return false;
92 }
93
94 foreach ( wdesignkit_get_widget_registry( 'gutenberg' ) as $entry ) {
95 if ( file_exists( $entry['file'] ) ) {
96 include $entry['file'];
97 }
98 }
99 }
100 }
101
102 add_filter( 'block_categories_all', 'wdkit_register_block_category', 9999992, 1 );
103
104 /**
105 * Gutenberg block category for The Plus Addon.
106 *
107 * @since 1.0.2
108 *
109 * @param array $categories Block categories.
110 */
111 function wdkit_register_block_category( $categories ) {
112 $category_list = get_option( 'wkit_builder', array() );
113 $new_categories = array();
114
115 if ( empty( $category_list ) || ! is_array( $category_list ) ) {
116 return $categories;
117 }
118
119 foreach ( $category_list as $value ) {
120 $new_categories[] = array(
121 'slug' => $value,
122 'title' => esc_html( $value ),
123 );
124 }
125
126 return array_merge( $new_categories, $categories );
127 }
128
129 Wdkit_Gutenberg_Files_Load::instance();
130 }
131