Making WordPress.org

Changeset 4503


Ignore:
Timestamp:
12/08/2016 12:20:33 PM (7 years ago)
Author:
ocean90
Message:

Support Forums: Disable REST API endpoint for users listing.

The default query doesn't scale well, see #core38878.

File:
1 edited

Legend:

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

    r4502 r4503  
    22
    33namespace WordPressdotorg\Forums;
     4
     5use WP_Error;
    46
    57class Performance_Optimizations {
     
    3133        // Redirect search results.
    3234        add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results_to_google_search' ) );
     35
     36        // REST API.
     37        add_filter( 'rest_endpoints', array( $this, 'disable_rest_api_users_endpoint' ) );
     38    }
     39
     40    /**
     41     * Disables REST API endpoint for users listing.
     42     *
     43     * @link https://core.trac.wordpress.org/ticket/38878
     44     *
     45     * @param array $endpoints The available endpoints.
     46     * @return array The filtered endpoints.
     47     */
     48    public function disable_rest_api_users_endpoint( $endpoints ) {
     49        foreach ( $endpoints['/wp/v2/users'] as &$handler ) {
     50            if ( isset( $handler['methods'] ) && 'GET' === $handler['methods'] ) {
     51                $handler['permission_callback'] = function() {
     52                    return new WP_Error(
     53                        'rest_not_implemented',
     54                        __( 'Sorry, you are not allowed to list users.' ),
     55                        array( 'status' => 501 )
     56                    );
     57                };
     58
     59                break;
     60            }
     61        }
     62
     63        return $endpoints;
    3364    }
    3465
Note: See TracChangeset for help on using the changeset viewer.