Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created January 24, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/09c436b55f4c5eecc4187d7fc438ea40 to your computer and use it in GitHub Desktop.
Save tommcfarlin/09c436b55f4c5eecc4187d7fc438ea40 to your computer and use it in GitHub Desktop.
[WordPress] Temporary Options in WordPress
<?php
public function init() {
add_action(
'update_option',
array( $this, 'manage_temporary_option' ),
10, 3
);
}
<?php
public function manage_temporary_option( $option_name, $old_value, $new_value ) {
if ( 'an_irrelevant_option' !== $option_name ) {
return;
}
$url = 'page-from-which-we-expect-to-come.php';
if ( $url === $_SERVER['REQUEST_URI'] ) {
update_option(
'our_temporary_option',
$new_value
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment