Skip to content

Commit

Permalink
[Block Library]: Less warnings when blocks try to render themselves. (#…
Browse files Browse the repository at this point in the history
…33032)

* Less warnings when blocks try to render themeselves.

* rename util to gutenberg_is_rest_api_request

* Log only if is `is_debug` and not in admin or REST request

* remove log entirely
  • Loading branch information
ntsekouras authored and youknowriad committed Jul 6, 2021
1 parent c44ba31 commit cd98556
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 34 deletions.
11 changes: 0 additions & 11 deletions packages/block-library/src/block/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ function render_block_core_block( $attributes ) {
}

if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
if ( ! is_admin() ) {
trigger_error(
sprintf(
// translators: %s is the user-provided title of the reusable block.
__( 'Could not render Reusable Block <strong>%s</strong>. Block cannot be rendered inside itself.' ),
$reusable_block->post_title
),
E_USER_WARNING
);
}

// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
// is set in `wp_debug_mode()`.
$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
Expand Down
16 changes: 4 additions & 12 deletions packages/block-library/src/post-content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ function render_block_core_post_content( $attributes, $content, $block ) {
$post_id = $block->context['postId'];

if ( isset( $seen_ids[ $post_id ] ) ) {
if ( ! is_admin() ) {
trigger_error(
sprintf(
// translators: %s is a post ID (integer).
__( 'Could not render Post Content block with post ID: <code>%s</code>. Block cannot be rendered inside itself.' ),
$post_id
),
E_USER_WARNING
);
}

// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
// is set in `wp_debug_mode()`.
$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;

return $is_debug ?
// translators: Visible only in the front end, this warning takes the place of a faulty block.
__( '[block rendering halted]' ) :
Expand All @@ -44,7 +36,7 @@ function render_block_core_post_content( $attributes, $content, $block ) {

$seen_ids[ $post_id ] = true;

if ( ! in_the_loop() ) {
if ( ! in_the_loop() && have_posts() ) {
the_post();
}

Expand Down
12 changes: 1 addition & 11 deletions packages/block-library/src/template-part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,11 @@ function render_block_core_template_part( $attributes ) {
}

if ( isset( $seen_ids[ $template_part_id ] ) ) {
if ( ! is_admin() ) {
trigger_error(
sprintf(
// translators: %s are the block attributes.
__( 'Could not render Template Part block with the attributes: <code>%s</code>. Block cannot be rendered inside itself.' ),
wp_json_encode( $attributes )
),
E_USER_WARNING
);
}

// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
// is set in `wp_debug_mode()`.
$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;

return $is_debug ?
// translators: Visible only in the front end, this warning takes the place of a faulty block.
__( '[block rendering halted]' ) :
Expand Down

0 comments on commit cd98556

Please sign in to comment.