Skip to content

Instantly share code, notes, and snippets.

@kurosuke
Last active November 18, 2018 08:15
Show Gist options
  • Save kurosuke/ac45958850c07790750d52851b957e31 to your computer and use it in GitHub Desktop.
Save kurosuke/ac45958850c07790750d52851b957e31 to your computer and use it in GitHub Desktop.
function shortcode_open_date_view($atts = '', $content = '') {
$tz = new DateTimeZone('Asia/Tokyo');
// get now
$now = new DateTime('now', $tz);
$format = 'Y-m-d H:i:s';
// get argment
extract(shortcode_atts([
'open' => ''], $atts));
// get argment open_date
$open_date = DateTime::createFromFormat($format, $open, $tz);
if ($now > $open_date) {
// view contents
// do shortcode in this shortcode
$content_expand = do_shortcode($content);
return $content_expand;
} else {
// not yet open date
return '';
}
}
add_shortcode('open_date_view', 'shortcode_open_date_view');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment