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, then it’s probably fast.

It seems like what you’re doing is convenient – you have the code in one place and call it from a couple of places it’s needed.

Even though it’s called from two places, as the code is in one place that’s quite maintainable. If you want to change what it does in future you don’t have two places and need to figure out where to put changes, you just change this one function and you know the effect will happen.

You could do this a different way but it sounds like you’re saying that this would involve a lot more time to learn the interface you’re using (i.e. WP script queueing orders) and this might not have a benefit for you.

So, on balance if it’s a fast function there’s no reason not to do this and it’s not bad design due to maintainability.