2023-06-27 10:24:19 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Server-side rendering of the `core/footnotes` block.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the `core/footnotes` block on the server.
|
|
|
|
*
|
2023-07-25 04:40:23 -04:00
|
|
|
* @since 6.3.0
|
|
|
|
*
|
2023-06-27 10:24:19 -04:00
|
|
|
* @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 );
|
|
|
|
|
2023-08-19 19:22:38 -04:00
|
|
|
if ( ! is_array( $footnotes ) || count( $footnotes ) === 0 ) {
|
2023-06-27 10:24:19 -04:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$wrapper_attributes = get_block_wrapper_attributes();
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
$footnote_index = 1;
|
2023-06-27 10:24:19 -04:00
|
|
|
|
|
|
|
$block_content = '';
|
|
|
|
|
|
|
|
foreach ( $footnotes as $footnote ) {
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
// Translators: %d: Integer representing the number of return links on the page.
|
|
|
|
$aria_label = sprintf( __( 'Jump to footnote reference %1$d' ), $footnote_index );
|
2023-06-27 10:24:19 -04:00
|
|
|
$block_content .= sprintf(
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
'<li id="%1$s">%2$s <a href="#%1$s-link" aria-label="%3$s">↩︎</a></li>',
|
2023-06-27 10:24:19 -04:00
|
|
|
$footnote['id'],
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
$footnote['content'],
|
|
|
|
$aria_label
|
2023-06-27 10:24:19 -04:00
|
|
|
);
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
++$footnote_index;
|
2023-06-27 10:24:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(
|
|
|
|
'<ol %1$s>%2$s</ol>',
|
|
|
|
$wrapper_attributes,
|
|
|
|
$block_content
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the `core/footnotes` block on the server.
|
2023-07-25 04:40:23 -04:00
|
|
|
*
|
|
|
|
* @since 6.3.0
|
2023-06-27 10:24:19 -04:00
|
|
|
*/
|
|
|
|
function register_block_core_footnotes() {
|
2024-02-20 06:16:26 -05:00
|
|
|
register_block_type_from_metadata(
|
|
|
|
__DIR__ . '/footnotes',
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
array(
|
2024-02-20 06:16:26 -05:00
|
|
|
'render_callback' => 'render_block_core_footnotes',
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
)
|
|
|
|
);
|
2024-02-20 06:16:26 -05:00
|
|
|
}
|
|
|
|
add_action( 'init', 'register_block_core_footnotes' );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the footnotes meta field required for footnotes to work.
|
|
|
|
*
|
|
|
|
* @since 6.5.0
|
|
|
|
*/
|
|
|
|
function register_block_core_footnotes_post_meta() {
|
|
|
|
$post_types = get_post_types( array( 'show_in_rest' => true ) );
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
foreach ( $post_types as $post_type ) {
|
|
|
|
// Only register the meta field if the post type supports the editor, custom fields, and revisions.
|
2024-02-20 06:16:26 -05:00
|
|
|
if (
|
|
|
|
post_type_supports( $post_type, 'editor' ) &&
|
|
|
|
post_type_supports( $post_type, 'custom-fields' ) &&
|
|
|
|
post_type_supports( $post_type, 'revisions' )
|
|
|
|
) {
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
register_post_meta(
|
|
|
|
$post_type,
|
|
|
|
'footnotes',
|
|
|
|
array(
|
|
|
|
'show_in_rest' => true,
|
|
|
|
'single' => true,
|
|
|
|
'type' => 'string',
|
|
|
|
'revisions_enabled' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2023-07-03 05:14:26 -04:00
|
|
|
}
|
2023-06-27 10:24:19 -04:00
|
|
|
}
|
2024-02-20 06:16:26 -05:00
|
|
|
/**
|
|
|
|
* Most post types are registered at priority 10, so use priority 20 here in
|
|
|
|
* order to catch them.
|
|
|
|
*/
|
|
|
|
add_action( 'init', 'register_block_core_footnotes_post_meta', 20 );
|
2023-07-25 04:40:23 -04:00
|
|
|
|
|
|
|
/**
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
* Adds the footnotes field to the revisions display.
|
2023-07-25 04:40:23 -04:00
|
|
|
*
|
|
|
|
* @since 6.3.0
|
|
|
|
*
|
|
|
|
* @param array $fields The revision fields.
|
|
|
|
* @return array The revision fields.
|
|
|
|
*/
|
|
|
|
function wp_add_footnotes_to_revision( $fields ) {
|
|
|
|
$fields['footnotes'] = __( 'Footnotes' );
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' );
|
|
|
|
|
|
|
|
/**
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 14:58:22 -04:00
|
|
|
* Gets the footnotes field from the revision for the revisions screen.
|
2023-07-25 04:40:23 -04:00
|
|
|
*
|
|
|
|
* @since 6.3.0
|
|
|
|
*
|
|
|
|
* @param string $revision_field The field value, but $revision->$field
|
|
|
|
* (footnotes) does not exist.
|
|
|
|
* @param string $field The field name, in this case "footnotes".
|
|
|
|
* @param object $revision The revision object to compare against.
|
|
|
|
* @return string The field value.
|
|
|
|
*/
|
|
|
|
function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) {
|
|
|
|
return get_metadata( 'post', $revision->ID, $field, true );
|
|
|
|
}
|
2023-08-01 04:01:54 -04:00
|
|
|
add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 );
|