Using WordPress ‘pre_site_option_{$option}’ PHP filter

The pre_site_option_{$option} WordPress PHP filter allows you to modify the value of an existing network option before it is retrieved. The dynamic part of the filter name, $option, refers to the option name.

Usage

add_filter('pre_site_option_{$option}', 'your_custom_function', 10, 4);

function your_custom_function($pre_option, $option, $network_id, $default_value) {
  // your custom code here
  return $pre_option;
}

Parameters

  • $pre_option (mixed): The value to return instead of the option value. Default is false (to skip past the short-circuit).
  • $option (string): Option name.
  • $network_id (int): ID of the network.
  • $default_value (mixed): The fallback value to return if the option does not exist. Default is false.

More information

See WordPress Developer Resources: pre_site_option_{$option}

Examples

Modify site name

Change the site name before it’s retrieved.

add_filter('pre_site_option_site_name', 'change_site_name', 10, 4);

function change_site_name($pre_option, $option, $network_id, $default_value) {
  return 'My New Site Name';
}

Modify admin email

Add a prefix to the admin email.

add_filter('pre_site_option_admin_email', 'add_prefix_admin_email', 10, 4);

function add_prefix_admin_email($pre_option, $option, $network_id, $default_value) {
  return 'prefix-' . $pre_option;
}

Set default theme

Set a default theme for all sites in the network.

add_filter('pre_site_option_default_theme', 'set_default_theme', 10, 4);

function set_default_theme($pre_option, $option, $network_id, $default_value) {
  return 'twentytwenty';
}

Modify site language

Change the site language to French.

add_filter('pre_site_option_WPLANG', 'change_site_language', 10, 4);

function change_site_language($pre_option, $option, $network_id, $default_value) {
  return 'fr_FR';
}

Update file upload space quota

Set a custom file upload space quota for all sites in the network.

add_filter('pre_site_option_upload_space_quota', 'custom_upload_space_quota', 10, 4);

function custom_upload_space_quota($pre_option, $option, $network_id, $default_value) {
  return 1000; // Set upload space quota to 1000MB
}