Skip to:

Info about the used action \"wp\"

  • TobiasBg



    I just looked through some of BP’s well structured source code, just to get an idea on how it works.

    There was one thing that I noticed and that is pretty new to me, so it would be really cool, if someone (probably one of the developers) has some information for me about this:

    BuddyPress uses the action “wp” quite often, e.g. it hooks functions to it like this:

    add_action( 'wp', 'some_function' );

    I haven’t found the corresponding “do_action( ‘wp’, … );” in BP, so I grep’d through the WP source and found it in the WP class there.

    I’m familiar a little bit with WP plugin development and have so far not seen the action used there.

    Thus my question: Why does BP use this action (and not e.g. “init” or “plugins_loaded”)? What are the advantages? What are the use cases for which this brings advantages?



Viewing 5 replies - 1 through 5 (of 5 total)

  • Windhamdavid


    I’ll try to get an answer for you on this from a dev, (ie.. bump this back to the top and repost in IRC since I’m a fan of wp-tables-reloaded) but my halfway educated ‘guess’ is that it’s to assure that BP loaded first for plugins dependent on it’s functions.



    Quoted from the WP codex:


    Executes after the query has been parsed and post(s) loaded, but before any template execution, inside the main WordPress function wp. Useful if you need to have access to post data but can’t use templates for output. Action function argument: an array with a reference to the global $wp object.

    Action priority level: (again from the codex)

    1. plugins_loaded

    2. sanitize_comment_cookies

    3. setup_theme

    4. auth_cookie_malformed

    5. auth_cookie_valid

    6. set_current_user

    7. init

    8. widgets_init

    9. parse_request

    10. send_headers

    11. pre_get_posts

    12. posts_selection

    13. wp

    14. template_redirect

    15. get_header

    16. wp_head

    17. wp_print_styles

    18. wp_print_scripts

    19. loop_start

    20. loop_end

    21. get_sidebar

    22. wp_meta

    23. get_footer

    24. wp_footer

    This might change at some point, we actually don’t want the post data on most pages.

    There’s a bumped ticket somewhere about this posts thing; might even have been r-a-y’s (required some WP patches, IIRC)




    thanks for all your answers!

    Makes sense now to me. I wasn’t really aware that the query was not fully set in “init”.

    I just needed to know this, in case BP relies on something that is not available before “wp”, for writing a plugin to BP. So I guess if I don’t need anything special it’s ok to use “init”.



Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Info about the used action \"wp\"’ is closed to new replies.
Skip to toolbar