PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.9.2
WP 2FA – Two-factor authentication for WordPress v2.9.2
1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Utils / class-date-time-utils.php
wp-2fa / includes / classes / Utils Last commit date
class-abstract-migration.php 10 months ago class-date-time-utils.php 10 months ago class-debugging.php 10 months ago class-generate-modal.php 10 months ago class-migration.php 10 months ago class-request-utils.php 10 months ago class-settings-utils.php 10 months ago class-user-utils.php 10 months ago class-validator.php 10 months ago class-white-label.php 10 months ago index.php 10 months ago
class-date-time-utils.php
78 lines
1 <?php
2 /**
3 * Responsible for date / time manipulation.
4 *
5 * @package wp2fa
6 * @subpackage utils
7 * @copyright 2025 Melapress
8 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
9 * @link https://wordpress.org/plugins/wp-2fa/
10 * @since 1.4.2
11 */
12
13 declare(strict_types=1);
14
15 namespace WP2FA\Utils;
16
17 use WP2FA\Admin\Helpers\User_Helper;
18
19 if ( ! class_exists( '\WP2FA\Utils\Date_Time_Utils' ) ) {
20 /**
21 * Utility class for date and time manipulation, format conversion and so on.
22 *
23 * @package WP2FA\Utils
24 *
25 * @since 1.4.2
26 */
27 class Date_Time_Utils {
28
29 /**
30 * Formats the date string
31 *
32 * @param string|null $grace_policy Grace policy value.
33 * @param int $grace_expiry Expiration time as unix based timestamp.
34 *
35 * @return string Translated grace period expiration string.
36 *
37 * @since 1.4.2
38 */
39 public static function format_grace_period_expiration_string( $grace_policy = null, $grace_expiry = -1 ) {
40 if ( null === $grace_policy ) {
41 $grace_policy = Settings_Utils::get_setting_role( User_Helper::get_user_role(), 'grace-policy' );
42 }
43
44 if ( 'no-grace-period' === $grace_policy ) {
45 return \esc_html__( 'no grace period', 'wp-2fa' );
46 }
47
48 if ( -1 === $grace_expiry ) {
49 if ( 'use-grace-period' === $grace_policy ) {
50 $grace_period = Settings_Utils::get_setting_role( User_Helper::get_user_role(), 'grace-period' );
51 $grace_period_denominator = Settings_Utils::get_setting_role( User_Helper::get_user_role(), 'grace-period-denominator' );
52 $grace_period_string = sanitize_text_field( $grace_period . ' ' . $grace_period_denominator );
53 $grace_expiry = (int) strtotime( $grace_period_string );
54 } else {
55 // this will probably never be reached, leaving it here for now just in case.
56 $grace_expiry = time();
57 }
58 }
59
60 $grace_expiry = \gmdate( 'Y-m-d H:i:s', $grace_expiry );
61
62 $expiration_date_time = implode(
63 ' ',
64 array(
65 // Purposefully not using the SettingsUtil class as we don't want this prefixed.
66 \get_date_from_gmt( $grace_expiry, get_option( 'date_format' ) ),
67 \get_date_from_gmt( $grace_expiry, get_option( 'time_format' ) ),
68 // wp_date( get_option( 'date_format' ), $grace_expiry ),
69 // wp_date( get_option( 'time_format' ), $grace_expiry ),
70 )
71 );
72
73 /* translators: Grace period expiration label. %s: Date and time formatted using WordPress date and time formats. */
74 return sprintf( \esc_html__( 'before %s', 'wp-2fa' ), esc_html( $expiration_date_time ) );
75 }
76 }
77 }
78