Skip to:
Content
Pages
Categories
Search
Top
Bottom

change css class of function with filter hook

  • @nouarah

    Participant

    I need to add a class to the dropdown topic select_class.
    the original function is:

    function bbp_get_form_topic_status_dropdown( $args = array() ) {
    
            // Parse arguments against default values
            $r = bbp_parse_args( $args, array(
                'select_id'    => 'bbp_topic_status',
                'select_class' => 'bbp_dropdown',
                'tab'          => false,
                'topic_id'     => 0,
                'selected'     => false
            ), 'topic_open_close_select' );
    
            // Filter & return
            return apply_filters( 'bbp_get_form_topic_status_dropdown', ob_get_clean(), $r, $args );
        }

    I tired to use this but didnt work

    function custom_callback($args = array() ) {
        
            $r = bbp_parse_args( $args, array(
                
                'select_class' => 'my-class',
                
            ) );
            
            return  $r;
    
    }
    add_filter( 'bbp_get_form_topic_status_dropdown', 'custom_callback', 12, 2);
Viewing 4 replies - 1 through 4 (of 4 total)
  • @robin-w

    Moderator

    the ‘,2’ might be the issue, as you only then use 1, but try this

    function custom_callback($args) {
        
            $args['select_class'] = 'my-class' ;
                
           return  $args;
    
    }
    add_filter( 'bbp_get_form_topic_status_dropdown', 'custom_callback');

    @nouarah

    Participant

    I got Uncaught TypeError: Cannot access offset of type string on string

    @robin-w

    Moderator

    ok, let’s just redo the whole thing

    function custom_callback( $args=array()) {
    
            // Parse arguments against default values
            $r = bbp_parse_args( $args, array(
                'select_id'    => 'bbp_topic_status',
                'select_class' => 'my-class',
                'tab'          => false,
                'topic_id'     => 0,
                'selected'     => false
            ), 'topic_open_close_select' );
    
            // Filter & return
            return apply_filters( 'custom_callback', ob_get_clean(), $r, $args );
        }
    	
    
    add_filter( 'bbp_get_form_topic_status_dropdown', 'custom_callback');

    @nouarah

    Participant

    I write the whole original function and it works now. thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar