Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to use bp hooks?


  • savantking99
    Participant

    @savantking99

    OKe, I have some custom input fields. And one custome field calls field_1. and I want to change the standard text: This is a required field. for a more specific text: you have to enter name.

    So I try it like this:

    apply_filters(‘bp_members_signup_error_message’, ‘function_voornaam’);

    function function_voornaam($value,  $fieldname ){
    
        if($fieldname == 'field_1'){
    
         return '<style>{font-family:bold}</style> wrong name';
    
        }    
    }

    But I don’t see any change.

    How can I improve this?

    Thank you

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

  • shanebp
    Moderator

    @shanebp

    Read the docs re how to use apply_filters.

    Try:
    add_filter('bp_members_signup_error_message', 'function_voornaam');


    savantking99
    Participant

    @savantking99

    Yes, I have done that. So the complete code is then like this:

    add_filter('bp_members_signup_error_message', 'function_voornaam');
    
    function function_voornaam($value,  $fieldname)
    {
    
        if ($fieldname == 'field_1') {
    
            return '<style>{font-family:bold}</style>  you have to enter name.';
        }
    }

    But then I get this error:

    
    atal error: Uncaught ArgumentCountError: Too few arguments to function function_voornaam(), 1 passed in E:\Xampp\htdocs\wordpress\wp-includes\class-wp-hook.php on line 303 and exactly 2 expected in E:\Xampp\htdocs\wordpress\wp-content\themes\buddyboss-theme-child\functions.php:49 Stack trace: #0 E:\Xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(303): function_voornaam('show_messagge') #1 E:\Xampp\htdocs\wordpress\wp-includes\plugin.php(189): WP_Hook->apply_filters('show_messagge', Array) #2 E:\Xampp\htdocs\wordpress\wp-content\themes\buddyboss-theme-child\functions.php(68): apply_filters('bp_members_sign...', 'show_messagge') #3 E:\Xampp\htdocs\wordpress\wp-settings.php(546): include('E:\\Xampp\\htdocs...') #4 E:\Xampp\htdocs\wordpress\wp-config.php(97): require_once('E:\\Xampp\\htdocs...') #5 E:\Xampp\htdocs\wordpress\wp-load.php(50): require_once('E:\\Xampp\\htdocs...') #6 E:\Xampp\htdocs\wordpress\wp-blog-header.php(13): require_once('E:\\Xampp\\htdocs...') #7 E:\Xampp\htdocs\wordpress\index.php(17): require('E:\\Xampp\\htdocs...') #8 {main} thrown in E:\Xampp\htdocs\wordpress\wp-content\themes\buddyboss-theme-child\functions.php on line 49
    

    savantking99
    Participant

    @savantking99

    But if I do this:

    apply_filters('bp_members_signup_error_message', 'function_voornaam()');
    
    function function_voornaam($value,  $fieldname)
    {
    
        if ($fieldname == 'field_1') {
    
            return '<style>{font-family:bold}</style> wrong name';
        }
    }

    I don’t get errors. But also the text is not changed. It is still shown:

    This is a required field.

    And I found this documentation:

    bp_members_signup_error_message


    kayart
    Participant

    @kayart

    Try this:

    add_filter( 'bp_members_signup_error_message', 'function_voornaam', 10, 2 );
    function function_voornaam( $value,  $fieldname ) {
        if ( $fieldname == 'field_1' ) {
            return '<style>{font-family:bold}</style>  you have to enter name.';
        }
    
        return $value;
    }

    savantking99
    Participant

    @savantking99

    thank you. But then I get this error:

    
    Fatal error: Uncaught ArgumentCountError: Too few arguments to function function_voornaam(), 1 passed in E:\Xampp\htdocs\wordpress\wp-includes\class-wp-hook.php on line 303 and exactly 2 expected in E:\Xampp\htdocs\wordpress\wp-content\themes\buddyboss-theme-child\functions.php:48 Stack trace: #0 E:\Xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(303): function_voornaam('show_messagge') #1 E:\Xampp\htdocs\wordpress\wp-includes\plugin.php(189): WP_Hook->apply_filters('show_messagge', Array) #2 E:\Xampp\htdocs\wordpress\wp-content\themes\buddyboss-theme-child\functions.php(66): apply_filters('bp_members_sign...', 'show_messagge') #3 E:\Xampp\htdocs\wordpress\wp-settings.php(546): include('E:\\Xampp\\htdocs...') #4 E:\Xampp\htdocs\wordpress\wp-config.php(97): require_once('E:\\Xampp\\htdocs...') #5 E:\Xampp\htdocs\wordpress\wp-load.php(50): require_once('E:\\Xampp\\htdocs...') #6 E:\Xampp\htdocs\wordpress\wp-blog-header.php(13): require_once('E:\\Xampp\\htdocs...') #7 E:\Xampp\htdocs\wordpress\index.php(17): require('E:\\Xampp\\htdocs...') #8 {main} thrown in E:\Xampp\htdocs\wordpress\wp-content\themes\buddyboss-theme-child\functions.php on line 48
    

    shanebp
    Moderator

    @shanebp

    You need to look at themes\buddyboss-theme-child\functions.php : Line 48 to see what arguments are passed in the filter hook and then change your function to include all those arguments.
    And the ‘2’ in
    add_filter( 'bp_members_signup_error_message', 'function_voornaam', 10, 2 );
    needs to equal the number of arguments passed in the filter hook.


    savantking99
    Participant

    @savantking99

    that is my own function: line 48.

    and this is the doucumentation from buddyboss:

    apply_filters( 'bp_members_signup_error_message', string $value, string $fieldname )

    So I pass two arguments.


    savantking99
    Participant

    @savantking99

    So how can I improve this?


    shanebp
    Moderator

    @shanebp

    There is already a filter with that name:
    apply_filters( 'bp_members_signup_error_message', '<div class="error">' . $error_message . '</div>' );
    It passes only one argument. You need to write a custom filter hook with a different name.

    also – these are the forums for BuddyPress.
    Please contact BuddyBoss for questions specific to their codebase.
    This thread is now closed.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to use bp hooks?’ is closed to new replies.
Skip to toolbar