wpfts_submit_settings_before (Filter)
The wpfts_submit_settings_before
filter in WP Fast Total Search is called before processing data submitted via the plugin’s AJAX settings form. It allows developers to intercept and process form data before it’s saved to the database.
When to Use
This filter can be useful if you need to:
- Validate form data: You can check the correctness of the entered data and display an error message if the data is invalid.
- Preprocess form data: You can modify the form data before saving it, for example, converting values to a specific format.
- Add or remove form data: You can add additional data to the form or remove unnecessary data.
- Completely override form processing: You can completely intercept form processing and perform your own actions.
Arguments
$is_form_processed
(bool): A flag indicating whether the form has already been processed. Initiallyfalse
. If you set this flag totrue
, the standard form processing will be skipped.$data
(array): An array of data submitted via the form.$jx
(object): TheWPFTS_jxResponse
object, used for sending AJAX responses.
Return Value
$is_form_processed
(bool): The modified flag indicating whether the form has been processed.
Example (Form Data Validation)
add_filter('wpfts_submit_settings_before', 'validate_my_addon_settings', 10, 3);
function validate_my_addon_settings($is_form_processed, $data, $jx) {
if (isset($data['my_addon_setting'])) {
if (!is_numeric($data['my_addon_setting'])) {
$jx->alert(__('My addon setting must be a number!', 'fulltext-search'));
return true; // Form processed (with an error), skip standard processing.
}
}
return $is_form_processed; // Form not processed, continue standard processing.
}
Important Notes
- The
wpfts_submit_settings_before
filter is called before the standard form processing. - If you set
$is_form_processed
totrue
, the standard form processing will be skipped. - You can use the
$jx
object to send error messages or other data back to JavaScript.
This filter gives developers the ability to control the processing of WP Fast Total Search settings and add their own data validation and preprocessing logic.