#58039 closed defect (bug) (invalid)
Fix non-strict checking issue on options-writing.php file
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | has-patch |
Focuses: | coding-standards | Cc: |
Description
This PR fixes a non-strict checking issue on the WordPress file options-writing.php. Specifically, on line 209, the code uses the "==" operator instead of the "===" operator. This can cause unexpected behavior since the "==" operator can coerce values and compare them in unexpected ways.
The fix involves replacing the "==" operator with the "===" operator to perform a strict comparison between the value returned by the get_option() function and the integer 1. This ensures that the comparison is done in a type-safe way and that unexpected behavior is avoided.
The fixed code is as follows:
<?php if ( 1 === get_option( 'blog_public' ) ) : ?>
With this fix, the code in the options-writing.php file will be more reliable and less prone to unexpected behavior.
Change History (6)
This ticket was mentioned in PR #4274 on WordPress/wordpress-develop by @faisalahammad.
2 years ago
#1
- Keywords has-patch added; needs-patch removed
#2
@
2 years ago
- Version trunk deleted
Hello and thanks for the ticket and patch @faisalahammad,
On a default and fresh WordPress installation, get_option( 'blog_public' )
returns a string, not an integer or a boolean, so actually, the proposed patch will probably break the condition.
Also, the above PR contains a lot of unrelated changes, and these changes contain some coding standards issues.
#3
@
2 years ago
Hi @audrasjb
Sorry about that, It was my first PR, so I wasn't sure how to handle this.
My VS Code extension auto formats lots of code, which made the issues. You may close the ticket.
Thank you
This PR fixes a non-strict checking issue on the WordPress file options-writing.php. Specifically, on line 209, the code uses the "==" operator instead of the "===" operator. This can cause unexpected behavior since the "==" operator can coerce values and compare them in unexpected ways.
The fix involves replacing the "==" operator with the "===" operator to perform a strict comparison between the value returned by the get_option() function and the integer 1. This ensures that the comparison is done in a type-safe way and that unexpected behavior is avoided.
The fixed code is as follows:
<?php if ( 1 === get_option( 'blog_public' ) ) : ?>
With this fix, the code in the options-writing.php file will be more reliable and less prone to unexpected behavior.
Trac ticket: 58039