Make WordPress Core

Changeset 27720


Ignore:
Timestamp:
03/25/2014 06:39:26 PM (11 years ago)
Author:
wonderboymusic
Message:

Popular tags' edit links should respect the current post type. Adds unit test.

Props mordauk, fahmiadib.
Fixes #25566.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-tags.php

    r27369 r27720  
    371371if ( !is_null( $tax->labels->popular_items ) ) {
    372372    if ( current_user_can( $tax->cap->edit_terms ) )
    373         $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
     373        $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) );
    374374    else
    375375        $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
  • trunk/src/wp-includes/category-template.php

    r27709 r27720  
    572572 * of the posts with that tag returns a text for the tooltip of the tag link.
    573573 *
     574 * The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type
     575 * passed to edit.php for the popular tags edit links.
     576 *
    574577 * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
    575578 * function. Only one should be used, because only one will be used and the
     
    585588        'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
    586589        'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
    587         'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
     590        'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true
    588591    );
    589592    $args = wp_parse_args( $args, $defaults );
     
    596599    foreach ( $tags as $key => $tag ) {
    597600        if ( 'edit' == $args['link'] )
    598             $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
     601            $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] );
    599602        else
    600603            $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
  • trunk/tests/phpunit/tests/post.php

    r27380 r27720  
    874874        $this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) );
    875875    }
     876
     877    /**
     878     * @ticket 25566
     879     */
     880    function test_wp_tag_cloud_link_with_post_type() {
     881        $post_type = 'new_post_type';
     882        $tax = 'new_tag';
     883        register_post_type( $post_type, array( 'taxonomies' => array( 'post_tag', $tax ) ) );
     884        register_taxonomy( $tax, $post_type );
     885
     886        $post = $this->factory->post->create( array( 'post_type' => $post_type ) );
     887        wp_set_object_terms( $post, rand_str(), $tax );
     888
     889        $wp_tag_cloud = wp_tag_cloud( array(
     890            'post_type' => $post_type,
     891            'taxonomy' => $tax,
     892            'echo' => false,
     893            'link' => 'edit'
     894        ) );
     895
     896        $terms = get_terms( $tax );
     897        $term = reset( $terms );
     898        $url = sprintf( '%s?action=edit&taxonomy=%s&tag_ID=%d&post_type=%s',
     899            admin_url( 'edit-tags.php' ),
     900            $tax,
     901            $term->term_id,
     902            $post_type
     903        );
     904        $expected_wp_tag_cloud = sprintf( "<a href='%s' class='tag-link-%d' title='1 topic' style='font-size: 8pt;'>%s</a>",
     905            $url,
     906            $term->term_id,
     907            $term->name
     908        );
     909        $this->assertEquals( $expected_wp_tag_cloud, $wp_tag_cloud );
     910
     911        _unregister_post_type( $post_type );
     912        _unregister_taxonomy( $tax );
     913    }
     914
    876915}
Note: See TracChangeset for help on using the changeset viewer.