Opened 9 years ago
Last modified 3 weeks ago
#43159 new enhancement
Introduce helper function for XMLRPC checks
| Reported by: | NathanAtmoz | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Bootstrap/Load | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Similar to #25669, it would be nice if there was a helper function for checking if WordPress is doing a XML-RPC request.
Attachments (3)
Change History (9)
#2
in reply to: ↑ 1
;
follow-up:
↓ 3
@
9 years ago
@birgire: Thanks for looking at the patch.
Replying to birgire:
- I don't think we should add
wp_doing_xmlrpc()in that line inwp-cron.php, because that file can be requested directly, (see e.g. withinspawn_cron()here ) and thenwp_doing_xmlrpc()wouldn't be defined and resulting in a PHP error. Some users rely on Unix Cron instead, requesting that file from there.
I don't see wp_doing_xmlrpc() in wp-cron.php in the patch? Am I missing something?
- I found an extra
defined( 'XMLRPC_REQUEST' )check inspawn_cron()(src), but I noticed thatdefined( 'DOING_AJAX' )anddefined( 'DOING_CRON' )have not been replaced. Most likely a reason for that, but we could look further into that.
I originally didn't use wp_doing_xmlrpc() here because the other constants hadn't been replaced. But this function is loaded really early, and the only place it's called in core is hooked to init.
#3
in reply to: ↑ 2
@
9 years ago
Replying to NathanAtmoz:
I don't see
wp_doing_xmlrpc()inwp-cron.phpin the patch? Am I missing something?
This part was meant to be a general note why it wasn't replaced in wp-cron.php, sorry that wasn't made more clear ;-)
I also checked in the tests/ directory and didn't find any use of XMLRPC_REQUEST there.
#4
@
2 years ago
- Keywords needs-refresh added
Patch no longer applies cleanly. I would support getting this in if someone wants to refresh the patch.
#6
@
3 weeks ago
Tested 43159.3.diff against current trunk (7.2-alpha-63166).
Applies cleanly (offsets only, no fuzz) and covers every remaining XMLRPC_REQUEST check in src/, including the newer ones in wp_die() and the Application Passwords check. All touched files lint clean on PHP 8.3. plugin.php loads before wp_debug_mode(), so the filter is safe at the earliest call site.
A few things before this is commit-ready:
- The new docblock is indented with a leading space, which will fail PHPCS.
- The filter's
@paramis named$wp_doing_cron; should be$wp_doing_xmlrpc. @since 6.7.0needs updating to the target release.- The
_publish_post_hook()docblock change ("Uses WP_IMPORTING constants") drops information and reads oddly. I'd leave the original line.
Behavior change worth noting: four call sites (admin-bar.php, cron.php, load.php, post.php) previously used a bare defined( 'XMLRPC_REQUEST' ). With the helper, define( 'XMLRPC_REQUEST', false ) now evaluates false there instead of true. Edge case, but it should be called out in the dev note.
Open question: should the two user.php sites go through the filter at all? In _wp_get_current_user(), a plugin incorrectly returning true from wp_doing_xmlrpc would log out every user on every request. The Application Passwords check already has application_password_is_api_request for extensibility. I'd lean toward keeping the raw constant check in both places, but would like a committer's view.
Attached unit tests covering the default, filter, and constant true/false cases (separate process for the constants). They pass locally with the patch applied.
@NathanAtmoz happy to refresh the patch with the fixes above if you'd prefer, otherwise I'll leave it with you. @jorbin since you offered support in comment:4, does keeping user.php on the raw constant sound right to you?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Thanks for the patch @NathanAtmoz
I'm not sure what the consensus is regarding
wp_doing_xmlrpc()but we now havewp_doing_ajax()since 4.7 andwp_doing_cron()since 4.8. So it would seem logical to introduce it. Also the discussion in #25669 doesn't seems to be against such a function, if I understand it correctly.I reviewed 43159.diff and here are some notes:
wp_doing_xmlrpc()in that line inwp-cron.php, because that file can be requested directly, (see e.g. withinspawn_cron()here ) and thenwp_doing_xmlrpc()wouldn't be defined and resulting in a PHP error. Some users rely on Unix Cron instead, requesting that file from there.|| defined( 'DOING_AJAX' )check inis_admin_bar_showing(). I think that removal must have been accidental and should be reverted.defined( 'XMLRPC_REQUEST' )check inspawn_cron()(src), but I noticed thatdefined( 'DOING_AJAX' )anddefined( 'DOING_CRON' )have not been replaced. Most likely a reason for that, but we could look further into that.defined( 'XMLRPC_REQUEST' )check in_publish_post_hook()(src), that seems to be valid for replacement withwp_doing_xmlrpc().