class-abstract-migration.php
3 years ago
class-date-time-utils.php
3 years ago
class-debugging.php
3 years ago
class-generate-modal.php
3 years ago
class-migration.php
3 years ago
class-request-utils.php
3 years ago
class-settings-utils.php
3 years ago
class-user-utils.php
3 years ago
index.php
5 years ago
class-date-time-utils.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsible for date / time manipulation. |
| 4 | * |
| 5 | * @package wp2fa |
| 6 | * @subpackage utils |
| 7 | * @copyright 2023 WP White Security |
| 8 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 9 | * @link https://wordpress.org/plugins/wp-2fa/ |
| 10 | */ |
| 11 | |
| 12 | namespace WP2FA\Utils; |
| 13 | |
| 14 | use WP2FA\WP2FA as WP2FA; |
| 15 | |
| 16 | /** |
| 17 | * Utility class for date and time manipulation, format conversion and so on. |
| 18 | * |
| 19 | * @package WP2FA\Utils |
| 20 | * @since 1.4.2 |
| 21 | */ |
| 22 | class Date_Time_Utils { |
| 23 | |
| 24 | /** |
| 25 | * Formats the date string |
| 26 | * |
| 27 | * @param string|null $grace_policy Grace policy value. |
| 28 | * @param int $grace_expiry Expiration time as unix based timestamp. |
| 29 | * |
| 30 | * @return string Translated grace period expiration string. |
| 31 | */ |
| 32 | public static function format_grace_period_expiration_string( $grace_policy = null, $grace_expiry = - 1 ) { |
| 33 | if ( null === $grace_policy ) { |
| 34 | $grace_policy = WP2FA::get_wp2fa_setting( 'grace-policy' ); |
| 35 | } |
| 36 | |
| 37 | if ( 'no-grace-period' === $grace_policy ) { |
| 38 | return esc_html__( 'no grace period', 'wp-2fa' ); |
| 39 | } |
| 40 | |
| 41 | if ( -1 === $grace_expiry ) { |
| 42 | if ( 'use-grace-period' === $grace_policy ) { |
| 43 | $grace_period = WP2FA::get_wp2fa_setting( 'grace-period' ); |
| 44 | $grace_period_denominator = WP2FA::get_wp2fa_setting( 'grace-period-denominator' ); |
| 45 | $grace_period_string = $grace_period . ' ' . $grace_period_denominator; |
| 46 | $grace_expiry = (int) strtotime( $grace_period_string ); |
| 47 | } else { |
| 48 | // this will probably never be reached, leaving it here for now just in case. |
| 49 | $grace_expiry = time(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | $expiration_date_time = implode( |
| 54 | ' ', |
| 55 | array( |
| 56 | // Purposefully not using the SettingsUtil class as we don't want this prefixed. |
| 57 | date_i18n( get_option( 'date_format' ), $grace_expiry ), |
| 58 | date_i18n( get_option( 'time_format' ), $grace_expiry ), |
| 59 | ) |
| 60 | ); |
| 61 | |
| 62 | /* translators: Grace period expiration label. %s: Date and time formatted using WordPress date and time formats. */ |
| 63 | return sprintf( esc_html__( 'before %s', 'wp-2fa' ), $expiration_date_time ); |
| 64 | } |
| 65 | } |
| 66 |