-
-
Save JoshuaDoshua/26ae2e34f6472db32f139ae4a4519fd4 to your computer and use it in GitHub Desktop.
Function to create Add to Google Calendar link
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 | |
function squarecandy_add_to_gcal( | |
$name, | |
$startDate, | |
$endDate = false, | |
$isAllDay = false, | |
$description = null, | |
$location = null | |
) { | |
$shortFormat = "Ymd"; | |
$longFormat = "Ymd\THis"; | |
$startDate = strtotime($startDate); | |
$endDate = strtotime($endDate); | |
$startDate = $isAllDay | |
? date($shortFormat, $startDate) | |
: date($longFormat, $startDate); | |
$endDate = $isAllDay | |
? date($shortFormat, $endDate) | |
: date($longFormat, $endDate); | |
$url = 'http://www.google.com/calendar/event?'; | |
$url .= http_build_query([ | |
'action' => 'TEMPLATE', | |
'dates' => $startdate . '/' . $enddate, | |
'details' => $description, | |
'location' => $location | |
]); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment