Skip to content

Commit

Permalink
Plugin: Fix PHP fatal error when using WP 5.9 (#42550)
Browse files Browse the repository at this point in the history
* Plugin: Fix PHP fatal error when using WP 5.9
* Use array

Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
  • Loading branch information
Mamaduka and ntsekouras authored Jul 20, 2022
1 parent 65c5477 commit 5d24908
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions lib/compat/wordpress-6.0/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,44 @@
* @package gutenberg
*/

/**
* Registers patterns from Pattern Directory provided by a theme's
* `theme.json` file.
*/
function gutenberg_register_remote_theme_patterns() {
if ( ! get_theme_support( 'core-block-patterns' ) ) {
return;
}
if ( ! function_exists( '_register_remote_theme_patterns' ) ) {
/**
* Registers patterns from Pattern Directory provided by a theme's
* `theme.json` file.
*/
function _register_remote_theme_patterns() {
if ( ! get_theme_support( 'core-block-patterns' ) ) {
return;
}

if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) {
return;
}
if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) {
return;
}

if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
return;
}
if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
return;
}

$pattern_settings = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data()->get_patterns();
if ( empty( $pattern_settings ) ) {
return;
}
$pattern_settings = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data()->get_patterns();
if ( empty( $pattern_settings ) ) {
return;
}

$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$request['slug'] = implode( ',', $pattern_settings );
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
$patterns_registry = WP_Block_Patterns_Registry::get_instance();
foreach ( $patterns as $pattern ) {
$pattern_name = sanitize_title( $pattern['title'] );
// Some patterns might be already registered as core patterns with the `core` prefix.
$is_registered = $patterns_registry->is_registered( $pattern_name ) || $patterns_registry->is_registered( "core/$pattern_name" );
if ( ! $is_registered ) {
register_block_pattern( $pattern_name, (array) $pattern );
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$request['slug'] = $pattern_settings;
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
$patterns_registry = WP_Block_Patterns_Registry::get_instance();
foreach ( $patterns as $pattern ) {
$pattern_name = sanitize_title( $pattern['title'] );
// Some patterns might be already registered as core patterns with the `core` prefix.
$is_registered = $patterns_registry->is_registered( $pattern_name ) || $patterns_registry->is_registered( "core/$pattern_name" );
if ( ! $is_registered ) {
register_block_pattern( $pattern_name, (array) $pattern );
}
}
}
}

0 comments on commit 5d24908

Please sign in to comment.