Better use two dedicated methods hooked with add_action() to different actions, or can it be twice the same method?

So there’s 4 factors: Performance (Speed, resource usage) Convenience Code maintainability Learning the API you’re using If you don’t know the performance of your function then it’s impossible to answer your question, but I would guess that if it doesn’t do or cause any database queries, and it’s not doing operations on lots of data, … Read more

Send email to user when I publish a new post

Updated code for statuses as per @Fredrik’s answer as his is more accurate. To trigger this when publishing, you could change your first if to if ( $new_status === ‘inherit’ && $old_status === ‘new’ ) That way, your code should trigger only when you publish a post. EDIT: Some notes on your code. if ( … Read more

If has action not working as expected

That’s not what has_action does. has_action is true, if functions are added to fire on that hook. It is not a way to detect do_action calls. However in that code: Nothing was added to the acf_add_class action If something had been added, it still wouldn’t work because the body_class filter has already ran. It would … Read more

Sharing varible between two add_actions

First of all, the order in which you use add_action is not relevant. The only thing it does is keep a tab of actions to undertake once the hook is encountered. Only when there are several functions on the same hook, the priority of the added action becomes relevant (read more). So, if your global … Read more