\MatthiasWeb\UtilsExpireOption

WordPress itself has a so-called "Transient API" which allows you to save custom results of e. g. database queries in the database `wp_options` table. While developing the plugin Real Media Library we experienced a lot of issues with Transients as there are a lot of performance and optimization plugins which clears the transients.

Note: You should not use this for huge query results as this option gets autoloaded if non-site-wide.

Summary

Methods
Properties
Constants
__construct()
get()
set()
delete()
enableTransientMigration()
getExpireName()
getName()
isSiteWide()
getExpiration()
getTransientMigration()
No public properties found
EXPIRE_SUFFIX
TRANSIENT_MIGRATION_DISABLED
TRANSIENT_MIGRATION_NON_SITE_WIDE
TRANSIENT_MIGRATION_SITE_WIDE
handleMigration()
No protected properties found
N/A
No private methods found
$name
$siteWide
$expiration
$transientMigration
N/A

Constants

EXPIRE_SUFFIX

EXPIRE_SUFFIX ='-expire'

TRANSIENT_MIGRATION_DISABLED

TRANSIENT_MIGRATION_DISABLED =0

TRANSIENT_MIGRATION_NON_SITE_WIDE

TRANSIENT_MIGRATION_NON_SITE_WIDE =1

TRANSIENT_MIGRATION_SITE_WIDE

TRANSIENT_MIGRATION_SITE_WIDE =2

Properties

$name

$name :

Type

$siteWide

$siteWide :

Type

$expiration

$expiration :

Type

$transientMigration

$transientMigration :

Type

Methods

__construct()

__construct(string  $name,boolean  $siteWide,integer  $expiration)

C'tor.

Parameters

string $name

Your option name

boolean $siteWide

Use e. g. get_site_transient instead of get_transient

integer $expiration

Time until expiration in seconds

get()

get(mixed  $fallback = false,boolean  $respectExpire = true)

Get option value. Returns `$fallback` if not found or expired.

Parameters

mixed $fallback
boolean $respectExpire

If false, you will always get the value from database (useful if you need to merge from previous data)

enableTransientMigration()

enableTransientMigration(integer  $type)

If you are migrating from a transient, use this method to allow reading the value via `get` from the transient value, when no option was found.

Parameters

integer $type

See class constants TRANSIENT_MIGRATION*

getExpireName()

getExpireName()

Get "expire" option name.

getName()

getName()

Get option name.

isSiteWide()

isSiteWide()

Get if option is site-wide.

getExpiration()

getExpiration()

Get expiration in seconds.

getTransientMigration()

getTransientMigration()

Get value of `transientMigration`.

handleMigration()

handleMigration(mixed  $fallback)

Handle the migration and return the correct value.

Parameters

mixed $fallback