Ticket #17109 (new enhancement)

Opened 11 months ago

Last modified 3 weeks ago

Add post-success action hooks to edit/create/delete calls.

Reported by: ericmann Owned by:
Priority: normal Milestone: Awaiting Review
Component: XML-RPC Version:
Severity: normal Keywords: has-patch needs-testing
Cc: ercoli@…

Description

It was suggested in #14283 that we add call_success hooks for post creation using the Blogger API. The ticket was later expanded to add hooks for all relevant post/page methods.

We should extend this workflow concept and add hooks to all edit/create/delete calls for different data types (comments, media, etc) to make the XML-RPC system more pluggable.

These hooks should use the following format:

do_action( 'xmlrpc_call_success_{method name}', {object id}, $args );

These hooks should be called before returning data to the client, but should not be called before any processing is done or before error messages are created.

Attachments

17109.diff Download (2.1 KB) - added by ericmann 11 months ago.
17109-2.diff Download (2.0 KB) - added by ericmann 5 months ago.
Uses filters where appropriate.
17109-3.diff Download (2.0 KB) - added by ericmann 2 weeks ago.
Switch new action hooks to filters.

Change History

  • Keywords has-patch needs-testing added; needs-patch removed

Add action hooks to the following calls:

  • wp_newCategory
  • wp_deleteCategory
  • wp_deleteComment
  • wp_editComment
  • wp_newComment
  • mw_newMediaObject

Post-related hooks are added by #14283.

comment:2 follow-ups: ↓ 3 ↓ 4   josephscott11 months ago

In order to potentially modify the data before returning it shouldn't we be filtering instead and returning the filter variable?

comment:3 in reply to: ↑ 2   ericmann11 months ago

Replying to josephscott:

In order to potentially modify the data before returning it shouldn't we be filtering instead and returning the filter variable?

That's a good question. But I would say no.

For many of these calls, the only thing returned at this stage is the ID or a boolean representing whether or not the call succeeded. Adding a filter doesn't add any value, but adding an action hook provides the user with a way to further manipulate data or act on the content of a successful call after it's completed. But there's no further output at this stage to be filtered.

comment:4 in reply to: ↑ 2   ericmann5 months ago

Replying to josephscott:

In order to potentially modify the data before returning it shouldn't we be filtering instead and returning the filter variable?

Actually, I've changed my mind. With the methods that actually return data, we should be using filters rather than actions. But not everything returns data. Some only return Boolean values that don't make sense being passed through a filter.

The new patch uses filters where they make sense, but sticks to actions where they don't.

Uses filters where appropriate.

  • Cc ercoli@… added

comment:6 follow-up: ↓ 7   josephscott3 weeks ago

Any reason not to make these all filters? Seems strange to allow for filtering the return value of some methods, but not others.

comment:7 in reply to: ↑ 6   ericmann3 weeks ago

Replying to josephscott:

Any reason not to make these all filters? Seems strange to allow for filtering the return value of some methods, but not others.

It was based on return values. For example, the functions that return data (i.e. IDs) are using filters on the IDs. The functions that return bools (i.e. success/failure) fire an action instead.

My intention was to only use filters when the result of the filter would be returned by the function and use actions elsewhere to still allow devs to hook in to the function.

Switch new action hooks to filters.

Note: See TracTickets for help on using tickets.