Skip to:
Content
Pages
Categories
Search
Top
Bottom

modifying functions in includes directory, use bbpress-functions.php?


  • Jerry
    Participant

    @jerrysc

    I have a general question. I am trying to modify the behavior of the function bbp_new_topic_handler, which is located in bbpress/includes/topics/functions.php. I use child themes extensively. I have not found a way to modify functions.php within my child theme. After reading the codex, and various searches, I THINK that I need to take the entire function, bbp_new_topic_handler, and re-declare it within bbpress-functions.php. I can’t declare a function twice, so that implies I need to remove it from functions.php within the above mentioned directory. Or perhaps I am on the wrong track?

    What I fear is making changes directly to functions.php and then having those changes wiped out in the next bbpress update. I can’t use filters because I intend to modify how the function works, not just the wording.

    So I suppose my question is as follows: How does one go about making changes to functions within a functions.php file, located in the includes directory? Does someone have a “best practice” recommendation for doing this?

    Thanks.

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

  • Robin W
    Moderator

    @robin-w

    These are exactly the questions I was asking 6 months ago, so I sense your frustration !!

    I was expecting to write some stuff on filtering, but having had a quick look at ‘bbp_new_topic_handler’ this doesn’t have any real filtering capability, although it does have some url filters.

    Fuller than probably needed answer for the benefit of others !
    Ok so you can usually
    either filter a function either using bbp_parse_args where you want to change some paramters that are being passed to wp-query

    or filter the whole function – if it ends with ‘return apply_filters(..)’ then you can easily copy the whole function and alter it within your child theme, just rename it slightly and then add a filter
    so a fictional function called ‘add_name’ in bbpress ends with
    Return apply_filters (‘add_name’, $name) ;

    you simply copy the whole function and change ‘add_name’ to say ‘my_add_name’ then add a line
    add_filter (‘add_name’, ‘my_add_name’)

    and wordpress will use your function to replace the original.

    But for your function, there is a url filter near the edn but otherwise this is a function that does, so no neat parameters that are replaceable at the end !

    I searched bbpress for where this function is used, and in includes/core/actions.php it is added as an action to wherever bbp_post_request is used

    Searching for that gets me a bit confused, as I’m not familiar with what this does, and have limited time to chase it down.

    Now, having written all that as I was going along, if I were you I’d do one of two things

    1. Go further back and find what is calling the function, and then change that. If it is a template, you can alter that in a bbpress folder within your theme to call your function instead, and neither will get overwritten by upgrades.

    2. There is no problem in changing core bbpress files as long as a) you are happy you know what you’re doing and b) you make a note of the changed function.

    Then on each upgrade, you’ll need to look at whether any code in the function has changed, and if not just overwrite it again. If it has changed, then you’ll need to redo your amendment taking into account the new code. But you sometimes need to do that anyway for a child theme function where bbpress is dealing differently with it.

    Yes changing core is ‘frowned’ upon, but only because people do it and then get upset when it is overwritten and they can’t remember what they changed !! Do it with knowledge and you’ll be fine !

    After all it just some code that someone’s written, and any ‘rules’ are just made up and have no authority !


    Jerry
    Participant

    @jerrysc

    Thanks for your answer Robin. I’ve saved it for the future, when I need to modify a function that does have the filtering in place. Thanks.

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

You must be logged in to reply to this topic.