WordPress.org

Ready to get started?Download WordPress

Forums

Can add_action have a variable to represent it's priority? (2 posts)

  1. harknell
    Member
    Posted 7 years ago #

    I'm writing a series of Plugins that use a similar call to place things in a theme. I would love for it to be possible to dynamically determine what priority they each have so that the end user from the admin area could adjust the order the plugins display. (so, if 3 plugins all displayed at the beginning of the loop, I would like it so that the user could determine the priority of each plugin so that they went in their desired order). I've tried placing a variable in the spot for priority in the add_action function, but WordPress gives an error if you do this. This seems like a major oversight in WordPress development if you can only supply a hard-coded number, since this priority value represents a huge capability for plugin authors.
    Am I missing something or am I out of luck?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    You're missing something. There's nothing preventing you from using a variable for the priority of add_action. As long as the variable has a number in it, it works fine.

    $priority = 10;
    add_action('whatever','call_this_function',$priority);

    That should work fine.

Topic Closed

This topic has been closed to new replies.

About this Topic