Make WordPress Core


Ignore:
Timestamp:
01/11/2023 11:18:12 PM (2 years ago)
Author:
audrasjb
Message:

Date/Time: Prevent errors in current_time() when using timestamp and no value for gmt_offset.

This changeset moves typecasting to affect the get_option value, which ensures that when math is done it does not generate any error. In PHP 7.4 and earlier the previous implementation was dismissed as a warning, but in PHP 8+ it would have throw a fatal error.

Follow-up to [45856].

Props Nick_theGeek, SergeyBiryukov, johnbillion.
Fixes #57035.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r54997 r55054  
    7373    // Don't use non-GMT timestamp, unless you know the difference and really need to.
    7474    if ( 'timestamp' === $type || 'U' === $type ) {
    75         return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
     75        return $gmt ? time() : time() + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    7676    }
    7777
Note: See TracChangeset for help on using the changeset viewer.