WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 14 months ago

#36964 closed enhancement (fixed)

Show/hide the tag-cloud on `edit-tags.php` admin pages using a filter

Reported by: ramiy Owned by: helen
Milestone: 4.7 Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: ui, administration Cc:
PR Number:

Description

The edit-tags.php page shows a tag-cloud with "Popular Tags" on non-hierarchical taxonomies. There is no way to remove this tag cloud and the H2 title from the admin screen.

This ticket introduces a new boolean filter "show_admin_popular_items_tag_cloud" that allows you to remove this blog-feature.


The current code that shows the tag cloud:

if ( ! is_null( $tax->labels->popular_items ) ) {
	if ( current_user_can( $tax->cap->edit_terms ) ) {
		$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) );
	} else {
		$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
	}

	if ( $tag_cloud ) :
	?>
<div class="tagcloud">
<h2><?php echo $tax->labels->popular_items; ?></h2>
<?php echo $tag_cloud; unset( $tag_cloud ); ?>
</div>
<?php
	endif;
}

The new code with the proposed filter:

$show_admin_popular_items = ! is_null( $tax->labels->popular_items );

/**
 * Filters whether to show the popular items tag cloud in the taxonomy admin screen.
 *
 * This filter controls the visibility of the popular items tag cloud in the
 * taxonomy admin screen.
 *
 * By default, the tag cloud is visible on non-hierarchy taxonomies admin pages.
 * You can hide it using `__return_false`.
 *
 * @since 4.6.0
 *
 * @param bool $show_admin_popular_items Whether to show the popular items tag cloud.
 */
if ( apply_filters( 'show_admin_popular_items_tag_cloud', $show_admin_popular_items ) ) {
	if ( current_user_can( $tax->cap->edit_terms ) ) {
		$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) );
	} else {
		$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
	}

	if ( $tag_cloud ) {
?>
<div class="tagcloud">
<h2><?php echo $tax->labels->popular_items; ?></h2>
<?php echo $tag_cloud; unset( $tag_cloud ); ?>
</div>
<?php
	}
}

Attachments (4)

texonomy-tags.png (71.3 KB) - added by ramiy 3 years ago.
36964.patch (1.4 KB) - added by ramiy 3 years ago.
36964.2.patch (1.3 KB) - added by ramiy 3 years ago.
updated patch for wp4.7
36964-remove-the-tag-cloud.patch (878 bytes) - added by ramiy 3 years ago.

Download all attachments as: .zip

Change History (30)

@ramiy
3 years ago

@ramiy
3 years ago

#1 @ramiy
3 years ago

  • Keywords has-patch has-screenshots added

The patch was tested.

You can hide the tag cloud using:

add_filter( 'show_admin_popular_items_tag_cloud', '__return_false' );

#2 follow-up: @swissspidy
3 years ago

How useful is that tag cloud anyway? Why not completely remove it instead of adding an option to do so?

#3 @DrewAPicture
3 years ago

For some history and context, the tag cloud on the tags screen was added around 2.7 when basic styling of any measurable kind was also added to the screen, see [9339]. At the time, this improvement was pre-list table, pre-edit-tag links, pre-most anything we're familiar with today.

For a bit of fun, you can see the progression:

I would be in favor of at least switching to hiding the tag cloud by default for tags going forward.

Last edited 3 years ago by DrewAPicture (previous) (diff)

#4 in reply to: ↑ 2 @ramiy
3 years ago

Replying to swissspidy:

How useful is that tag cloud anyway? Why not completely remove it instead of adding an option to do so?

Removing this "blog-era-feature" sounds good, either by removing it from the code entirely or by filtering the preview.

Last edited 3 years ago by ramiy (previous) (diff)

#5 @KingYes
3 years ago

+1 for removing the tag cloud from the taxonomy admin screen.

#6 @nir_r
3 years ago

+1 from me as well...no need to have the cloud tag in this place...

#7 @ariel.k
3 years ago

I like the idea. It's very useful for custom taxonomies with other behaviour than tags

#8 @ramiy
3 years ago

@swissspidy @DrewAPicture Maybe in 4.7 ?

#9 @DrewAPicture
3 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 4.7

@ramiy Sure. Let's refresh the patch for 4.7 and additionally pass $taxonomy to the filter. Also, we should keep the current style of if/endif because it wraps markup.

Let's also look at hiding it by default (opposite of current behavior). So rather than assigning the current condition to the filter via a variable, the filter should be in addition to that and the logic reversed, e.g.

<?php
$show_admin_popular_items = apply_filters( 'show_admin_popular_items_tag_cloud', false, $taxonomy );

if ( ! is_null( $tax->labels->popular_items ) && true === $show_admin_popular_items ) {
Last edited 3 years ago by DrewAPicture (previous) (diff)

#10 follow-up: @DrewAPicture
3 years ago

Do we also want to look at display of the popular items in the tags meta box in the post editing screen?

#11 in reply to: ↑ 10 @ramiy
3 years ago

Replying to DrewAPicture:

Do we also want to look at display of the popular items in the tags meta box in the post editing screen?

Not in this ticket.

@ramiy
3 years ago

updated patch for wp4.7

#12 @ramiy
3 years ago

@DrewAPicture,

  1. patch refreshed for 4.7
  2. $tax object was added as a parameter
  3. current if/endif style is not changed
  4. the tag cloud is now hidden by default (opposite of current behavior)
  5. phpDocs updated, mentioning the behavior change

#13 @Destac
3 years ago

+1 for removing it entirely. Seems dated and unnecessary if I am editing the tags and I want a particular one I will probably search for it or click for it.

#14 @ramiy
3 years ago

  • Keywords needs-refresh removed

This ticket was mentioned in Slack in #core by ramiy. View the logs.


3 years ago

This ticket was mentioned in Slack in #core by aaroncampbell. View the logs.


3 years ago

#17 @aaroncampbell
3 years ago

  • Keywords commit added; has-screenshots removed

I like this, especially hidden by default. I tested the patch and it seems to work as expected.

#18 follow-up: @stevenkword
3 years ago

I can confirm that the patch applies cleanly and that it functions as advertised. However, I disagree with having a feature in Core that is disabled by default. I'm in favor of either 1.) Reversing the logic, or 2.) Removing the Tag Cloud from Core completely.

#19 in reply to: ↑ 18 @Destac
3 years ago

Replying to stevenkword:

I can confirm that the patch applies cleanly and that it functions as advertised. However, I disagree with having a feature in Core that is disabled by default. I'm in favor of either 1.) Reversing the logic, or 2.) Removing the Tag Cloud from Core completely.

It's not the first time something like this was done the link manager in core was hidden but can be enabled by a single line of code. There are times when this works I don't think this tag clouds adds any real value and should be removed but having it simply not enabled by default works as well.

#20 @johnbillion
3 years ago

  • Keywords commit removed

I agree with @Destac and @stevenkword - if this is to be hidden by default it should be removed entirely.

#21 @aaroncampbell
3 years ago

@johnbillion Thanks for fixing that keyword. I meant to loop back to this after @stevenkword and I did the bug scrub, and then travel happened.

Basically, Steven convinced me. I'd prefer to just remove it. We could even drop in a hook there if one doesn't exist that would let people put it back (by actually echoing the title and cloud, not a filter where they just return true).

If we decide we can't remove it, then the current method defaulting to display would be reasonable.

#22 @ramiy
3 years ago

The new patch removes the tag cloud entirely.

This ticket was mentioned in Slack in #core by helen. View the logs.


3 years ago

#24 @helen
3 years ago

  • Owner set to helen
  • Resolution set to fixed
  • Status changed from new to closed

In 38735:

Taxonomy: Remove the popular tag cloud from edit-tags.php.

Sorting by count (which wasn't possible at the time the tag cloud was introduced) is more effective, though we should likely make count sort by DESC initially rather than ASC.

props ramiy.
fixes #36964.

#25 @SergeyBiryukov
3 years ago

If someone wants to restore the tag cloud, add_tag_form action can be used for that:

function wp36964_restore_tag_cloud_on_tags_screen() {
	global $taxnow, $taxonomy, $post_type;

	$tax = get_taxonomy( $taxnow );
	if ( ! is_null( $tax->labels->popular_items ) ) {
		if ( current_user_can( $tax->cap->edit_terms ) ) {
			$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) );
		} else {
			$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
		}

		if ( $tag_cloud ) : ?> 
			<div class="tagcloud">
				<h2><?php echo $tax->labels->popular_items; ?></h2>
				<?php echo $tag_cloud; ?>
			</div>
			<?php
		endif;
	}
}
add_action( 'add_tag_form', 'wp36964_restore_tag_cloud_on_tags_screen' );

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


14 months ago

Note: See TracTickets for help on using tickets.