Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spacedmonkey/eeeb20e73238d9ef5376db43202f6b41 to your computer and use it in GitHub Desktop.
Save spacedmonkey/eeeb20e73238d9ef5376db43202f6b41 to your computer and use it in GitHub Desktop.
class WP_Short_Circuit_Result {
private $name = null;
private $value = null;
public $has_changed = false;
public function __construct( $name = null, $value = null ) {
$this->name = $name;
$this->value = $value;
$this->has_changed = false;
}
public function __set( $name, $value ) {
$this->$name = $value;
if( $name == 'value' ){
$this->has_changed = true;
}
}
public function set_value( $value ) {
$this->value = $value;
$this->has_changed = true;
}
public function get_value(){
return $this->value;
}
public function has_short_circuit(){
return $this->had_changed;
}
}
Implemntation
$short_circuit_result = new WP_Short_Circuit_Result( $option, $default );
do_action( 'short_circuit_get_option', $short_circuit_result );
if ( $short_circuit_result->has_short_circuit() ) {
return $short_circuit_result->get_value();
}
function add_short_circuit($name, $value){
add_action($name, function($short_circuit_result){
$short_circuit_result->set_value( $value );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment