-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tag Cloud: Improve state of block with no tags #63774
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -30,7 +30,7 @@ function render_block_core_tag_cloud( $attributes ) { | |||
$tag_cloud = wp_tag_cloud( $args ); | |||
|
|||
if ( ! $tag_cloud ) { | |||
$tag_cloud = __( 'There’s no content to show here yet.' ); | |||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the server-side rendered block. Returning an empty string will also render nothing in the editor. The linked issue only states that it should render nothing on the front-end.
@@ -29,8 +29,13 @@ function render_block_core_tag_cloud( $attributes ) { | |||
); | |||
$tag_cloud = wp_tag_cloud( $args ); | |||
|
|||
if ( ! $tag_cloud ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for chaining !
to empty
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes code more readable in my opinion. Do you need me to revert it to avoid unnecessary changes?
…enhancement/63684-improve-state-of-tag-cloud
// Display placeholder content when there are no tags only in editor. | ||
if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || is_admin() ) { | ||
$tag_cloud = __( 'There’s no content to show here yet.' ); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WP introduced the wp_is_serving_rest_request
method, which we could use here. The is_admin
check shouldn't be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank your for a review. I have addressed your feedback.
…enhancement/63684-improve-state-of-tag-cloud
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected. The placeholder is displayed in the editor, and nothing is rendered on the front-end.
* Render nothing when no tags are available in tag cloud block * Added condition to display placeholder in editor * Fix phpcs errors * Use wp_is_serving_rest_request function for conditional check Co-authored-by: akasunil <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: richtabor <[email protected]>
What?
Part of #63684
Why?
Tag cloud block render message in frontend when there are no tags available to display.
How?
Render nothing when no tags are available to display.
Testing Instructions
Screenshots or screencast