Last active
December 19, 2015 10:09
-
-
Save lgedeon/5938567 to your computer and use it in GitHub Desktop.
1st pass - needs sanitization, optional parameters (have to reorder), abstract to do actions too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FilterWithArgs { | |
protected $filter; | |
protected $function; | |
protected $priority; | |
protected $arg_count; | |
protected $args; | |
public function __construct( $filter, $function, $priority, $arg_count, $args ) { | |
$this->filter = $filter; | |
$this->function = $function; | |
$this->priority = $priority; | |
$this->arg_count = $arg_count; | |
$this->args = $args; | |
add_filter( $this->filter, array( $this, 'do_filter' ), $this->priority, $this->arg_count ); | |
} | |
public function do_filter() { | |
$args = array_merge( func_get_args(), $this->args ); | |
call_user_func( $this->function, $args ); | |
} | |
public function remove_filter() { | |
remove_filter( $this->filter, array( $this, 'do_filter' ), $this->priority, $this->arg_count ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment