Skip to:
Content
Pages
Categories
Search
Top
Bottom

What is the purpose of do_action(‘bp_after_message_content’)

  • @thirstcard

    Member

    I see snippets of php such as do_action( ‘bp_after_message_content’ ) or do_action( ‘bp_before_message_content’ ) everywhere in the template files. What do these snippets actually do?

Viewing 7 replies - 1 through 7 (of 7 total)
  • @shanebp

    Moderator

    do_action is a WP thing. Tons of info on it. Google it.
    Given all the things you’re trying to do ( based on your posts to these forums ) you’ll be a lot more effective if you start learning about the environment you’re coding in.

    @thirstcard

    Member

    @shanebp I only ever post in the forums once i’ve Googled/read the Codex and still not fully understood a topic. Apologies if i’ve asked lots of questions today, your help has been much appreciated :}

    @shanebp

    Moderator

    No problem.
    Don’t forget that you’re trying to learn two code bases – WP and BP – so you’ll have to look web-wide.

    @chrisclayton

    Participant

    @thirstcard
    The do_action() creates a hook. Basically it prints out the contents of the function that is added to that tag (bp_after_message_content) with add_action.

    Usage? Let’s say Developer A makes a plugin that will place some text at the bottom of message contents, Instead of the end user having to edit the theme templates to add a call to the function, the developer can use `add_action(‘bp_after_message_content’, ‘plugins_function_that_does_stuff’);` WordPress will remember that function and will print it out where it finds `do_action( ‘bp_after_message_content’ )`

    Does that help?

    @thirstcard

    Member

    @ChrisClayton

    Ah, I see now & I can see where using these would be useful – there is no need to edit the WordPress/BuddyPress core.

    The part I couldn’t get my head around was why you wouldn’t just place the whole function in the theme but now I realise by using do_action() you can insert multiple functions at that specific particular point in the code.

    Thanks for helping out!

    @hnla

    Participant

    Yep it just represents an insertion point in a file, marker points throughout a theme template file where ‘stuff’ may be added.

    @chrisclayton

    Participant

    The wp_footer() and wp_head() functions located in the footer and header files use just do_action to print all of there ‘stuff’ (meta, css, js etc).

    https://core.trac.wordpress.org/browser/tags/3.3.2/wp-includes/general-template.php#L1576

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘What is the purpose of do_action(‘bp_after_message_content’)’ is closed to new replies.
Skip to toolbar