Before Save
apply_filters_ref_array( 'vikappointments_before_save_{$type}', bool $save, mixed &$data, JTable $table )
Fires before saving a record.
Description
This hook is triggered before creating or updating a service record. It can be used to bind the data that are going to be saved within the database.
The dynamic portion of the hook name, $type
, refers to the name of the table calling the hook. This means that, for example, the service table will trigger an hook called vikappointments_before_save_service
. The name of the table is always equals to the base name of the file that declares the $table
instance.
It is possible to read a list of supported types by looking at the files stored within the following directory:
/wp-content/plugins/vikappointments/admin/tables/
TIP: in case of failure while saving the record, it is possible to throw an exception to abort the saving process and return a readable error message. The same can be accomplished by registering an error to the table and returning false
.
// throw an exception
throw new Exception('Missing required field', 404);
// or register the error
$table->setError('Missing required field');
return false;
Parameters
- $save
-
(bool) Use false to abort the saving process.
- &$data
-
(array|object) Either an array or an object specifying the record properties to bind.
- $table
-
(JTable) The table instance that handles the saving process.
Example
/**
* Trigger hook to allow the plugins to bind the object that
* is going to be saved.
*
* @param boolean $save False to abort the saving process.
* @param mixed &$data The array/object to bind.
* @param JTable $table The table instance.
*/
add_filter('vikappointments_before_save_{$type}', function($save, &$data, $table)
{
/**
* @todo it is possible to bind here the $data object
*/
return $save;
}, 10, 3);
Changelog
Version | Description |
---|---|
1.2 | Introduced. |