Skip to:
Content
Pages
Categories
Search
Top
Bottom

Correct way to replace functions in bp-core.php

  • Avatar of thebloghouse
    thebloghouse
    Participant

    @thebloghouse

    Hi all

    I am wanting to create a custom version of the following core function and have added my custom version into my bp-custom.php file and it works fine but rather than simply cut or comment out the standard BuddyPress function within bp-core.php is there some way of overwiting individual functions as I want to be able to leave bp-core.php as untouched as possible?

    bp_core_action_search_site

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of Jeff Sayre
    Jeff Sayre
    Participant

    @jeffsayre

    Look at line 1426 of that function:

    add_action( 'init', 'bp_core_action_search_site', 5 );

    In your bp-custom.php, you can stop that action by doing this:

    remove_action( 'init', 'bp_core_action_search_site', 5 );

    You’ll need to place that within a function.

    See this for more info: http://codex.wordpress.org/Function_Reference/remove_action

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    You have to remove the action after it’s defined by bp. Which is after bp loads up. In bp-custom.php:

    function replace_bp_core_action_search_site(){

    remove_action( ‘init’, ‘bp_core_action_search_site’, 5 );

    add_action( ‘init’, ‘YOUR_bp_core_action_search_site’, 5 );

    }

    add_action(‘plugins_loaded’, ‘replace_bp_core_action_search_site’);

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    Jeff and I seem to be writing posts at the same time. Maybe we need walkie talkies or something. :)

    Avatar of Jeff Sayre
    Jeff Sayre
    Participant

    @jeffsayre

    Haha! I beat you to it this time, Burt!

    You’ve provided a little more detail though, so–team effort wins!

    Avatar of thebloghouse
    thebloghouse
    Participant

    @thebloghouse

    Wow – thanks you both so much for the quick and concise replies.

    This is the most helpful and knowlegable forum I have ever used!

    Burt’s code was perfect :)

    Avatar of Jeff Sayre
    Jeff Sayre
    Participant

    @jeffsayre

    @thebloghous

    You’re welcome. As others have seen me say before, we aim to please and sometimes we actually manage to do so!

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

You must be logged in to reply to this topic.