wpfts_default_options (Filter)
The wpfts_default_options
filter in WP Fast Total Search allows developers to modify the plugin’s default option values. It’s called once during plugin initialization and allows setting initial values for all options.
When to Use
This filter is useful if you need to change the plugin’s default behavior or set values for options that don’t have default values. For example, you can:
- Change the default weight for a specific cluster.
- Set the default search results page URL.
- Add your own custom options to the plugin.
Arguments
$default_options
(array): An associative array of the plugin’s default options. The array keys are the option names, and the values are the default values.
Return Value
$default_options
(array): The modified array of the plugin’s default options.
Example (Changing the weight of the post_title
cluster)
add_filter('wpfts_default_options', 'my_wpfts_default_options_filter');
function my_wpfts_default_options_filter($default_options) {
$default_options['cluster_weights'] = serialize(array(
'post_title' => 1, // Sets the maximum weight for the title by default.
'post_content' => 0.5
));
return $default_options;
}
Example (Adding a new option)
add_filter('wpfts_default_options', 'add_my_custom_option');
function add_my_custom_option($default_options)
{
$default_options['my_custom_option'] = 'my_default_value'; // Adds a new option.
return $default_options;
}
Important Notes
- The
wpfts_default_options
filter is called only once during plugin initialization. Subsequent calls toWPFTS_Core::get_option()
will use values from the database if they exist. - If you add new options, you will also need to handle their saving to the database.
- Be cautious when modifying default option values, as this can affect the plugin’s functionality.
- For serialized options, the
serialize()
function must be used. This should be explicitly stated in the documentation.
The wpfts_default_options
filter allows developers to customize the initial values of WP Fast Total Search options, providing greater flexibility when integrating the plugin with other plugins and themes.