Last active
November 11, 2023 15:50
-
-
Save yuriinalivaiko/8cd1cf313bba5f8d9bfabeda8d25647e to your computer and use it in GitHub Desktop.
This code snippet extends the "File upload" field type to add video formats. An array of supported video formats: 'mp4', 'm4v', 'webm', 'ogv', 'flv'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Allow to upload video files via the "File Upload" field type. | |
* Add this code to the file functions.php in the active theme directory. | |
*/ | |
add_filter( 'um_allowed_file_types', 'um_add_video_file_types' ); | |
add_filter( 'um_profile_field_filter_hook__file', 'um_profile_field_filter_hook__file_video', 101, 2 ); | |
/** | |
* Extend "Allowed File Types" in the File Upload field. | |
* | |
* @param array $allowed_types List of supported formats. | |
* @return array | |
*/ | |
function um_add_video_file_types( $allowed_types ) { | |
$video_file_types = array(); | |
foreach( wp_get_video_extensions() as $ext ) { | |
$video_file_types[ $ext ] = strtoupper( $ext ) . ' video'; | |
} | |
return array_merge( $video_file_types, (array) $allowed_types ); | |
} | |
/** | |
* Embed video files and play them in profile view. | |
* | |
* @param string $value Field Value. | |
* @param array $data Field Data. | |
* @return string | |
*/ | |
function um_profile_field_filter_hook__file_video( $value, $data ) { | |
$filename = um_user( $data['metakey'] ); | |
$fileinfo = um_user( $data['metakey'] . '_metadata' ); | |
if ( $filename && is_array( $fileinfo ) && in_array( $fileinfo['ext'], wp_get_video_extensions(), true ) ) { | |
$file_url = trailingslashit( UM()->uploader()->get_upload_user_base_url( um_profile_id() ) ) . $filename; | |
$shortcode = '[video src="' . esc_url( $file_url ) . '"]'; | |
$value = apply_shortcodes( $shortcode ); | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is a part of the article um_allowed_file_types.
Documentation: https://docs.ultimatemember.com/
Support forum: https://wordpress.org/support/plugin/ultimate-member/
Related WordPress documentation:
Examples
Image - The File Upload field type with allowed video formats.

Image - The File Upload field type with video in profile.
