wpfts_get_option (Filter)

The wpfts_get_option filter in WP Fast Total Search allows developers to modify plugin option values before they are used. This enables dynamic configuration of plugin behavior without directly altering settings in the database or through the administrative interface.

When to Use

This filter can be useful in the following scenarios:

  • Dynamic setting changes depending on context: For example, you can change the search results page URL based on the current page or post type.
  • Temporary setting changes for testing: You can use this filter to temporarily change settings without altering them in the database.
  • Adding settings from other plugins: If your plugin integrates with WPFTS, you can use this filter to add your own settings.

Arguments

  • $v (mixed): The current value of the option. The value type depends on the option type.
  • $optname (string): The name of the option.
  • $is_force_reread (bool): A flag indicating whether to force rereading the option value from the database.

Return Value

  • $v (mixed): The modified value of the option.

Example (Changing the Results Page URL)

add_filter('wpfts_get_option', 'change_search_results_url', 10, 3);
function change_search_results_url($v, $optname, $is_force_reread) {
	if ($optname === 'results_url' && is_singular('product')) {
		// If on a product page, change the URL to the product archive page
		return get_post_type_archive_link('product');
	}
	return $v;
}

Important Notes

  • The wpfts_get_option filter is called every time the plugin retrieves an option value using the WPFTS_Core::get_option() method.
  • Be cautious when modifying option values, as this may affect plugin functionality.
  • If you modify the option value, ensure the returned value has the correct data type.
  • The $is_force_reread parameter is usually not used in addon code.

The wpfts_get_option filter is a powerful tool for dynamically configuring WP Fast Total Search, allowing you to adapt the plugin to various requirements without modifying the plugin’s code itself.