Skip to:
Content

bbPress.org

Changeset 7809


Ignore:
Timestamp:
10/04/2026 12:46:34 PM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Topic Tags: Respect explicit tags in edit links and descriptions.

Pass the resolved tag to edit-link generation for both permalink styles, and initialize the explicit tag before passing it to description filters. Add regression coverage for missing tags, output, permalink styles, and filter context.

In trunk, for 2.7.

See #3700.
See #3701.
See #3695.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.md

    r7807 r7809  
    4545### Fixed
    4646
     47- Used explicitly supplied topic tags in edit links and passed their slug to description filters.
    4748- Prevented threaded reply ancestry from including an invalid parent and avoided redundant reply-position writes.
    4849- Restored assigned moderator names in forum edit forms and corrected forum type and visibility dropdown behavior.
  • trunk/src/includes/topics/template.php

    r7731 r7809  
    38533853                // Pretty or ugly URL
    38543854                $retval = bbp_use_pretty_urls()
    3855                         ? user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_slug() )
    3856                         : add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), bbp_get_topic_tag_link() );
     3855                        ? user_trailingslashit( trailingslashit( bbp_get_topic_tag_link( $tag ) ) . bbp_get_edit_slug() )
     3856                        : add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), bbp_get_topic_tag_link( $tag ) );
    38573857
    38583858        // No link
    … …  
    38973897
    38983898        // Get the term
    3899         if ( ! empty( $r['tag'] ) ) {
    3900                 $term = get_term_by( 'slug', $r['tag'], bbp_get_topic_tag_tax_id() );
     3899        $tag = $r['tag'];
     3900        if ( ! empty( $tag ) ) {
     3901                $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
    39013902        } else {
    3902                 $tag  = $r['tag'] = get_query_var( 'term' );
     3903                $tag = $r['tag'] = get_query_var( 'term' );
    39033904                $term = get_queried_object();
    39043905        }
  • trunk/tests/phpunit/testcases/topics/template/topic-tag.php

    r7791 r7809  
    135135         * @covers ::bbp_topic_tag_edit_link
    136136         * @covers ::bbp_get_topic_tag_edit_link
    137          * @todo   Implement test_bbp_get_topic_tag_edit_link().
    138137         */
    139138        public function test_bbp_get_topic_tag_edit_link() {
    140                 // Remove the following lines when you implement this test.
    141                 $this->markTestIncomplete(
    142                         'This test has not been implemented yet.'
    143                 );
     139                $term = wp_insert_term( 'Alpha', bbp_get_topic_tag_tax_id(), array( 'slug' => 'alpha' ) );
     140                $this->assertFalse( is_wp_error( $term ) );
     141                $link = bbp_get_topic_tag_link( 'alpha' );
     142                $this->assertSame( '', bbp_get_topic_tag_edit_link( 'missing-tag' ) );
     143
     144                add_filter( 'bbp_pretty_urls', '__return_false' );
     145                try {
     146                        $edit_link = add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), $link );
     147                        $this->assertSame( $edit_link, bbp_get_topic_tag_edit_link( 'alpha' ) );
     148                        $this->expectOutputString( esc_url( $edit_link ) );
     149                        bbp_topic_tag_edit_link( 'alpha' );
     150                        remove_filter( 'bbp_pretty_urls', '__return_false' );
     151                        add_filter( 'bbp_pretty_urls', '__return_true' );
     152                        $this->assertSame( user_trailingslashit( trailingslashit( $link ) . bbp_get_edit_slug() ), bbp_get_topic_tag_edit_link( 'alpha' ) );
     153                } finally {
     154                        remove_filter( 'bbp_pretty_urls', '__return_false' );
     155                        remove_filter( 'bbp_pretty_urls', '__return_true' );
     156                }
    144157        }
    145158
    … …  
    147160         * @covers ::bbp_topic_tag_description
    148161         * @covers ::bbp_get_topic_tag_description
    149          * @todo   Implement test_bbp_get_topic_tag_description().
    150162         */
    151163        public function test_bbp_get_topic_tag_description() {
    152                 // Remove the following lines when you implement this test.
    153                 $this->markTestIncomplete(
    154                         'This test has not been implemented yet.'
    155                 );
     164                $term = wp_insert_term( 'Alpha', bbp_get_topic_tag_tax_id(), array( 'slug' => 'alpha', 'description' => 'Alpha description' ) );
     165                $this->assertFalse( is_wp_error( $term ) );
     166                $args = array( 'tag' => 'alpha', 'before' => '<p>', 'after' => '</p>' );
     167                $seen = array();
     168                $filter = function ( $description, $parsed, $original, $tag, $term ) use ( &$seen ) {
     169                        $seen[] = array( $tag, $term->term_id );
     170                        return $description;
     171                };
     172                add_filter( 'bbp_get_topic_tag_description', $filter, 10, 5 );
     173
     174                try {
     175                        $this->assertSame( '<p>Alpha description</p>', bbp_get_topic_tag_description( $args ) );
     176                        $this->assertSame( array( array( 'alpha', $term['term_id'] ) ), $seen );
     177                        $this->expectOutputString( '<p>Alpha description</p>' );
     178                        bbp_topic_tag_description( $args );
     179                } finally {
     180                        remove_filter( 'bbp_get_topic_tag_description', $filter, 10 );
     181                }
    156182        }
    157183}
Note: See TracChangeset for help on using the changeset viewer.