\um\adminWP_Config

Class WP_Config

Thin wrapper around the bundled wp-cli/wp-config-transformer library used to safely add/update/remove PHP constants in wp-config.php. Backs the api_key settings field type, whose secret values are stored as constants instead of in the um_options DB array.

Summary

Methods
Properties
Constants
is_available()
get_config_path()
is_writable()
set_constant()
remove_constant()
No public properties found
No constants found
flush_config_opcache()
$lib_path
N/A
No private methods found
No private properties found
N/A

Properties

$lib_path

$lib_path : string

Path to the bundled WPConfigTransformer library.

Mirrors the Action Scheduler bundling convention (\um\action_scheduler\Init) — the file is copied into includes/lib/ at build time via the wp-config-transformer composer script.

Type

normal

Methods

is_available()

is_available() : bool

Whether the WPConfigTransformer library is loadable.

Returns

bool

get_config_path()

get_config_path() : string

Resolve the path to wp-config.php, handling the standard WordPress non-subdir fallback (wp-config.php one level above ABSPATH when it isn't a subdirectory install).

Returns

string

is_writable()

is_writable() : bool

Whether constants can currently be written to wp-config.php.

Returns

bool

set_constant()

set_constant(string  $name, string  $value) : bool

Add or update a constant in wp-config.php.

Uses WPConfigTransformer::update() with add => true, which replaces the value in place when the constant already exists and adds it otherwise — so it never duplicates a define().

Parameters

string $name

Constant name.

string $value

Constant value.

Returns

bool —

True on success, false on failure (e.g. wp-config.php not writable).

remove_constant()

remove_constant(string  $name) : bool

Remove a constant from wp-config.php.

Parameters

string $name

Constant name.

Returns

bool —

True on success (including when the constant was already absent), false on failure.

flush_config_opcache()

flush_config_opcache() : mixed

Invalidate the OPcache entry for wp-config.php after writing to it.

OPcache caches the compiled wp-config.php and only revalidates its mtime every opcache.revalidate_freq seconds (default 2). Without this, the redirect that follows a settings save reloads the stale wp-config.php, so a freshly written constant isn't defined yet and the field renders empty until the next request. Forcing invalidation makes the new constant available on the very next request.

Returns

mixed