Last active
December 5, 2022 13:19
-
-
Save indikatordesign/272a9fd869027c7722526b460aa103dc to your computer and use it in GitHub Desktop.
WordPress - Get the next 12 am timestamp (sheduled actions etc.)
This file contains hidden or 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 | |
/** | |
* Do not allow direct access | |
* | |
* @since 1.0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) die( 'Nothing to find Ma\'am..' ); | |
/** | |
* Your Plugin Name - Controller Helpers | |
* | |
* @since 1.0 | |
*/ | |
if ( ! class_exists( 'controllerHelpers' ) ) | |
{ | |
final class controllerHelpers | |
{ | |
/** | |
* Get the next 12:00 am timestamp | |
* | |
* @since 1.0 | |
*/ | |
public function twelveTimestamp() | |
{ | |
$time = time(); | |
$hour = (int) date( 'H', $time ); | |
if ( $hour >= 11 ) // to be sure | |
$add = 24 - $hour + 2; // next day | |
if ( isset( $add ) ) | |
$setTarget = date( 'Y-m-d', $time + ( $add * HOUR_IN_SECONDS ) ) . ' 12:00:00'; | |
else | |
$setTarget = date( 'Y-m-d', $time ) . ' 12:00:00'; | |
return DateTime::createFromFormat( 'Y-m-d H:i:s', $setTarget )->getTimestamp(); | |
} // end twelveTimestamp | |
} // end class | |
} // end if | |
$timestamp = ( new controllerHelpers )->twelveTimestamp(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment