froger-me / wp-remote-users-sync

Synchronise users across WordPress websites
GNU General Public License v3.0
71 stars 34 forks source link

Added $data filters to create, update, meta, and abstract API classes #22

Closed verygoodplugins closed 3 years ago

verygoodplugins commented 3 years ago

Suggesting a few additional filters in the outgoing $data array for the create, update and meta fire_remote() functions, as well a generic one in fire_action()

froger-me commented 3 years ago

Hi @verygoodplugins !

Good suggestion. Filtering the data before sending it and/or after receiving it has been on my todo list like mentioned here.

The pull request is appreciated and refreshing - it is good to see developers taking action and not just flatly demanding new features for once ;). The proposed solution is somehow too granular though, and can be condensed. All notify_remote methods call fire_action or fire_async_actions already. Instead, it is more optimized to add $data = apply_filters( 'wprus_action_data', $data, $endpoint, $url ); to the fire_action, do_async_actions_redirect and print_async_actions_markup methods.

It is possible to get the user ID via the username in the $data parameter if needed, and the specific action (create, update, meta, etc) with the $endpoint parameter.

I pushed a new version reflecting that (1.2.7). Also, as a side note, it is important to document every hook, so I included that too.

Again, thank you for your pull request!

verygoodplugins commented 3 years ago

@froger-me Nice, thanks for the quick turnaround. That solution works for us as well.

Haha yeah I know what you mean. We get a ton of requests, but if someone bothers to do a PR I tend to take them a little more seriously ;)

Context.... We've added a WP Remote Users Sync integration into the next update of WP Fusion (https://wpfusion.com/documentation/other/wp-remote-users-sync/).

We're making use of these hooks so that when a new user is synced to a remote site, their CRM contact ID from wp_usermeta follows them, without requiring a separate Metadata outgoing action. Better for performance and less setup for our users.

Thanks for making this. We've been getting asked to build something like this for a long time, and now we don't have to. Super.