WordPress Store Authentication token in memory

Solution:

In this case, I would work with WordPress transients:

https://developer.wordpress.org/reference/functions/set_transient/ https://developer.wordpress.org/reference/functions/get_transient/

To set a transient, you can use this code:

$transient  = 'your_token_name';
$value      = 'your_token'
$expiration = 3600

set_transient( $transient, $value, $expiration );

To receive the value of your transient again, you can use:

$token = get_transient( $transient );

Using these methods is better than update_option or get_option since WordPress manages the expiration (deletion) of transients completely, so you don’t have to implement your own logic for this.

Before you pass the value to the transient method, you can encrypt and decrypt it by storing a salt/key in your wp-config.php. You can find more infos about this topic here:

http://php.net/manual/es/function.openssl-encrypt.php http://php.net/manual/es/function.openssl-decrypt.php

To define a constant in WordPress you need to go to your wp-config.php file and add it between the “you can edit” words:

define( 'YOUR_SALT', '12345678' );

You can read it again as a normal constant in WordPress:

$salt = YOUR_SALT;