render_block_core_social_link

The timeline below displays how wordpress function render_block_core_social_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array    $attributes The block attributes.
 * @param String   $content    InnerBlocks content of the Block.
 * @param WP_Block $block      Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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();
}

WordPress Version: 6.3

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array    $attributes The block attributes.
 * @param String   $content    InnerBlocks content of the Block.
 * @param WP_Block $block      Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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:' . $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', esc_attr($rel) . ' noopener nofollow');
        $processor->set_attribute('target', '_blank');
    } elseif ('' !== $rel) {
        $processor->set_attribute('rel', esc_attr($rel));
    }
    return $processor->get_updated_html();
}

WordPress Version: 6.2

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array    $attributes The block attributes.
 * @param String   $content    InnerBlocks content of the Block.
 * @param WP_Block $block      Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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:' . $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, '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>';
    $w = new WP_HTML_Tag_Processor($link);
    $w->next_tag('a');
    if ($open_in_new_tab) {
        $w->set_attribute('rel', esc_attr($rel) . ' noopener nofollow');
        $w->set_attribute('target', '_blank');
    } elseif ('' !== $rel) {
        $w->set_attribute('rel', esc_attr($rel));
    }
    return $w;
}

WordPress Version: 6.1

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array    $attributes The block attributes.
 * @param String   $content    InnerBlocks content of the Block.
 * @param WP_Block $block      Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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);
    $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:' . $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;
    }
    $rel_target_attributes = '';
    if ($open_in_new_tab) {
        $rel_target_attributes = 'rel="noopener nofollow" target="_blank"';
    }
    $icon = block_core_social_link_get_icon($service);
    $wrapper_attributes = get_block_wrapper_attributes(array('class' => 'wp-social-link wp-social-link-' . $service, 'style' => block_core_social_link_get_color_styles($block->context)));
    $link = '<li ' . $wrapper_attributes . '>';
    $link .= '<a href="' . esc_url($url) . '" ' . $rel_target_attributes . ' 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>';
    return $link;
}

WordPress Version: 5.8

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array    $attributes The block attributes.
 * @param String   $content    InnerBlocks content of the Block.
 * @param WP_Block $block      Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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'] : sprintf(
        /* translators: %1$s: Social-network name. %2$s: URL. */
        __('%1$s: %2$s'),
        block_core_social_link_get_name($service),
        $url
    );
    $class_name = isset($attributes['className']) ? ' ' . $attributes['className'] : false;
    // Don't render a link if there is no URL set.
    if (!$url) {
        return '';
    }
    $attribute = '';
    if ($open_in_new_tab) {
        $attribute = 'rel="noopener nofollow" target="_blank"';
    }
    $icon = block_core_social_link_get_icon($service);
    $wrapper_attributes = get_block_wrapper_attributes(array('class' => 'wp-social-link wp-social-link-' . $service . $class_name, 'style' => block_core_social_link_get_color_styles($block->context)));
    return '<li ' . $wrapper_attributes . '><a href="' . esc_url($url) . '" aria-label="' . esc_attr($label) . '" ' . $attribute . ' class="wp-block-social-link-anchor"> ' . $icon . '</a></li>';
}

WordPress Version: 5.7

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array   $attributes The block attributes.
 * @param String  $content InnerBlocks content of the Block.
 * @param WPBlock $block Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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);
    $class_name = isset($attributes['className']) ? ' ' . $attributes['className'] : false;
    // Don't render a link if there is no URL set.
    if (!$url) {
        return '';
    }
    $attribute = '';
    if ($open_in_new_tab) {
        $attribute = 'rel="noopener nofollow" target="_blank"';
    }
    $icon = block_core_social_link_get_icon($service);
    $wrapper_attributes = get_block_wrapper_attributes(array('class' => 'wp-social-link wp-social-link-' . $service . $class_name, 'style' => block_core_social_link_get_color_styles($block->context)));
    return '<li ' . $wrapper_attributes . '><a href="' . esc_url($url) . '" aria-label="' . esc_attr($label) . '" ' . $attribute . ' class="wp-block-social-link-anchor"> ' . $icon . '</a></li>';
}

WordPress Version: 5.6

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param Array   $attributes The block attributes.
 * @param String  $content InnerBlocks content of the Block.
 * @param WPBlock $block Block object.
 *
 * @return string Rendered HTML of the referenced block.
 */
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);
    $class_name = isset($attributes['className']) ? ' ' . $attributes['className'] : false;
    // Don't render a link if there is no URL set.
    if (!$url) {
        return '';
    }
    $attribute = '';
    if ($open_in_new_tab) {
        $attribute = 'rel="noopener nofollow" target="_blank"';
    }
    $icon = block_core_social_link_get_icon($service);
    $wrapper_attributes = get_block_wrapper_attributes(array('class' => 'wp-social-link wp-social-link-' . $service . $class_name));
    return '<li ' . $wrapper_attributes . '><a href="' . esc_url($url) . '" aria-label="' . esc_attr($label) . '" ' . $attribute . '> ' . $icon . '</a></li>';
}

WordPress Version: 5.5

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered HTML of the referenced block.
 */
function render_block_core_social_link($attributes)
{
    $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);
    $class_name = isset($attributes['className']) ? ' ' . $attributes['className'] : false;
    // Don't render a link if there is no URL set.
    if (!$url) {
        return '';
    }
    $icon = block_core_social_link_get_icon($service);
    return '<li class="wp-social-link wp-social-link-' . esc_attr($service) . esc_attr($class_name) . '"><a href="' . esc_url($url) . '" aria-label="' . esc_attr($label) . '"> ' . $icon . '</a></li>';
}

WordPress Version: 5.4

/**
 * Server-side rendering of the `core/social-link` blocks.
 *
 * @package WordPress
 */
/**
 * Renders the `core/social-link` block on server.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered HTML of the referenced block.
 */
function render_block_core_social_link($attributes)
{
    $service = isset($attributes['service']) ? $attributes['service'] : 'Icon';
    $url = isset($attributes['url']) ? $attributes['url'] : false;
    $label = isset($attributes['label']) ? $attributes['label'] : sprintf(__('Link to %s'), block_core_social_link_get_name($service));
    $class_name = isset($attributes['className']) ? ' ' . $attributes['className'] : false;
    // Don't render a link if there is no URL set.
    if (!$url) {
        return '';
    }
    $icon = block_core_social_link_get_icon($service);
    return '<li class="wp-social-link wp-social-link-' . esc_attr($service) . esc_attr($class_name) . '"><a href="' . esc_url($url) . '" aria-label="' . esc_attr($label) . '"> ' . $icon . '</a></li>';
}