From 9fbe63269c83934e74df3117aa52da3626027cc4 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 27 Aug 2020 23:08:55 +1000 Subject: [PATCH] Enable future events in WP 5.5 REST API --- includes/api/class-sp-rest-posts-controller.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/api/class-sp-rest-posts-controller.php b/includes/api/class-sp-rest-posts-controller.php index 78b7de33..617e1c25 100644 --- a/includes/api/class-sp-rest-posts-controller.php +++ b/includes/api/class-sp-rest-posts-controller.php @@ -6,5 +6,20 @@ if ( class_exists( 'WP_REST_Posts_Controller' ) ) { parent::__construct( $post_type ); $this->namespace = 'sportspress/v2'; } - } + + public function check_read_permission( $post ) { + $post_type = get_post_type_object( $post->post_type ); + if ( ! $this->check_is_post_type_allowed( $post_type ) ) { + return false; + } + + if ( 'sp_event' === $post->post_type ) { + if ( in_array( $post->post_status, array( 'publish', 'future' ) ) || current_user_can( 'read_post', $post->ID ) ) { + return true; + } + } else { + return WP_REST_Posts_Controller::check_read_permission( $post ); + } + } + } }