Skip to content

Instantly share code, notes, and snippets.

@dovy
Last active October 3, 2016 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dovy/6608987 to your computer and use it in GitHub Desktop.
Save dovy/6608987 to your computer and use it in GitHub Desktop.
Simple method for recovering redux values if you wish to not use the global variable.
<?
function redux_get_variables( $name, $key = false ) {
global $MY_VAR_NAME; // Update to your opt_name or global_variable name
$options = $MY_VAR_NAME; // Update to your opt_name or global_variable name
$var = ""; // Set this to your preferred default value
if ( empty( $name ) && !empty( $options ) ) {
$var = $options;
} else {
if ( !empty( $options[$name] ) ) {
if ( !empty( $key ) && !empty( $options[$name][$key] ) ) {
$var = $options[$name][$key];
} else {
$var = $options[$name];
}
}
}
return $var;
}
// To use this, you'd call anywhere you want redux_get_variables().
// You can specify the name of the option by id, and a key within it to return.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment