Making WordPress.org

Changeset 5719


Ignore:
Timestamp:
07/26/2017 02:45:28 AM (9 years ago)
Author:
tellyworth
Message:

Plugin directory: limit browse queries to 99 pages of results. Props @SergeyBiryukov

Fixes #496

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r5718 r5719  
    3636                add_filter( 'term_link', array( $this, 'filter_term_link' ), 10, 2 );
    3737                add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
     38                add_filter( 'found_posts', array( $this, 'filter_found_posts' ), 10, 2 );
    3839                add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) );
    3940                add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) );
     
    799800                        $wp_query->query_vars['meta_key'] = '_active_installs';
    800801                }
     802        }
     803
     804        /**
     805         * Filter to limit the total number of found posts in browse queries.
     806         * Stops search crawlers from paginating through the entire DB.
     807         */
     808        public function filter_found_posts( $found_posts, $wp_query ) {
     809                if ( isset( $wp_query->query['browse'] ) && in_array( 'plugin', $wp_query->query_vars['post_type'] ) ) {
     810                        return min( $found_posts, 99 * $wp_query->query_vars['posts_per_page'] ); // 99 pages
     811                }
     812
     813                return $found_posts;
    801814        }
    802815
Note: See TracChangeset for help on using the changeset viewer.