Making WordPress.org

Changeset 3902


Ignore:
Timestamp:
09/01/2016 03:00:35 AM (9 years ago)
Author:
jmdodd
Message:

Support Forums: Improve performance on individual topic and topic_title filters.

File:
1 edited

Legend:

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

    r3900 r3902  
    7373    public function check_topic_for_compat() {
    7474        if ( bbp_is_single_topic() ) {
    75             $slug = wp_get_object_terms( bbp_get_topic_id(), $this->taxonomy(), array( 'fields' => 'slugs' ) );
    76 
    77             // Match found for this compat.
    78             if ( ! empty( $slug ) ) {
    79                 $slug = $slug[0];
     75            $terms = get_the_terms( bbp_get_topic_id(), $this->taxonomy() );
     76            if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
     77                $slug = $terms[0]->slug;
    8078
    8179                // Basic setup.
     
    9694
    9795    public function get_topic_title( $title, $topic_id ) {
    98         if ( bbp_is_single_topic() || ( bbp_is_single_view() && in_array( bbp_get_view_id(), array( $this->compat(), 'reviews', 'active' ) ) ) ) {
    99             return $title;
    100         }
    101 
    102         $slug = wp_get_object_terms( $topic_id, $this->taxonomy(), array( 'fields' => 'slugs' ) );
    103         if ( ! empty( $slug ) ) {
    104             $slug = $slug[0];
    105             $object = $this->get_object( $slug );
    106             $title = sprintf( "[%s] %s", esc_html( $object->post_title ), esc_html( $title ) );
     96        if (
     97            ( bbp_is_single_forum() && bbp_get_forum_id() == $this->forum_id() )
     98        ||
     99            ( bbp_is_single_view() && ! in_array( bbp_get_view_id(), array( $this->compat(), 'reviews', 'active' ) ) )
     100        ) {
     101            $terms = get_the_terms( $topic_id, $this->taxonomy() );
     102            if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
     103                $term = $terms[0];
     104                $object = $this->get_object( $term->slug );
     105                $title = sprintf( "[%s] %s", esc_html( $object->post_title ), esc_html( $title ) );
     106            }
    107107        }
    108108        return $title;
Note: See TracChangeset for help on using the changeset viewer.