Skip to content

Commit

Permalink
Coding Standards: Ensure $current cookie time is int in `wp_user_…
Browse files Browse the repository at this point in the history
…settings()`.

This addresses an issue where a string (`$current`) is compared to an integer (`$last_saved`). The issue is resolved by casting the results of `preg_replace()` to type `int` when `$current` is defined.

Follow-up to [8784], [10083], [25109].

Props justlevine.
See #52217.

git-svn-id: https://develop.svn.wordpress.org/trunk@59373 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Nov 7, 2024
1 parent 9503db2 commit 2b99f6d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,11 @@ function wp_user_settings() {
}

$last_saved = (int) get_user_option( 'user-settings-time', $user_id );
$current = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0;
$current = 0;

if ( isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ) {
$current = (int) preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] );
}

// The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
if ( $current > $last_saved ) {
Expand Down

0 comments on commit 2b99f6d

Please sign in to comment.