wp/wp-includes/class-wp-block.php
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:52:52 +0200
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
permissions -rw-r--r--
Update WordPress to latest version (6.7) - Sync WordPress core files from latest release - Updated admin interface, blocks, and core functionality - Enhanced block editor features and performance - Security updates and bug fixes - Preserved custom wp-content directory and configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Blocks API: WP_Block class
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Class representing a parsed instance of a block.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @property array $attributes
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 */
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    15
#[AllowDynamicProperties]
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
class WP_Block {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	 * Original parsed array representation of block.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	public $parsed_block;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 * Name of block.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @example "core/paragraph"
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 * @var string
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	public $name;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * Block type associated with the instance.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 * @var WP_Block_Type
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	public $block_type;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 * Block context values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	public $context = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 * All available context of the current hierarchy.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 * @access protected
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 */
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    59
	protected $available_context = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    62
	 * Block type registry.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    63
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    64
	 * @since 5.9.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    65
	 * @var WP_Block_Type_Registry
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    66
	 * @access protected
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    67
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    68
	protected $registry;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    69
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    70
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 * List of inner blocks (of this same class)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	 * @since 5.5.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    74
	 * @var WP_Block_List
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	public $inner_blocks = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * Resultant HTML from inside block comment delimiters after removing inner
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 * blocks.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 * @example "...Just <!-- wp:test /--> testing..." -> "Just testing..."
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	 * @var string
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	public $inner_html = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	 * List of string fragments and null markers where inner blocks were found
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	 * @example array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	 *   'inner_html'    => 'BeforeInnerAfter',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	 *   'inner_blocks'  => array( block, block ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	 *   'inner_content' => array( 'Before', null, 'Inner', null, 'After' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	 * )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	public $inner_content = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 * Constructor.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	 * Populates object properties from the provided block instance argument.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 * The given array of context values will not necessarily be available on
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 * the instance itself, but is treated as the full set of values provided by
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 * the block's ancestry. This is assigned to the private `available_context`
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 * property. Only values which are configured to consumed by the block via
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 * its registered type will be assigned to the block's `context` property.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	 *
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   116
	 * @param array                  $block             {
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   117
	 *     An associative array of a single parsed block object. See WP_Block_Parser_Block.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   118
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   119
	 *     @type string   $blockName    Name of block.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   120
	 *     @type array    $attrs        Attributes from block comment delimiters.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   121
	 *     @type array    $innerBlocks  List of inner blocks. An array of arrays that
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   122
	 *                                  have the same structure as this one.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   123
	 *     @type string   $innerHTML    HTML from inside block comment delimiters.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   124
	 *     @type array    $innerContent List of string fragments and null markers where inner blocks were found.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   125
	 * }
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 * @param array                  $available_context Optional array of ancestry context values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	 * @param WP_Block_Type_Registry $registry          Optional block type registry.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	public function __construct( $block, $available_context = array(), $registry = null ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		$this->parsed_block = $block;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		$this->name         = $block['blockName'];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		if ( is_null( $registry ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			$registry = WP_Block_Type_Registry::get_instance();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   137
		$this->registry = $registry;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   138
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		$this->block_type = $registry->get_registered( $this->name );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
		$this->available_context = $available_context;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   143
		$this->refresh_context_dependents();
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   144
	}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   145
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   146
	/**
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   147
	 * Updates the context for the current block and its inner blocks.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   148
	 *
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   149
	 * The method updates the context of inner blocks, if any, by passing down
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   150
	 * any context values the block provides (`provides_context`).
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   151
	 *
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   152
	 * If the block has inner blocks, the method recursively processes them by creating new instances of `WP_Block`
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   153
	 * for each inner block and updating their context based on the block's `provides_context` property.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   154
	 *
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   155
	 * @since 6.8.0
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   156
	 */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   157
	public function refresh_context_dependents() {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   158
		/*
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   159
		 * Merging the `$context` property here is not ideal, but for now needs to happen because of backward compatibility.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   160
		 * Ideally, the `$context` property itself would not be filterable directly and only the `$available_context` would be filterable.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   161
		 * However, this needs to be separately explored whether it's possible without breakage.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   162
		 */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   163
		$this->available_context = array_merge( $this->available_context, $this->context );
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   164
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		if ( ! empty( $this->block_type->uses_context ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
			foreach ( $this->block_type->uses_context as $context_name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
				if ( array_key_exists( $context_name, $this->available_context ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
					$this->context[ $context_name ] = $this->available_context[ $context_name ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
				}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   173
		$this->refresh_parsed_block_dependents();
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   174
	}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   175
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   176
	/**
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   177
	 * Updates the parsed block content for the current block and its inner blocks.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   178
	 *
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   179
	 * This method sets the `inner_html` and `inner_content` properties of the block based on the parsed
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   180
	 * block content provided during initialization. It ensures that the block instance reflects the
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   181
	 * most up-to-date content for both the inner HTML and any string fragments around inner blocks.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   182
	 *
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   183
	 * If the block has inner blocks, this method initializes a new `WP_Block_List` for them, ensuring the
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   184
	 * correct content and context are updated for each nested block.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   185
	 *
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   186
	 * @since 6.8.0
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   187
	 */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   188
	public function refresh_parsed_block_dependents() {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   189
		if ( ! empty( $this->parsed_block['innerBlocks'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
			$child_context = $this->available_context;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			if ( ! empty( $this->block_type->provides_context ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
				foreach ( $this->block_type->provides_context as $context_name => $attribute_name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
					if ( array_key_exists( $attribute_name, $this->attributes ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
						$child_context[ $context_name ] = $this->attributes[ $attribute_name ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
					}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
				}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   200
			$this->inner_blocks = new WP_Block_List( $this->parsed_block['innerBlocks'], $child_context, $this->registry );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   203
		if ( ! empty( $this->parsed_block['innerHTML'] ) ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   204
			$this->inner_html = $this->parsed_block['innerHTML'];
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   207
		if ( ! empty( $this->parsed_block['innerContent'] ) ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   208
			$this->inner_content = $this->parsed_block['innerContent'];
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	 * Returns a value from an inaccessible property.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
	 * This is used to lazily initialize the `attributes` property of a block,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	 * such that it is only prepared with default attributes at the time that
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
	 * the property is accessed. For all other inaccessible properties, a `null`
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	 * value is returned.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
	 * @param string $name Property name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
	 * @return array|null Prepared attributes, or null.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
	public function __get( $name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		if ( 'attributes' === $name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
			$this->attributes = isset( $this->parsed_block['attrs'] ) ?
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
				$this->parsed_block['attrs'] :
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
				array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			if ( ! is_null( $this->block_type ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
				$this->attributes = $this->block_type->prepare_attributes_for_render( $this->attributes );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
			return $this->attributes;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
		return null;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   242
	 * Processes the block bindings and updates the block attributes with the values from the sources.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   243
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   244
	 * A block might contain bindings in its attributes. Bindings are mappings
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   245
	 * between an attribute of the block and a source. A "source" is a function
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   246
	 * registered with `register_block_bindings_source()` that defines how to
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   247
	 * retrieve a value from outside the block, e.g. from post meta.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   248
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   249
	 * This function will process those bindings and update the block's attributes
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   250
	 * with the values coming from the bindings.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   251
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   252
	 * ### Example
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   253
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   254
	 * The "bindings" property for an Image block might look like this:
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   255
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   256
	 * ```json
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   257
	 * {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   258
	 *   "metadata": {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   259
	 *     "bindings": {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   260
	 *       "title": {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   261
	 *         "source": "core/post-meta",
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   262
	 *         "args": { "key": "text_custom_field" }
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   263
	 *       },
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   264
	 *       "url": {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   265
	 *         "source": "core/post-meta",
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   266
	 *         "args": { "key": "url_custom_field" }
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   267
	 *       }
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   268
	 *     }
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   269
	 *   }
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   270
	 * }
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   271
	 * ```
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   272
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   273
	 * The above example will replace the `title` and `url` attributes of the Image
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   274
	 * block with the values of the `text_custom_field` and `url_custom_field` post meta.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   275
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   276
	 * @since 6.5.0
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   277
	 * @since 6.6.0 Handle the `__default` attribute for pattern overrides.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   278
	 * @since 6.7.0 Return any updated bindings metadata in the computed attributes.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   279
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   280
	 * @return array The computed block attributes for the provided block bindings.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   281
	 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   282
	private function process_block_bindings() {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   283
		$parsed_block               = $this->parsed_block;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   284
		$computed_attributes        = array();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   285
		$supported_block_attributes = array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   286
			'core/paragraph' => array( 'content' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   287
			'core/heading'   => array( 'content' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   288
			'core/image'     => array( 'id', 'url', 'title', 'alt' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   289
			'core/button'    => array( 'url', 'text', 'linkTarget', 'rel' ),
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   290
		);
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   291
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   292
		// If the block doesn't have the bindings property, isn't one of the supported
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   293
		// block types, or the bindings property is not an array, return the block content.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   294
		if (
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   295
			! isset( $supported_block_attributes[ $this->name ] ) ||
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   296
			empty( $parsed_block['attrs']['metadata']['bindings'] ) ||
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   297
			! is_array( $parsed_block['attrs']['metadata']['bindings'] )
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   298
		) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   299
			return $computed_attributes;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   300
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   301
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   302
		$bindings = $parsed_block['attrs']['metadata']['bindings'];
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   303
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   304
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   305
		 * If the default binding is set for pattern overrides, replace it
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   306
		 * with a pattern override binding for all supported attributes.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   307
		 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   308
		if (
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   309
			isset( $bindings['__default']['source'] ) &&
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   310
			'core/pattern-overrides' === $bindings['__default']['source']
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   311
		) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   312
			$updated_bindings = array();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   313
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   314
			/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   315
			 * Build a binding array of all supported attributes.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   316
			 * Note that this also omits the `__default` attribute from the
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   317
			 * resulting array.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   318
			 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   319
			foreach ( $supported_block_attributes[ $parsed_block['blockName'] ] as $attribute_name ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   320
				// Retain any non-pattern override bindings that might be present.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   321
				$updated_bindings[ $attribute_name ] = isset( $bindings[ $attribute_name ] )
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   322
					? $bindings[ $attribute_name ]
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   323
					: array( 'source' => 'core/pattern-overrides' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   324
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   325
			$bindings = $updated_bindings;
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   326
			/*
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   327
			 * Update the bindings metadata of the computed attributes.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   328
			 * This ensures the block receives the expanded __default binding metadata when it renders.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   329
			 */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   330
			$computed_attributes['metadata'] = array_merge(
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   331
				$parsed_block['attrs']['metadata'],
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   332
				array( 'bindings' => $bindings )
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   333
			);
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   334
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   335
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   336
		foreach ( $bindings as $attribute_name => $block_binding ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   337
			// If the attribute is not in the supported list, process next attribute.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   338
			if ( ! in_array( $attribute_name, $supported_block_attributes[ $this->name ], true ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   339
				continue;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   340
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   341
			// If no source is provided, or that source is not registered, process next attribute.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   342
			if ( ! isset( $block_binding['source'] ) || ! is_string( $block_binding['source'] ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   343
				continue;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   344
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   345
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   346
			$block_binding_source = get_block_bindings_source( $block_binding['source'] );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   347
			if ( null === $block_binding_source ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   348
				continue;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   349
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   350
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   351
			// Adds the necessary context defined by the source.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   352
			if ( ! empty( $block_binding_source->uses_context ) ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   353
				foreach ( $block_binding_source->uses_context as $context_name ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   354
					if ( array_key_exists( $context_name, $this->available_context ) ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   355
						$this->context[ $context_name ] = $this->available_context[ $context_name ];
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   356
					}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   357
				}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   358
			}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   359
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   360
			$source_args  = ! empty( $block_binding['args'] ) && is_array( $block_binding['args'] ) ? $block_binding['args'] : array();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   361
			$source_value = $block_binding_source->get_value( $source_args, $this, $attribute_name );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   362
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   363
			// If the value is not null, process the HTML based on the block and the attribute.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   364
			if ( ! is_null( $source_value ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   365
				$computed_attributes[ $attribute_name ] = $source_value;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   366
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   367
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   368
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   369
		return $computed_attributes;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   370
	}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   371
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   372
	/**
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   373
	 * Depending on the block attribute name, replace its value in the HTML based on the value provided.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   374
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   375
	 * @since 6.5.0
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   376
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   377
	 * @param string $block_content  Block content.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   378
	 * @param string $attribute_name The attribute name to replace.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   379
	 * @param mixed  $source_value   The value used to replace in the HTML.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   380
	 * @return string The modified block content.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   381
	 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   382
	private function replace_html( string $block_content, string $attribute_name, $source_value ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   383
		$block_type = $this->block_type;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   384
		if ( ! isset( $block_type->attributes[ $attribute_name ]['source'] ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   385
			return $block_content;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   386
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   387
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   388
		// Depending on the attribute source, the processing will be different.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   389
		switch ( $block_type->attributes[ $attribute_name ]['source'] ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   390
			case 'html':
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   391
			case 'rich-text':
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   392
				$block_reader = new WP_HTML_Tag_Processor( $block_content );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   393
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   394
				// TODO: Support for CSS selectors whenever they are ready in the HTML API.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   395
				// In the meantime, support comma-separated selectors by exploding them into an array.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   396
				$selectors = explode( ',', $block_type->attributes[ $attribute_name ]['selector'] );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   397
				// Add a bookmark to the first tag to be able to iterate over the selectors.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   398
				$block_reader->next_tag();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   399
				$block_reader->set_bookmark( 'iterate-selectors' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   400
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   401
				// TODO: This shouldn't be needed when the `set_inner_html` function is ready.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   402
				// Store the parent tag and its attributes to be able to restore them later in the button.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   403
				// The button block has a wrapper while the paragraph and heading blocks don't.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   404
				if ( 'core/button' === $this->name ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   405
					$button_wrapper                 = $block_reader->get_tag();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   406
					$button_wrapper_attribute_names = $block_reader->get_attribute_names_with_prefix( '' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   407
					$button_wrapper_attrs           = array();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   408
					foreach ( $button_wrapper_attribute_names as $name ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   409
						$button_wrapper_attrs[ $name ] = $block_reader->get_attribute( $name );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   410
					}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   411
				}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   412
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   413
				foreach ( $selectors as $selector ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   414
					// If the parent tag, or any of its children, matches the selector, replace the HTML.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   415
					if ( strcasecmp( $block_reader->get_tag(), $selector ) === 0 || $block_reader->next_tag(
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   416
						array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   417
							'tag_name' => $selector,
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   418
						)
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   419
					) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   420
						$block_reader->release_bookmark( 'iterate-selectors' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   421
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   422
						// TODO: Use `set_inner_html` method whenever it's ready in the HTML API.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   423
						// Until then, it is hardcoded for the paragraph, heading, and button blocks.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   424
						// Store the tag and its attributes to be able to restore them later.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   425
						$selector_attribute_names = $block_reader->get_attribute_names_with_prefix( '' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   426
						$selector_attrs           = array();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   427
						foreach ( $selector_attribute_names as $name ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   428
							$selector_attrs[ $name ] = $block_reader->get_attribute( $name );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   429
						}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   430
						$selector_markup = "<$selector>" . wp_kses_post( $source_value ) . "</$selector>";
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   431
						$amended_content = new WP_HTML_Tag_Processor( $selector_markup );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   432
						$amended_content->next_tag();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   433
						foreach ( $selector_attrs as $attribute_key => $attribute_value ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   434
							$amended_content->set_attribute( $attribute_key, $attribute_value );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   435
						}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   436
						if ( 'core/paragraph' === $this->name || 'core/heading' === $this->name ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   437
							return $amended_content->get_updated_html();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   438
						}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   439
						if ( 'core/button' === $this->name ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   440
							$button_markup  = "<$button_wrapper>{$amended_content->get_updated_html()}</$button_wrapper>";
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   441
							$amended_button = new WP_HTML_Tag_Processor( $button_markup );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   442
							$amended_button->next_tag();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   443
							foreach ( $button_wrapper_attrs as $attribute_key => $attribute_value ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   444
								$amended_button->set_attribute( $attribute_key, $attribute_value );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   445
							}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   446
							return $amended_button->get_updated_html();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   447
						}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   448
					} else {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   449
						$block_reader->seek( 'iterate-selectors' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   450
					}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   451
				}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   452
				$block_reader->release_bookmark( 'iterate-selectors' );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   453
				return $block_content;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   454
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   455
			case 'attribute':
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   456
				$amended_content = new WP_HTML_Tag_Processor( $block_content );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   457
				if ( ! $amended_content->next_tag(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   458
					array(
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   459
						// TODO: build the query from CSS selector.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   460
						'tag_name' => $block_type->attributes[ $attribute_name ]['selector'],
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   461
					)
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   462
				) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   463
					return $block_content;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   464
				}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   465
				$amended_content->set_attribute( $block_type->attributes[ $attribute_name ]['attribute'], $source_value );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   466
				return $amended_content->get_updated_html();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   467
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   468
			default:
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   469
				return $block_content;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   470
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   471
	}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   472
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   473
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   474
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	 * Generates the render output for the block.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	 * @since 5.5.0
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   478
	 * @since 6.5.0 Added block bindings processing.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   479
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   480
	 * @global WP_Post $post Global post object.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	 * @param array $options {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   483
	 *     Optional options object.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   485
	 *     @type bool $dynamic Defaults to 'true'. Optionally set to false to avoid using the block's render_callback.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	 * }
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	 * @return string Rendered block output.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	public function render( $options = array() ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
		global $post;
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   491
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   492
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   493
		 * There can be only one root interactive block at a time because the rendered HTML of that block contains
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   494
		 * the rendered HTML of all its inner blocks, including any interactive block.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   495
		 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   496
		static $root_interactive_block = null;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   497
		/**
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   498
		 * Filters whether Interactivity API should process directives.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   499
		 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   500
		 * @since 6.6.0
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   501
		 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   502
		 * @param bool $enabled Whether the directives processing is enabled.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   503
		 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   504
		$interactivity_process_directives_enabled = apply_filters( 'interactivity_process_directives', true );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   505
		if (
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   506
			$interactivity_process_directives_enabled && null === $root_interactive_block && (
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   507
				( isset( $this->block_type->supports['interactivity'] ) && true === $this->block_type->supports['interactivity'] ) ||
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   508
				! empty( $this->block_type->supports['interactivity']['interactive'] )
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   509
			)
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   510
		) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   511
			$root_interactive_block = $this;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   512
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   513
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
		$options = wp_parse_args(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
			$options,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
			array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
				'dynamic' => true,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
			)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   521
		// Process the block bindings and get attributes updated with the values from the sources.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   522
		$computed_attributes = $this->process_block_bindings();
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   523
		if ( ! empty( $computed_attributes ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   524
			// Merge the computed attributes with the original attributes.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   525
			$this->attributes = array_merge( $this->attributes, $computed_attributes );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   526
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   527
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
		$is_dynamic    = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
		$block_content = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
		if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
			$index = 0;
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   533
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
			foreach ( $this->inner_content as $chunk ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   535
				if ( is_string( $chunk ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   536
					$block_content .= $chunk;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   537
				} else {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   538
					$inner_block  = $this->inner_blocks[ $index ];
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   539
					$parent_block = $this;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   540
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   541
					/** This filter is documented in wp-includes/blocks.php */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   542
					$pre_render = apply_filters( 'pre_render_block', null, $inner_block->parsed_block, $parent_block );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   543
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   544
					if ( ! is_null( $pre_render ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   545
						$block_content .= $pre_render;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   546
					} else {
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   547
						$source_block        = $inner_block->parsed_block;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   548
						$inner_block_context = $inner_block->context;
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   549
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   550
						/** This filter is documented in wp-includes/blocks.php */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   551
						$inner_block->parsed_block = apply_filters( 'render_block_data', $inner_block->parsed_block, $source_block, $parent_block );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   552
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   553
						/** This filter is documented in wp-includes/blocks.php */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   554
						$inner_block->context = apply_filters( 'render_block_context', $inner_block->context, $inner_block->parsed_block, $parent_block );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   555
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   556
						/*
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   557
						 * The `refresh_context_dependents()` method already calls `refresh_parsed_block_dependents()`.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   558
						 * Therefore the second condition is irrelevant if the first one is satisfied.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   559
						 */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   560
						if ( $inner_block->context !== $inner_block_context ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   561
							$inner_block->refresh_context_dependents();
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   562
						} elseif ( $inner_block->parsed_block !== $source_block ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   563
							$inner_block->refresh_parsed_block_dependents();
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   564
						}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   565
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   566
						$block_content .= $inner_block->render();
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   567
					}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   568
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   569
					++$index;
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   570
				}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   574
		if ( ! empty( $computed_attributes ) && ! empty( $block_content ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   575
			foreach ( $computed_attributes as $attribute_name => $source_value ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   576
				$block_content = $this->replace_html( $block_content, $attribute_name, $source_value );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   577
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   578
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   579
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		if ( $is_dynamic ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   581
			$global_post = $post;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   582
			$parent      = WP_Block_Supports::$block_to_render;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   583
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   584
			WP_Block_Supports::$block_to_render = $this->parsed_block;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   585
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
			$block_content = (string) call_user_func( $this->block_type->render_callback, $this->attributes, $block_content, $this );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   587
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   588
			WP_Block_Supports::$block_to_render = $parent;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   589
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   590
			$post = $global_post;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   593
		if ( ( ! empty( $this->block_type->script_handles ) ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   594
			foreach ( $this->block_type->script_handles as $script_handle ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   595
				wp_enqueue_script( $script_handle );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   596
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   597
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   598
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   599
		if ( ! empty( $this->block_type->view_script_handles ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   600
			foreach ( $this->block_type->view_script_handles as $view_script_handle ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   601
				wp_enqueue_script( $view_script_handle );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   602
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   605
		if ( ! empty( $this->block_type->view_script_module_ids ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   606
			foreach ( $this->block_type->view_script_module_ids as $view_script_module_id ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   607
				wp_enqueue_script_module( $view_script_module_id );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   608
			}
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   609
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   610
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   611
		/*
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   612
		 * For Core blocks, these styles are only enqueued if `wp_should_load_separate_core_block_assets()` returns
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   613
		 * true. Otherwise these `wp_enqueue_style()` calls will not have any effect, as the Core blocks are relying on
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   614
		 * the combined 'wp-block-library' stylesheet instead, which is unconditionally enqueued.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   615
		 */
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   616
		if ( ( ! empty( $this->block_type->style_handles ) ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   617
			foreach ( $this->block_type->style_handles as $style_handle ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   618
				wp_enqueue_style( $style_handle );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   619
			}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   620
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   621
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   622
		if ( ( ! empty( $this->block_type->view_style_handles ) ) ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   623
			foreach ( $this->block_type->view_style_handles as $view_style_handle ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   624
				wp_enqueue_style( $view_style_handle );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   625
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
		/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		 * Filters the content of a single block.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
		 * @since 5.0.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   632
		 * @since 5.9.0 The `$instance` parameter was added.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		 *
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   634
		 * @param string   $block_content The block content.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   635
		 * @param array    $block         The full block, including name and attributes.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   636
		 * @param WP_Block $instance      The block instance.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   638
		$block_content = apply_filters( 'render_block', $block_content, $this->parsed_block, $this );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   639
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   640
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   641
		 * Filters the content of a single block.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   642
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   643
		 * The dynamic portion of the hook name, `$name`, refers to
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   644
		 * the block name, e.g. "core/paragraph".
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   645
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   646
		 * @since 5.7.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   647
		 * @since 5.9.0 The `$instance` parameter was added.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   648
		 *
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   649
		 * @param string   $block_content The block content.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   650
		 * @param array    $block         The full block, including name and attributes.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   651
		 * @param WP_Block $instance      The block instance.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   652
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   653
		$block_content = apply_filters( "render_block_{$this->name}", $block_content, $this->parsed_block, $this );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   654
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   655
		if ( $root_interactive_block === $this ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   656
			// The root interactive block has finished rendering. Time to process directives.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   657
			$block_content          = wp_interactivity_process_directives( $block_content );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   658
			$root_interactive_block = null;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   659
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   660
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   661
		return $block_content;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
}