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