Skip to:

Explanation for recurring coding pattern in BP core

  • terraling


    After the very helpful response of @hnla to an earlier question I posted I’ve been reading through more of the core files to understand what I can and can’t hook into, and there is a recurring pattern I see in how the files are set up and I’m curious as to why, if anyone is able to elucidate.

    Random example, from bp-members-template.php

    function bp_members_slug() {
    	echo bp_get_members_slug();
    function bp_get_members_slug() {
    	global $bp;
    	return apply_filters( 'bp_get_members_slug', $bp->members->slug );

    If all bp_members_slug() does is echo bp_get_members_slug(), why not just use bp_get_members_slug() directly?

    It is such a common pattern there is obviously a good reason for it…

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

  • shanebp


    Sometimes you want to echo the returned value.
    Sometimes you just want the value.

    in other words if you are needing to pass the function return through another function like a shortcode or filter the last thing you want is the function trying to echo out the content as it causes problems.

    This is a common WP construct that BP follows, it’s useful to remember that nearly always when you see a WP function if you stick _get_ in there somewhere you’ll grab the value.



    OK, simple now you point it out, thanks to you both…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Explanation for recurring coding pattern in BP core’ is closed to new replies.
Skip to toolbar