API / Minn\Runtime / Options

Options final class

Minn\Runtime\Options · public/minn/src/Minn/Runtime/Options.php · 498 lines

Options as plugin code sees them, kept where the reference keeps them: wp_cache's options group (OptionsGroup) holds the autoloaded list, the names known unset, and a key per option not autoloaded, so a plugin that reads, writes or drops those keys is heard. get_option() and wp_load_alloptions() pass the list through pre_wp_load_alloptions and alloptions. A value written this request is held as it was written (an int stays an int, true stays true), arrays and objects as stored. Each stored text is decoded once while it stays the same, except one holding an object, decoded afresh on every read as the reference does: a plugin that changes the object it was handed and saves it must find the stored copy still different, or its change is never written.

Constants and properties

privateALL = 'alloptions'
privateMISSING = 'notoptions'
constGUARDED = array ( 0 => 'minn_runtime_symbols', 1 => 'minn_recovery_strikes', 2 => 'minn_cron_lock', )

The options the engine keeps for itself: the symbol-gate cache a plugin could otherwise rewrite to pass its own gate, the recovery strikes, the cron lock, and the sign-in throttle rows. The facade refuses to write them; the engine writes them through this class directly.

privateGUARDED_PREFIX = 'minn_login_throttle_'
constON_DEMAND = array ( 0 => 'minn_admin_changelog', 1 => 'minn_changelog', 2 => 'minn_release', 3 => 'minn_plugin_info', 4 => 'minn_updates', 5 => '_transient_minn_admin_uploads_size', 6 => '_transient_timeout_minn_admin_uploads_size', 7 => 'minn_admin_uploads_size_lock', )

The engine's own caches, read on demand and written with autoload off (Site::setOption). Rows an older engine wrote autoloaded are set right the first time a loaded list holds them.

constAUTOLOAD_VALUES = array ( 0 => 'yes', 1 => 'on', 2 => 'auto-on', 3 => 'auto', )

The autoload column values that load an option with every request, in the reference's order.

constEVERY_REQUEST = array ( 0 => 'minn_runtime_symbols', 1 => 'paused_plugins', 2 => 'WPLANG', 3 => 'https_migration_required', 4 => 'minn_admin_post_types', 5 => 'minn_admin_taxonomies', )

Options not autoloaded that are read on every request (the symbol survey, recovery's paused plugins, the site language, the HTTPS migration flag, and the post types and taxonomies Minn Admin keeps and registers as it loads): read together as a request begins, as one read rather than one each.

privatereadonly Minn\Runtime\OptionsGroup $group
privatearray $decoded
privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
methodisFor(Minn\Db $db): bool#

Whether this store reads through the given connection.

staticguarded(string $name): bool#

Whether plugin code is refused a write to this option.

methodautoloaded(bool $force = false): mixed#

The autoloaded list as wp_load_alloptions() gives it: pre_wp_load_alloptions may answer first (told whether the cache was forced), and then alloptions is not heard; otherwise the list the group holds, through alloptions, which may add or change entries without the group keeping them.

methodfiltered(string $name, mixed ...$default): mixed#

An option as get_option() reads it, through the filters plugins hook: pre_option_{name}, then pre_option, may answer first; then the autoloaded list is read through its filters on every read; an unset option is its default (false when none is given) through default_option_{name}, which is told whether one was given; a set one goes through option_{name}.

methodraw(string $name): ?string#

An option's stored text, as Db::option() gives it, or null when it is unset: from the list or the group, a value written this request in its stored form (true as "1", a list serialized).

methodget(string $name): mixed#

An option's value, decoded, or null when unset; home and siteurl answer to wp-config.php's constants.

methodprime(array $names): void#

Reads several options at once (wp_prime_option_caches): the ones not held yet in one query, each kept under its own key or noted unset, as a read of each one alone would leave them.

$nameslist<string>
methodexists(string $name): bool#

Whether an option exists.

methodknownMissing(string $name): bool#

Whether a read this request already found the option unset (the reference's notoptions).

methodadd(string $name, mixed $value, string $autoload = 'auto'): bool#

Writes a new option. add_option has already decided it is new (its value is still the default); a row that is there anyway is written over, as the reference's add does, and false comes back when it already held this value. An autoloaded one joins the list.

methodupsert(string $name, string $stored, string $autoload): bool#

Writes an option row whether or not one exists, as the reference does for every add: two requests that both find a transient missing and both add it must not fail on the unique name, so the second write lands over the first. True when the row was inserted or changed, false when the same value was already there.

methodupdate(string $name, mixed $value, ?string $autoload = NULL): bool#

False when the value is unchanged, as the reference reports.

methodmarkAutoload(string $name): bool#

Flips the autoload column; false when the option is missing or already so. The list is read again, the option's own key dropped.

methodunmarkAutoload(string $name): bool#

Stops an option loading on every request; false when it already did not, or is unset. It leaves the list.

methoddelete(string $name): bool#

Removes an option: out of the list or its own key, and known unset.

methodexpiredTransientNames(int $now, string $prefix = '_transient_timeout_'): array#

The names of transients whose expiry has passed. The timeout row is the one that knows, so the sweep reads those and hands back the bare names.

@return list<string>
methodforget(string $name): void#

Brings the group back in step with an option the engine wrote behind the store (its own rows, the CLI): the row is read again, into the list when it autoloads, and nothing else written this request is lost.

statictoStorage(mixed $value): string#

What the reference stores (maybe_serialize): arrays and objects serialized, a string that looks serialized serialized again so it reads back as that string, other scalars as their string form.

staticfromStorage(string $raw): mixed#

A stored option value decoded the way the reference reads it.

Internals 8

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatelisted(): array#

The autoloaded options, kept in the group under alloptions: read in one query when the group has no list, each as stored except one written since. @return array<string, mixed>

@return array<string, mixed>
privatemissing(): array#
@return array<string, true> the names a read found unset, kept in the group under notoptions
privatelookup(string $name, array $list): mixed#

An option's held value, or null when it is unset: from the list given, else not at all when it is known unset, else its own key, else its row (kept under its own key, or noted unset).

$listarray<string, mixed>
privatedecode(string $name, mixed $held): mixed#

A held value decoded the way the reference reads it, once while it stays the same (never one holding an object).

privateremember(string $name, mixed $value): mixed#

What the group holds for a value just written: scalars as given, arrays and objects as stored. Its decoded form is the value itself, so a string that only looks serialized reads back as that string.

privatefound(string $name): void#

Takes a name off the list of those known unset.

privateholdsObject(string $stored): bool#

Whether a stored value has an object record in it (a string that only mentions one decodes afresh too, which is harmless).

privateswitchAutoload(string $name, string $wanted, array $already): bool#
$alreadylist<string>the stored values that already mean $wanted