Using WordPress ‘mu_options()’ PHP function

The mu_options() WordPress PHP function retrieves WordPress Multisite (WPMU) options.

Usage

To use the mu_options() function, simply call it without any parameters:

$mu_options = mu_options();

Parameters

  • None.

More information

See WordPress Developer Resources: mu_options

Examples

Get WPMU options and display them

This example retrieves WPMU options and displays them in an unordered list.

$mu_options = mu_options();

echo '<ul>';
foreach ($mu_options as $key => $value) {
    echo '<li><strong>' . $key . '</strong>: ' . $value . '</li>';
}
echo '</ul>';

Check if a specific WPMU option exists

This example checks if a specific WPMU option, ‘my_custom_option’, exists.

$mu_options = mu_options();

if (array_key_exists('my_custom_option', $mu_options)) {
    echo 'Option exists.';
} else {
    echo 'Option does not exist.';
}

Retrieve the value of a specific WPMU option

This example retrieves the value of a specific WPMU option, ‘my_custom_option’, and displays it.

$mu_options = mu_options();

if (array_key_exists('my_custom_option', $mu_options)) {
    echo 'Value: ' . $mu_options['my_custom_option'];
} else {
    echo 'Option does not exist.';
}

Count the number of WPMU options

This example counts the number of WPMU options and displays the result.

$mu_options = mu_options();
$count = count($mu_options);

echo 'Total WPMU options: ' . $count;

Retrieve all WPMU options starting with a specific prefix

This example retrieves all WPMU options starting with the prefix ‘myprefix‘.

$mu_options = mu_options();
$prefix = 'my_prefix_';
$filtered_options = array();

foreach ($mu_options as $key => $value) {
    if (strpos($key, $prefix) === 0) {
        $filtered_options[$key] = $value;
    }
}

// Display the filtered options
echo '<pre>';
print_r($filtered_options);
echo '</pre>';