Making WordPress.org

Ticket #496: 496.diff

File 496.diff, 1.6 KB (added by SergeyBiryukov, 8 years ago)
  • wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

     
    3535                add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 );
    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' ) );
    4041                add_action( 'template_redirect', array( $this, 'prevent_canonical_for_plugins' ), 9 );
     
    795796        }
    796797
    797798        /**
     799         * Filter to limit the total number of found posts in browse queries.
     800         * Stops search crawlers from paginating through the entire DB.
     801         */
     802        public function filter_found_posts( $found_posts, $wp_query ) {
     803                if ( isset( $wp_query->query['browse'] ) && in_array( 'plugin', $wp_query->query_vars['post_type'] ) ) {
     804                        return min( $found_posts, 99 * $wp_query->query_vars['posts_per_page'] ); // 99 pages
     805                }
     806
     807                return $found_posts;
     808        }
     809
     810        /**
    798811         * Filter to bypass caching for options critical to Jetpack sync to work around race conditions and other unidentified bugs.
    799812         * If this works and becomes a permanent solution, it probably belongs elsewhere.
    800813         */