Skip to:
Content
Pages
Categories
Search
Top
Bottom

change css class of function with filter hook


  • Nowarah
    Participant

    @nouarah

    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

    @robin-w

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

    Nowarah
    Participant

    @nouarah

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


    Robin W
    Moderator

    @robin-w

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

    Nowarah
    Participant

    @nouarah

    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