Skip to content

Instantly share code, notes, and snippets.

@bskousen
Created December 17, 2019 18:18
Show Gist options
  • Save bskousen/1cb8946e5d617c1a4369eab9538fad6d to your computer and use it in GitHub Desktop.
Save bskousen/1cb8946e5d617c1a4369eab9538fad6d to your computer and use it in GitHub Desktop.
The Events Calendar REST API Hide from Listing fix
<?php
/**
* Plugin Name: The Events Calendar REST API Hide from Listing fix
* Description: This plugin is a temporary fix for The Events Calendar REST API issue that prevents events updated via
* the REST API from correctly showing in the calendar.
*/
/**
* Filters the post array arguments generated during a TEC REST request to update an event to remove empty
* `hide_from_listings` values.
*
* @param array $postarr The post array, as prepared from The Events Calendar code.
*
* @return array The post array, filtered to remove the empty `_EventHideFromUpcoming` value, if required.
*/
function remove_empty_hide_from_listings_value( array $postarr ) {
if ( isset( $postarr['EventHideFromUpcoming'] ) && ! tribe_is_truthy( $postarr['EventHideFromUpcoming'] ) ) {
$postarr = array_diff_key( $postarr, [ 'EventHideFromUpcoming', 'EventHideFromUpcoming' ] );
}
return $postarr;
}
add_filter( 'tribe_events_rest_event_prepare_postarr', 'remove_empty_hide_from_listings_value' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment