Skip to:
Content
Pages
Categories
Search
Top
Bottom

Correct way to replace functions in bp-core.php

  • @thebloghouse

    Participant

    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)
  • @jeffsayre

    Participant

    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: https://codex.wordpress.org/Function_Reference/remove_action

    @burtadsit

    Participant

    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’);

    @burtadsit

    Participant

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

    @jeffsayre

    Participant

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

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

    @thebloghouse

    Participant

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

    @jeffsayre

    Participant

    @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)
  • The topic ‘Correct way to replace functions in bp-core.php’ is closed to new replies.
Skip to toolbar