Making WordPress.org

Changeset 4980


Ignore:
Timestamp:
02/22/2017 12:56:30 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Add plugin or theme name to compat view feed titles.

bbPress' default title is "All Topics", which isn't useful when dealing with plugin or theme support.

Fixes #2078.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

    r4976 r4980  
    2929            // Intercept feed requests prior to bbp_request_feed_trap.
    3030            add_filter( 'bbp_request', array( $this, 'request' ), 9 );
     31
     32            // Add plugin or theme name to view feed titles.
     33            add_action( 'bbp_feed', array( $this, 'add_compat_title_to_feed' ) );
    3134
    3235            // Define the taxonomy and query vars for this view.
     
    126129    }
    127130
     131    /**
     132     * Add plugin or theme name to view feed titles.
     133     *
     134     * bbPress uses 'All Topics' title for view feeds, which isn't useful when
     135     * dealing with plugin or theme support.
     136     *
     137     * @see https://meta.trac.wordpress.org/ticket/2078
     138     * @see https://bbpress.trac.wordpress.org/ticket/3064
     139     */
     140    public function add_compat_title_to_feed() {
     141        if ( empty( $this->query['bbp_view'] ) || empty( $this->query[ $this->query_var() ] ) ) {
     142            return;
     143        }
     144
     145        add_filter( 'gettext', array( $this, 'title_correction_for_feed' ), 10, 3 );
     146    }
     147
     148    /**
     149     * Replace 'All Topics' feed title with an appropriate view title
     150     * that includes the plugin or theme name.
     151     *
     152     * @see https://meta.trac.wordpress.org/ticket/2078
     153     * @see https://bbpress.trac.wordpress.org/ticket/3064
     154     *
     155     * @param string $translation Translated text.
     156     * @param string $text        Text to translate.
     157     * @param string $domain      Text domain.
     158     * @return string New feed title.
     159     */
     160    public function title_correction_for_feed( $translation, $text, $domain ) {
     161        if ( 'bbpress' !== $domain || 'All Topics' !== $text ) {
     162            return $translation;
     163        }
     164
     165        remove_filter( 'gettext', array( $this, 'title_correction_for_feed' ), 10, 3 );
     166
     167        $object = $this->get_object( $this->query[ $this->query_var() ] );
     168        if ( ! $object ) {
     169            return $translation;
     170        }
     171
     172        $this->{$this->compat()} = $object;
     173
     174        switch ( $this->query['bbp_view'] ) {
     175            case 'plugin':
     176            case 'theme':
     177                $translation = $this->compat_title();
     178                break;
     179            case 'reviews':
     180                $translation = $this->reviews_title();
     181                break;
     182            case 'active':
     183                $translation = $this->activity_title();
     184                break;
     185        }
     186
     187        return $translation;
     188    }
     189
    128190    public function get_view_query_args_for_feed( $retval, $view ) {
    129191        switch ( $this->query['bbp_view'] ) {
Note: See TracChangeset for help on using the changeset viewer.