PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / Blocks / Blocks_Register.php

Blocks_Register.php in Forumax – AI Powered Advanced Community Forum Plugin 2.2.0, at includes/Blocks/Blocks_Register.php

138 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Block Registration and Orchestration.
4 *
5 * This class handles Gutenberg block registration, editor assets,
6 * and block category setup. Individual block render callbacks are
7 * delegated to dedicated classes inside the Render/ directory.
8 *
9 * @package BBP_Core
10 */
11
12 namespace admin\Blocks;
13
14 // Load render classes.
15 require_once __DIR__ . '/Render/forum-posts.php';
16 require_once __DIR__ . '/Render/forum-tab.php';
17 require_once __DIR__ . '/Render/forums.php';
18 require_once __DIR__ . '/Render/search.php';
19 require_once __DIR__ . '/Render/single-forum.php';
20 require_once __DIR__ . '/Render/forum-ajax.php';
21 require_once __DIR__ . '/Render/forum-overview.php';
22
23 use admin\Blocks\Render\Forum_Posts;
24 use admin\Blocks\Render\Forum_Tab;
25 use admin\Blocks\Render\Forums;
26 use admin\Blocks\Render\Search;
27 use admin\Blocks\Render\Single_Forum;
28 use admin\Blocks\Render\Forum_Ajax;
29 use admin\Blocks\Render\Forum_Overview;
30
31 class Blocks_Register {
32
33 /**
34 * Render class instances.
35 *
36 * @var object[]
37 */
38 private $renderers = array();
39
40 /**
41 * Constructor — hooks into WordPress.
42 */
43 public function __construct() {
44 add_action( 'init', array( $this, 'blocks_init' ) );
45 add_filter( 'block_categories_all', array( $this, 'register_block_category' ), 10, 2 );
46 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) );
47
48 // Instantiate render classes.
49 $this->renderers['forum_posts'] = new Forum_Posts();
50 $this->renderers['forum_tab'] = new Forum_Tab();
51 $this->renderers['forums'] = new Forums();
52 $this->renderers['search'] = new Search();
53 $this->renderers['single_forum'] = new Single_Forum();
54 $this->renderers['forum_ajax'] = new Forum_Ajax();
55 $this->renderers['forum_overview'] = new Forum_Overview();
56 }
57
58 /**
59 * Register the Forumax block category.
60 *
61 * @param array $categories Existing categories.
62 * @param WP_Post $post Current post.
63 * @return array Modified categories.
64 */
65 public function register_block_category( $categories, $post ) {
66 return array_merge(
67 $categories,
68 array(
69 array(
70 'slug' => 'forumax',
71 'title' => __( 'Forumax', 'forumax' ),
72 ),
73 )
74 );
75 }
76
77 /**
78 * Enqueue assets for the Gutenberg block editor.
79 *
80 * This ensures the AJAX URL and upsell configuration
81 * are available for block scripts.
82 */
83 public function enqueue_editor_assets() {
84 $is_pro_active = class_exists( 'Forumax_Pro' ) && function_exists( 'bc_fs' ) && bc_fs()->can_use_premium_code();
85
86 wp_localize_script( 'wp-edit-post', 'bbpc_editor_config', array(
87 'ajaxurl' => admin_url( 'admin-ajax.php' ),
88 'nonce' => wp_create_nonce( 'forumax-nonce' ),
89 ) );
90
91 wp_localize_script( 'wp-edit-post', 'bbpc_upsell_config', array(
92 'is_pro_active' => $is_pro_active,
93 'upsell_image_url' => defined( 'FORUMAX_IMG' ) ? FORUMAX_IMG . 'upsell-forum-ajax.png' : '',
94 'upgrade_url' => admin_url( 'admin.php?page=forumax-pricing' ),
95 ) );
96 }
97
98 /**
99 * Register all Gutenberg blocks.
100 *
101 * Each block points to its compiled build directory and
102 * delegates rendering to the appropriate Render class.
103 */
104 public function blocks_init() {
105
106 register_block_type( __DIR__ . '/../../build/forum-posts', array(
107 'render_callback' => array( $this->renderers['forum_posts'], 'render_forum_posts' ),
108 ) );
109
110 register_block_type( __DIR__ . '/../../build/forum-tab', array(
111 'render_callback' => array( $this->renderers['forum_tab'], 'render_forum_tab' ),
112 ) );
113
114 register_block_type( __DIR__ . '/../../build/forums', array(
115 'render_callback' => array( $this->renderers['forums'], 'render_forums' ),
116 ) );
117
118 register_block_type( __DIR__ . '/../../build/search', array(
119 'render_callback' => array( $this->renderers['search'], 'render_search' ),
120 ) );
121
122 register_block_type( __DIR__ . '/../../build/single-forum', array(
123 'render_callback' => array( $this->renderers['single_forum'], 'render_single_forum' ),
124 ) );
125
126 // Only register forum-ajax from bbp-core if Forumax Pro hasn't already registered it.
127 if ( ! \WP_Block_Type_Registry::get_instance()->is_registered( 'bbp-core/forum-ajax' ) ) {
128 register_block_type( __DIR__ . '/../../build/forum-ajax', array(
129 'render_callback' => array( $this->renderers['forum_ajax'], 'render_forum_ajax' ),
130 ) );
131 }
132
133 register_block_type( __DIR__ . '/../../build/forum-overview', array(
134 'render_callback' => array( $this->renderers['forum_overview'], 'render_forum_overview' ),
135 ) );
136 }
137 }
138