Making WordPress.org

Changeset 9044


Ignore:
Timestamp:
07/15/2019 05:30:46 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Only link to plugin tags with more than 1 plugin.

Plugins are limited to 6 tags already, but this now adds the restriction that if the tag isn't used by at least 1 other plugin, it won't be displayed.
This won't affect searches, which may still use one of the 6 tags, even if it's not displayed.

Fixes #4544.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-meta.php

    r8032 r9044  
    186186            ?>
    187187
    188             <?php if ( empty( $args['hide_tags'] ) && $tags = get_the_term_list( $post->ID, 'plugin_tags', '<div class="tags">', '', '</div>' ) ) : ?>
    189                 <li class="clear">
    190                     <?php
    191                     $terms = get_the_terms( $post, 'plugin_tags' );
    192                     /* translators: %s: tag list */
    193                     printf( _n( 'Tag: %s', 'Tags: %s', count( $terms ), 'wporg-plugins' ), $tags );
    194                     ?>
    195                 </li>
    196             <?php endif; ?>
     188            <?php if ( empty( $args['hide_tags'] ) ) {
     189                $terms = get_the_terms( $post, 'plugin_tags' );
     190                if ( is_wp_error( $terms ) ) {
     191                    $terms = array();
     192                }
     193                // Trim it to tags with more than 1 plugin.
     194                $terms = array_filter( $terms, function( $term ) {
     195                    return $term->count > 1;
     196                } );
     197
     198                // If we have some terms still, generate the sidebar entry.
     199                if ( $terms ) {
     200                    $term_links = array_filter( array_map( function( $term ) {
     201                        $link = get_term_link( $term, 'plugin_tags' );
     202                            if ( is_wp_error( $link ) ) {
     203                                return '';
     204                            }
     205                            return '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
     206                        }, $terms ) );
     207
     208                    echo '<li class="clear">';
     209                    printf(
     210                        /* translators: %s: tag list */
     211                        _n( 'Tag: %s', 'Tags: %s', count( $term_links ), 'wporg-plugins' ),
     212                        '<div class="tags">' . implode( $term_links ) . '</div>'
     213                    );
     214                    echo '</li>';
     215                }
     216            } ?>
    197217
    198218            <?php if ( ! get_query_var( 'plugin_advanced' ) ) : ?>
Note: See TracChangeset for help on using the changeset viewer.