Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-block.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Blocks API: WP_Block class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.5.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class representing a parsed instance of a block.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 5.5.0
[11] Fix | Delete
* @property array $attributes
[12] Fix | Delete
*/
[13] Fix | Delete
class WP_Block {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Original parsed array representation of block.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 5.5.0
[19] Fix | Delete
* @var array
[20] Fix | Delete
*/
[21] Fix | Delete
public $parsed_block;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Name of block.
[25] Fix | Delete
*
[26] Fix | Delete
* @example "core/paragraph"
[27] Fix | Delete
*
[28] Fix | Delete
* @since 5.5.0
[29] Fix | Delete
* @var string
[30] Fix | Delete
*/
[31] Fix | Delete
public $name;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Block type associated with the instance.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 5.5.0
[37] Fix | Delete
* @var WP_Block_Type
[38] Fix | Delete
*/
[39] Fix | Delete
public $block_type;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Block context values.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 5.5.0
[45] Fix | Delete
* @var array
[46] Fix | Delete
*/
[47] Fix | Delete
public $context = array();
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* All available context of the current hierarchy.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 5.5.0
[53] Fix | Delete
* @var array
[54] Fix | Delete
* @access protected
[55] Fix | Delete
*/
[56] Fix | Delete
protected $available_context;
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* List of inner blocks (of this same class)
[60] Fix | Delete
*
[61] Fix | Delete
* @since 5.5.0
[62] Fix | Delete
* @var WP_Block[]
[63] Fix | Delete
*/
[64] Fix | Delete
public $inner_blocks = array();
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Resultant HTML from inside block comment delimiters after removing inner
[68] Fix | Delete
* blocks.
[69] Fix | Delete
*
[70] Fix | Delete
* @example "...Just <!-- wp:test /--> testing..." -> "Just testing..."
[71] Fix | Delete
*
[72] Fix | Delete
* @since 5.5.0
[73] Fix | Delete
* @var string
[74] Fix | Delete
*/
[75] Fix | Delete
public $inner_html = '';
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* List of string fragments and null markers where inner blocks were found
[79] Fix | Delete
*
[80] Fix | Delete
* @example array(
[81] Fix | Delete
* 'inner_html' => 'BeforeInnerAfter',
[82] Fix | Delete
* 'inner_blocks' => array( block, block ),
[83] Fix | Delete
* 'inner_content' => array( 'Before', null, 'Inner', null, 'After' ),
[84] Fix | Delete
* )
[85] Fix | Delete
*
[86] Fix | Delete
* @since 5.5.0
[87] Fix | Delete
* @var array
[88] Fix | Delete
*/
[89] Fix | Delete
public $inner_content = array();
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Constructor.
[93] Fix | Delete
*
[94] Fix | Delete
* Populates object properties from the provided block instance argument.
[95] Fix | Delete
*
[96] Fix | Delete
* The given array of context values will not necessarily be available on
[97] Fix | Delete
* the instance itself, but is treated as the full set of values provided by
[98] Fix | Delete
* the block's ancestry. This is assigned to the private `available_context`
[99] Fix | Delete
* property. Only values which are configured to consumed by the block via
[100] Fix | Delete
* its registered type will be assigned to the block's `context` property.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 5.5.0
[103] Fix | Delete
*
[104] Fix | Delete
* @param array $block Array of parsed block properties.
[105] Fix | Delete
* @param array $available_context Optional array of ancestry context values.
[106] Fix | Delete
* @param WP_Block_Type_Registry $registry Optional block type registry.
[107] Fix | Delete
*/
[108] Fix | Delete
public function __construct( $block, $available_context = array(), $registry = null ) {
[109] Fix | Delete
$this->parsed_block = $block;
[110] Fix | Delete
$this->name = $block['blockName'];
[111] Fix | Delete
[112] Fix | Delete
if ( is_null( $registry ) ) {
[113] Fix | Delete
$registry = WP_Block_Type_Registry::get_instance();
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
$this->block_type = $registry->get_registered( $this->name );
[117] Fix | Delete
[118] Fix | Delete
$this->available_context = $available_context;
[119] Fix | Delete
[120] Fix | Delete
if ( ! empty( $this->block_type->uses_context ) ) {
[121] Fix | Delete
foreach ( $this->block_type->uses_context as $context_name ) {
[122] Fix | Delete
if ( array_key_exists( $context_name, $this->available_context ) ) {
[123] Fix | Delete
$this->context[ $context_name ] = $this->available_context[ $context_name ];
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( ! empty( $block['innerBlocks'] ) ) {
[129] Fix | Delete
$child_context = $this->available_context;
[130] Fix | Delete
[131] Fix | Delete
if ( ! empty( $this->block_type->provides_context ) ) {
[132] Fix | Delete
foreach ( $this->block_type->provides_context as $context_name => $attribute_name ) {
[133] Fix | Delete
if ( array_key_exists( $attribute_name, $this->attributes ) ) {
[134] Fix | Delete
$child_context[ $context_name ] = $this->attributes[ $attribute_name ];
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
$this->inner_blocks = new WP_Block_List( $block['innerBlocks'], $child_context, $registry );
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
if ( ! empty( $block['innerHTML'] ) ) {
[143] Fix | Delete
$this->inner_html = $block['innerHTML'];
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
if ( ! empty( $block['innerContent'] ) ) {
[147] Fix | Delete
$this->inner_content = $block['innerContent'];
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Returns a value from an inaccessible property.
[153] Fix | Delete
*
[154] Fix | Delete
* This is used to lazily initialize the `attributes` property of a block,
[155] Fix | Delete
* such that it is only prepared with default attributes at the time that
[156] Fix | Delete
* the property is accessed. For all other inaccessible properties, a `null`
[157] Fix | Delete
* value is returned.
[158] Fix | Delete
*
[159] Fix | Delete
* @since 5.5.0
[160] Fix | Delete
*
[161] Fix | Delete
* @param string $name Property name.
[162] Fix | Delete
* @return array|null Prepared attributes, or null.
[163] Fix | Delete
*/
[164] Fix | Delete
public function __get( $name ) {
[165] Fix | Delete
if ( 'attributes' === $name ) {
[166] Fix | Delete
$this->attributes = isset( $this->parsed_block['attrs'] ) ?
[167] Fix | Delete
$this->parsed_block['attrs'] :
[168] Fix | Delete
array();
[169] Fix | Delete
[170] Fix | Delete
if ( ! is_null( $this->block_type ) ) {
[171] Fix | Delete
$this->attributes = $this->block_type->prepare_attributes_for_render( $this->attributes );
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
return $this->attributes;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
return null;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Generates the render output for the block.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 5.5.0
[184] Fix | Delete
*
[185] Fix | Delete
* @param array $options {
[186] Fix | Delete
* Optional options object.
[187] Fix | Delete
*
[188] Fix | Delete
* @type bool $dynamic Defaults to 'true'. Optionally set to false to avoid using the block's render_callback.
[189] Fix | Delete
* }
[190] Fix | Delete
* @return string Rendered block output.
[191] Fix | Delete
*/
[192] Fix | Delete
public function render( $options = array() ) {
[193] Fix | Delete
global $post;
[194] Fix | Delete
$options = wp_parse_args(
[195] Fix | Delete
$options,
[196] Fix | Delete
array(
[197] Fix | Delete
'dynamic' => true,
[198] Fix | Delete
)
[199] Fix | Delete
);
[200] Fix | Delete
[201] Fix | Delete
$is_dynamic = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic();
[202] Fix | Delete
$block_content = '';
[203] Fix | Delete
[204] Fix | Delete
if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
[205] Fix | Delete
$index = 0;
[206] Fix | Delete
foreach ( $this->inner_content as $chunk ) {
[207] Fix | Delete
$block_content .= is_string( $chunk ) ?
[208] Fix | Delete
$chunk :
[209] Fix | Delete
$this->inner_blocks[ $index++ ]->render();
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
if ( $is_dynamic ) {
[214] Fix | Delete
$global_post = $post;
[215] Fix | Delete
$parent = WP_Block_Supports::$block_to_render;
[216] Fix | Delete
[217] Fix | Delete
WP_Block_Supports::$block_to_render = $this->parsed_block;
[218] Fix | Delete
[219] Fix | Delete
$block_content = (string) call_user_func( $this->block_type->render_callback, $this->attributes, $block_content, $this );
[220] Fix | Delete
[221] Fix | Delete
WP_Block_Supports::$block_to_render = $parent;
[222] Fix | Delete
[223] Fix | Delete
$post = $global_post;
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
if ( ! empty( $this->block_type->script ) ) {
[227] Fix | Delete
wp_enqueue_script( $this->block_type->script );
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
if ( ! empty( $this->block_type->style ) ) {
[231] Fix | Delete
wp_enqueue_style( $this->block_type->style );
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Filters the content of a single block.
[236] Fix | Delete
*
[237] Fix | Delete
* @since 5.0.0
[238] Fix | Delete
*
[239] Fix | Delete
* @param string $block_content The block content about to be appended.
[240] Fix | Delete
* @param array $block The full block, including name and attributes.
[241] Fix | Delete
*/
[242] Fix | Delete
$block_content = apply_filters( 'render_block', $block_content, $this->parsed_block );
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Filters the content of a single block.
[246] Fix | Delete
*
[247] Fix | Delete
* The dynamic portion of the hook name, `$name`, refers to
[248] Fix | Delete
* the block name, e.g. "core/paragraph".
[249] Fix | Delete
*
[250] Fix | Delete
* @since 5.7.0
[251] Fix | Delete
*
[252] Fix | Delete
* @param string $block_content The block content about to be appended.
[253] Fix | Delete
* @param array $block The full block, including name and attributes.
[254] Fix | Delete
*/
[255] Fix | Delete
$block_content = apply_filters( "render_block_{$this->name}", $block_content, $this->parsed_block );
[256] Fix | Delete
[257] Fix | Delete
return $block_content;
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function