1

I am working on a plugin that needs to duplicate some built-in WordPress logic. (This logic can't be invoked with any built-in method, nor can it be hooked into independently.)

During this sequence of actions, WordPress's normal behavior is to call an action hook (do_action('wp_login', ...)) and a filter hook (apply_filters('login_redirect', ...)).

If they're invoked at points in time which correspond to when they would have been invoked in Core, is it safe (and acceptable practice) to invoke these built-in hooks directly from my plugin? Or is the risk too great that other developers who have hooked into this expect the action to be executed at a very specific time?

2

I think there is a difference here between do_action and apply_filters.

do_action usually triggers a global state change, either output, enqueuing of resource, initialization of modules, and such. This, like anything which infuance global state can result in surprising side effect when used out of context.

apply_filters OTOH behaves much more like a function call, and if written properly should return the same result whenever it is "called".

Still, the quality of plugins varies (just few hours ago someone asked about a "pro" plugin that uses eval :( ), so your implementation strategy will depend in the end on the coding skills some 5$/hr developer copy pasting snippets he finds around the internet. You will need proper testing against leading plugins to make sure that your code works with at least the leading ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.