From 6723b5d5cb835575fb30e99179b40b0d9a076185 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Tue, 12 Nov 2024 11:05:25 +0200 Subject: [PATCH 1/5] Make next payment date translatable * ENHANCEMENT: Adjusted the `format_subscription_date` to be translatable and reworked the logic to support this. --- classes/class-pmpro-subscription.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/classes/class-pmpro-subscription.php b/classes/class-pmpro-subscription.php index 3233b3de6..f6958330e 100644 --- a/classes/class-pmpro-subscription.php +++ b/classes/class-pmpro-subscription.php @@ -783,22 +783,24 @@ private function format_subscription_date( $date, $format = 'timestamp', $local_ // Get date in WP local timezone. if ( $local_time ) { - if( 'U' === $format ){ - // When formatting using the epoch, the date must already consider the timezone offset. - // Then, first apply a simple format to add the timezone. - $date = get_date_from_gmt( $date ); + + $date = get_date_from_gmt( $date ); + + // If it's not a timestamp, conver it to one for the date_i18n function. + if ( ! is_numeric( $date ) ) { + $date = strtotime( $date ); } - return get_date_from_gmt( $date, $format ); + return date_i18n( $format, $date, true ); } - // Allow timestamps. + // If it's not a timestamp, conver it to one for the date_i18n function. if ( ! is_numeric( $date ) ) { $date = strtotime( $date ); } - // Get date in GMT timezone. - return gmdate( $format, $date ); + $date = gmdate( $date ); + return date_i18n( $format, $date, true ); } /** From 49bfc6a1d5b659f2b76ee8c0e3893fd071f343c3 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Tue, 12 Nov 2024 11:08:26 +0200 Subject: [PATCH 2/5] Rework is_numeric. It's not needed --- classes/class-pmpro-subscription.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/classes/class-pmpro-subscription.php b/classes/class-pmpro-subscription.php index f6958330e..040d86087 100644 --- a/classes/class-pmpro-subscription.php +++ b/classes/class-pmpro-subscription.php @@ -783,14 +783,7 @@ private function format_subscription_date( $date, $format = 'timestamp', $local_ // Get date in WP local timezone. if ( $local_time ) { - - $date = get_date_from_gmt( $date ); - - // If it's not a timestamp, conver it to one for the date_i18n function. - if ( ! is_numeric( $date ) ) { - $date = strtotime( $date ); - } - + $date = strtotime( get_date_from_gmt( $date ) ); return date_i18n( $format, $date, true ); } From 12809189d93e5bd9a83371f1f4b8b2b2a32a48e1 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Tue, 12 Nov 2024 11:10:29 +0200 Subject: [PATCH 3/5] Update class-pmpro-subscription.php --- classes/class-pmpro-subscription.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/class-pmpro-subscription.php b/classes/class-pmpro-subscription.php index 040d86087..88f21840c 100644 --- a/classes/class-pmpro-subscription.php +++ b/classes/class-pmpro-subscription.php @@ -784,7 +784,7 @@ private function format_subscription_date( $date, $format = 'timestamp', $local_ // Get date in WP local timezone. if ( $local_time ) { $date = strtotime( get_date_from_gmt( $date ) ); - return date_i18n( $format, $date, true ); + return date_i18n( $format, $date ); } // If it's not a timestamp, conver it to one for the date_i18n function. @@ -793,7 +793,7 @@ private function format_subscription_date( $date, $format = 'timestamp', $local_ } $date = gmdate( $date ); - return date_i18n( $format, $date, true ); + return date_i18n( $format, $date ); } /** From cee06265796ca71b49988f014a87b82e76ab901c Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Mon, 25 Nov 2024 15:53:32 +0200 Subject: [PATCH 4/5] Fixes to use wp_date instead --- classes/class-pmpro-subscription.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/classes/class-pmpro-subscription.php b/classes/class-pmpro-subscription.php index 88f21840c..c7c3f7c2e 100644 --- a/classes/class-pmpro-subscription.php +++ b/classes/class-pmpro-subscription.php @@ -780,20 +780,19 @@ private function format_subscription_date( $date, $format = 'timestamp', $local_ } elseif ( 'date_format' === $format ) { $format = get_option( 'date_format' ); } - // Get date in WP local timezone. if ( $local_time ) { - $date = strtotime( get_date_from_gmt( $date ) ); - return date_i18n( $format, $date ); + // wp_date() returns time in local timezone by default. + return wp_date( $format, strtotime( $date ) ); } - // If it's not a timestamp, conver it to one for the date_i18n function. + // If it's not a timestamp, convert it to one. if ( ! is_numeric( $date ) ) { $date = strtotime( $date ); } - $date = gmdate( $date ); - return date_i18n( $format, $date ); + // Get date in GMT timezone. + return wp_date( $format, $date, new DateTimezone('GMT') ); } /** From a24549867a79bc22c180cfe68e5cd5b98a670fc4 Mon Sep 17 00:00:00 2001 From: David Parker Date: Tue, 17 Dec 2024 13:02:20 -0500 Subject: [PATCH 5/5] Simplification --- classes/class-pmpro-subscription.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/classes/class-pmpro-subscription.php b/classes/class-pmpro-subscription.php index c7c3f7c2e..7ce7125b3 100644 --- a/classes/class-pmpro-subscription.php +++ b/classes/class-pmpro-subscription.php @@ -780,19 +780,8 @@ private function format_subscription_date( $date, $format = 'timestamp', $local_ } elseif ( 'date_format' === $format ) { $format = get_option( 'date_format' ); } - // Get date in WP local timezone. - if ( $local_time ) { - // wp_date() returns time in local timezone by default. - return wp_date( $format, strtotime( $date ) ); - } - - // If it's not a timestamp, convert it to one. - if ( ! is_numeric( $date ) ) { - $date = strtotime( $date ); - } - // Get date in GMT timezone. - return wp_date( $format, $date, new DateTimezone('GMT') ); + return wp_date( $format, strtotime( $date ), $local_time ? null : new DateTimezone( 'UTC' ) ); } /**