Skip to content

Commit

Permalink
Migrate 'Site Health Check' related code to 'ft-maintenance' (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion authored Feb 10, 2024
2 parents 26ab97c + 612b827 commit c4fc637
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
46 changes: 21 additions & 25 deletions inc/disable-public-json-rest-api/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
*
* @return void
*/
function bootstrap() :void {
function bootstrap(): void {

add_action( 'init', __NAMESPACE__ . '\\load', 0 );

}

/**
* Load the modifications to the REST API.
*
* @return void
*/
function load() :void {
function load(): void {

// Disable some endpoints for unauthenticated users.
add_filter( 'rest_endpoints', __NAMESPACE__ . '\\disable_default_endpoints', 1000 );
Expand Down Expand Up @@ -77,25 +76,25 @@ function load() :void {
*
* ```
* add_filter( 'rest_authentication_errors', function( $result ) {
* // If a previous authentication check was applied,
* // pass that result along without modification.
* if ( true === $result || is_wp_error( $result ) ) {
* return $result;
* }
* // If a previous authentication check was applied,
* // pass that result along without modification.
* if ( true === $result || is_wp_error( $result ) ) {
* return $result;
* }
*
* // No authentication has been performed yet.
* // Return an error if user is not logged in.
* if ( ! is_user_logged_in() ) {
* return new WP_Error(
* 'rest_not_logged_in',
* __( 'You are not currently logged in.' ),
* array( 'status' => 401 )
* );
* }
* // No authentication has been performed yet.
* // Return an error if user is not logged in.
* if ( ! is_user_logged_in() ) {
* return new WP_Error(
* 'rest_not_logged_in',
* __( 'You are not currently logged in.' ),
* array( 'status' => 401 )
* );
* }
*
* // Our custom authentication check should have no effect
* // on logged-in requests
* return $result;
* // Our custom authentication check should have no effect
* // on logged-in requests
* return $result;
* });
* ```
*/
Expand All @@ -112,7 +111,7 @@ function load() :void {
*
* @return array<string, mixed> $endpoints
*/
function disable_default_endpoints( array $endpoints ) :array {
function disable_default_endpoints( array $endpoints ): array {

if ( is_user_logged_in() ) {
return $endpoints;
Expand Down Expand Up @@ -195,9 +194,6 @@ function disable_default_endpoints( array $endpoints ) :array {

'/wp/v2/ft_product',

'/wp-site-health/v1/tests',
'/wp-site-health/v1/directory-sizes',

'/wp-block-editor/v1',
'/wp-block-editor/v1/url-details',
'/wp-block-editor/v1/export',
Expand Down Expand Up @@ -239,7 +235,7 @@ function disable_default_endpoints( array $endpoints ) :array {

$endpoints = array_filter(
$endpoints,
function( $k ) use ( $endpoints_to_remove ) {
function ( $k ) use ( $endpoints_to_remove ) {

// Reduce keys.
$_k = explode( '/(?P', $k );
Expand Down
2 changes: 1 addition & 1 deletion inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @return void
*/
function register() :void {
function register(): void {

$default_settings = [
'enabled' => true, // Needs to be set.
Expand Down

0 comments on commit c4fc637

Please sign in to comment.