mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 10:38:11 +01:00
919ea56557
Includes miscellaneous bug fixes and enhancements to the Library task (#58579) and to the site vs content editing task (#58641) Fixes #58701. Built from https://develop.svn.wordpress.org/trunk@56127 git-svn-id: http://core.svn.wordpress.org/trunk@55639 1a063a9b-81f0-0310-95a4-ce76da25c4cd
81 lines
1.7 KiB
PHP
81 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Server-side rendering of the `core/footnotes` block.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
/**
|
|
* Renders the `core/footnotes` block on the server.
|
|
*
|
|
* @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
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Registers the `core/footnotes` block on the server.
|
|
*/
|
|
function register_block_core_footnotes() {
|
|
foreach ( array( 'post', 'page' ) as $post_type ) {
|
|
register_post_meta(
|
|
$post_type,
|
|
'footnotes',
|
|
array(
|
|
'show_in_rest' => true,
|
|
'single' => true,
|
|
'type' => 'string',
|
|
)
|
|
);
|
|
}
|
|
register_block_type_from_metadata(
|
|
__DIR__ . '/footnotes',
|
|
array(
|
|
'render_callback' => 'render_block_core_footnotes',
|
|
)
|
|
);
|
|
}
|
|
add_action( 'init', 'register_block_core_footnotes' );
|