page = $page; } public function register(): void { add_action( 'init', array( $this, 'register_blocks' ) ); } public function register_blocks(): void { if ( ! function_exists( 'register_block_type' ) ) { return; } wp_register_script( self::EDITOR_SCRIPT, ACTR_URL . 'assets/js/blocks.js', array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'wp-server-side-render' ), ACTR_VERSION, true ); wp_set_script_translations( self::EDITOR_SCRIPT, 'action-receipts' ); register_block_type( ACTR_DIR . 'blocks/status', array( 'render_callback' => array( $this, 'render_status' ) ) ); register_block_type( ACTR_DIR . 'blocks/lookup', array( 'render_callback' => array( $this, 'render_lookup' ) ) ); } /** * The status block has no attributes yet. */ public function render_status(): string { return $this->wrap( $this->page->render_status_or_lookup() ); } /** * @param array $attributes Block attributes: showTitle. */ public function render_lookup( $attributes = array() ): string { $show_title = ! isset( $attributes['showTitle'] ) || (bool) $attributes['showTitle']; return $this->wrap( $this->page->render_lookup( $show_title ) ); } private function wrap( string $html ): string { return '