Skip to content

Commit

Permalink
Block overrides work for Gutenberg or WordPress 5.9 #25
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Jan 12, 2022
1 parent 52a6e23 commit 08e495a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
13 changes: 7 additions & 6 deletions includes/block-override-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -78,4 +79,4 @@ function fizzie_report_recursion_error( $message=null, $class=null ) {
}
$html = $recursion_error->report_recursion_error( $message );
return $html;
}
}
16 changes: 8 additions & 8 deletions includes/block-overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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;
}
6 changes: 5 additions & 1 deletion includes/navigation-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion includes/post-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 08e495a

Please sign in to comment.