Making WordPress.org

Ticket #2934: 2934-rest-api.diff

File 2934-rest-api.diff, 3.2 KB (added by RMarks, 6 years ago)

Disable REST API

  • wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wordcamp-coming-soon-page.php

    diff --git wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wordcamp-coming-soon-page.php wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wordcamp-coming-soon-page.php
    index 0f832ce..9912397 100644
    class WordCamp_Coming_Soon_Page { 
    88         * Constructor
    99         */
    1010        public function __construct() {
    11                 add_action( 'init',               array( $this, 'init' ), 11 );                               // after WCCSP_Settings::init()
    12                 add_action( 'wp_enqueue_scripts', array( $this, 'manage_plugin_theme_stylesheets' ), 99 );    // (hopefully) after all plugins/themes have enqueued their styles
    13                 add_action( 'wp_head',            array( $this, 'render_dynamic_styles' ) );
    14                 add_filter( 'template_include',   array( $this, 'override_theme_template' ) );
    15                 add_action( 'template_redirect',  array( $this, 'disable_jetpacks_open_graph' ) );
    16                 add_action( 'admin_bar_menu',     array( $this, 'admin_bar_menu_item' ), 1000 );
    17                 add_action( 'admin_head',         array( $this, 'admin_bar_styling' ) );
    18                 add_action( 'wp_head',            array( $this, 'admin_bar_styling' ) );
    19                 add_action( 'admin_notices',      array( $this, 'block_new_post_admin_notice' ) );
    20                 add_filter( 'get_post_metadata',  array( $this, 'jetpack_dont_email_post_to_subs' ), 10, 4 );
     11                add_action( 'init',                       array( $this, 'init' ), 11 );                               // after WCCSP_Settings::init()
     12                add_action( 'wp_enqueue_scripts',         array( $this, 'manage_plugin_theme_stylesheets' ), 99 );    // (hopefully) after all plugins/themes have enqueued their styles
     13                add_action( 'wp_head',                    array( $this, 'render_dynamic_styles' ) );
     14                add_filter( 'template_include',           array( $this, 'override_theme_template' ) );
     15                add_action( 'template_redirect',          array( $this, 'disable_jetpacks_open_graph' ) );
     16                add_filter( 'rest_authentication_errors', array( $this, 'disable_rest_endpoints' ) );
     17                add_action( 'admin_bar_menu',             array( $this, 'admin_bar_menu_item' ), 1000 );
     18                add_action( 'admin_head',                 array( $this, 'admin_bar_styling' ) );
     19                add_action( 'wp_head',                    array( $this, 'admin_bar_styling' ) );
     20                add_action( 'admin_notices',              array( $this, 'block_new_post_admin_notice' ) );
     21                add_filter( 'get_post_metadata',          array( $this, 'jetpack_dont_email_post_to_subs' ), 10, 4 );
    2122
    2223                add_image_size( 'wccsp_image_medium_rectangle', 500, 300 );
    2324        }
    class WordCamp_Coming_Soon_Page { 
    119120        }
    120121
    121122        /**
     123         * Disable the REST API when the Coming Soon page is active
     124         */
     125        public function disable_rest_endpoints( $access ) {
     126                if ( $this->override_theme_template ) {
     127                        return new WP_Error( 'rest_cannot_access', __( 'The REST API has been disabled while in Coming Soon mode.', 'disable-json-api' ), array( 'status' => 403 ) );
     128                }
     129        }
     130
     131        /**
    122132         * Collect all of the variables the Coming Soon template will need
    123133         * Doing this here keeps the template less cluttered and more of a pure view
    124134         *