Ticket #496: 496-limit-found-posts.diff
File 496-limit-found-posts.diff, 1.5 KB (added by , 8 years ago) |
---|
-
class-plugin-directory.php
33 33 add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 ); 34 34 add_filter( 'term_link', array( $this, 'filter_term_link' ), 10, 2 ); 35 35 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); 36 add_filter( 'found_posts', array( $this, 'filter_found_posts' ), 10, 2 ); 36 37 add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) ); 37 38 add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) ); 38 39 add_action( 'template_redirect', array( $this, 'prevent_canonical_for_plugins' ), 9 ); … … 803 804 } 804 805 805 806 /** 807 * Filter to limit the total number of found posts in browse queries. 808 * Stops search crawlers from paginating through the entire DB. 809 */ 810 public function filter_found_posts( $found_posts, $wp_query ) { 811 if ( isset( $wp_query->query['browse'] ) && in_array( 'plugin', $wp_query->query_vars['post_type'] ) ) 812 return min( $found_posts, 200 * $wp_query->query_vars['posts_per_page'] ); // 200 pages 813 return $found_posts; 814 } 815 816 /** 806 817 * Filter to bypass caching for options critical to Jetpack sync to work around race conditions and other unidentified bugs. 807 818 * If this works and becomes a permanent solution, it probably belongs elsewhere. 808 819 */