[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> blocks.php (summary)

Functions related to registering and parsing blocks.

File Size: 1330 lines (43 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 34 functions

  remove_block_asset_path_prefix()
  generate_block_asset_handle()
  register_block_script_handle()
  register_block_style_handle()
  get_block_metadata_i18n_schema()
  register_block_type_from_metadata()
  register_block_type()
  unregister_block_type()
  has_blocks()
  has_block()
  get_dynamic_block_names()
  serialize_block_attributes()
  strip_core_block_namespace()
  get_comment_delimited_block_content()
  serialize_block()
  serialize_blocks()
  filter_block_content()
  filter_block_kses()
  filter_block_kses_value()
  excerpt_remove_blocks()
  _excerpt_render_inner_blocks()
  render_block()
  parse_blocks()
  do_blocks()
  _restore_wpautop_hook()
  block_version()
  register_block_style()
  unregister_block_style()
  block_has_support()
  wp_migrate_old_typography_shape()
  build_query_vars_from_query_block()
  get_query_pagination_arrow()
  wp_enqueue_block_style()
  _wp_multiple_block_styles()

Functions
Functions that are not part of a class:

remove_block_asset_path_prefix( $asset_handle_or_path )   X-Ref
Removes the block asset's path prefix if provided.

since: 5.5.0
return: string Path without the prefix or the original value.
param: string $asset_handle_or_path Asset handle or prefixed path.

generate_block_asset_handle( $block_name, $field_name )   X-Ref
Generates the name for an asset based on the name of the block
and the field name provided.

since: 5.5.0
return: string Generated asset name for the block's field.
param: string $block_name Name of the block.
param: string $field_name Name of the metadata field.

register_block_script_handle( $metadata, $field_name )   X-Ref
Finds a script handle for the selected block metadata field. It detects
when a path to file was provided and finds a corresponding asset file
with details necessary to register the script under automatically
generated handle name. It returns unprocessed script handle otherwise.

since: 5.5.0
return: string|false Script handle provided directly or created through
param: array  $metadata   Block metadata.
param: string $field_name Field name to pick from metadata.

register_block_style_handle( $metadata, $field_name )   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.

since: 5.5.0
return: string|false Style handle provided directly or created through
param: array  $metadata   Block metadata.
param: string $field_name Field name to pick from metadata.

get_block_metadata_i18n_schema()   X-Ref
Gets i18n schema for block's metadata read from `block.json` file.

since: 5.9.0
return: array The schema for block's metadata.

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.

since: 5.5.0
since: 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields.
since: 5.9.0 Added support for `variations` and `viewScript` fields.
return: WP_Block_Type|false The registered block type on success, or false on failure.
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

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.

since: 5.0.0
since: 5.8.0 First parameter now accepts a path to the `block.json` file.
return: WP_Block_Type|false The registered block type on success, or false on failure.
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

unregister_block_type( $name )   X-Ref
Unregisters a block type.

since: 5.0.0
return: WP_Block_Type|false The unregistered block type on success, or false on failure.
param: string|WP_Block_Type $name Block type name including namespace, or alternatively

has_blocks( $post = null )   X-Ref
Determine 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.

since: 5.0.0
return: bool Whether the post has blocks.
param: int|string|WP_Post|null $post Optional. Post content, post ID, or post object.

has_block( $block_name, $post = null )   X-Ref
Determine 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
reusable blocks. For strict accuracy, you should use the block parser on post content.

since: 5.0.0
return: bool Whether the post content contains the specified block.
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.

get_dynamic_block_names()   X-Ref
Returns an array of the names of all registered dynamic block types.

since: 5.0.0
return: string[] Array of dynamic block names.

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.

since: 5.3.1
return: string Serialized attributes.
param: array $block_attributes Attributes object.

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.

since: 5.3.1
return: string Block name to use for serialization.
param: string $block_name Original block name.

get_comment_delimited_block_content( $block_name, $block_attributes, $block_content )   X-Ref
Returns the content of a block, including comment delimiters.

since: 5.3.1
return: string Comment-delimited block content.
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.

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.

since: 5.3.1
return: string String of rendered HTML.
param: WP_Block_Parser_Block $block A single parsed block object.

serialize_blocks( $blocks )   X-Ref
Returns a joined string of the aggregate serialization of the given parsed
blocks.

since: 5.3.1
return: string String of rendered HTML.
param: WP_Block_Parser_Block[] $blocks Parsed block objects.

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.

since: 5.3.1
return: string The filtered and sanitized content result.
param: string         $text              Text that may contain block content.
param: array[]|string $allowed_html      An array of allowed HTML elements
param: string[]       $allowed_protocols Array of allowed URL protocols.

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.

since: 5.3.1
return: array The filtered and sanitized block object result.
param: WP_Block_Parser_Block $block             The parsed block object.
param: array[]|string        $allowed_html      An array of allowed HTML
param: string[]              $allowed_protocols Allowed URL protocols.

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.

since: 5.3.1
return: string[]|string The filtered and sanitized result.
param: string[]|string $value             The attribute value to filter.
param: array[]|string  $allowed_html      An array of allowed HTML elements
param: string[]        $allowed_protocols Array of allowed URL protocols.

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.

since: 5.0.0
return: string The parsed and filtered content.
param: string $content The content to parse.

_excerpt_render_inner_blocks( $parsed_block, $allowed_blocks )   X-Ref
Render inner blocks from the allowed wrapper blocks
for generating an excerpt.

since: 5.8.0
return: string The rendered inner blocks.
param: array $parsed_block   The parsed block.
param: array $allowed_blocks The list of allowed inner blocks.

render_block( $parsed_block )   X-Ref
Renders a single block into a HTML string.

since: 5.0.0
return: string String of rendered HTML.
param: array $parsed_block A single parsed block object.

parse_blocks( $content )   X-Ref
Parses blocks out of a content string.

since: 5.0.0
return: array[] Array of parsed block objects.
param: string $content Post content.

do_blocks( $content )   X-Ref
Parses dynamic blocks out of `post_content` and re-renders them.

since: 5.0.0
return: string Updated post content.
param: string $content 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.

since: 5.0.0
return: string The unmodified content.
param: string $content The post content running through this filter.

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.

since: 5.0.0
return: int The block format version is 1 if the content contains one or more blocks, 0 otherwise.
param: string $content Content to test.

register_block_style( $block_name, $style_properties )   X-Ref
Registers a new block style.

since: 5.3.0
return: bool True if the block style was registered with success and false otherwise.
param: string $block_name       Block type name including namespace.
param: array  $style_properties Array containing the properties of the style name,

unregister_block_style( $block_name, $block_style_name )   X-Ref
Unregisters a block style.

since: 5.3.0
return: bool True if the block style was unregistered with success and false otherwise.
param: string $block_name       Block type name including namespace.
param: string $block_style_name Block style name.

block_has_support( $block_type, $feature, $default = false )   X-Ref
Checks whether the current block type supports the feature requested.

since: 5.8.0
return: bool Whether the feature is supported.
param: WP_Block_Type $block_type Block type to check for support.
param: string        $feature    Name of the feature to check support for.
param: mixed         $default    Optional. Fallback value for feature support. Default false.

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.

since: 5.8.0
return: array Filtered metadata for registering a block type.
param: array $metadata 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.

since: 5.8.0
return: array Returns the constructed WP_Query arguments.
param: WP_Block $block Block instance.
param: int      $page  Current query's page.

get_query_pagination_arrow( $block, $is_next )   X-Ref
Helper function that returns the proper pagination arrow html for
`QueryPaginationNext` and `QueryPaginationPrevious` blocks based
on the provided `paginationArrow` from `QueryPagination` context.

It's used in QueryPaginationNext and QueryPaginationPrevious blocks.

since: 5.9.0
return: string|null Returns the constructed WP_Query arguments.
param: WP_Block $block   Block instance.
param: boolean  $is_next Flag for handling `next/previous` blocks.

wp_enqueue_block_style( $block_name, $args )   X-Ref
Enqueues a stylesheet for a specific block.

If the theme has opted-in to separate-styles loading,
then the stylesheet will be enqueued on-render,
otherwise when the block inits.

since: 5.9.0
return: void
param: string $block_name The block-name, including namespace.
param: array  $args       An array of arguments [handle,src,deps,ver,media].

_wp_multiple_block_styles( $metadata )   X-Ref
Allow multiple block styles.

since: 5.9.0
return: array Metadata for registering a block type.
param: array $metadata Metadata for registering a block type.



Generated: Fri Jan 21 01:00:03 2022 Cross-referenced by PHPXref 0.7.1