WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 21 months ago

#43159 new enhancement

Introduce helper function for XMLRPC checks

Reported by: NathanAtmoz Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Bootstrap/Load Keywords: has-patch
Focuses: Cc:
PR Number:

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 (2)

43159.diff (2.3 KB) - added by NathanAtmoz 21 months ago.
43159.2.diff (4.1 KB) - added by NathanAtmoz 21 months ago.

Download all attachments as: .zip

Change History (5)

@NathanAtmoz
21 months ago

#1 follow-up: @birgire
21 months ago

  • Keywords has-patch added

Thanks for the patch @NathanAtmoz

I'm not sure what the consensus is regarding wp_doing_xmlrpc() but we now have wp_doing_ajax() since 4.7 and wp_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:

  • I don't think we should add wp_doing_xmlrpc() in that line in wp-cron.php, because that file can be requested directly, (see e.g. within spawn_cron() here ) and then wp_doing_xmlrpc() wouldn't be defined and resulting in a PHP error. Some users rely on Unix Cron instead, requesting that file from there.
  • It removes the || defined( 'DOING_AJAX' ) check in is_admin_bar_showing(). I think that removal must have been accidental and should be reverted.
  • I found an extra defined( 'XMLRPC_REQUEST' ) check in spawn_cron() (src), but I noticed that defined( 'DOING_AJAX' ) and defined( 'DOING_CRON' ) have not been replaced. Most likely a reason for that, but we could look further into that.
  • I also found an extra defined( 'XMLRPC_REQUEST' ) check in _publish_post_hook() (src), that seems to be valid for replacement with wp_doing_xmlrpc().
Last edited 21 months ago by birgire (previous) (diff)

#2 in reply to: ↑ 1 ; follow-up: @NathanAtmoz
21 months ago

@birgire: Thanks for looking at the patch.

Replying to birgire:

  • I don't think we should add wp_doing_xmlrpc() in that line in wp-cron.php, because that file can be requested directly, (see e.g. within spawn_cron() here ) and then wp_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 in spawn_cron() (src), but I noticed that defined( 'DOING_AJAX' ) and defined( '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 @birgire
21 months ago

Replying to NathanAtmoz:

I don't see wp_doing_xmlrpc() in wp-cron.php in 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.

Note: See TracTickets for help on using tickets.