Making WordPress.org

Changeset 3990


Ignore:
Timestamp:
09/07/2016 03:15:35 PM (9 years ago)
Author:
jmdodd
Message:

Support Forums: Prevent forum changes on topic edit for topics in the compat forums.

File:
1 edited

Legend:

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

    r3986 r3990  
    1313        if ( ! $this->loaded ) {
    1414
     15            // Exclude compat forums from forum dropdown.
     16            add_filter( 'bbp_after_get_dropdown_parse_args', array( $this, 'get_dropdown' ) );
     17
    1518            // Topic resolution modifications.
    1619            add_filter( 'wporg_bbp_topic_resolution_is_enabled_on_forum', array( $this, 'is_enabled_on_forum' ), 10, 2 );
     
    1821            $this->loaded = true;
    1922        }
     23    }
     24
     25    /**
     26     * Remove compat forums from forum dropdown.
     27     *
     28     * @param array $r The function args
     29     * @return array The filtered args
     30     */
     31    public function get_dropdown( $r ) {
     32        if ( ! isset( $r['post_type'] ) || ! $r['post_type'] == bbp_get_forum_post_type() ) {
     33            return $r;
     34        }
     35
     36        // Set up compat forum exclusion.
     37        if ( bbp_is_topic_edit() || bbp_is_single_view() ) {
     38            $r['exclude'] = array_unique( array_merge( $r['exclude'], self::get_compat_forums() ) );
     39
     40            if ( self::is_compat_forum( $r['selected'] ) ) {
     41                // Prevent forum changes for topics in compat forums.
     42                add_filter( 'bbp_get_dropdown', array( $this, 'dropdown' ), 10, 2 );
     43            }
     44        }
     45        return $r;
     46    }
     47
     48    /**
     49     * Disable forum changes on topics in the compat forums.
     50     *
     51     * @param string $retval The dropdown
     52     * @param array $r The function arguments
     53     * @return string The dropdown, or substituted hidden input
     54     */
     55    public function dropdown( $retval, $r ) {
     56        if ( self::is_compat_forum( $r['selected'] ) ) {
     57            $retval = esc_html( bbp_get_forum_title( $r['selected'] ) );
     58            $retval .= sprintf( '<input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="%d" />', (int) $r['selected'] );
     59        }
     60        return $retval;
    2061    }
    2162
     
    4586        return $retval;
    4687    }
     88
     89    public static function get_compat_forums() {
     90        return array( Plugin::PLUGINS_FORUM_ID, Plugin::THEMES_FORUM_ID, Plugin::REVIEWS_FORUM_ID );
     91    }
     92
     93    public static function is_compat_forum( $post_id = 0 ) {
     94        if ( empty( $post_id ) ) {
     95            return false;
     96        }
     97        return in_array( $post_id, self::get_compat_forums() );
     98    }
    4799}
Note: See TracChangeset for help on using the changeset viewer.