Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  System  >  Management  >  Before Delete

apply_filters( 'vikrestaurants_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 room table will trigger an hook called vikrestaurants_before_delete_room. 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/vikrestaurants/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  bool    $delete  False to abort the cancellation process.
 * @param  array   $ids     An array of IDs to delete.
 * @param  JTable  $table   The table instance.
 */
add_filter('vikrestaurants_before_delete_{$type}', function($delete, $ids, $table) {
    /**
     * @todo it is possible to apply further conditions here
     */

    return $delete;
}, 10, 3);

Changelog

Version Description
1.3 Introduced.
Ultimo aggiornamento: 2024-01-04
Utile?
Potrebbe interessarti: