Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: block.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName // Needed for WP_Block_Cloner helper class.
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/block` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/block` block on server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.0.0
[10] Fix | Delete
*
[11] Fix | Delete
* @global WP_Embed $wp_embed
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $attributes The block attributes.
[14] Fix | Delete
*
[15] Fix | Delete
* @return string Rendered HTML of the referenced block.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_block( $attributes, $content, $block_instance ) {
[18] Fix | Delete
static $seen_refs = array();
[19] Fix | Delete
[20] Fix | Delete
if ( empty( $attributes['ref'] ) ) {
[21] Fix | Delete
return '';
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
$reusable_block = get_post( $attributes['ref'] );
[25] Fix | Delete
if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
[26] Fix | Delete
return '';
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
[30] Fix | Delete
// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
[31] Fix | Delete
// is set in `wp_debug_mode()`.
[32] Fix | Delete
$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY;
[33] Fix | Delete
[34] Fix | Delete
return $is_debug ?
[35] Fix | Delete
// translators: Visible only in the front end, this warning takes the place of a faulty block.
[36] Fix | Delete
__( '[block rendering halted]' ) :
[37] Fix | Delete
'';
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
[41] Fix | Delete
return '';
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
$seen_refs[ $attributes['ref'] ] = true;
[45] Fix | Delete
[46] Fix | Delete
// Handle embeds for reusable blocks.
[47] Fix | Delete
global $wp_embed;
[48] Fix | Delete
$content = $wp_embed->run_shortcode( $reusable_block->post_content );
[49] Fix | Delete
$content = $wp_embed->autoembed( $content );
[50] Fix | Delete
[51] Fix | Delete
// Back compat.
[52] Fix | Delete
// For blocks that have not been migrated in the editor, add some back compat
[53] Fix | Delete
// so that front-end rendering continues to work.
[54] Fix | Delete
[55] Fix | Delete
// This matches the `v2` deprecation. Removes the inner `values` property
[56] Fix | Delete
// from every item.
[57] Fix | Delete
if ( isset( $attributes['content'] ) ) {
[58] Fix | Delete
foreach ( $attributes['content'] as &$content_data ) {
[59] Fix | Delete
if ( isset( $content_data['values'] ) ) {
[60] Fix | Delete
$is_assoc_array = is_array( $content_data['values'] ) && ! wp_is_numeric_array( $content_data['values'] );
[61] Fix | Delete
[62] Fix | Delete
if ( $is_assoc_array ) {
[63] Fix | Delete
$content_data = $content_data['values'];
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
// This matches the `v1` deprecation. Rename `overrides` to `content`.
[70] Fix | Delete
if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
[71] Fix | Delete
$attributes['content'] = $attributes['overrides'];
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
// Apply Block Hooks.
[75] Fix | Delete
$content = apply_block_hooks_to_content_from_post_object( $content, $reusable_block );
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* We attach the blocks from $content as inner blocks to the Synced Pattern block instance.
[79] Fix | Delete
* This ensures that block context available to the Synced Pattern block instance is provided to
[80] Fix | Delete
* those blocks.
[81] Fix | Delete
*/
[82] Fix | Delete
$block_instance->parsed_block['innerBlocks'] = parse_blocks( $content );
[83] Fix | Delete
$block_instance->parsed_block['innerContent'] = array_fill( 0, count( $block_instance->parsed_block['innerBlocks'] ), null );
[84] Fix | Delete
if ( method_exists( $block_instance, 'refresh_context_dependents' ) ) {
[85] Fix | Delete
// WP_Block::refresh_context_dependents() was introduced in WordPress 6.8.
[86] Fix | Delete
$block_instance->refresh_context_dependents();
[87] Fix | Delete
} else {
[88] Fix | Delete
// This branch can be removed once Gutenberg requires WordPress 6.8 or later.
[89] Fix | Delete
if ( ! class_exists( 'WP_Block_Cloner' ) ) {
[90] Fix | Delete
// phpcs:ignore Gutenberg.Commenting.SinceTag.MissingClassSinceTag
[91] Fix | Delete
class WP_Block_Cloner extends WP_Block {
[92] Fix | Delete
/**
[93] Fix | Delete
* Static methods of subclasses have access to protected properties
[94] Fix | Delete
* of instances of the parent class.
[95] Fix | Delete
* In this case, this gives us access to `available_context` and `registry`.
[96] Fix | Delete
*/
[97] Fix | Delete
// phpcs:ignore Gutenberg.Commenting.SinceTag.MissingMethodSinceTag
[98] Fix | Delete
public static function clone_instance( $instance ) {
[99] Fix | Delete
return new WP_Block(
[100] Fix | Delete
$instance->parsed_block,
[101] Fix | Delete
$instance->available_context,
[102] Fix | Delete
$instance->registry
[103] Fix | Delete
);
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
$block_instance = WP_Block_Cloner::clone_instance( $block_instance );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$content = $block_instance->render( array( 'dynamic' => false ) );
[111] Fix | Delete
unset( $seen_refs[ $attributes['ref'] ] );
[112] Fix | Delete
[113] Fix | Delete
return $content;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Registers the `core/block` block.
[118] Fix | Delete
*
[119] Fix | Delete
* @since 5.3.0
[120] Fix | Delete
*/
[121] Fix | Delete
function register_block_core_block() {
[122] Fix | Delete
register_block_type_from_metadata(
[123] Fix | Delete
__DIR__ . '/block',
[124] Fix | Delete
array(
[125] Fix | Delete
'render_callback' => 'render_block_core_block',
[126] Fix | Delete
)
[127] Fix | Delete
);
[128] Fix | Delete
}
[129] Fix | Delete
add_action( 'init', 'register_block_core_block' );
[130] Fix | Delete
[131] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function