Making WordPress.org

Ticket #2078: meta-2078.patch

File meta-2078.patch, 2.7 KB (added by SergeyBiryukov, 8 years ago)
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

     
    2929                        // Intercept feed requests prior to bbp_request_feed_trap.
    3030                        add_filter( 'bbp_request', array( $this, 'request' ), 9 );
    3131
     32                        // Add plugin or theme name to view feed titles.
     33                        add_action( 'bbp_feed', array( $this, 'add_compat_title_to_feed' ) );
     34
    3235                        // Define the taxonomy and query vars for this view.
    3336                        add_action( 'plugins_loaded', array( $this, 'always_load' ) );
    3437
     
    125128                return $value;
    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
     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'] ) {
    130192                        // Return new topics from the support forum.