Making WordPress.org

Changeset 4583


Ignore:
Timestamp:
12/23/2016 07:11:25 PM (8 years ago)
Author:
coffee2code
Message:

Support Forums: Hide select forums from forum listings.

Forums are intentionally still directly accessible and may not necessarily be closed.

Hides Meetups, Plugins and Hacks, Reviews, Themes and Templates, Your WordPress.

File:
1 edited

Legend:

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

    r4331 r4583  
    1212    var $user       = null;
    1313
     14    /**
     15     * Forums to be hidden from main forum listing.
     16     *
     17     * @var array
     18     */
     19    const HIDDEN_FORUMS = array(
     20        21261, // Themes and Templates
     21        21262, // Plugins and Hacks
     22        21267, // Your WordPress
     23        21270, // Meetups
     24        21272, // Reviews
     25    );
     26
    1427    public function __construct() {
    1528        if ( ! $this->loaded ) {
     
    4053            add_action( 'template_redirect', array( $this, 'redirect_old_topic_id' ), 9 );
    4154
     55            // Exclude certain forums from forum queries.
     56            add_action( 'pre_get_posts', array( $this, 'exclude_hidden_forums' ), 1 );
     57
    4258            $this->loaded = true;
     59        }
     60    }
     61
     62    /**
     63     * Excludes certain forums from queries for forums.
     64     *
     65     * Notes:
     66     * - The forums themselves are still meant to be directly accessible.
     67     * - A hidden forum may not necessarily be closed.
     68     *
     69     * @param WP_Query $q Query object.
     70     */
     71    public function exclude_hidden_forums( $q ) {
     72        if (
     73            ! is_admin()
     74            &&
     75            ! empty( $q->query_vars['post_type'] )
     76            &&
     77            bbp_get_forum_post_type() === $q->query_vars['post_type']
     78            &&
     79            empty( $q->query_vars['forum'] )
     80        ) {
     81            $q->query_vars['post__not_in'] = array_merge( $q->query_vars['post__not_in'], self::HIDDEN_FORUMS );
    4382        }
    4483    }
Note: See TracChangeset for help on using the changeset viewer.