Last active
July 21, 2021 17:25
-
-
Save andrasguseo/f9c37187d4b57ad1ebac3e3c7cc5f0e5 to your computer and use it in GitHub Desktop.
GigPress > Add an end date to the event schema markup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Description: Add an end date to the event schema markup. | |
* Usage: Paste the below snippet into your active (child) theme's functions.php file | |
* | |
* Plugin: GigPress | |
* Author: Andras Guseo | |
* Last updated: 2021-07-21 | |
*/ | |
add_filter( 'gigpress_show_json_ld_markup', 'gigpress_add_enddate_to_schema', 10, 2 ); | |
function gigpress_add_enddate_to_schema( $show_markup, $showdata ) { | |
// Do if end date is not set | |
if ( empty( $show_markup['endDate'] ) ) { | |
// Grab the end date and make a DateTime object | |
// This will make it UTC timezone despite what the site timezone is | |
$end_date = new DateTime( $showdata['iso_end_date'] ); | |
// Set the timezone to the site timezone | |
// This will also adjust the time as well | |
$end_date->setTimezone( wp_timezone() ); | |
// Get the timezone offset between UTC (PHP timezone?) and site timezone | |
$tz_offset = timezone_offset_get( wp_timezone(), $end_date ); | |
// Substract the timezone difference from the time | |
// This will 'reset' the time to the original with the appropriate time zone | |
date_sub( $end_date, date_interval_create_from_date_string( $tz_offset . ' seconds' ) ); | |
// Add 1 hour to the end date | |
date_add( $end_date, date_interval_create_from_date_string('1 hour' ) ); | |
// Format it | |
$end_date = date_format( $end_date, 'c' ); | |
// Add it to the array | |
$show_markup['endDate'] = $end_date; | |
} | |
return $show_markup; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment