Skip to content
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

Merged
merged 6 commits into from
Aug 22, 2024

Conversation

akasunil
Copy link
Member

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

  • Add tag could block in post
  • Select taxonomy with no terms, Save the post.
  • Go to front-end, and make sure tag cloud block isn't rendered.

Screenshots or screencast

@akasunil akasunil added [Type] Enhancement A suggestion for improvement. [Block] Tag Cloud Affects the Tag Cloud Block labels Jul 21, 2024
@akasunil akasunil marked this pull request as ready for review July 21, 2024 10:37
@akasunil akasunil requested a review from ajitbohra as a code owner July 21, 2024 10:37
Copy link

github-actions bot commented Jul 21, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: akasunil <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: richtabor <[email protected]>

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&#8217;s no content to show here yet.' );
return '';
Copy link
Member

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 ) {
Copy link
Member

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?

Copy link
Member Author

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?

Comment on lines 33 to 36
// Display placeholder content when there are no tags only in editor.
if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || is_admin() ) {
$tag_cloud = __( 'There&#8217;s no content to show here yet.' );
} else {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@Mamaduka Mamaduka left a 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.

@akasunil akasunil merged commit cf4d798 into trunk Aug 22, 2024
63 checks passed
@akasunil akasunil deleted the enhancement/63684-improve-state-of-tag-cloud branch August 22, 2024 13:37
@github-actions github-actions bot added this to the Gutenberg 19.2 milestone Aug 22, 2024
bph pushed a commit to bph/gutenberg that referenced this pull request Aug 31, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Tag Cloud Affects the Tag Cloud Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants