Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Last active December 19, 2015 10:09
Show Gist options
  • Save lgedeon/5938567 to your computer and use it in GitHub Desktop.
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.
<?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