Making WordPress.org


Ignore:
Timestamp:
06/23/2018 11:27:35 AM (7 years ago)
Author:
ocean90
Message:

Rosetta: Change priority of the timezone filters to avoid an "A non-numeric value encountered" PHP warning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/class-plugin.php

    r6174 r7330  
    9898                     */
    9999                    $offset_or_tz = _x( '0', 'default GMT offset or timezone string', 'rosetta' );
    100                     if ( $offset_or_tz && ! is_numeric( $offset_or_tz ) && in_array( $offset_or_tz, timezone_identifiers_list() ) ) {
     100                    if ( $offset_or_tz && ! is_numeric( $offset_or_tz ) && in_array( $offset_or_tz, timezone_identifiers_list(), true ) ) {
    101101                        return $offset_or_tz;
    102102                    } else {
     
    104104                    }
    105105                } )
    106                 ->set_priority( 9 ) // Before `wp_timezone_override_offset()`
    107106        );
    108107
     
    111110                ->set_name( 'gmt_offset' )
    112111                ->set_callback( function() {
     112                    // Do the smart timezone handling like `wp_timezone_override_offset()`.
     113                    $timezone_string = get_option( 'timezone_string' );
     114                    if ( $timezone_string ) {
     115                        $timezone_object = timezone_open( $timezone_string );
     116                        $datetime_object = date_create();
     117                        if ( false !== $timezone_object && false !== $datetime_object ) {
     118                            return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 );
     119                        }
     120                    }
     121
    113122                    /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
    114123                     * or a valid timezone string (America/New_York). See https://secure.php.net/manual/timezones.php
     
    117126                    $offset_or_tz = _x( '0', 'default GMT offset or timezone string', 'rosetta' );
    118127                    if ( $offset_or_tz && is_numeric( $offset_or_tz ) ) {
    119                         return $offset_or_tz;
     128                        return (int) $offset_or_tz;
    120129                    } else {
    121130                        return 0;
    122131                    }
    123132                } )
    124                 ->set_priority( 9 ) // Before `wp_timezone_override_offset()`
     133                ->set_priority( 11 ) // After `wp_timezone_override_offset()`.
    125134        );
    126135
Note: See TracChangeset for help on using the changeset viewer.