Skip to content

Commit

Permalink
Issue #25 - refactor post excerpt overrides into post-excerpt.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Nov 14, 2020
1 parent 93b524a commit 3a65a25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
26 changes: 3 additions & 23 deletions includes/block-overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
require_once __DIR__ . '/query-pagination.php';
require_once __DIR__ . '/query-loop.php';
require_once __DIR__ . '/post-excerpt.php';



Expand All @@ -24,13 +25,7 @@
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-loop', 'render_block_core_query_loop' );


if ( 'core/post-excerpt' == $args['name'] ) {
if ( 'gutenberg_render_block_core_post_excerpt' == $args['render_callback'] ) {
$args['render_callback'] = 'fizzie_render_block_core_post_excerpt';
}
}
$args = fizzie_maybe_override_block( $args,'core/post-excerpt', 'render_block_core_post_excerpt' );

if ( 'core/post-content' == $args['name'] ) {
if ( 'gutenberg_render_block_core_post_content' == $args['render_callback'] ) {
Expand Down Expand Up @@ -71,22 +66,7 @@ function fizzie_register_block_type_args( $args ) {
return $args;
}

/**
* Appends the missing </div> to the core/post-excerpt block.
*
* @param $attributes
* @param $content
* @param $block
* @return string
*/
function fizzie_render_block_core_post_excerpt( $attributes, $content, $block ) {
$html = gutenberg_render_block_core_post_excerpt( $attributes, $content, $block );
// Should really check that it's missing.
if ( 0 !== strrpos( $html, '</div>') ) {
$html .= '</div>';
}
return $html;
}


/**
* Overrides core/post-content to return early in certain circumstances.
Expand Down
17 changes: 17 additions & 0 deletions includes/post-excerpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Appends the missing </div> to the core/post-excerpt block.
*
* @param $attributes
* @param $content
* @param $block
* @return string
*/
function fizzie_render_block_core_post_excerpt( $attributes, $content, $block ) {
$html = gutenberg_render_block_core_post_excerpt( $attributes, $content, $block );
// Should really check that it's missing.
if ( 0 !== strrpos( $html, '</div>') ) {
$html .= '</div>';
}
return $html;
}

0 comments on commit 3a65a25

Please sign in to comment.