render_block_core_social_link()WP 1.0

Renders the core/social-link block on server.

No Hooks.

Return

String. Rendered HTML of the referenced block.

Usage

render_block_core_social_link( $attributes, $content, $block );
$attributes(Array) (required)
The block attributes.
$content(String) (required)
InnerBlocks content of the Block.
$block(WP_Block) (required)
Block object.

render_block_core_social_link() code WP 6.5.2

function render_block_core_social_link( $attributes, $content, $block ) {
	$open_in_new_tab = isset( $block->context['openInNewTab'] ) ? $block->context['openInNewTab'] : false;

	$service     = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
	$url         = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
	$label       = ( isset( $attributes['label'] ) ) ? $attributes['label'] : block_core_social_link_get_name( $service );
	$rel         = ( isset( $attributes['rel'] ) ) ? $attributes['rel'] : '';
	$show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false;

	// Don't render a link if there is no URL set.
	if ( ! $url ) {
		return '';
	}

	/**
	 * Prepend emails with `mailto:` if not set.
	 * The `is_email` returns false for emails with schema.
	 */
	if ( is_email( $url ) ) {
		$url = 'mailto:' . antispambot( $url );
	}

	/**
	 * Prepend URL with https:// if it doesn't appear to contain a scheme
	 * and it's not a relative link starting with //.
	 */
	if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) ) {
		$url = 'https://' . $url;
	}

	$icon               = block_core_social_link_get_icon( $service );
	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => 'wp-social-link wp-social-link-' . $service . block_core_social_link_get_color_classes( $block->context ),
			'style' => block_core_social_link_get_color_styles( $block->context ),
		)
	);

	$link  = '<li ' . $wrapper_attributes . '>';
	$link .= '<a href="' . esc_url( $url ) . '" class="wp-block-social-link-anchor">';
	$link .= $icon;
	$link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">';
	$link .= esc_html( $label );
	$link .= '</span></a></li>';

	$processor = new WP_HTML_Tag_Processor( $link );
	$processor->next_tag( 'a' );
	if ( $open_in_new_tab ) {
		$processor->set_attribute( 'rel', trim( $rel . ' noopener nofollow' ) );
		$processor->set_attribute( 'target', '_blank' );
	} elseif ( '' !== $rel ) {
		$processor->set_attribute( 'rel', trim( $rel ) );
	}
	return $processor->get_updated_html();
}