#54798 closed defect (bug) (fixed)
Check for int in menu priority
Reported by: | kirtan95 | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description (last modified by )
Similar to #48249, this ticket focuses on ensuring that devs don't accidentally pass non-integer values in the position argument.
A similar issue was also reported in #40927, where passing a float argument in add_menu_page
causes to override menu item.
For backward compatibility, I'd like to suggest informing users with _doing_it_wrong
if a non-integer value is passed.
Optionally, we can also typecast float to string to ensure in case someone has passed float value, at least it doesn't override menus.
Attachments (3)
Change History (21)
#1
@
3 years ago
- Summary changed from Check for int in menu priority implementation to Check for int in menu priority
This ticket was mentioned in PR #2143 on WordPress/wordpress-develop by kirtangajjar.
3 years ago
#2
- Keywords has-patch has-unit-tests added
#3
@
3 years ago
- Milestone changed from Awaiting Review to 6.0
- Owner set to audrasjb
- Status changed from assigned to reviewing
- Version trunk deleted
#5
@
3 years ago
- Keywords commit added
Hello and welcome back to Trac @kirtan95 !
This change looks good to me.
Self-assigning for commit
consideration.
3 years ago
#7
Committed in https://core.trac.wordpress.org/changeset/52569
#9
@
3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Looking back on the code committed in [52569], it looks like there is a missing indentation in the translators comment. Also, /* translators: %s: add_submenu_page() */
should probably be replaced with /* translators: %s: add_menu_page() */
.
Reopening to address those issues.
This ticket was mentioned in Slack in #core by costdev. View the logs.
3 years ago
#12
@
3 years ago
- Keywords commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening, as there are some concerns with the current implementation that does not allow for float values, which are widely used by plugins to prevent "first come first serve" issues where menus go up and down sporadically.
#13
@
3 years ago
@SergeyBiryukov So is it fine to add type check for float values? It will at least prevent users from passing float values as strings and plugin authors will be easily able to migrate their code in case they're passing float as a string.
If passing a float value is so widely used, perhaps we can even change the function docstring of both add_menu_page and add_submenu_page to reflect that they accept float values.
The motive of this PR was to add stricter type checks that would help developers spot bugs early during development, so I think the above two suggestions will help achieve this goal.
#14
@
3 years ago
- Resolution set to fixed
- Status changed from reopened to closed
I think this can be closed with the commits on #40927
add_menu_page()
position:
- can be either a float or an integer in line with common plugin practices
- the default position,
null
, adds the menu as the last item - a
_doing_it_wrong()
notice is triggered if the position is not numberic float
types are cast tostring
to ensure PHP doesn't internally cast the number to an integer- the position is sorted as a human would expect it, eg:
1, "1.043", "2", 3
.
#15
@
3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Commit [52569] introduced an new incompatibility with PHP 8.1 Implicit conversion from float 1.5 to int loses precision
....
This needs a follow-up to fix that.
#16
follow-up:
↓ 17
@
3 years ago
- Resolution set to fixed
- Status changed from reopened to closed
@jrf Could you please open a follow up ticket.
This has commits on a closed milestone. Reopening and moving to a new milestone will create confusion during bisects and similar investigation of code history.
#17
in reply to:
↑ 16
@
3 years ago
Replying to peterwilsoncc:
@jrf Could you please open a follow up ticket.
I will move the patch to #55656 which is already open for PHP 8.x patches.
As a general word of warning though: the fact that PHP 8.1 build does not currently pass, does not mean that it is acceptable to introduce new incompatibilities... Please always check the build manually for newly introduced errors.
It will throw error with _doing_it_wrong if the typeof position is not
int.
Additionally, if the type of position is float, it will conver it to
string instead of typecasting it down to int which can cause override.
Fixes #54798, #40927
Trac Link - https://core.trac.wordpress.org/ticket/54798#comment:1
Trac ticket: