Skip to:
Content
Pages
Categories
Search
Top
Bottom

Modify/Override Buddypress Function


  • jturet
    Participant

    @jturet

    Hello, I am attempting to override the following function:

    /**
     * Locate a custom group front template if it exists.
     *
     * @since 2.4.0
     *
     * @param  BP_Groups_Group|null $group Optional. Falls back to current group if not passed.
     * @return string|bool                 Path to front template on success; boolean false on failure.
     */
    function bp_groups_get_front_template( $group = null ) {
    	if ( ! is_a( $group, 'BP_Groups_Group' ) ) {
    		$group = groups_get_current_group();
    	}
    
    	if ( ! isset( $group->id ) ) {
    		return false;
    	}
    
    	if ( isset( $group->front_template ) ) {
    		return $group->front_template;
    	}
    
    	$template_names = apply_filters( 'bp_groups_get_front_template', array(
    		'groups/single/front-id-'     . sanitize_file_name( $group->id )     . '.php',
    		'groups/single/front-slug-'   . sanitize_file_name( $group->slug )   . '.php',
    		'groups/single/front-status-' . sanitize_file_name( $group->status ) . '.php',
    		'groups/single/front.php'
    	) );
    
    	return bp_locate_template( $template_names, false, true );
    }
    

    My new function replaces

    'groups/single/front-slug-' . sanitize_file_name( $group->slug ) . '.php',

    with

    'groups/single/front-slug-' . sanitize_file_name( current(explode("/", $group->slug)) ) . '.php',

    but that is not the important part. My real question is how can I override/replace this function in my theme’s functions.php file. (Want to keep things upgrade-proof!)

    Thanks in advance!

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

  • shanebp
    Moderator

    @shanebp

    You can’t ‘override/replace this function in my theme’s functions.php file’.

    You can use the filter hook and write a function for use in theme/functions:
    Something like:

    
    function jturet_group_front_template( $template_names ) {
    
        $template_names[1] = // make your changes
    
        return $template_names;
    
    }
    add_filter( 'bp_groups_get_front_template', 'jturet_group_front_template' );

    jturet
    Participant

    @jturet

    Thanks for the response, i’ve tried several different things but can’t seem to put it together correctly. Could you help me set up the code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Modify/Override Buddypress Function’ is closed to new replies.
Skip to toolbar