Skip to:
Content
Pages
Categories
Search
Top
Bottom

Overwriting a core function without modifying core files


  • Hope
    Participant

    @amalsh

    Hi dears,

    I asked this question previously and didn’t get a useful answer so I’m asking it again:

    I had to modify functions in the bp-members-functions.php file to accommodate my requirements but as everybody knows, core files should not be modified since this modification will be overridden after each update.
    So my question is: How can I overwrite any function without touching the core files?

    A simple example: I want to allow underscores in usernames upon registration so for now I commented the “No underscores….” code part in bp_core_validate_user_signup function, how can I implement this without modifying the function directly?

    Thanks for your help
    Hope

Viewing 4 replies - 1 through 4 (of 4 total)
  • > I asked this question previously and didn’t get a useful answer

    What post and why are you not continuing in that thread rather than creating a new one? Perhaps the advice was don’t do this?

    If you want to modify core functionality then the WP approach is via hooks and filters, BP adds filters on a liberal basis where they would help in allowing devs to modify or interact with functions so you’ll need to check the functions in core see what filters are available for you to work with.

    fwiw I’m not sure it’s wise to start messing around with the core WP signup process, these aspects are tricky, have you considered they may well be a reason underscores aren’t allowed, and regardless why would you think them useful?


    Hope
    Participant

    @amalsh

    @hnla Thanks for your reply and help!

    would you please give me an example of how to use the filters? and where to find it? for example, in “bp_core_validate_user_signup” function there are:
    $result = apply_filters( ‘wpmu_validate_user_signup’, $result );
    and
    return apply_filters( ‘bp_core_validate_user_signup’, $result );

    Are those the filters you meant? How can I use it?

    Unfortunately I cannot prevent underscores in usernames since the naming policy in my institution for the users is: name_number and it should be used the same in the social network.

    Thanks
    Hope

    Yep, but not sure if this is going to work, essentially you would need a function that passes in $user_name & $user_email then run your user_name checks as the bp function does but omitting the underscore check then pass those two variables into the $results array as bp does but the $user_name will be based on your checks with the $user_mail & $errors just passed into that array as is and $result returned in the function, then you add_filter(‘bp_core_validate_blog_signup’, ‘your_function_name’, 2)

    Note though likely I have got most of that wrong 🙂 WP has codex pages on working with filters that you probably should read for a better understanding of how to use them.


    Hope
    Participant

    @amalsh

    Okay, I’ll search for how to use filters and try it.

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Overwriting a core function without modifying core files’ is closed to new replies.
Skip to toolbar