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