Created
November 2, 2018 17:49
-
-
Save debonx/3a93726313decd2efaabc5f92849343c to your computer and use it in GitHub Desktop.
How to update and check transients on Wordpress. More at https://xilab.co.
This file contains 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
/* | |
* @param $tag = tag to use for this transient | |
* @param $element = value to associate the transient | |
* @param $duration / $expiration = time in seconds > 3600*24 for 1 day | |
* @return true > if needed to update | false > if still not expired | |
*/ | |
function update_transient($tag, $element, $duration, $expiration){ | |
$elements_in_tag = get_transient($tag); | |
$need_to_update = isset($elements_in_tag[$element]) && $elements_in_tag[$element] > (time() - ($duration)); | |
if($need_to_update){ | |
$elements_in_tag[$element] = time(); | |
set_transient($tag, $elements_in_tag, $expiration); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment