Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: block.php
<?php
[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 ) {
[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
/**
[75] Fix | Delete
* We set the `pattern/overrides` context through the `render_block_context`
[76] Fix | Delete
* filter so that it is available when a pattern's inner blocks are
[77] Fix | Delete
* rendering via do_blocks given it only receives the inner content.
[78] Fix | Delete
*/
[79] Fix | Delete
$has_pattern_overrides = isset( $attributes['content'] ) && null !== get_block_bindings_source( 'core/pattern-overrides' );
[80] Fix | Delete
if ( $has_pattern_overrides ) {
[81] Fix | Delete
$filter_block_context = static function ( $context ) use ( $attributes ) {
[82] Fix | Delete
$context['pattern/overrides'] = $attributes['content'];
[83] Fix | Delete
return $context;
[84] Fix | Delete
};
[85] Fix | Delete
add_filter( 'render_block_context', $filter_block_context, 1 );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
// Apply Block Hooks.
[89] Fix | Delete
$content = apply_block_hooks_to_content_from_post_object( $content, $reusable_block );
[90] Fix | Delete
[91] Fix | Delete
$content = do_blocks( $content );
[92] Fix | Delete
unset( $seen_refs[ $attributes['ref'] ] );
[93] Fix | Delete
[94] Fix | Delete
if ( $has_pattern_overrides ) {
[95] Fix | Delete
remove_filter( 'render_block_context', $filter_block_context, 1 );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
return $content;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Registers the `core/block` block.
[103] Fix | Delete
*
[104] Fix | Delete
* @since 5.3.0
[105] Fix | Delete
*/
[106] Fix | Delete
function register_block_core_block() {
[107] Fix | Delete
register_block_type_from_metadata(
[108] Fix | Delete
__DIR__ . '/block',
[109] Fix | Delete
array(
[110] Fix | Delete
'render_callback' => 'render_block_core_block',
[111] Fix | Delete
)
[112] Fix | Delete
);
[113] Fix | Delete
}
[114] Fix | Delete
add_action( 'init', 'register_block_core_block' );
[115] Fix | Delete
[116] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function