Skip to content

Commit bf09fe5

Browse files
committed
Date/Time, PHP Compat: Prevent type errors using GMT offset option.
Prevents a potential type errors when making use of the `gmt_offset` option by casting the value to a float prior to performing calculations with the value. This mainly accounts for incorrect storage of values, such as an empty string or city name. Follow up to [58923]. Props chaion07, hellofromtonya, kirasong, mhshohel, mukesh27, nicolefurlan, nihar007, nurielmeni, oglekler, peterwilsoncc, prionkor, rajinsharwar, rarst, rleeson, sabernhardt, SergeyBiryukov, swissspidy, toastercookie, verygoode. Fixes #56358, #58986, #60629. git-svn-id: https://develop.svn.wordpress.org/trunk@59064 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3b24863 commit bf09fe5

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/wp-admin/update-core.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ function do_undismiss_core_update() {
10961096
$current = get_site_transient( 'update_core' );
10971097

10981098
if ( $current && isset( $current->last_checked ) ) {
1099-
$last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
1099+
$last_update_check = $current->last_checked + (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
11001100
}
11011101

11021102
echo '<h2 class="wp-current-version">';

src/wp-includes/bookmark-template.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function _walk_bookmarks( $bookmarks, $args = '' ) {
9090
__( 'Last updated: %s' ),
9191
gmdate(
9292
get_option( 'links_updated_date_format' ),
93-
$bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )
93+
$bookmark->link_updated_f + (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )
9494
)
9595
);
9696
$title .= ')';

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ public function prepare_item_for_response( $item, $request ) {
18161816
* with the site's timezone offset applied.
18171817
*/
18181818
if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) {
1819-
$post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
1819+
$post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
18201820
} else {
18211821
$post_modified_gmt = $post->post_modified_gmt;
18221822
}

src/wp-mail.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL );
4646

47-
$time_difference = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
47+
$time_difference = (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
4848

4949
$phone_delim = '::';
5050

0 commit comments

Comments
 (0)