Skip to content

Instantly share code, notes, and snippets.

@ozh
Created May 5, 2015 04:36
Show Gist options
  • Save ozh/988a49419d4b34c431ad to your computer and use it in GitHub Desktop.
Save ozh/988a49419d4b34c431ad to your computer and use it in GitHub Desktop.
Example of how to add and remove filters (or actions) within a YOURLS plugin class
<?php
/**
* Example of how to add and remove filters (or actions) within a plugin class
*/
class Add_Remove_Filter {
function __construct() {
yourls_add_filter( 'ozh', array( $this, 'do_something' ) );
}
function check(){
var_dump( yourls_has_filter( 'ozh' ) );
var_dump( yourls_has_filter( 'ozh', array( $this, 'do_something' ) ) );
}
function remove() {
var_dump( yourls_remove_filter( 'ozh', array( $this, 'do_something' ) ) );
}
function do_something( $value ) {
// do something
}
}
$ozh = new Add_Remove_Filter;
$ozh->check();
// boolean true
// int 10
$ozh->remove();
// boolean true
$ozh->check();
// boolean false
// boolean false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment