English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Media  >  Before Delete

apply_filters( 'vikappointments_before_delete_media', bool $delete, mixed $id, mixed $path, JModel $model )

Fires before deleting a media file.


Description

Trigger hook to allow the plugins to make something before deleting one or more media files.

TIP: in case of failure while deleting the record, it is possible to throw an exception to abort the deleting process and return a readable error message. The same can be accomplished by registering an error to the model and returning false.

// throw an exception
throw new Exception('You are not authorised', 403);
// or register the error
$model->setError('You are not authorised');
return false;

Parameters

$delete

(bool)  Use false to abort the deleting process.

$id

(array|string)  Either the file name or an array of files to delete.

$path

(string|null)  An optional path from which the file should be deleted. If not specified, the default media folder will be used.

$model

(JModel)  The model instance that handles the deleting process.


Example

/**
 * Trigger hook to allow the plugins to make something before
 * deleting one or more media files.
 *
 * @param  boolean  $delete  False to abort the saving process.
 * @param  mixed    $id      Either the record ID or a list of records.
 * @param  mixed    $path    An optional path from which the file should be deleted.
 * @param  JModel   $model   The model instance.
 */
add_filter('vikappointments_before_delete_media', function($delete, $id, $path, $model)
{
    /**
     * @todo do something before deleting the media file
     */

    return $delete;
}, 10, 4);

Changelog

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