init_hooks(); } /** * Get the single instance of the Register class. * * @since 1.0.0 * @access public * * @return Register The single instance. */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Initialize WordPress hooks. * * @since 1.0.0 * @access private * * @return void */ private function init_hooks() { add_action( 'init', array( $this, 'register_blocks' ) ); // check if the theme is not a block theme if( ! wp_is_block_theme() ) { add_filter( 'should_load_separate_core_block_assets', '__return_true' ); } } /** * Register all Acumenpopup blocks. * * Loops through the blocks array and registers each block * from its block.json in the build directory. * * @since 1.0.0 * @access public * * @return void */ public function register_blocks() { $build_dir = trailingslashit( ACUMENPOPUP_PLUGIN_DIR ) . 'build/blocks/'; foreach ( $this->blocks as $block ) { $block_path = $build_dir . $block; // Only register if block.json exists. if ( file_exists( $block_path . '/block.json' ) ) { register_block_type( $block_path ); } } } /** * Get the list of registered block names. * * @since 1.0.0 * @access public * * @return array Array of block names. */ public function get_blocks() { return $this->blocks; } /** * Add a block to the registration list. * * @since 1.0.0 * @access public * * @param string $block_name The block name (without prefix). * * @return void */ public function add_block( $block_name ) { if ( ! in_array( $block_name, $this->blocks, true ) ) { $this->blocks[] = sanitize_key( $block_name ); } } /** * Remove a block from the registration list. * * @since 1.0.0 * @access public * * @param string $block_name The block name to remove. * * @return void */ public function remove_block( $block_name ) { $key = array_search( $block_name, $this->blocks, true ); if ( false !== $key ) { unset( $this->blocks[ $key ] ); $this->blocks = array_values( $this->blocks ); } } /** * Prevent cloning of the instance. * * @since 1.0.0 * @access public * * @return void */ public function __clone() { _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'acumen-popup' ), '1.0.0' ); } /** * Prevent unserializing of the instance. * * @since 1.0.0 * @access public * * @return void */ public function __wakeup() { _doing_it_wrong( __FUNCTION__, esc_html__( 'Unserializing is forbidden.', 'acumen-popup' ), '1.0.0' ); } }