#57839 closed task (blessed) (fixed)
Coding Standards fixes for WP 6.3
Reported by: | hellofromTonya | Owned by: | |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch has-unit-tests |
Focuses: | coding-standards | Cc: |
Change History (89)
This ticket was mentioned in PR #4294 on WordPress/wordpress-develop by @wpfy.
20 months ago
#2
- Keywords has-patch added
The WordPress coding standards recommend using 'elseif' instead of 'else if' for conditionals to ensure consistency in the code syntax. This is because 'else if' is not compatible with the colon syntax for if|elseif blocks.
However, in the WordPress core file '/wp-includes/ID3/module.audio.ogg.php', on line 608, 'else if' is used for conditionals. To ensure consistency with the WordPress coding standards and improve the readability and maintainability of the code, I propose replacing 'else if' with 'elseif' on this line.
Trac ticket:
https://core.trac.wordpress.org/ticket/57839
This ticket was mentioned in PR #4296 on WordPress/wordpress-develop by @faisalahammad.
20 months ago
#3
The WordPress coding standards recommend adding spaces before and after function arguments to improve code readability and consistency. However, in the wp-includes/Text/Diff/Renderer/inline.php
file, some functions do not follow this standard.
To improve the code quality and consistency, I have updated the affected functions by adding spaces before and after their arguments.
Trac ticket: https://core.trac.wordpress.org/ticket/57839
This ticket was mentioned in PR #4299 on WordPress/wordpress-develop by @faisalahammad.
20 months ago
#4
This pull request fixes the issue of using "else if" instead of "elseif" in the WordPress coding standard. According to the standard, "elseif" should be used instead of "else if" because the latter is not compatible with the colon syntax for if|elseif blocks.
I have identified wp-admin/includes/theme.php
where this issue exists and have made the necessary changes to replace all occurrences of "else if" with "elseif".
Trac ticket: https://core.trac.wordpress.org/ticket/57839
@audrasjb commented on PR #4294:
20 months ago
#5
Thanks for the PR @akramulhasan.
However, this is an actively maintained upstream library, so this has to be fixed in the related upstream repository, not in WordPress core.
Here is the lib: https://github.com/JamesHeinrich/getID3
Closing this PR for now.
This ticket was mentioned in PR #4302 on WordPress/wordpress-develop by @wpfy.
20 months ago
#6
According to the WordPress PHP coding standards, it is recommended to use require[_once] instead of include[_once] for unconditional includes. However, in two files of the twenty twenty one theme, I have found include_once used unconditionally.
To improve consistency and ensure better security and stability of the code, I propose replacing include_once with require_once in these two files.
This change will ensure that if the file cannot be found, a Fatal Error will be thrown, preventing any potential security leaks or other issues that may arise due to the file not being loaded properly.
I have created a pull request for these changes, and I kindly request a review from the WordPress core team.
Trac ticket: https://core.trac.wordpress.org/ticket/57839
@faisalahammad commented on PR #4299:
20 months ago
#7
Sorry @audrasjb
I was unable to revert the changes. Could you please ignore/delete this PR and I'm going to create another PR?
@audrasjb commented on PR #4299:
20 months ago
#8
of course :)
This ticket was mentioned in PR #4303 on WordPress/wordpress-develop by @faisalahammad.
20 months ago
#9
This pull request fixes the issue of using "else if" instead of "elseif" in the WordPress coding standard. According to the standard, "elseif" should be used instead of "else if" because the latter is not compatible with the colon syntax for if|elseif blocks.
I have identified wp-admin/includes/theme.php where this issue exists and have made the necessary changes to replace all occurrences of "else if" with "elseif".
Trac ticket: https://core.trac.wordpress.org/ticket/57839
This ticket was mentioned in PR #4304 on WordPress/wordpress-develop by @kausaralm.
20 months ago
#10
This pull request replace an unconditional include_once statement found in the file '/wp-admin/includes/class-wp-plugin-install-list-table.php' at line number 91, which violates the WordPress PHP coding standards.
Trac ticket: https://core.trac.wordpress.org/ticket/57839
@SergeyBiryukov commented on PR #4302:
20 months ago
#14
Thanks for the PR! Merged in r55633.
@SergeyBiryukov commented on PR #4304:
20 months ago
#16
Thanks for the PR! Merged in r55641 as part of a few other similar changes.
This ticket was mentioned in PR #3873 on WordPress/wordpress-develop by @SergeyBiryukov.
20 months ago
#17
- Keywords has-unit-tests added
@SergeyBiryukov commented on PR #4296:
20 months ago
#19
Thanks for the PR! However:
Text/Diff
is an external library that has only been patched on rare occasions, and is excluded from coding standards checks.- The
<# } else if ( .. ) { #>
fragments in widget classes are from Backbone/Underscore.js templates and use JavaScript syntax, not PHP, soelseif
would not work there.
@SergeyBiryukov commented on PR #4303:
20 months ago
#20
Thanks for the PR! However, please note that:
class-pclzip.php
is an external library that has only been patched on rare occasions, and is excluded from coding standards checks.- The
<# } else if ( .. ) { #>
fragments inwp-admin/includes/theme.php
are from Backbone/Underscore.js templates and use JavaScript syntax, not PHP, soelseif
would not work there.
This ticket was mentioned in PR #4312 on WordPress/wordpress-develop by @faisalahammad.
20 months ago
#21
This pull request fixes the issue of using "else if" instead of "elseif" in the WordPress coding standard. According to the standard, "elseif" should be used instead of "else if" because the latter is not compatible with the colon syntax for if|elseif blocks.
I have identified in a couple of files where this issue exists and have made the necessary changes to replace all occurrences of "else if" with "elseif".
Trac ticket: https://core.trac.wordpress.org/ticket/57839
This ticket was mentioned in PR #4313 on WordPress/wordpress-develop by @sarequl.
20 months ago
#22
The issue with the code in /wp-includes/theme-compat/comments.php line 35 is that the comparison operator "==" is being used to compare the response code returned by get_comments_number() with the integer value 1. This is a non-strict comparison operator, which means that it will also return true if the response code is a string "1". This can lead to unexpected behavior or security vulnerabilities.
Trac ticket: https://core.trac.wordpress.org/ticket/57839
20 months ago
#24
Hi,
At a glance it looks like that all files edited in this PR comes from included libraries, and should be fixed upstream.
@SergeyBiryukov commented on PR #4312:
20 months ago
#26
Thanks for the PR!
As noted above, these are external libraries, and they are excluded from coding standards checks:
- ID3 and SimplePie have active upstream repositories, but they don't really have to follow the WordPress coding standards, so these changes might not be accepted upstream.
- IXR and AtomLib can be considered "adopted", but they have only been patched on rare occasions in the past, and don't have to follow the WordPress coding standards either.
@SergeyBiryukov commented on PR #4313:
20 months ago
#27
Hi there, thanks for the PR!
This is a non-strict comparison operator, which means that it will also return true if the response code is a string "1".
Please note that get_comments_number()
does in fact return the number of comments as a numeric string, not an integer (unless the post does not exist), so 1 === get_comments_number()
won't work as expected.
The correct comparison would be '1' === get_comments_number()
, see r55420 for example.
@SergeyBiryukov commented on PR #4313:
19 months ago
#43
Merged in r55849.
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
19 months ago
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
18 months ago
#63
@
18 months ago
Just a heads up: The strict comparison added to WP_List_Util::filter
via [55908] broke a test on a project I maintain.
// $created contains objects with maybe property disabled === '0' $active = wp_filter_object_list( $created, [ 'disabled' => 0 ] );
I like the change to strict comparison, so no complaint here. But, I'm not sure how much 3rd party code there may be that accidentally relies on this being loose. :)
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
18 months ago
#70
@
18 months ago
Having the r55908 deployed on the WordPress.com revealed that the change may easily affect any code which has been (unintentionally) relying on type juggling when using the wp_list_filter
function (in our case, it's been a string vs. int type juggling which got broken with the strict comparison).
It's a similar thing to the one reported above in https://core.trac.wordpress.org/ticket/57839#comment:63
I do understand the benefits of the strict comparison, but wanted to report the issue, since it's hard to spot and may easily break things in existing code in plugins/themes which is taking advantage of those handy functions.
#71
follow-up:
↓ 74
@
17 months ago
@SergeyBiryukov Yea, tseems [55908] introduced a regression in WP_List_Util::filter()
. That function was doing loose comparison (no documentation about the types too), and now the way it works has changed.
Wondering if this change "can get away with" casting to strings before comparing. Seems int is also a valid key and/or value type there too.
The same is probably true for the strict comparison in WP_List_Util::sort_callback()
. May miss things when comparing strings to int.
#74
in reply to:
↑ 71
@
17 months ago
Replying to jeremyfelt:
Just a heads up: The strict comparison added to
WP_List_Util::filter
via [55908] broke a test on a project I maintain.
// $created contains objects with maybe property disabled === '0' $active = wp_filter_object_list( $created, [ 'disabled' => 0 ] );
Replying to david.binda:
Having the r55908 deployed on the WordPress.com revealed that the change may easily affect any code which has been (unintentionally) relying on type juggling when using the
wp_list_filter
function (in our case, it's been a string vs. int type juggling which got broken with the strict comparison).
Good catch, thanks!
Replying to azaozz:
Yea, seems [55908] introduced a regression in
WP_List_Util::filter()
. That function was doing loose comparison (no documentation about the types too), and now the way it works has changed.
Wondering if this change "can get away with" casting to strings before comparing. Seems int is also a valid key and/or value type there too.
Seems reasonable, we already do that in a few other places, e.g. __checked_selected_helper()
. But [56137] caused a few Array to string conversion
warnings in wp_filter_object_list()
tests, so restoring the loose comparison appears to be a safer option at this point.
Should be fixed in [56138] :)
This ticket was mentioned in Slack in #core by sergey. View the logs.
17 months ago
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
17 months ago
#85
@
17 months ago
- Resolution set to fixed
- Status changed from new to closed
As we are now entering the RC cycle of WP 6.3, let's close this umbrella ticket as fixed.
Further coding standard fixes can ship in #58831.
Thanks!
@SergeyBiryukov commented on PR #3873:
3 months ago
#89
This will need tests before it can be merged:
Indeed, this is basically still a draft where I cherry-pick certain changes after a closer review, making sure they are covered by new or existing tests. I will investigate anything related to wp_parse_args()
and WP_Query
, thanks!
In 55540: