render_block_core_footnotes

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

WordPress Version: 6.4

/**
 * Server-side rendering of the `core/footnotes` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/footnotes` block on the server.
 *
 * @since 6.3.0
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 *
 * @return string Returns the HTML representing the footnotes.
 */
function render_block_core_footnotes($attributes, $content, $block)
{
    // Bail out early if the post ID is not set for some reason.
    if (empty($block->context['postId'])) {
        return '';
    }
    if (post_password_required($block->context['postId'])) {
        return;
    }
    $footnotes = get_post_meta($block->context['postId'], 'footnotes', true);
    if (!$footnotes) {
        return;
    }
    $footnotes = json_decode($footnotes, true);
    if (!is_array($footnotes) || count($footnotes) === 0) {
        return '';
    }
    $wrapper_attributes = get_block_wrapper_attributes();
    $footnote_index = 1;
    $block_content = '';
    foreach ($footnotes as $footnote) {
        // Translators: %d: Integer representing the number of return links on the page.
        $aria_label = sprintf(__('Jump to footnote reference %1$d'), $footnote_index);
        $block_content .= sprintf('<li id="%1$s">%2$s <a href="#%1$s-link" aria-label="%3$s">↩︎</a></li>', $footnote['id'], $footnote['content'], $aria_label);
        ++$footnote_index;
    }
    return sprintf('<ol %1$s>%2$s</ol>', $wrapper_attributes, $block_content);
}

WordPress Version: 3.1

/**
 * Server-side rendering of the `core/footnotes` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/footnotes` block on the server.
 *
 * @since 6.3.0
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 *
 * @return string Returns the HTML representing the footnotes.
 */
function render_block_core_footnotes($attributes, $content, $block)
{
    // Bail out early if the post ID is not set for some reason.
    if (empty($block->context['postId'])) {
        return '';
    }
    if (post_password_required($block->context['postId'])) {
        return;
    }
    $footnotes = get_post_meta($block->context['postId'], 'footnotes', true);
    if (!$footnotes) {
        return;
    }
    $footnotes = json_decode($footnotes, true);
    if (!is_array($footnotes) || count($footnotes) === 0) {
        return '';
    }
    $wrapper_attributes = get_block_wrapper_attributes();
    $block_content = '';
    foreach ($footnotes as $footnote) {
        $block_content .= sprintf('<li id="%1$s">%2$s <a href="#%1$s-link">↩︎</a></li>', $footnote['id'], $footnote['content']);
    }
    return sprintf('<ol %1$s>%2$s</ol>', $wrapper_attributes, $block_content);
}

WordPress Version: 6.3

/**
 * Server-side rendering of the `core/footnotes` block.
 *
 * @package WordPress
 */
/**
 * Renders the `core/footnotes` block on the server.
 *
 * @since 6.3.0
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 *
 * @return string Returns the HTML representing the footnotes.
 */
function render_block_core_footnotes($attributes, $content, $block)
{
    // Bail out early if the post ID is not set for some reason.
    if (empty($block->context['postId'])) {
        return '';
    }
    if (post_password_required($block->context['postId'])) {
        return;
    }
    $footnotes = get_post_meta($block->context['postId'], 'footnotes', true);
    if (!$footnotes) {
        return;
    }
    $footnotes = json_decode($footnotes, true);
    if (count($footnotes) === 0) {
        return '';
    }
    $wrapper_attributes = get_block_wrapper_attributes();
    $block_content = '';
    foreach ($footnotes as $footnote) {
        $block_content .= sprintf('<li id="%1$s">%2$s <a href="#%1$s-link">↩︎</a></li>', $footnote['id'], $footnote['content']);
    }
    return sprintf('<ol %1$s>%2$s</ol>', $wrapper_attributes, $block_content);
}