Skip to:
Content
Pages
Categories
Search
Top
Bottom

What is the purpose of do_action(‘bp_after_message_content’)

  • Avatar of Henry
    Henry
    Member

    @thirstcard

    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)
  • Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    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.

    Avatar of Henry
    Henry
    Member

    @thirstcard

    @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 :}

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    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.

    Avatar of @ChrisClayton
    @ChrisClayton
    Participant

    @chrisclayton

    @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?

    Avatar of Henry
    Henry
    Member

    @thirstcard

    @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!

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

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

    Avatar of @ChrisClayton
    @ChrisClayton
    Participant

    @chrisclayton

    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).

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

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

You must be logged in to reply to this topic.