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

apply_filters_ref_array( 'vikappointments_before_rename_media', bool $rename, string &$new, string $prev, JModel $model )

Fires before renaming a media file.


Description

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

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 model and returning false.

// throw an exception
throw new Exception('Invalid name', 500);
// or register the error
$model->setError('Invalid name');
return false;

Parameters

$rename

(bool)  Use false to abort the renaming process.

&$new

(string)  The new file name.

$prev

(string)  The current file name.

$model

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


Example

/**
 * Trigger event to allow the plugins to make something before
 * renaming one or more media files.
 *
 * @param  boolean  $rename  False to abort the saving process.
 * @param  string   &$new    The new file name.
 * @param  string   $prev    The current file name.
 * @param  JModel   $model   The model instance.
 */
add_filter('vikappointments_before_rename_media', function($rename, &$new, $prev, $model)
{
    /**
     * @todo do something before renaming the media file
     */

    return $rename;
}, 10, 4);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-08-08
Helpful?
See Also:
This site uses cookies. By continuing to browse you accept their use. Further information