[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Functions related to registering and parsing blocks.
File Size: | 2835 lines (105 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
remove_block_asset_path_prefix( $asset_handle_or_path ) X-Ref |
Removes the block asset's path prefix if provided. param: string $asset_handle_or_path Asset handle or prefixed path. return: string Path without the prefix or the original value. |
generate_block_asset_handle( $block_name, $field_name, $index = 0 ) X-Ref |
Generates the name for an asset based on the name of the block and the field name provided. param: string $block_name Name of the block. param: string $field_name Name of the metadata field. param: int $index Optional. Index of the asset when multiple items passed. return: string Generated asset name for the block's field. |
get_block_asset_url( $path ) X-Ref |
Gets the URL to a block asset. param: string $path A normalized path to a block asset. return: string|false The URL to the block asset or false on failure. |
register_block_script_module_id( $metadata, $field_name, $index = 0 ) X-Ref |
Finds a script module ID for the selected block metadata field. It detects when a path to file was provided and optionally finds a corresponding asset file with details necessary to register the script module under with an automatically generated module ID. It returns unprocessed script module ID otherwise. param: array $metadata Block metadata. param: string $field_name Field name to pick from metadata. param: int $index Optional. Index of the script module ID to register when multiple return: string|false Script module ID or false on failure. |
register_block_script_handle( $metadata, $field_name, $index = 0 ) X-Ref |
Finds a script handle for the selected block metadata field. It detects when a path to file was provided and optionally finds a corresponding asset file with details necessary to register the script under automatically generated handle name. It returns unprocessed script handle otherwise. param: array $metadata Block metadata. param: string $field_name Field name to pick from metadata. param: int $index Optional. Index of the script to register when multiple items passed. return: string|false Script handle provided directly or created through |
register_block_style_handle( $metadata, $field_name, $index = 0 ) X-Ref |
Finds a style handle for the block metadata field. It detects when a path to file was provided and registers the style under automatically generated handle name. It returns unprocessed style handle otherwise. param: array $metadata Block metadata. param: string $field_name Field name to pick from metadata. param: int $index Optional. Index of the style to register when multiple items passed. return: string|false Style handle provided directly or created through |
get_block_metadata_i18n_schema() X-Ref |
Gets i18n schema for block's metadata read from `block.json` file. return: object The schema for block's metadata. |
wp_register_block_metadata_collection( $path, $manifest ) X-Ref |
Registers a block metadata collection. This function allows core and third-party plugins to register their block metadata collections in a centralized location. Registering collections can improve performance by avoiding multiple reads from the filesystem and parsing JSON. param: string $path The base path in which block files for the collection reside. param: string $manifest The path to the manifest file for the collection. |
register_block_type_from_metadata( $file_or_folder, $args = array() X-Ref |
Registers a block type from the metadata stored in the `block.json` file. param: string $file_or_folder Path to the JSON file with metadata definition for param: array $args Optional. Array of block type arguments. Accepts any public property return: WP_Block_Type|false The registered block type on success, or false on failure. |
register_block_type( $block_type, $args = array() X-Ref |
Registers a block type. The recommended way is to register a block type using the metadata stored in the `block.json` file. param: string|WP_Block_Type $block_type Block type name including namespace, or alternatively param: array $args Optional. Array of block type arguments. Accepts any public property return: WP_Block_Type|false The registered block type on success, or false on failure. |
unregister_block_type( $name ) X-Ref |
Unregisters a block type. param: string|WP_Block_Type $name Block type name including namespace, or alternatively return: WP_Block_Type|false The unregistered block type on success, or false on failure. |
has_blocks( $post = null ) X-Ref |
Determines whether a post or content string has blocks. This test optimizes for performance rather than strict accuracy, detecting the pattern of a block but not validating its structure. For strict accuracy, you should use the block parser on post content. param: int|string|WP_Post|null $post Optional. Post content, post ID, or post object. return: bool Whether the post has blocks. |
has_block( $block_name, $post = null ) X-Ref |
Determines whether a $post or a string contains a specific block type. This test optimizes for performance rather than strict accuracy, detecting whether the block type exists but not validating its structure and not checking synced patterns (formerly called reusable blocks). For strict accuracy, you should use the block parser on post content. param: string $block_name Full block type to look for. param: int|string|WP_Post|null $post Optional. Post content, post ID, or post object. return: bool Whether the post content contains the specified block. |
get_dynamic_block_names() X-Ref |
Returns an array of the names of all registered dynamic block types. return: string[] Array of dynamic block names. |
get_hooked_blocks() X-Ref |
Retrieves block types hooked into the given block, grouped by anchor block type and the relative position. return: array[] Array of block types grouped by anchor block type and the relative position. |
insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) X-Ref |
Returns the markup for blocks hooked to the given anchor block in a specific relative position. param: array $parsed_anchor_block The anchor block, in parsed block array format. param: string $relative_position The relative position of the hooked blocks. param: array $hooked_blocks An array of hooked block types, grouped by anchor block and relative position. param: WP_Block_Template|WP_Post|array $context The block template, template part, or pattern that the anchor block belongs to. return: string |
set_ignored_hooked_blocks_metadata( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) X-Ref |
Adds a list of hooked block types to an anchor block's ignored hooked block types. This function is meant for internal use only. param: array $parsed_anchor_block The anchor block, in parsed block array format. param: string $relative_position The relative position of the hooked blocks. param: array $hooked_blocks An array of hooked block types, grouped by anchor block and relative position. param: WP_Block_Template|WP_Post|array $context The block template, template part, or pattern that the anchor block belongs to. return: string Empty string. |
apply_block_hooks_to_content( $content, $context, $callback = 'insert_hooked_blocks' ) X-Ref |
Runs the hooked blocks algorithm on the given content. param: string $content Serialized content. param: WP_Block_Template|WP_Post|array $context A block template, template part, `wp_navigation` post object, param: callable $callback A function that will be called for each block to generate return: string The serialized markup. |
remove_serialized_parent_block( $serialized_block ) X-Ref |
Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the inner blocks. param: string $serialized_block The serialized markup of a block and its inner blocks. return: string The serialized markup of the inner blocks. |
extract_serialized_parent_block( $serialized_block ) X-Ref |
Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the wrapper block. param: string $serialized_block The serialized markup of a block and its inner blocks. return: string The serialized markup of the wrapper block. |
update_ignored_hooked_blocks_postmeta( $post ) X-Ref |
Updates the wp_postmeta with the list of ignored hooked blocks where the inner blocks are stored as post content. Currently only supports `wp_navigation` post types. param: stdClass $post Post object. return: stdClass The updated post object. |
insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) X-Ref |
Returns the markup for blocks hooked to the given anchor block in a specific relative position and then adds a list of hooked block types to an anchor block's ignored hooked block types. This function is meant for internal use only. param: array $parsed_anchor_block The anchor block, in parsed block array format. param: string $relative_position The relative position of the hooked blocks. param: array $hooked_blocks An array of hooked block types, grouped by anchor block and relative position. param: WP_Block_Template|WP_Post|array $context The block template, template part, or pattern that the anchor block belongs to. return: string |
insert_hooked_blocks_into_rest_response( $response, $post ) X-Ref |
Hooks into the REST API response for the core/navigation block and adds the first and last inner blocks. param: WP_REST_Response $response The response object. param: WP_Post $post Post object. return: WP_REST_Response The response object. |
make_before_block_visitor( $hooked_blocks, $context, $callback = 'insert_hooked_blocks' ) X-Ref |
Returns a function that injects the theme attribute into, and hooked blocks before, a given block. The returned function can be used as `$pre_callback` argument to `traverse_and_serialize_block(s)`, where it will inject the `theme` attribute into all Template Part blocks, and prepend the markup for any blocks hooked `before` the given block and as its parent's `first_child`, respectively. This function is meant for internal use only. param: array $hooked_blocks An array of blocks hooked to another given block. param: WP_Block_Template|WP_Post|array $context A block template, template part, `wp_navigation` post object, param: callable $callback A function that will be called for each block to generate return: callable A function that returns the serialized markup for the given block, |
make_after_block_visitor( $hooked_blocks, $context, $callback = 'insert_hooked_blocks' ) X-Ref |
Returns a function that injects the hooked blocks after a given block. The returned function can be used as `$post_callback` argument to `traverse_and_serialize_block(s)`, where it will append the markup for any blocks hooked `after` the given block and as its parent's `last_child`, respectively. This function is meant for internal use only. param: array $hooked_blocks An array of blocks hooked to another block. param: WP_Block_Template|WP_Post|array $context A block template, template part, `wp_navigation` post object, param: callable $callback A function that will be called for each block to generate return: callable A function that returns the serialized markup for the given block, |
serialize_block_attributes( $block_attributes ) X-Ref |
Given an array of attributes, returns a string in the serialized attributes format prepared for post content. The serialized result is a JSON-encoded string, with unicode escape sequence substitution for characters which might otherwise interfere with embedding the result in an HTML comment. This function must produce output that remains in sync with the output of the serializeAttributes JavaScript function in the block editor in order to ensure consistent operation between PHP and JavaScript. param: array $block_attributes Attributes object. return: string Serialized attributes. |
strip_core_block_namespace( $block_name = null ) X-Ref |
Returns the block name to use for serialization. This will remove the default "core/" namespace from a block name. param: string|null $block_name Optional. Original block name. Null if the block name is unknown, return: string Block name to use for serialization. |
get_comment_delimited_block_content( $block_name, $block_attributes, $block_content ) X-Ref |
Returns the content of a block, including comment delimiters. param: string|null $block_name Block name. Null if the block name is unknown, param: array $block_attributes Block attributes. param: string $block_content Block save content. return: string Comment-delimited block content. |
serialize_block( $block ) X-Ref |
Returns the content of a block, including comment delimiters, serializing all attributes from the given parsed block. This should be used when preparing a block to be saved to post content. Prefer `render_block` when preparing a block for display. Unlike `render_block`, this does not evaluate a block's `render_callback`, and will instead preserve the markup as parsed. param: array $block { return: string String of rendered HTML. |
serialize_blocks( $blocks ) X-Ref |
Returns a joined string of the aggregate serialization of the given parsed blocks. param: array[] $blocks { return: string String of rendered HTML. |
traverse_and_serialize_block( $block, $pre_callback = null, $post_callback = null ) X-Ref |
Traverses a parsed block tree and applies callbacks before and after serializing it. Recursively traverses the block and its inner blocks and applies the two callbacks provided as arguments, the first one before serializing the block, and the second one after serializing it. If either callback returns a string value, it will be prepended and appended to the serialized block markup, respectively. The callbacks will receive a reference to the current block as their first argument, so that they can also modify it, and the current block's parent block as second argument. Finally, the `$pre_callback` receives the previous block, whereas the `$post_callback` receives the next block as third argument. Serialized blocks are returned including comment delimiters, and with all attributes serialized. This function should be used when there is a need to modify the saved block, or to inject markup into the return value. Prefer `serialize_block` when preparing a block to be saved to post content. This function is meant for internal use only. param: array $block An associative array of a single parsed block object. See WP_Block_Parser_Block. param: callable $pre_callback Callback to run on each block in the tree before it is traversed and serialized. param: callable $post_callback Callback to run on each block in the tree after it is traversed and serialized. return: string Serialized block markup. |
resolve_pattern_blocks( $blocks ) X-Ref |
Replaces patterns in a block tree with their content. param: array $blocks An array blocks. return: array An array of blocks with patterns replaced by their content. |
traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_callback = null ) X-Ref |
Given an array of parsed block trees, applies callbacks before and after serializing them and returns their concatenated output. Recursively traverses the blocks and their inner blocks and applies the two callbacks provided as arguments, the first one before serializing a block, and the second one after serializing. If either callback returns a string value, it will be prepended and appended to the serialized block markup, respectively. The callbacks will receive a reference to the current block as their first argument, so that they can also modify it, and the current block's parent block as second argument. Finally, the `$pre_callback` receives the previous block, whereas the `$post_callback` receives the next block as third argument. Serialized blocks are returned including comment delimiters, and with all attributes serialized. This function should be used when there is a need to modify the saved blocks, or to inject markup into the return value. Prefer `serialize_blocks` when preparing blocks to be saved to post content. This function is meant for internal use only. param: array[] $blocks An array of parsed blocks. See WP_Block_Parser_Block. param: callable $pre_callback Callback to run on each block in the tree before it is traversed and serialized. param: callable $post_callback Callback to run on each block in the tree after it is traversed and serialized. return: string Serialized block markup. |
filter_block_content( $text, $allowed_html = 'post', $allowed_protocols = array() X-Ref |
Filters and sanitizes block content to remove non-allowable HTML from parsed block attribute values. param: string $text Text that may contain block content. param: array[]|string $allowed_html Optional. An array of allowed HTML elements and attributes, param: string[] $allowed_protocols Optional. Array of allowed URL protocols. return: string The filtered and sanitized content result. |
_filter_block_content_callback( $matches ) X-Ref |
Callback used for regular expression replacement in filter_block_content(). param: array $matches Array of preg_replace_callback matches. return: string Replacement string. |
filter_block_kses( $block, $allowed_html, $allowed_protocols = array() X-Ref |
Filters and sanitizes a parsed block to remove non-allowable HTML from block attribute values. param: WP_Block_Parser_Block $block The parsed block object. param: array[]|string $allowed_html An array of allowed HTML elements and attributes, param: string[] $allowed_protocols Optional. Array of allowed URL protocols. return: array The filtered and sanitized block object result. |
filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array() X-Ref |
Filters and sanitizes a parsed block attribute value to remove non-allowable HTML. param: string[]|string $value The attribute value to filter. param: array[]|string $allowed_html An array of allowed HTML elements and attributes, param: string[] $allowed_protocols Optional. Array of allowed URL protocols. param: array $block_context Optional. The block the attribute belongs to, in parsed block array format. return: string[]|string The filtered and sanitized result. |
filter_block_core_template_part_attributes( $attribute_value, $attribute_name, $allowed_html ) X-Ref |
Sanitizes the value of the Template Part block's `tagName` attribute. param: string $attribute_value The attribute value to filter. param: string $attribute_name The attribute name. param: array[]|string $allowed_html An array of allowed HTML elements and attributes, return: string The sanitized attribute value. |
excerpt_remove_blocks( $content ) X-Ref |
Parses blocks out of a content string, and renders those appropriate for the excerpt. As the excerpt should be a small string of text relevant to the full post content, this function renders the blocks that are most likely to contain such text. param: string $content The content to parse. return: string The parsed and filtered content. |
excerpt_remove_footnotes( $content ) X-Ref |
Parses footnotes markup out of a content string, and renders those appropriate for the excerpt. param: string $content The content to parse. return: string The parsed and filtered content. |
_excerpt_render_inner_blocks( $parsed_block, $allowed_blocks ) X-Ref |
Renders inner blocks from the allowed wrapper blocks for generating an excerpt. param: array $parsed_block The parsed block. param: array $allowed_blocks The list of allowed inner blocks. return: string The rendered inner blocks. |
render_block( $parsed_block ) X-Ref |
Renders a single block into a HTML string. param: array $parsed_block { return: string String of rendered HTML. |
parse_blocks( $content ) X-Ref |
Parses blocks out of a content string. param: string $content Post content. return: array[] { |
do_blocks( $content ) X-Ref |
Parses dynamic blocks out of `post_content` and re-renders them. param: string $content Post content. return: string Updated post content. |
_restore_wpautop_hook( $content ) X-Ref |
If do_blocks() needs to remove wpautop() from the `the_content` filter, this re-adds it afterwards, for subsequent `the_content` usage. param: string $content The post content running through this filter. return: string The unmodified content. |
block_version( $content ) X-Ref |
Returns the current version of the block format that the content string is using. If the string doesn't contain blocks, it returns 0. param: string $content Content to test. return: int The block format version is 1 if the content contains one or more blocks, 0 otherwise. |
register_block_style( $block_name, $style_properties ) X-Ref |
Registers a new block style. param: string|string[] $block_name Block type name including namespace or array of namespaced block type names. param: array $style_properties Array containing the properties of the style name, label, return: bool True if the block style was registered with success and false otherwise. |
unregister_block_style( $block_name, $block_style_name ) X-Ref |
Unregisters a block style. param: string $block_name Block type name including namespace. param: string $block_style_name Block style name. return: bool True if the block style was unregistered with success and false otherwise. |
block_has_support( $block_type, $feature, $default_value = false ) X-Ref |
Checks whether the current block type supports the feature requested. param: WP_Block_Type $block_type Block type to check for support. param: string|array $feature Feature slug, or path to a specific feature to check support for. param: mixed $default_value Optional. Fallback value for feature support. Default false. return: bool Whether the feature is supported. |
wp_migrate_old_typography_shape( $metadata ) X-Ref |
Converts typography keys declared under `supports.*` to `supports.typography.*`. Displays a `_doing_it_wrong()` notice when a block using the older format is detected. param: array $metadata Metadata for registering a block type. return: array Filtered metadata for registering a block type. |
build_query_vars_from_query_block( $block, $page ) X-Ref |
Helper function that constructs a WP_Query args array from a `Query` block properties. It's used in Query Loop, Query Pagination Numbers and Query Pagination Next blocks. param: WP_Block $block Block instance. param: int $page Current query's page. return: array Returns the constructed WP_Query arguments. |
get_query_pagination_arrow( $block, $is_next ) X-Ref |
No description |
build_comment_query_vars_from_block( $block ) X-Ref |
Helper function that constructs a comment query vars array from the passed block properties. It's used with the Comment Query Loop inner blocks. param: WP_Block $block Block instance. return: array Returns the comment query parameters to use with the |
get_comments_pagination_arrow( $block, $pagination_type = 'next' ) X-Ref |
Helper function that returns the proper pagination arrow HTML for `CommentsPaginationNext` and `CommentsPaginationPrevious` blocks based on the provided `paginationArrow` from `CommentsPagination` context. It's used in CommentsPaginationNext and CommentsPaginationPrevious blocks. param: WP_Block $block Block instance. param: string $pagination_type Optional. Type of the arrow we will be rendering. return: string|null The pagination arrow HTML or null if there is none. |
_wp_filter_post_meta_footnotes( $footnotes ) X-Ref |
Strips all HTML from the content of footnotes, and sanitizes the ID. This function expects slashed data on the footnotes content. param: string $footnotes JSON-encoded string of an array containing the content and ID of each footnote. return: string Filtered content without any HTML on the footnote content and with the sanitized ID. |
_wp_footnotes_kses_init_filters() X-Ref |
Adds the filters for footnotes meta field. |
_wp_footnotes_remove_filters() X-Ref |
Removes the filters for footnotes meta field. |
_wp_footnotes_kses_init() X-Ref |
Registers the filter of footnotes meta field if the user does not have `unfiltered_html` capability. |
_wp_footnotes_force_filtered_html_on_import_filter( $arg ) X-Ref |
Initializes the filters for footnotes meta field when imported data should be filtered. This filter is the last one being executed on {@see 'force_filtered_html_on_import'}. If the input of the filter is true, it means we are in an import situation and should enable kses, independently of the user capabilities. So in that case we call _wp_footnotes_kses_init_filters(). param: string $arg Input argument of the filter. return: string Input argument of the filter. |
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |