English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Media  >  Detect Type

apply_filters( 'vikappointments_detect_media_type', string $type, string $fileJModel $model )

Fires while detecting the media type of a file.


Description

Trigger hook to allow external plugins to register their own media types or to extend the existing ones.

Take a look at the vikappointments_check_file_allowed hook for a complete list with all the supported media types (also mentioned as categories).

This hook is useful when supporting new file types/categories without injecting them within the $model->allowedFiles property.

Let's take the following example.

add_filter('vikappointments_check_file_allowed', function($allow, $file, $model)
{
    if (preg_match("/\.(php|css|html|js)$/i", $file))
    {
        return true;
    }
}, 10, 3);

Here the system is going to support the upload of 4 new file types (PHP, HTML, CSS and JS) without registering them within the list of supported files. At this point, we could use this hook to categorize them under the coding group.

add_filter('vikappointments_detect_media_type', function($type, $file, $model)
{
    if (preg_match("/\.(php|css|html|js)$/i", $file))
    {
        $type = 'coding';
    }

    return $type;
}, 10, 3);

In case the media type is extracted from the array, this hook won't be triggered.

When it is not possible to detect a media type, the default "binary" one will be used.


Parameters

$type

(string)  The assigned media type.

$file

(string)  The file path/name to check.

$model

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


Example

/**
 * Trigger hook to allow external plugins to register their own media types
 * or to extend the existing ones.
 *
 * @param  string  $type   The detected file type.
 * @param  string  $file   The file name/path to check.
 * @param  JModel  $model  The model instance.
 */
add_filter('vikappointments_detect_media_type', function($type, $file, $model)
{
    if (preg_match("/\.web$/i", $file))
    {
        $type = 'image';
    }
    else if (preg_match("/\.avi$/i", $file))
    {
        $type = 'video';
    }

    return $type;
}, 10, 3);

Changelog

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