English (United Kingdom)

apply_filters( 'vikappointments_before_delete_{$type}', bool $delete, array $ids, JTable $table )

Fires before deleting a record.


Description

Trigger hook to allow the plugins to make something before deleting one or more records from 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_delete_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 order to prevent the system from deleting the records, it is possible to throw an exception to abort the cancellation 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('You are not allowed to delete this record', 403);
// or register the error
$table->setError('You are not allowed to delete this record');
return false;

Parameters

$delete

(bool)  Use false to abort the cancellation process.

$ids

(array)  An array of IDs to delete.

$table

(JTable)  The table instance that handles the cancellation process.


Example

/**
 * Trigger hook to allow the plugins to make something before deleting
 * one or more records from the database.
 *
 * @param  boolean  $delete  False to abort the cancellation process.
 * @param  array    $ids     An array of IDs to delete.
 * @param  JTable   $table   The table instance.
 */
add_filter('vikappointments_before_delete_{$type}', function($delete, $ids, $table)
{
    /**
     * @todo it is possible to apply further conditions here
     */

    return $delete;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-08-29
Helpful?
See Also: