Using add_filter() in Widgets

<?php
/**
 * Display the actual Widget
 *
 * @param Array $args
 * @param Array $instance
 */
public function widget($args, $instance){
    …
    $wcss = apply_filters( 'my-filter-name', $wcss );
    …
}
?>

To create your own filter hook just use the function “apply_filters” then
as you mentioned add a function in your constructor i.e.

function __constructor()
{
    …
    add_filter( 'my-filter-name', array( &$this, 'my_function_name' );
    …
}

Be sure your function returns something

function my_function_name( $css )
{
    // Do whatever you want
    return $css;
}

Leave a Comment