Created
August 9, 2017 10:25
-
-
Save spacedmonkey/eeeb20e73238d9ef5376db43202f6b41 to your computer and use it in GitHub Desktop.
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
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