diff --git a/docs/designers-developers/developers/backward-compatibility/deprecations.md b/docs/designers-developers/developers/backward-compatibility/deprecations.md index cf98cdb9fe1dde..6db2ed322b6a5b 100644 --- a/docs/designers-developers/developers/backward-compatibility/deprecations.md +++ b/docs/designers-developers/developers/backward-compatibility/deprecations.md @@ -2,6 +2,17 @@ The Gutenberg project's deprecation policy is intended to support backward compatibility for releases, when possible. The current deprecations are listed below and are grouped by _the version at which they will be removed completely_. If your plugin depends on these behaviors, you must update to the recommended alternative before the noted version. +## 5.2.0 + +- The PHP function `gutenberg_parse_blocks` has been removed. Use [`parse_blocks`](https://developer.wordpress.org/reference/functions/parse_blocks/) instead. +- The PHP function `get_dynamic_blocks_regex` has been removed. +- The PHP function `gutenberg_render_block` has been removed. Use [`render_block`](https://developer.wordpress.org/reference/functions/render_block/) instead. +- The PHP function `strip_dynamic_blocks` has been removed. For use in excerpt preparation, consider [`excerpt_remove_blocks`](https://developer.wordpress.org/reference/functions/excerpt_remove_blocks/) instead. +- The PHP function `strip_dynamic_blocks_add_filter` has been removed. +- The PHP function `strip_dynamic_blocks_remove_filter` has been removed. +- The PHP function `gutenberg_post_has_blocks` has been removed. Use [`has_blocks`](https://developer.wordpress.org/reference/functions/has_blocks/) instead. +- The PHP function `gutenberg_content_has_blocks` has been removed. Use [`has_blocks`](https://developer.wordpress.org/reference/functions/has_blocks/) instead. + ## 4.5.0 - `Dropdown.refresh()` has been deprecated as the contained `Popover` is now automatically refreshed. - `wp.editor.PostPublishPanelToggle` has been deprecated in favor of `wp.editor.PostPublishButton`. diff --git a/lib/blocks.php b/lib/blocks.php index 0b11041d0576de..3419e81c8bb38d 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -9,89 +9,20 @@ die( 'Silence is golden.' ); } -if ( ! function_exists( 'register_block_type' ) ) { - /** - * Registers a block type. - * - * @since 0.1.0 - * @since 0.6.0 Now also accepts a WP_Block_Type instance as first parameter. - * - * @param string|WP_Block_Type $name Block type name including namespace, or alternatively a - * complete WP_Block_Type instance. In case a WP_Block_Type - * is provided, the $args parameter will be ignored. - * @param array $args { - * Optional. Array of block type arguments. Any arguments may be defined, however the - * ones described below are supported by default. Default empty array. - * - * @type callable $render_callback Callback used to render blocks of this block type. - * } - * @return WP_Block_Type|false The registered block type on success, or false on failure. - */ - function register_block_type( $name, $args = array() ) { - return WP_Block_Type_Registry::get_instance()->register( $name, $args ); - } -} - -if ( ! function_exists( 'unregister_block_type' ) ) { - /** - * Unregisters a block type. - * - * @since 0.1.0 - * @since 0.6.0 Now also accepts a WP_Block_Type instance as first parameter. - * - * @param string|WP_Block_Type $name Block type name including namespace, or alternatively a - * complete WP_Block_Type instance. - * @return WP_Block_Type|false The unregistered block type on success, or false on failure. - */ - function unregister_block_type( $name ) { - return WP_Block_Type_Registry::get_instance()->unregister( $name ); - } -} - if ( ! function_exists( 'gutenberg_parse_blocks' ) ) { /** * Parses blocks out of a content string. * * @since 0.5.0 + * @deprecated 5.0.0 parse_blocks() * * @param string $content Post content. * @return array Array of parsed block objects. */ function gutenberg_parse_blocks( $content ) { - /** - * Filter to allow plugins to replace the server-side block parser - * - * @since 3.8.0 - * - * @param string $parser_class Name of block parser class - */ - $parser_class = apply_filters( 'block_parser_class', 'WP_Block_Parser' ); - // Load default block parser for server-side parsing if the default parser class is being used. - if ( 'WP_Block_Parser' === $parser_class ) { - require_once dirname( __FILE__ ) . '/../packages/block-serialization-default-parser/parser.php'; - } - $parser = new $parser_class(); - return $parser->parse( $content ); - } -} - -if ( ! function_exists( 'get_dynamic_block_names' ) ) { - /** - * Returns an array of the names of all registered dynamic block types. - * - * @return array Array of dynamic block names. - */ - function get_dynamic_block_names() { - $dynamic_block_names = array(); + _deprecated_function( __FUNCTION__, '5.0.0', 'parse_blocks()' ); - $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered(); - foreach ( $block_types as $block_type ) { - if ( $block_type->is_dynamic() ) { - $dynamic_block_names[] = $block_type->name; - } - } - - return $dynamic_block_names; + return parse_blocks( $content ); } } @@ -100,10 +31,13 @@ function get_dynamic_block_names() { * Retrieve the dynamic blocks regular expression for searching. * * @since 3.6.0 + * @deprecated 5.0.0 * * @return string */ function get_dynamic_blocks_regex() { + _deprecated_function( __FUNCTION__, '5.0.0' ); + $dynamic_block_names = get_dynamic_block_names(); $dynamic_block_pattern = ( '/'; $this->assertEmpty( strip_dynamic_blocks( $content ) ); @@ -89,30 +92,4 @@ function test_strip_dynamic_blocks() { // Dynamic block with options, embedded in other content. $this->assertEquals( $this->filtered_content, strip_dynamic_blocks( $this->content ) ); } - - /** - * Tests that dynamic blocks don't cause an out-of-memory error. - * - * When dynamic blocks happen to generate an excerpt, they can cause an - * infinite loop if that block is part of the post's content. - * - * `wp_trim_excerpt()` applies the `the_content` filter, which has - * `do_blocks` attached to it, trying to render the block which again will - * attempt to return an excerpt of that post. - * - * This infinite loop can be avoided by stripping dynamic blocks before - * `the_content` gets applied, just like shortcodes. - * - * @covers ::strip_dynamic_blocks_add_filter, ::strip_dynamic_blocks_remove_filter - */ - function test_excerpt_infinite_loop() { - $query = new WP_Query( - array( - 'post__in' => array( self::$post_id ), - ) - ); - $query->the_post(); - - $this->assertEmpty( do_blocks( '' ) ); - } }