LLMS_Shortcodes_Blocks::render_block( array $attributes, string $content, WP_Block $block )

Renders a shortcode block.


Parameters Parameters

$attributes

(array) (Required) The block attributes.

$content

(string) (Required) The block default content.

$block

(WP_Block) (Required) The block instance.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/shortcodes/class.llms.shortcodes.blocks.php

	public function render_block( array $attributes, string $content, WP_Block $block ): string {
		if ( ! property_exists( $block, 'name' ) ) {
			return '';
		}

		$name   = str_replace( 'llms/', '', $block->name );
		$config = $this->get_config();
		$render = $config[ $name ]['render'] ?? array();

		if ( method_exists( $render[0] ?? '', 'instance' ) ) {
			$render = array( $render[0]::instance(), $render[1] ?? '' );
		}

		if ( ! is_callable( $render ) ) {
			return '';
		}

		if ( ! apply_filters( 'llms_render_block', true, $block ) ) {
			return '';
		}

		$text = $attributes['text'] ?? '';

		unset( $attributes['text'] );

		$args = array( $attributes );

		if ( $text ) {
			$args[] = $text;
		}

		$html = call_user_func( $render, ...$args );

		// This allows emptyResponsePlaceholder to be used when no content is returned.
		if ( ! $html ) {
			return '';
		}

		// Use emptyResponsePlaceholder for Courses block instead of shortcode message.
		if ( false !== strpos( $html, __( 'No products were found matching your selection.', 'lifterlms' ) ) ) {
			return '';
		}

		return sprintf(
			'<div %1$s>%2$s</div>',
			get_block_wrapper_attributes(),
			trim( $html )
		);
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.