[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Blocks API: WP_Block class
File Size: | 609 lines (20 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
WP_Block:: (5 methods):
__construct()
__get()
process_block_bindings()
replace_html()
render()
__construct( $block, $available_context = array() X-Ref |
Constructor. Populates object properties from the provided block instance argument. The given array of context values will not necessarily be available on the instance itself, but is treated as the full set of values provided by the block's ancestry. This is assigned to the private `available_context` property. Only values which are configured to consumed by the block via its registered type will be assigned to the block's `context` property. param: array $block { param: array $available_context Optional array of ancestry context values. param: WP_Block_Type_Registry $registry Optional block type registry. |
__get( $name ) X-Ref |
Returns a value from an inaccessible property. This is used to lazily initialize the `attributes` property of a block, such that it is only prepared with default attributes at the time that the property is accessed. For all other inaccessible properties, a `null` value is returned. return: array|null Prepared attributes, or null. param: string $name Property name. |
process_block_bindings() X-Ref |
Processes the block bindings and updates the block attributes with the values from the sources. A block might contain bindings in its attributes. Bindings are mappings between an attribute of the block and a source. A "source" is a function registered with `register_block_bindings_source()` that defines how to retrieve a value from outside the block, e.g. from post meta. This function will process those bindings and update the block's attributes with the values coming from the bindings. ### Example The "bindings" property for an Image block might look like this: ```json { "metadata": { "bindings": { "title": { "source": "core/post-meta", "args": { "key": "text_custom_field" } }, "url": { "source": "core/post-meta", "args": { "key": "url_custom_field" } } } } } ``` The above example will replace the `title` and `url` attributes of the Image block with the values of the `text_custom_field` and `url_custom_field` post meta. return: array The computed block attributes for the provided block bindings. |
replace_html( string $block_content, string $attribute_name, $source_value ) X-Ref |
Depending on the block attribute name, replace its value in the HTML based on the value provided. return: string The modified block content. param: string $block_content Block content. param: string $attribute_name The attribute name to replace. param: mixed $source_value The value used to replace in the HTML. |
render( $options = array() X-Ref |
Generates the render output for the block. return: string Rendered block output. param: array $options { |
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |