renderers['forum_posts'] = new Forum_Posts(); $this->renderers['forum_tab'] = new Forum_Tab(); $this->renderers['forums'] = new Forums(); $this->renderers['search'] = new Search(); $this->renderers['single_forum'] = new Single_Forum(); $this->renderers['forum_ajax'] = new Forum_Ajax(); $this->renderers['forum_overview'] = new Forum_Overview(); } /** * Register the Forumax block category. * * @param array $categories Existing categories. * @param WP_Post $post Current post. * @return array Modified categories. */ public function register_block_category( $categories, $post ) { return array_merge( $categories, array( array( 'slug' => 'forumax', 'title' => __( 'Forumax', 'forumax' ), ), ) ); } /** * Enqueue assets for the Gutenberg block editor. * * This ensures the AJAX URL and upsell configuration * are available for block scripts. */ public function enqueue_editor_assets() { $is_pro_active = class_exists( 'Forumax_Pro' ) && function_exists( 'bc_fs' ) && bc_fs()->can_use_premium_code(); wp_localize_script( 'wp-edit-post', 'bbpc_editor_config', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'forumax-nonce' ), ) ); wp_localize_script( 'wp-edit-post', 'bbpc_upsell_config', array( 'is_pro_active' => $is_pro_active, 'upsell_image_url' => defined( 'FORUMAX_IMG' ) ? FORUMAX_IMG . 'upsell-forum-ajax.png' : '', 'upgrade_url' => admin_url( 'admin.php?page=forumax-pricing' ), ) ); } /** * Register all Gutenberg blocks. * * Each block points to its compiled build directory and * delegates rendering to the appropriate Render class. */ public function blocks_init() { $blocks = array( 'forum-posts' => 'forum_posts', 'forum-tab' => 'forum_tab', 'forums' => 'forums', 'search' => 'search', 'single-forum' => 'single_forum', 'forum-ajax' => 'forum_ajax', 'forum-overview' => 'forum_overview', ); foreach ( $blocks as $block_dir => $renderer_key ) { if ( 'forum-ajax' === $block_dir && \WP_Block_Type_Registry::get_instance()->is_registered( 'bbp-core/forum-ajax' ) ) { continue; } $block_path = __DIR__ . '/../../build/' . $block_dir; if ( file_exists( $block_path . '/block.json' ) ) { register_block_type( $block_path, array( 'render_callback' => array( $this->renderers[ $renderer_key ], 'render_' . $renderer_key ), ) ); } } } }