Making WordPress.org


Ignore:
Timestamp:
10/26/2016 10:59:07 PM (8 years ago)
Author:
coffee2code
Message:

Support Forums, Support Compat: Insert link to plugin or theme's support or review view into breadcrumbs in single topic view.

The breadcrumb was already modified in this manner in plugin and theme support/review views, but not for their constituent topics.

Fixes #2181.

File:
1 edited

Legend:

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

    r4290 r4298  
    3333            // Load plugin/theme subscriptions.
    3434            add_action( 'plugins_loaded', array( $this, 'load_compat_subscriptions' ), 9 );
     35
     36            // Adjust breadcrumbs for plugin and theme related topics.
     37            add_filter( 'bbp_breadcrumbs', array( $this, 'breadcrumbs' ) );
    3538
    3639            $this->loaded = true;
     
    354357        return $cleanslugs;
    355358    }
     359
     360    /**
     361     * Modifies breadcrumbs for plugin or theme related support or review topic
     362     * views to insert a link to the specific plugin/theme's support or review
     363     * view.
     364     *
     365     * @param array $r Breadcrumb items.
     366     * @return array
     367     */
     368    public function breadcrumbs( $r ) {
     369        if ( ! bbp_is_single_topic() ) {
     370            return $r;
     371        }
     372
     373        $forum_id = bbp_get_topic_forum_id();
     374        $topic_id = bbp_get_topic_id();
     375        $slugs = $types = array();
     376
     377        // Check if the topic is associated with a plugin.
     378        if ( $forum_id === Plugin::PLUGINS_FORUM_ID ) {
     379            $types = array( 'plugin' );
     380        }
     381        // Else check if the topic is associated with a theme.
     382        elseif ( $forum_id === Plugin::THEMES_FORUM_ID ) {
     383            $types = array( 'theme' );
     384        }
     385        // Else check if the topic is a review.
     386        elseif ( $forum_id === Plugin::REVIEWS_FORUM_ID ) {
     387            // Need to check for plugin AND theme association to know which the review is for.
     388            $types = array( 'plugin', 'theme' );
     389        }
     390        // Else not a type of concern.
     391        else {
     392            return $r;
     393        }
     394
     395        foreach ( $types as $type ) {
     396            $slugs = wp_get_post_terms( $topic_id, 'topic-' . $type, array( 'fields' => 'slugs' ) );
     397            if ( $slugs ) {
     398                break;
     399            }
     400        }
     401
     402        if ( ! $slugs ) {
     403            return $r;
     404        }
     405
     406        $obj = Directory_Compat::get_object_by_slug_and_type( $slugs[0], $type );
     407
     408        if ( ! $obj ) {
     409            return $r;
     410        }
     411
     412        $url = 'https://wordpress.org/support/' . $type . '/' . $obj->post_name . '/';
     413        if ( $forum_id === Plugin::REVIEWS_FORUM_ID ) {
     414            $url .= 'reviews';
     415        }
     416
     417        $link = sprintf(
     418            '<a href="%s" class="bbp-breadcrumb-forum">%s</a>',
     419            esc_url( $url ),
     420            esc_html( $obj->post_title )
     421        );
     422
     423        // Insert link before topic title.
     424        array_splice( $r, 2, 0, $link );
     425
     426        return $r;
     427    }
     428
    356429}
Note: See TracChangeset for help on using the changeset viewer.