Making WordPress.org

Changeset 12529


Ignore:
Timestamp:
04/11/2023 03:18:35 AM (4 years ago)
Author:
dd32
Message:

Support Forums: Disable RSS feeds for bbPress views that don't exist.

These views ultimately query for all posts, without any query restrictions, which ultimately causes exceesive load on the support forums.

See ​https://bbpress.trac.wordpress.org/ticket/3544.

File:
1 edited

Legend:

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

    r12031 r12529  
    6464                // ..and don't do expensive orderbys & counting for user queries that don't need it.
    6565                add_action( 'pre_get_users', array( $this, 'pre_get_users' ) );
     66
     67                // Disable feeds for non-existent views. See https://bbpress.trac.wordpress.org/ticket/3544
     68                add_action( 'bbp_request', array( $this, 'bbp_request_disable_missing_view_feeds' ), 9 ); // Before bbp_request_feed_trap().
    6669        }
    6770
    … …  
    636639                }
    637640        }
     641
     642        /**
     643         * Disable feeds for missing bbPress views.
     644         *
     645         * @see https://bbpress.trac.wordpress.org/ticket/3544
     646         *
     647         * @param array $query_vars
     648         * @return array
     649         */
     650        public function bbp_request_disable_missing_view_feeds( $query_vars ) {
     651                $view_id = bbp_get_view_rewrite_id();
     652
     653                if (
     654                        isset( $query_vars['feed'] ) &&
     655                        isset( $query_vars[ $view_id ] ) &&
     656                        ! bbp_get_view_query_args( $query_vars[ $view_id ] )
     657                ) {
     658                        unset( $query_vars[ $view_id ] );
     659
     660                        // Set a 404 status, without this bbPress is unsure of what to do.
     661                        $query_vars['error'] = 404;
     662                }
     663
     664                return $query_vars;
     665        }
    638666}
Note: See TracChangeset for help on using the changeset viewer.