From d3e3a6524e4393b10e219ba585455f25ed9c76ab Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 30 Oct 2016 18:30:21 +1100 Subject: [PATCH] Fix view future events via REST API --- includes/sp-template-hooks.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index 7ad5aeb2..cfd2a693 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -280,6 +280,28 @@ function sportspress_show_future_posts( $where, $that ) { } add_filter( 'posts_where', 'sportspress_show_future_posts', 2, 10 ); +function sportspress_give_event_read_permissions( $allcaps, $caps, $args ) { + + // Bail out if we're not asking about viewing an event + if ( 'read_sp_event' !== $args[0] ) + return $allcaps; + + // Load the post data + $post = get_post( $args[2] ); + + // Bail out if the event isn't scheduled + if ( 'future' != $post->post_status ) + return $allcaps; + + // Add post capabilities + foreach ( $caps as $cap ) { + $allcaps[ $cap ] = true; + } + + return $allcaps; +} +add_filter( 'user_has_cap', 'sportspress_give_event_read_permissions', 10, 3 ); + function sportspress_sanitize_title( $title ) { if ( isset( $_POST ) && array_key_exists( 'taxonomy', $_POST ) ):