Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: footnotes.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/footnotes` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/footnotes` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.3.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
* @param WP_Block $block Block instance.
[14] Fix | Delete
*
[15] Fix | Delete
* @return string Returns the HTML representing the footnotes.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_footnotes( $attributes, $content, $block ) {
[18] Fix | Delete
// Bail out early if the post ID is not set for some reason.
[19] Fix | Delete
if ( empty( $block->context['postId'] ) ) {
[20] Fix | Delete
return '';
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
if ( post_password_required( $block->context['postId'] ) ) {
[24] Fix | Delete
return;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
$footnotes = get_post_meta( $block->context['postId'], 'footnotes', true );
[28] Fix | Delete
[29] Fix | Delete
if ( ! $footnotes ) {
[30] Fix | Delete
return;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
$footnotes = json_decode( $footnotes, true );
[34] Fix | Delete
[35] Fix | Delete
if ( ! is_array( $footnotes ) || count( $footnotes ) === 0 ) {
[36] Fix | Delete
return '';
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes();
[40] Fix | Delete
$footnote_index = 1;
[41] Fix | Delete
[42] Fix | Delete
$block_content = '';
[43] Fix | Delete
[44] Fix | Delete
foreach ( $footnotes as $footnote ) {
[45] Fix | Delete
// Translators: %d: Integer representing the number of return links on the page.
[46] Fix | Delete
$aria_label = sprintf( __( 'Jump to footnote reference %1$d' ), $footnote_index );
[47] Fix | Delete
$block_content .= sprintf(
[48] Fix | Delete
'<li id="%1$s">%2$s <a href="#%1$s-link" aria-label="%3$s">↩︎</a></li>',
[49] Fix | Delete
$footnote['id'],
[50] Fix | Delete
$footnote['content'],
[51] Fix | Delete
$aria_label
[52] Fix | Delete
);
[53] Fix | Delete
++$footnote_index;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
return sprintf(
[57] Fix | Delete
'<ol %1$s>%2$s</ol>',
[58] Fix | Delete
$wrapper_attributes,
[59] Fix | Delete
$block_content
[60] Fix | Delete
);
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Registers the `core/footnotes` block on the server.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 6.3.0
[67] Fix | Delete
*/
[68] Fix | Delete
function register_block_core_footnotes() {
[69] Fix | Delete
register_block_type_from_metadata(
[70] Fix | Delete
__DIR__ . '/footnotes',
[71] Fix | Delete
array(
[72] Fix | Delete
'render_callback' => 'render_block_core_footnotes',
[73] Fix | Delete
)
[74] Fix | Delete
);
[75] Fix | Delete
}
[76] Fix | Delete
add_action( 'init', 'register_block_core_footnotes' );
[77] Fix | Delete
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Registers the footnotes meta field required for footnotes to work.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 6.5.0
[83] Fix | Delete
*/
[84] Fix | Delete
function register_block_core_footnotes_post_meta() {
[85] Fix | Delete
$post_types = get_post_types( array( 'show_in_rest' => true ) );
[86] Fix | Delete
foreach ( $post_types as $post_type ) {
[87] Fix | Delete
// Only register the meta field if the post type supports the editor, custom fields, and revisions.
[88] Fix | Delete
if (
[89] Fix | Delete
post_type_supports( $post_type, 'editor' ) &&
[90] Fix | Delete
post_type_supports( $post_type, 'custom-fields' ) &&
[91] Fix | Delete
post_type_supports( $post_type, 'revisions' )
[92] Fix | Delete
) {
[93] Fix | Delete
register_post_meta(
[94] Fix | Delete
$post_type,
[95] Fix | Delete
'footnotes',
[96] Fix | Delete
array(
[97] Fix | Delete
'show_in_rest' => true,
[98] Fix | Delete
'single' => true,
[99] Fix | Delete
'type' => 'string',
[100] Fix | Delete
'revisions_enabled' => true,
[101] Fix | Delete
)
[102] Fix | Delete
);
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
/*
[107] Fix | Delete
* Most post types are registered at priority 10, so use priority 20 here in
[108] Fix | Delete
* order to catch them.
[109] Fix | Delete
*/
[110] Fix | Delete
add_action( 'init', 'register_block_core_footnotes_post_meta', 20 );
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Adds the footnotes field to the revisions display.
[114] Fix | Delete
*
[115] Fix | Delete
* @since 6.3.0
[116] Fix | Delete
*
[117] Fix | Delete
* @param array $fields The revision fields.
[118] Fix | Delete
* @return array The revision fields.
[119] Fix | Delete
*/
[120] Fix | Delete
function wp_add_footnotes_to_revision( $fields ) {
[121] Fix | Delete
$fields['footnotes'] = __( 'Footnotes' );
[122] Fix | Delete
return $fields;
[123] Fix | Delete
}
[124] Fix | Delete
add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' );
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Gets the footnotes field from the revision for the revisions screen.
[128] Fix | Delete
*
[129] Fix | Delete
* @since 6.3.0
[130] Fix | Delete
*
[131] Fix | Delete
* @param string $revision_field The field value, but $revision->$field
[132] Fix | Delete
* (footnotes) does not exist.
[133] Fix | Delete
* @param string $field The field name, in this case "footnotes".
[134] Fix | Delete
* @param object $revision The revision object to compare against.
[135] Fix | Delete
* @return string The field value.
[136] Fix | Delete
*/
[137] Fix | Delete
function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) {
[138] Fix | Delete
return get_metadata( 'post', $revision->ID, $field, true );
[139] Fix | Delete
}
[140] Fix | Delete
add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 );
[141] Fix | Delete
[142] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function