PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.3.3
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.3.3
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
← All changes | inc/init.php +321 -466 trunk3.3.3 View file →
@@ -1,536 +1,391 @@
1 1 <?php
2 -
3 -/**
4 - * inc/init.php
5 - * @package Blockspare
6 - */
7 -
2 +//Exit if directly acess
8 3 defined('ABSPATH') or die('No script kiddies please!');
9 4
10 -class Blockspare_Init
11 -{
12 - public function __construct()
5 +if (!class_exists('BlockspareInit')) {
6 + class BlockspareInit
13 7 {
8 + /**
9 + * Member Variable
10 + *
11 + * @var instance
12 + */
13 + private static $instance;
14 14
15 - // 1. Hooks
16 - add_action('init', [$this, 'blockspare_plugin_init']);
17 - add_action('admin_enqueue_scripts', [$this, 'blockspare_enqueue_editor_assets']);
18 - add_action('customize_controls_enqueue_scripts', [$this, 'blockspare_enqueue_customizer_assets']);
19 - add_action('enqueue_block_assets', [$this, 'blockspare_fb_enqueue_frontend_assets']);
15 + /**
16 + * Initiator
17 + */
18 + public static function get_instance()
19 + {
20 + if (!isset(self::$instance)) {
21 + self::$instance = new self();
22 + }
23 + return self::$instance;
24 + }
25 + public function __construct()
26 + {
27 + add_action('init', array($this, 'blockspare_blocks_block_assets'));
28 + add_action('enqueue_block_editor_assets', array($this, 'blockspare_create_block'));
29 + if (version_compare(get_bloginfo('version'), '5.8', '<')) {
30 + add_action('wp_enqueue_scripts', array($this, 'blockspare_load_scripts'));
31 + } else {
32 + add_action('enqueue_block_assets', array($this, 'blockspare_load_scripts'), 1);
33 + }
34 + add_action('plugins_loaded', array($this, 'blockspare_blocks_loader'));
35 + add_action('rest_api_init', array($this, 'blockspare_blocks_register_api_endpoints'));
36 + }
20 37
21 - add_action('wp_enqueue_scripts', [$this, 'blockspare_enqueue_frontend_script']);
22 - add_filter('block_categories_all', [$this, 'blockspare_register_custom_categories'], 10, 2);
23 - add_action('plugins_loaded', [$this, 'blockspare_load_dynamic_blocks']);
24 - add_action('rest_api_init', array($this, 'blockspare_blocks_register_api_endpoints'));
25 - }
38 + public function blockspare_blocks_block_assets()
39 + {
40 + // wp_register_style(
41 + // 'fontawesome',
42 + // plugins_url('assets/fontawesome/css/all.css', dirname(__FILE__)),
43 + // array()
26 44
27 - public function blockspare_plugin_init()
28 - {
29 - $this->blockspare_blocks_register_blocks();
30 - //$this->blockspare_fb_enqueue_frontend_assets();
31 - $this->blockspare_load_load_text_domain();
32 - }
33 - // ══════════════════════════════════════════════════════════════════════════
34 - // Helper Functions
35 - // ══════════════════════════════════════════════════════════════════════════
36 - public static function get_post_types()
37 - {
38 - static $cache = null;
39 - if ($cache !== null) return $cache;
45 + // );
46 + // // Load the compiled styles.
47 + // wp_enqueue_style(
48 + // 'blockspare-frontend-block-style-css',
49 + // plugins_url('dist/style-blocks.css', dirname(__FILE__)),
50 + // array()
51 + // );
40 52
41 - $transient = get_transient('blockspare_post_types');
42 - if ($transient !== false) {
43 - $cache = $transient;
44 - return $cache;
45 - }
46 53
54 + // wp_register_style('slick', BLOCKSPARE_PLUGIN_URL . 'assets/slick/css/slick.css', array(), '', 'all');
55 + // if (is_admin()) {
56 + // wp_enqueue_style('slick');
57 + // }
47 58
48 - $args = ['public' => true, 'show_in_rest' => true];
49 - $post_types = get_post_types($args, 'objects');
59 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/accordion');
60 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/button');
61 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/call-to-action');
62 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/content-box');
63 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/container');
64 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/counter');
65 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/icon-set');
66 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/image-carousel');
67 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/linear-progressbar');
68 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/list');
69 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/logos');
70 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/image-masonry');
71 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/notice-bar');
72 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/price-list');
73 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/pricing-table');
74 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/social-links');
75 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/section-header');
76 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/services');
77 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/image-slider');
78 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/star-ratings');
79 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/testimonial');
80 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/user-profile');
81 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/shape-divider');
82 + register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/empty-section');
50 83
51 - $output = [];
52 - foreach ($post_types as $post_type) {
53 - if ($post_type->name === 'attachment') continue;
54 -
55 - $output[] = [
56 - 'value' => $post_type->name,
57 - 'label' => $post_type->label,
58 - ];
84 + include BLOCKSPARE_PLUGIN_DIR . '/admin/notice-setup.php';
85 + include BLOCKSPARE_PLUGIN_DIR . '/admin/notice-upgrade.php';
59 86 }
60 87
61 - set_transient('blockspare_post_types', $output, HOUR_IN_SECONDS);
62 - $cache = apply_filters('aft_blocks_post_types', $output);
88 + public function blockspare_load_scripts()
89 + {
63 90
64 - return $cache;
65 - }
91 + wp_register_style(
92 + 'fontawesome',
93 + plugins_url('assets/fontawesome/css/all.css', dirname(__FILE__)),
94 + array()
66 95
67 - public static function get_taxonomies()
68 - {
69 - static $cache = null;
70 - if ($cache !== null) return $cache;
96 + );
97 + // Load the compiled styles.
98 + wp_enqueue_style(
99 + 'blockspare-frontend-block-style-css',
100 + plugins_url('dist/style-blocks.css', dirname(__FILE__)),
101 + array()
102 + );
71 103
72 - $transient = get_transient('blockspare_taxonomies');
73 - if ($transient !== false) {
74 - $cache = $transient;
75 - return $cache;
76 - }
104 + wp_enqueue_style(
105 + 'blockspare-frontend-banner-style-css',
106 + plugins_url('dist/style-banner_group.css', dirname(__FILE__)),
107 + array()
108 + );
77 109
78 - $post_types = self::get_post_types();
79 - $output = [];
80 110
81 - foreach ($post_types as $post_type) {
82 - $pt = $post_type['value'];
83 - $taxonomies = get_object_taxonomies($pt, 'objects');
84 -
85 - foreach ($taxonomies as $term_slug => $term) {
86 - if (!$term->public || !$term->show_ui) continue;
87 -
88 - $terms = get_terms([
89 - 'taxonomy' => $term_slug,
90 - 'hide_empty' => false,
91 - ]);
92 -
93 - if (!empty($terms) && !is_wp_error($terms)) {
94 - foreach ($terms as $term_item) {
95 - $output[$pt]['terms'][$term_slug][] = [
96 - 'value' => $term_item->term_id,
97 - 'label' => $term_item->name,
98 - ];
99 - }
100 - }
111 + wp_register_style('slick', BLOCKSPARE_PLUGIN_URL . 'assets/slick/css/slick.css', array(), '', 'all');
112 + if (is_admin()) {
113 + wp_enqueue_style('slick');
101 114 }
102 115
103 - $output[$pt]['taxonomy'] = $taxonomies;
104 - }
105 -
106 - set_transient('blockspare_taxonomies', $output, HOUR_IN_SECONDS);
107 - $cache = apply_filters('aft_blocks_taxonomies', $output);
108 -
109 - return $cache;
110 - }
111 -
112 - // ══════════════════════════════════════════════════════════════════════════
113 - // 1. Register blocks
114 - // ══════════════════════════════════════════════════════════════════════════
115 - public function blockspare_blocks_register_blocks()
116 - {
117 - $blocks = glob(BLOCKSPARE_PLUGIN_DIR . 'build/block/*/block.json');
118 -
119 - if ($blocks) {
120 - foreach ($blocks as $block) {
121 - register_block_type(dirname($block));
116 + wp_enqueue_style('fontawesome');
117 + $min = (SCRIPT_DEBUG == true) ? '' : '.min';
118 + wp_register_script('slick', BLOCKSPARE_PLUGIN_URL . 'assets/slick/js/slick.js', array('jquery'), '', true);
119 + if (has_blocks() || has_block('blockspare/blockspare-carousel') || has_block('blockspare/blockspare-slider') || has_block('blockspare/latest-posts-block-carousel-grid') || has_block('blockspare/blockspare-posts-block-slider')) {
120 + wp_enqueue_script('slick');
121 + wp_enqueue_style('slick');
122 122 }
123 - }
124 123
125 - wp_enqueue_style(
126 - 'blockspare-fontawesome',
127 - BLOCKSPARE_PLUGIN_URL . 'assets/fontawesome/css/all.css',
128 - [],
129 - BLOCKSPARE_VERSION
130 - );
131 - }
124 + wp_register_script('countup', BLOCKSPARE_PLUGIN_URL . 'assets/js/countup/jquery.counterup.min.js', array('waypoint'), true);
125 + wp_enqueue_script('waypoint', BLOCKSPARE_PLUGIN_URL . 'assets/js/countup/waypoints.min.js', array('jquery'), '', true);
132 126
133 - public function blockspare_enqueue_frontend_script()
134 - {
135 - wp_register_style(
136 - 'slick',
137 - BLOCKSPARE_PLUGIN_URL . 'assets/slick/css/slick.min.css',
138 - array(),
139 - BLOCKSPARE_VERSION
140 - );
141 -
142 - wp_register_script(
143 - 'slick',
144 - BLOCKSPARE_PLUGIN_URL . 'assets/slick/js/slick.min.js',
145 - array('jquery'),
146 - BLOCKSPARE_VERSION,
147 - true
148 - );
149 - global $post;
150 -
151 - if ($post && has_blocks($post->post_content)) {
152 - $content = $post->post_content;
153 -
154 - $hasCarousel = has_block('blockspare/blockspare-carousel', $content);
155 - $hasSlider = has_block('blockspare/blockspare-slider', $content);
156 - $hasMasonry = has_block('blockspare/blockspare-masonry', $content);
157 -
158 - if ($hasCarousel || $hasSlider) {
159 - wp_enqueue_style('slick');
160 - wp_enqueue_script('slick');
161 - }
162 - if ($hasMasonry) {
127 + if (has_blocks() || has_block('blockspare/blockspare-masonry')) {
163 128 wp_enqueue_script('jquery-masonry');
164 129 }
165 - }
130 + wp_enqueue_script('blockspare-animation', BLOCKSPARE_PLUGIN_URL . 'dist/block_animation.js', array(), '', true);
131 + wp_enqueue_script('blockspare-script', BLOCKSPARE_PLUGIN_URL . 'dist/block_frontend.js', array('jquery', 'waypoint', 'countup'), '', true);
132 + if (has_blocks() || has_block('blockspare/blockspare-tabs')) {
166 133
167 -
168 -
169 -
170 - wp_enqueue_script(
171 - 'block_animation_script',
172 - BLOCKSPARE_PLUGIN_URL . 'dist/block_animation_script.js',
173 - ['jquery'],
174 - BLOCKSPARE_VERSION,
175 - true
176 - );
177 - wp_register_script(
178 - 'block_pagination_script',
179 - BLOCKSPARE_PLUGIN_URL . 'dist/block_pagination_script.js',
180 - ['jquery'],
181 - BLOCKSPARE_VERSION,
182 - true
183 - );
184 - wp_localize_script('block_pagination_script', 'blocsparePagination', array(
185 - 'ajaxurl' => admin_url('admin-ajax.php'),
186 - 'nonce' => wp_create_nonce('blockspare-load-more-nonce'),
187 - ));
188 - }
189 -
190 - // ══════════════════════════════════════════════════════════════════════════
191 - // 2. Editor-only assets
192 - // ══════════════════════════════════════════════════════════════════════════
193 - public function blockspare_enqueue_editor_assets()
194 - {
195 -
196 - global $pagenow;
197 -
198 - // ✅ Prevent unnecessary loading
199 - if (!in_array($pagenow, ['post.php', 'post-new.php', 'widgets.php'])) {
200 - return;
134 + wp_enqueue_script('blockspare-tabs', BLOCKSPARE_PLUGIN_URL . 'dist/block_tabs.js', array('jquery'), '', true);
135 + }
136 + wp_register_script('blockspare-pagination-js', BLOCKSPARE_PLUGIN_URL . 'dist/block_pagination.js', array(), '', true);
137 + wp_localize_script('blockspare-pagination-js', 'blocsparePagination', array(
138 + 'ajaxurl' => admin_url('admin-ajax.php'),
139 + 'nonce' => wp_create_nonce('blockspare-load-more-nonce'),
140 + ));
201 141 }
202 142
203 - wp_register_script(
204 - 'blockspare-category',
205 - BLOCKSPARE_PLUGIN_URL . 'dist/block_category.js',
206 - [
207 - 'wp-blocks',
208 - 'wp-i18n',
209 - 'wp-element',
210 - 'wp-components',
211 - 'wp-block-editor',
212 - 'wp-api-fetch',
213 - ],
214 - BLOCKSPARE_VERSION,
215 - true
216 - );
143 + public function blockspare_create_block()
144 + {
217 145
218 - global $pagenow;
219 - $loadscripton = ($pagenow === 'widgets.php' || is_customize_preview());
146 + $script_dep_path = BLOCKSPARE_BASE_DIR . 'dist/blocks.asset.php';
147 + $script_info = file_exists($script_dep_path) ? include $script_dep_path : array(
148 + 'dependencies' => array(),
149 + 'version' => BLOCKSPARE_VERSION,
150 + );
151 + if (version_compare(get_bloginfo('version'), '5.8', '<')) {
152 + $script_dep = array_merge($script_info['dependencies'], array(
153 + 'wp-blocks',
154 + 'wp-i18n',
155 + 'wp-element',
156 + 'wp-components',
157 + 'wp-editor',
158 + 'wp-api-fetch',
159 + ));
160 + } else {
161 + $script_dep = $script_info['dependencies'];
162 + }
220 163
221 - wp_add_inline_script(
222 - 'wp-blocks',
223 - 'var blockspare_globals = ' . wp_json_encode($this->blockspare_get_globals()) . ';',
224 - 'before'
225 - );
164 + wp_enqueue_script(
165 + 'blockspare-blocks-block-js', // Handle.
166 + BLOCKSPARE_PLUGIN_URL . 'dist/blocks.js',
167 + $script_dep, // Dependencies, defined above.
168 + $script_info['version'], // AFT_PRICING_TABLE_VERSION.
169 + true
170 + // Enqueue the script in the footer.
171 + );
226 172
227 -
228 - wp_enqueue_script('blockspare-category');
229 -
230 - wp_enqueue_style(
231 - 'blockspare-panel',
232 - BLOCKSPARE_PLUGIN_URL . 'dist/panel.css',
233 - ['wp-edit-blocks'],
234 - BLOCKSPARE_VERSION
235 - );
236 - wp_enqueue_style(
237 - 'blockspare-animation-blocks',
238 - BLOCKSPARE_PLUGIN_URL . 'dist/block_animation.css',
239 - [],
240 - BLOCKSPARE_VERSION
241 - );
242 - if (is_admin()):
243 173 wp_enqueue_script(
244 - 'blockspare-design-btn',
245 - BLOCKSPARE_PLUGIN_URL . 'dist/block_design_btn.js',
246 - array('blockspare-category'),
247 - BLOCKSPARE_VERSION,
174 + 'blockspare-banner-group-js', // Handle.
175 + BLOCKSPARE_PLUGIN_URL . 'dist/banner_group.js',
176 + $script_dep, // Dependencies, defined above.
177 + $script_info['version'], // AFT_PRICING_TABLE_VERSION.
248 178 true
179 + // Enqueue the script in the footer.
249 180 );
250 - endif;
251 181
252 182
253 - wp_localize_script('blockspare-category', 'cbvData', [
254 - 'isLoggedIn' => is_user_logged_in(),
255 - ]);
256 - }
257 183
258 - public function blockspare_enqueue_customizer_assets()
259 - {
260 - global $pagenow;
261 - if (!in_array($pagenow, ['customize.php'])) {
262 - return;
263 - }
264 - // Register globals as a standalone no-file script
265 - wp_register_script(
266 - 'blockspare-globals',
267 - false, // ← no actual JS file
268 - [],
269 - null,
270 - false
271 - );
184 + if (is_admin()):
185 + wp_enqueue_style('fontawesome');
186 + wp_enqueue_style(
187 + 'blockspare-block-edit-style',
188 + BLOCKSPARE_PLUGIN_URL . 'dist/blocks.css',
189 + array('wp-edit-blocks')
190 + );
191 + wp_enqueue_style(
192 + 'blockspare-banner-edit-style',
193 + BLOCKSPARE_PLUGIN_URL . 'dist/banner_group.css',
194 + array('wp-edit-blocks')
195 + );
272 196
273 - wp_add_inline_script(
274 - 'blockspare-globals',
275 - 'var blockspare_globals = ' . wp_json_encode($this->blockspare_get_globals()) . ';'
276 - );
197 + wp_enqueue_script('blockspare-design-btn', BLOCKSPARE_PLUGIN_URL . 'dist/block_design_btn.js', array('blockspare-blocks-block-js'), $script_info['version'], true);
198 + wp_enqueue_script('blockspare-design', BLOCKSPARE_PLUGIN_URL . 'dist/block_design.js', array('blockspare-blocks-block-js'), $script_info['version'], true);
199 + wp_enqueue_style('blockspare-design', BLOCKSPARE_PLUGIN_URL . 'dist/block_design.css', array('blockspare-block-edit-style'));
200 + endif;
277 201
278 - wp_enqueue_script('blockspare-globals');
202 + $blockspare_priview_img_url = BLOCKSPARE_PLUGIN_URL . 'assets/blockspare-placeholder-img.jpg';
203 + $blockspare_food_img_url = BLOCKSPARE_PLUGIN_URL . 'assets/blockspare-placeholder-img-square.jpg';
204 + $blockspare_dashboard_logo = BLOCKSPARE_PLUGIN_URL . 'assets/images/blockspare-logo.png';
205 + $taxonomies = get_categories();
206 + $txnm = array();
279 207
280 - // Also enqueue your category script for the widgets customizer
281 - wp_enqueue_script(
282 - 'blockspare-category',
283 - BLOCKSPARE_PLUGIN_URL . 'dist/block_category.js',
284 - [
285 - 'blockspare-globals', // ← depends on globals, so globals loads first
286 - 'wp-blocks',
287 - 'wp-i18n',
288 - 'wp-element',
289 - 'wp-components',
290 - 'wp-block-editor',
291 - 'wp-api-fetch',
292 - 'wp-plugins',
293 - 'wp-edit-post',
294 - ],
295 - BLOCKSPARE_VERSION,
296 - true
297 - );
208 + foreach ($taxonomies as $type) {
298 209
299 - wp_enqueue_style(
300 - 'blockspare-panel',
301 - BLOCKSPARE_PLUGIN_URL . 'dist/panel.css',
302 - ['wp-edit-blocks'],
303 - BLOCKSPARE_VERSION
304 - );
305 - }
210 + $txnm[] = array(
211 + 'label' => $type->name,
212 + 'value' => $type->term_id,
213 + );
214 + }
306 215
307 - private function blockspare_get_globals(): array
308 - {
309 - $blockspare_priview_img_url = BLOCKSPARE_PLUGIN_URL . 'assets/blockspare-placeholder-img.jpg';
310 - $blockspare_food_img_url = BLOCKSPARE_PLUGIN_URL . 'assets/blockspare-placeholder-img-square.jpg';
311 - $blockspare_promo_img = BLOCKSPARE_PLUGIN_URL . 'assets/banner-promo-1120-wu-1.png';
312 - $date = wp_kses_post(date_i18n(get_option('date_format')));
313 - $date_format = date_i18n(get_option('date_format'), current_time('timestamp'));
314 - $open_design = isset($_GET['blockspare_show_intro']) && $_GET['blockspare_show_intro'] === 'true';
315 - $blockData = '';
216 + $date = wp_kses_post(date_i18n(get_option('date_format')));
217 + $open_design = false;
218 + if (isset($_GET['blockspare_show_intro'])) {
219 + if ($_GET['blockspare_show_intro'] == 'true') {
220 + $open_design = true;
221 + }
222 + }
223 + $date_format = date_i18n(get_option('date_format'), current_time('timestamp'));
316 224
317 - if (isset($_GET['blockspare_create_block'])) {
225 + $blockData = '';
226 + if (isset($_GET['blockspare_create_block'])) {
227 + $blockName = $_GET['blockspare_create_block'];
228 + $blocks_lists = array();
318 229
319 - $blockName = sanitize_text_field($_GET['blockspare_create_block']);
320 - $blockTitle = sanitize_text_field($_GET['post_title']);
230 + $filterdata = apply_filters('blockspare_template_library', $blocks_lists);
321 231
322 - // Get from template library filter
323 - $filterdata = apply_filters('blockspare_template_library', []);
232 + foreach ($filterdata as $block) {
233 + if (isset($block['key']) && $block['key'] === $blockName) {
234 + // Found the block with the desired key, retrieve the content
235 + $blockData = $block['content'];
236 + break; // Stop looping once the desired block is found
237 + }
238 + }
239 + }
324 240
325 - foreach ($filterdata as $block) {
326 - if (isset($block['key']) && $block['key'] === $blockName) {
327 - $blockData = $block['content'];
328 - break;
329 - }
241 + global $pagenow;
242 + $loadscripton = true;
243 + if ($pagenow !== 'widgets.php' && !is_customize_preview()) {
244 + $loadscripton = false;
330 245 }
246 + //$blockspare_current_wp_version = '6.5';
247 + $blockspare_current_wp_version = get_bloginfo('version');
331 248
332 - // Get from bs_templates post type if not found
333 - if (empty($blockData) && ! empty($blockTitle)) {
249 + wp_localize_script(
250 + 'blockspare-blocks-block-js',
251 + 'blockspare_globals',
252 + array(
253 + 'srcUrl' => untrailingslashit(plugins_url('/', BLOCKSPARE_BASE_DIR . '/dist/')),
254 + 'rest_url' => esc_url(rest_url()),
255 + 'img' => $blockspare_priview_img_url,
256 + 'homeUrl' => home_url(),
257 + 'blogUrl' => get_site_url(),
258 + 'menu_img_url' => $blockspare_food_img_url,
259 + 'logo' => $blockspare_dashboard_logo,
260 + 'postTypes' => $this->aft_get_post_types(),
261 + 'taxonomies' => $this->aft_get_taxonomies(),
262 + 'postQueryEndpoint' => 'aft/v1/post-query',
263 + 'config' => '',
264 + 'configuration' => '',
265 + 'settings' => '',
266 + 'bs_date' => $date,
267 + "imagePath" => "https://raw.githubusercontent.com/afthemes/blockspare-demo-data/master/blocks/",
268 + "open_design" => $open_design,
269 + 'date_format ' => $date_format,
270 + 'blockData' => $blockData,
271 + 'template_link' => admin_url('edit.php?post_type=bs_templates'),
272 + 'newTemlateUrl' => admin_url('post-new.php?post_type=bs_templates&blockspare_create_block&blockspare_show_intro=true'),
273 + 'loadscripton' => $loadscripton,
274 + 'wpversion' => (version_compare($blockspare_current_wp_version, '6.6') >= 0) ? 'true' : 'false',
275 + )
276 + );
277 + }
334 278
335 - $templates = get_posts([
336 - 'post_type' => 'bs_templates',
337 - 'post_status' => 'publish',
338 - 'title' => $blockTitle,
339 - 'posts_per_page' => 1,
340 - ]);
279 + public function aft_get_post_types()
280 + {
281 + $args = array(
282 + 'public' => true,
283 + 'show_in_rest' => true,
284 + );
285 + $post_types = get_post_types($args, 'objects');
286 + $output = array();
287 + foreach ($post_types as $post_type) {
341 288
342 - if (! empty($templates)) {
343 - $blockData = $templates[0]->post_content;
289 + if ('attachment' == $post_type->name) {
290 + continue;
344 291 }
292 + $output[] = array(
293 + 'value' => $post_type->name,
294 + 'label' => $post_type->label,
295 + );
345 296 }
297 +
298 + return apply_filters('aft_blocks_post_types', $output);
346 299 }
347 300
348 - $blockspare_current_wp_version = get_bloginfo('version');
349 - $loadscripton = (isset($GLOBALS['pagenow']) && $GLOBALS['pagenow'] === 'widgets.php') || is_customize_preview();
301 + public function aft_get_taxonomies()
302 + {
303 + $post_types = $this->aft_get_post_types();
304 + $output = array();
305 + foreach ($post_types as $key => $post_type) {
306 + $taxonomies = get_object_taxonomies($post_type['value'], 'objects');
307 + $taxs = array();
308 + foreach ($taxonomies as $term_slug => $term) {
309 + if (!$term->public || !$term->show_ui) {
310 + continue;
311 + }
312 + $taxs[$term_slug] = $term;
313 + $terms = get_terms($term_slug);
314 + $term_items = array();
315 + if (!empty($terms)) {
316 + foreach ($terms as $term_key => $term_item) {
317 + $term_items[] = array(
318 + 'value' => $term_item->term_id,
319 + 'label' => $term_item->name,
320 + );
321 + }
322 + $output[$post_type['value']]['terms'][$term_slug] = $term_items;
323 + }
324 + }
325 + $output[$post_type['value']]['taxonomy'] = $taxs;
326 + }
350 327
351 - return [
352 - 'srcUrl' => untrailingslashit(plugins_url('/', BLOCKSPARE_BASE_DIR . '/build/')),
353 - 'rest_url' => esc_url(rest_url()),
354 - 'nonce' => wp_create_nonce('wp_rest'),
355 - 'img' => $blockspare_priview_img_url,
356 - 'menu_img_url' => $blockspare_food_img_url,
357 - 'block_key' => '',
358 - 'homeUrl' => home_url(),
359 - 'blogUrl' => get_site_url(),
360 - 'postTypes' => self::get_post_types(),
361 - 'taxonomies' => self::get_taxonomies(),
362 - 'postQueryEndpoint' => 'aft/v1/post-query',
363 - 'config' => '',
364 - 'configuration' => '',
365 - 'settings' => '',
366 - 'bs_date' => $date,
367 - 'promo_img' => $blockspare_promo_img,
368 - 'imagePath' => 'https:raw.githubusercontent.com/afthemes/blockspare-demo-data/master/blocks/new/',
369 - 'open_design' => $open_design,
370 - 'date_format' => $date_format,
371 - 'blockData' => $blockData,
372 - 'template_link' => admin_url('edit.php?post_type=bs_templates'),
373 - 'newTemlateUrl' => admin_url('post-new.php?post_type=bs_templates&blockspare_create_block&blockspare_show_intro=true'),
374 - 'loadscripton' => $loadscripton,
375 - 'wpversion' => (version_compare($blockspare_current_wp_version, '6.6') >= 0) ? 'true' : 'false',
376 - 'inspector_imgs' => BLOCKSPARE_PLUGIN_URL . 'assets/images',
377 - 'upgradeUrl' => 'https://afthemes.com/blockspare-pro/',
378 - 'isPro' => false,
379 - 'allowedFonts' => $this->blockspare_allow_fonts()
380 - ];
381 - }
382 - public function blockspare_allow_fonts()
383 - {
384 - return ['ABeeZee', 'Abel', 'Lato', 'Oswald'];
385 - }
328 + return apply_filters('aft_blocks_taxonomies', $output);
329 + }
386 330
387 - public function blockspare_fb_enqueue_frontend_assets()
388 - {
389 - wp_enqueue_style(
390 - 'blockspare-fontawesome',
391 - BLOCKSPARE_PLUGIN_URL . 'assets/fontawesome/css/all.css',
392 - [],
393 - BLOCKSPARE_VERSION
394 - );
395 - wp_enqueue_style(
396 - 'blockspare-common-latest-post',
397 - BLOCKSPARE_PLUGIN_URL . 'dist/lates_post_css.css',
398 - [],
399 - BLOCKSPARE_VERSION
400 - );
331 + public function blockspare_blocks_loader()
332 + {
401 333
402 - wp_enqueue_style(
403 - 'blockspare-common-all-blocks',
404 - BLOCKSPARE_PLUGIN_URL . 'dist/common_all_blocks.css',
405 - [],
406 - BLOCKSPARE_VERSION
407 - );
408 - wp_enqueue_style(
409 - 'blockspare-animation-blocks',
410 - BLOCKSPARE_PLUGIN_URL . 'dist/block_animation.css',
411 - [],
412 - BLOCKSPARE_VERSION
413 - );
414 - }
334 + if (PHP_VERSION_ID >= 50600) {
335 + require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/class-image-importer.php';
336 + require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/functions.php';
337 + require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/registry.php';
338 + require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/components.php';
415 339
416 - // ══════════════════════════════════════════════════════════════════════════
417 - // 3. Custom block categories
418 - // ══════════════════════════════════════════════════════════════════════════
419 - public function blockspare_register_custom_categories($categories)
420 - {
421 - $custom = [
422 - [
423 - 'slug' => 'blockspare-post',
424 - 'title' => __('Editorial & Content', 'blockspare'),
340 + /**
341 + * REST API Endpoints for Layouts.
342 + */
343 + require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/endpoints.php';
344 + require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/save-templates.php';
425 345
426 - ],
427 - [
428 - 'slug' => 'blockspare',
429 - 'title' => __('Business & Layout', 'blockspare'),
346 + /**
347 + * Import Pattern
348 + */
430 349
431 - ],
350 + // require_once BLOCKSPARE_PLUGIN_DIR . 'inc/pattern/pattern.php';
351 + }
432 352
433 - ];
353 + //Load Gutenberg Block php Files
354 + include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/date-time/index.php';
355 + include BLOCKSPARE_PLUGIN_DIR . '/inc/other-block/social-sharing/index.php';
356 + include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-grid/index.php';
357 + include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-list/index.php';
434 358
435 - return array_merge($custom, $categories);
436 - }
359 + include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-express-grid/index.php';
360 + include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-express-grid/post-content.php';
437 361
438 - // ══════════════════════════════════════════════════════════════════════════
439 - // 4. Load server-side render files
440 - // ══════════════════════════════════════════════════════════════════════════
441 - public function blockspare_load_dynamic_blocks()
442 - {
443 - $this->load_layout_dependencies();
444 - $this->load_block_includes();
445 - }
362 + include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-carousel-grid/index.php';
363 + include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-slider/index.php';
446 364
447 - private function load_layout_dependencies()
448 - {
449 - if (PHP_VERSION_ID < 50600) {
450 - return;
365 + include BLOCKSPARE_PLUGIN_DIR . '/inc/post-banner/banner-1/index.php';
366 + include BLOCKSPARE_PLUGIN_DIR . '/inc/post-banner/banner-2/index.php';
367 + include BLOCKSPARE_PLUGIN_DIR . '/inc/post-banner/banner-9/index.php';
368 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/ajax-pagination.php';
369 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-post-rest-api.php';
370 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-multiauthor-backend.php';
371 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-multiauthor-frontend.php';
372 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/tax-category.php';
373 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-bs-post.php';
374 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-banner/frontend-render/post-banner-config.php';
375 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-banner/frontend-render/post-banner-style.php';
376 + include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/search/index.php';
377 + include BLOCKSPARE_PLUGIN_DIR . 'inc/latest-post-block/posts-flash/index.php';
378 + include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/popular-tags/index.php';
379 + include BLOCKSPARE_PLUGIN_DIR . 'inc/page-templates/module.php';
380 + include BLOCKSPARE_PLUGIN_DIR . 'inc/block-banner/frontend-render/post-category-style.php';
451 381 }
452 382
453 - $layout_files = [
454 - 'inc/layout/class-image-importer.php',
455 - 'inc/layout/functions.php',
456 - 'inc/layout/registry.php',
457 - 'inc/layout/components.php',
458 - 'inc/layout/endpoints.php',
459 - 'inc/layout/save-templates.php',
460 - ];
383 + public function blockspare_blocks_register_api_endpoints()
384 + {
461 385
462 - $this->include_files($layout_files);
463 - }
464 -
465 - private function load_block_includes()
466 - {
467 - $block_files = [
468 - 'inc/rest-api-function.php',
469 - 'inc/latest-post-block/posts-grid/index.php',
470 - 'inc/latest-post-block/posts-carousel-grid/index.php',
471 - 'inc/latest-post-block/posts-slider/index.php',
472 - 'inc/latest-post-block/posts-list/index.php',
473 - 'inc/latest-post-block/posts-flash/index.php',
474 - 'inc/latest-post-block/posts-express-grid/index.php',
475 - 'inc/other-block/date-time/index.php',
476 - 'inc/latest-post-block/posts-popular-tags/index.php',
477 - 'inc/blockspare-functions.php',
478 - 'inc/block-posts-config/class-post-rest-api.php',
479 - 'inc/block-posts-config/class-multiauthor-backend.php',
480 - 'inc/block-posts-config/class-multiauthor-frontend.php',
481 - 'inc/block-posts-config/tax-category.php',
482 - 'inc/block-posts-config/class-bs-post.php',
483 - 'inc/block-posts-config/latest-post-tile-common.php',
484 - 'inc/other-block/social-sharing/index.php',
485 - 'inc/other-block/search/index.php',
486 - 'inc/block-banner/frontend-render/post-category-style.php',
487 - 'inc/block-banner/frontend-render/post-banner-config.php',
488 - 'inc/block-banner/frontend-render/post-banner-style.php',
489 - 'inc/block-posts-config/ajax-pagination.php',
490 -
491 - 'inc/post-banner/banner-1/index.php',
492 - 'inc/post-banner/banner-2/index.php',
493 - 'inc/post-banner/banner-9/index.php',
494 - ];
495 - $this->include_files($block_files);
496 - }
497 -
498 - /**
499 - * Reusable file loader
500 - */
501 - private function include_files($files = [])
502 - {
503 -
504 - foreach ($files as $file) {
505 - $filepath = BLOCKSPARE_PLUGIN_DIR . $file;
506 -
507 - if (file_exists($filepath)) {
508 - include_once $filepath;
509 - }
386 + $posts_controller = new Aft_Post_Rest_Controller();
387 + $posts_controller->register_routes();
510 388 }
511 389 }
512 -
513 - public function blockspare_blocks_register_api_endpoints()
514 - {
515 -
516 - $posts_controller = new Aft_Post_Rest_Controller();
517 - $posts_controller->register_routes();
518 - }
519 -
520 -
521 -
522 - // ══════════════════════════════════════════════════════════════════════════
523 - // 5. Load text domain
524 - // ══════════════════════════════════════════════════════════════════════════
525 - public function blockspare_load_load_text_domain()
526 - {
527 - load_plugin_textdomain(
528 - 'blockspare',
529 - false,
530 - dirname(plugin_basename(BLOCKSPARE_BASE_FILE)) . '/languages'
531 - );
532 - }
390 + BlockspareInit::get_instance();
533 391 }
534 -
535 -// Initialize the class
536 -new Blockspare_Init();