From 08e495a8817de019a28b9030d0cdcc4678ed5924 Mon Sep 17 00:00:00 2001 From: Herb Miller Date: Wed, 12 Jan 2022 08:14:47 +0000 Subject: [PATCH] Block overrides work for Gutenberg or WordPress 5.9 #25 --- includes/block-override-functions.php | 13 +++++++------ includes/block-overrides.php | 16 ++++++++-------- includes/navigation-link.php | 6 +++++- includes/post-content.php | 6 +++++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/includes/block-override-functions.php b/includes/block-override-functions.php index 96cb1c0..dffa5a7 100644 --- a/includes/block-override-functions.php +++ b/includes/block-override-functions.php @@ -9,10 +9,11 @@ /** * Overrides a core block's render_callback method, if required. * - * For the given blockname, if the overriding function is available - * and the current callback is the gutenberg function + * For the given block name, if the overriding function is available, * replace the render_callback with our own function. - * + * Note: For WordPress 5.9, as Gutenberg is no longer a pre-requisite to FSE themes, + * this no longer checks that the implementing render callback function is prefixed with `gutenberg_` + * * @param array $args Block attributes. * @param string $blockname The block name to test for. * @param string $render_callback The common suffix for the block's callback function. @@ -21,9 +22,9 @@ function fizzie_maybe_override_block( $args, $blockname, $render_callback ) { $fizzie_render_callback = 'fizzie_' . $render_callback; if ( $blockname == $args['name'] && function_exists( $fizzie_render_callback ) ) { - if ( 'gutenberg_' . $render_callback == $args['render_callback'] ) { + //if ( 'gutenberg_' . $render_callback == $args['render_callback'] ) { $args['render_callback'] = $fizzie_render_callback; - } + // } } return $args; } @@ -78,4 +79,4 @@ function fizzie_report_recursion_error( $message=null, $class=null ) { } $html = $recursion_error->report_recursion_error( $message ); return $html; -} +} \ No newline at end of file diff --git a/includes/block-overrides.php b/includes/block-overrides.php index 9fb20f8..018bd0c 100644 --- a/includes/block-overrides.php +++ b/includes/block-overrides.php @@ -18,12 +18,12 @@ //require_once __DIR__ . '/query-pagination.php'; //require_once __DIR__ . '/query-pagination-numbers.php'; //require_once __DIR__ . '/query-loop.php'; -require_once __DIR__ . '/post-excerpt.php'; +//require_once __DIR__ . '/post-excerpt.php'; require_once __DIR__ . '/post-content.php'; //require_once __DIR__ . '/template-part.php'; //require_once __DIR__ . '/navigation.php'; require_once __DIR__ . '/navigation-link.php'; -require_once __DIR__ . '/post-hierarchical-terms.php'; +//require_once __DIR__ . '/post-hierarchical-terms.php'; //require_once __DIR__ . '/block.php'; /** @@ -38,16 +38,16 @@ * @return array */ function fizzie_register_block_type_args( $args ) { - $args = fizzie_maybe_override_block( $args,'core/query-pagination', 'render_block_core_query_pagination'); - $args = fizzie_maybe_override_block( $args,'core/query-pagination-numbers', 'render_block_core_query_pagination_numbers'); + //$args = fizzie_maybe_override_block( $args,'core/query-pagination', 'render_block_core_query_pagination'); + //$args = fizzie_maybe_override_block( $args,'core/query-pagination-numbers', 'render_block_core_query_pagination_numbers'); //$args = fizzie_maybe_override_block( $args,'core/query-loop', 'render_block_core_query_loop' ); - $args = fizzie_maybe_override_block( $args,'core/post-excerpt', 'render_block_core_post_excerpt' ); + //$args = fizzie_maybe_override_block( $args,'core/post-excerpt', 'render_block_core_post_excerpt' ); $args = fizzie_maybe_override_block( $args,'core/post-content', 'render_block_core_post_content' ); $args = fizzie_maybe_override_block( $args,'core/template-part', 'render_block_core_template_part' ); - $args = fizzie_maybe_override_block( $args,'core/navigation', 'render_block_core_navigation' ); + //$args = fizzie_maybe_override_block( $args,'core/navigation', 'render_block_core_navigation' ); $args = fizzie_maybe_override_block( $args,'core/navigation-link', 'render_block_core_navigation_link' ); - $args = fizzie_maybe_override_block( $args,'core/post-hierarchical-terms', 'render_block_core_post_hierarchical_terms' ); - $args = fizzie_maybe_override_block( $args,'core/block', 'render_block_core_block' ); + //$args = fizzie_maybe_override_block( $args,'core/post-hierarchical-terms', 'render_block_core_post_hierarchical_terms' ); + //$args = fizzie_maybe_override_block( $args,'core/block', 'render_block_core_block' ); return $args; } \ No newline at end of file diff --git a/includes/navigation-link.php b/includes/navigation-link.php index bcc2b7e..918b218 100644 --- a/includes/navigation-link.php +++ b/includes/navigation-link.php @@ -10,7 +10,11 @@ function fizzie_render_block_core_navigation_link( $attributes, $content, $block ) { $attributes = fizzie_fiddle_nav_atts( $attributes ); $block->context = fizzie_fiddle_block_context( $attributes, $block ); - $html = gutenberg_render_block_core_navigation_link($attributes, $content, $block); + if ( function_exists( 'gutenberg_render_block_core_navigation_link' )) { + $html = gutenberg_render_block_core_navigation_link($attributes, $content, $block); + } else { + $html = render_block_core_navigation_link($attributes, $content, $block); + } return $html; } diff --git a/includes/post-content.php b/includes/post-content.php index e4387b0..d2625f3 100644 --- a/includes/post-content.php +++ b/includes/post-content.php @@ -22,7 +22,11 @@ function fizzie_render_block_core_post_content( $attributes, $content, $block ) */ if ( fizzie_process_this_content( $block->context['postId'], $block->name ) ) { - $html = gutenberg_render_block_core_post_content( $attributes, $content, $block ); + if ( function_exists( 'gutenberg_render_block_core_post_content') ) { + $html = gutenberg_render_block_core_post_content($attributes, $content, $block); + } else { + $html = render_block_core_post_content($attributes, $content, $block); + } fizzie_clear_processed_content(); } else { $html = fizzie_report_recursion_error();