Skip to:
Content
Pages
Categories
Search
Top
Bottom

Overrding BuddyPress files


  • Hardeep Asrani
    Participant

    @hardeepasrani

    I’m trying to override following file from BuddyPress core:

    /bp-templates/bp-legacy/buddypress/members/single/member-header.php

    in my custom plugin, by adding it as:

    my-plugin/buddypress/bp-templates/bp-legacy/buddypress/members/single/member-header.php

    and it’s not working. Am I doing it right? Or is there something missing or I need to add in my plugin file….

    Thanks 🙂

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

  • Renato Alves
    Moderator

    @espellcaste

    Try not to repeat all the file path. Just putting:

    themes/your-theme/buddypress/members/single/member-header.php


    Renato Alves
    Moderator

    @espellcaste

    Sorry, I misunderstood. I’m not sure if the above example would work in a plugin directory.


    b a
    Participant

    @mpa4hu

    add_action('get_template_part_members/single/member-header', 'add_member_header_stack', 10, 2);
    add_action('bp_locate_template', 'remove_member_header_stack', 10, 6);
    function add_member_header_stack($slug, $name) {
    	add_filter( 'bp_get_template_stack', 'my_custom_stack' );
    }
    function remove_member_header_stack($located, $template_name, $template_names, $template_locations, $load, $require_once) {
    	if("members/single/member-header.php" == $template_name) {
    		remove_filter( 'bp_get_template_stack', 'my_custom_stack' );
    	}
    }
    function my_custom_stack( $stacks = array() ) {
    	$retval = array();
    	$retval[] = '/path/to/plugin';
    	foreach ($stacks as $stack) {
    		$retval[] = $stack;
    	}
    	return $retval;
    }

    This is the best way to do this in my opinion.
    Also just adding your stack would work, but I added conditions to only apply this filter when needed and remove after. Not sure how much resource it will save but just tried to be fancy.

    To understand what this function filter does, I suggest reading this codex


    Hardeep Asrani
    Participant

    @hardeepasrani

    Would I have to do any modifications on your code, and the plugin structure will be like:

    my-plugin/buddypress/members/single/member-header.php

    ??

    Thanks for the help 🙂


    b a
    Participant

    @mpa4hu

    modification goes here $retval[] = '/path/to/plugin'; and yes, you have to have structure like that


    Hardeep Asrani
    Participant

    @hardeepasrani

    And it will be like pluginfolder/pluginfile.php ? Or something else?


    Hardeep Asrani
    Participant

    @hardeepasrani

    Here’s how it looks like a plugin: https://sites.google.com/site/hardeepasrani/bp-plugin-override.zip?attredirects=0&d=1

    Hope you can help with this…Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Overrding BuddyPress files’ is closed to new replies.
Skip to toolbar