The pre_add_site_option_{$option} WordPress PHP filter allows you to modify the value of a specific network option before it is added. The dynamic part of the hook name, $option
, refers to the option name.
Usage
add_filter('pre_add_site_option_example_option', 'your_custom_function', 10, 3); function your_custom_function($value, $option, $network_id) { // your custom code here return $value; }
Parameters
$value
(mixed): Value of the network option.$option
(string): Option name.$network_id
(int): ID of the network.
More information
See WordPress Developer Resources: pre_add_site_option_{$option}
Examples
Add a prefix to the site option value
add_filter('pre_add_site_option_site_name', 'add_prefix_to_site_name', 10, 3); function add_prefix_to_site_name($value, $option, $network_id) { $prefix = 'My Prefix - '; $value = $prefix . $value; return $value; }
Limit the maximum value for an option
add_filter('pre_add_site_option_max_posts', 'limit_max_posts', 10, 3); function limit_max_posts($value, $option, $network_id) { $max_value = 100; if ($value > $max_value) { $value = $max_value; } return $value; }
Set a default value for an option if empty
add_filter('pre_add_site_option_footer_text', 'default_footer_text', 10, 3); function default_footer_text($value, $option, $network_id) { if (empty($value)) { $value = 'Default footer text'; } return $value; }
Add the current date to an option value
add_filter('pre_add_site_option_last_updated', 'add_current_date', 10, 3); function add_current_date($value, $option, $network_id) { $current_date = date('Y-m-d H:i:s'); $value = $current_date; return $value; }
Modify a numerical option value by a factor
add_filter('pre_add_site_option_max_items', 'modify_max_items', 10, 3); function modify_max_items($value, $option, $network_id) { $factor = 2; $value = $value * $factor; return $value; }