WordPress.org

Make WordPress Core

Changeset 35984


Ignore:
Timestamp:
12/17/2015 04:26:06 PM (5 years ago)
Author:
boonebgorges
Message:

Introduce 'tag-link-position-x' class to tag cloud links.

The new class describes the cardinal position of a link in the cloud, allowing
more fine-grained CSS and JS targeting.

Props Mte90, chmac.
Fixes #5172.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r35850 r35984  
    905905    // generate the output links array
    906906    foreach ( $tags_data as $key => $tag_data ) {
    907         $a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $tag_data['class'] ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>";
     907        $class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 );
     908        $a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $class ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>";
    908909    }
    909910
  • trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php

    r35242 r35984  
    7979            'hide_empty' => false,
    8080        ) );
    81         $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
     81        $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
    8282        $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    8383            'hide_empty' => false,
     
    9595        ) );
    9696
    97         $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
     97        $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
    9898        $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    9999            'hide_empty' => false,
     
    110110        ) );
    111111
    112         $expected = "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a></li>\n</ul>\n";
     112        $expected = "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a></li>\n</ul>\n";
    113113        $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    114114            'hide_empty' => false,
     
    130130        ) );
    131131
    132         $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a>\n".
    133             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a>\n".
    134             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a>\n".
    135             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>";
     132        $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a>\n".
     133            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1 tag-link-position-2' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a>\n".
     134            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2 tag-link-position-3' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a>\n".
     135            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3 tag-link-position-4' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>";
    136136        $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    137137            'hide_empty' => false,
     
    153153
    154154        $expected = "<ul class='wp-tag-cloud'>\n\t<li>".
    155             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a></li>\n\t<li>".
    156             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a></li>\n\t<li>".
    157             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a></li>\n\t<li>".
    158             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>".
     155            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a></li>\n\t<li>".
     156            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1 tag-link-position-2' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a></li>\n\t<li>".
     157            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2 tag-link-position-3' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a></li>\n\t<li>".
     158            "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3 tag-link-position-4' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>".
    159159            "</li>\n</ul>\n";
    160160
     
    221221
    222222    /**
     223     * @ticket 5172
     224     */
     225    public function test_should_include_tag_link_position_class() {
     226        register_taxonomy( 'wptests_tax', 'post' );
     227        $term_ids = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     228
     229        $p = self::factory()->post->create();
     230        wp_set_post_terms( $p, $term_ids, 'wptests_tax' );
     231
     232        $term_objects = get_terms( 'wptests_tax', array(
     233            'include' => $term_ids,
     234        ) );
     235
     236        $cloud = wp_generate_tag_cloud( $term_objects );
     237        preg_match_all( '|tag\-link\-position-([0-9]+)|', $cloud, $matches );
     238
     239        $this->assertSame( array( 1, 2, 3 ), array_map( 'intval', $matches[1] ) );
     240    }
     241
     242    /**
    223243     * Helper method retrieve the created terms.
    224244     *
Note: See TracChangeset for help on using the changeset viewer.