#54700 closed defect (bug) (fixed)
wp-includes/vars.php can trigger warning
Reported by: | janh2 | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | minor | Version: | 5.8.2 |
Component: | Bootstrap/Load | Keywords: | php8 has-patch commit |
Focuses: | Cc: |
Description
Some plugins are calling wp-load.php directly and handle the requests by hooking into actions (InfiniteWP in my case, "/wp-load.php?no_cache_XXXXX=1234567890", but I've seen it before in a different setting that I can't recall) which leads to warnings while setting $pagenow when using php8 (E_WARNING: Undefined array key 1 in wp-includes/vars.php:32).
wp-includes/vars.php lines 25-32
<?php if ( is_network_admin() ) { preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); } elseif ( is_user_admin() ) { preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); } else { preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); } $pagenow = $self_matches[1];
If the preg_match does not match, $self_matches will be an empty array.
It's not really caused by WP (since the plugin is not using official APIs), but since this code can be hit in that way, I believe it should check whether a match has occurred.
Change History (6)
#1
@
3 years ago
- Component changed from General to Bootstrap/Load
- Milestone changed from Awaiting Review to 6.0
This ticket was mentioned in PR #2278 on WordPress/wordpress-develop by konradyoast.
3 years ago
#3
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/54700
#4
@
2 years ago
- Keywords commit added
The linked pull request looks good to me.
I did some manual testing in wp cli to ensure each step provided an expected value, it does.
I can't really see how to unit test this as the variables aren't defined within a function.
#5
@
2 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 53294:
SergeyBiryukov commented on PR #2278:
2 years ago
#6
Thanks for the PR! Merged in https://core.trac.wordpress.org/changeset/53294.
Hi there, welcome to WordPress Trac! Thanks for the report.
Just linking to some related tickets here: #29161, #41171.