resolver = $resolver; $this->renderer = $renderer; } public function register() { add_action( 'init', array( $this, 'register_block' ) ); } public function register_block() { register_block_type( GLOVARIO_PATH . 'blocks/site-variable', array( 'render_callback' => array( $this, 'render' ) ) ); } public function render( $attributes ) { $key = isset( $attributes['key'] ) ? sanitize_key( $attributes['key'] ) : ''; if ( '' === $key ) { return is_admin() ? '' . esc_html__( 'No Site Variable selected.', 'glovario' ) . '' : ''; } $context = array( 'source' => 'block', 'image_size' => isset( $attributes['imageSize'] ) ? sanitize_key( $attributes['imageSize'] ) : '', ); if ( BuiltinVariables::CURRENT_DATE_KEY === $key ) { $context['date_format'] = BuiltinVariables::sanitize_date_format( $attributes['dateFormat'] ?? '' ); } $resolved = $this->resolver->resolve( $key, $context ); if ( ! $resolved ) { return ''; } return sprintf( '
%2$s
', get_block_wrapper_attributes(), $this->renderer->render( $resolved['value'], $resolved['variable']['type'], $resolved['context'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); } }