Add thread view, quote posts, and GIF picker: full conversation tree modal, quote any beep by URL/ID, Giphy-powered GIF search
This commit is contained in:
@@ -311,4 +311,85 @@ class Beep_Media {
|
||||
'</div>';
|
||||
}
|
||||
|
||||
// Video file upload support
|
||||
private static $video_types = ['video/mp4', 'video/webm', 'video/ogg', 'video/quicktime'];
|
||||
private static $max_video_size = 100 * 1024 * 1024; // 100 MB
|
||||
|
||||
public static function handle_video_upload($post_id, $file) {
|
||||
if (!is_array($file) || $file['error'] !== UPLOAD_ERR_OK) {
|
||||
return new WP_Error('upload_error', 'Upload failed.');
|
||||
}
|
||||
if ($file['size'] > self::$max_video_size) {
|
||||
return new WP_Error('file_too_large', 'Video exceeds 100 MB limit.');
|
||||
}
|
||||
$mime = mime_content_type($file['tmp_name']);
|
||||
if (!in_array($mime, self::$video_types, true)) {
|
||||
return new WP_Error('invalid_type', 'Only MP4, WebM, OGG, and MOV are allowed.');
|
||||
}
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/media.php';
|
||||
|
||||
$file_return = wp_handle_upload($file, [
|
||||
'test_form' => false,
|
||||
'mimes' => [
|
||||
'mp4' => 'video/mp4',
|
||||
'webm' => 'video/webm',
|
||||
'ogg' => 'video/ogg',
|
||||
'mov' => 'video/quicktime',
|
||||
],
|
||||
]);
|
||||
|
||||
if (isset($file_return['error'])) {
|
||||
return new WP_Error('upload_error', $file_return['error']);
|
||||
}
|
||||
|
||||
$attachment = [
|
||||
'post_mime_type' => $file_return['type'],
|
||||
'post_title' => preg_replace('/\.[^.]+$/', '', basename($file_return['file'])),
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit',
|
||||
'guid' => $file_return['url'],
|
||||
];
|
||||
|
||||
$attachment_id = wp_insert_attachment($attachment, $file_return['file'], $post_id);
|
||||
if (is_wp_error($attachment_id)) {
|
||||
return $attachment_id;
|
||||
}
|
||||
|
||||
$attach_data = wp_generate_attachment_metadata($attachment_id, $file_return['file']);
|
||||
wp_update_attachment_metadata($attachment_id, $attach_data);
|
||||
|
||||
update_post_meta($post_id, 'beep_video_url', wp_get_attachment_url($attachment_id));
|
||||
update_post_meta($post_id, 'beep_video_id', $attachment_id);
|
||||
|
||||
return [
|
||||
'id' => $attachment_id,
|
||||
'url' => wp_get_attachment_url($attachment_id),
|
||||
];
|
||||
}
|
||||
|
||||
public static function get_upload_video_url($post_id) {
|
||||
return esc_url_raw(get_post_meta($post_id, 'beep_video_url', true));
|
||||
}
|
||||
|
||||
public static function remove_video($post_id) {
|
||||
$id = (int) get_post_meta($post_id, 'beep_video_id', true);
|
||||
if ($id) {
|
||||
wp_delete_attachment($id, true);
|
||||
}
|
||||
delete_post_meta($post_id, 'beep_video_url');
|
||||
delete_post_meta($post_id, 'beep_video_id');
|
||||
}
|
||||
|
||||
public static function render_video_player($post_id) {
|
||||
$url = self::get_upload_video_url($post_id);
|
||||
if (!$url) return '';
|
||||
return '<div class="beep-video-player">' .
|
||||
'<video controls preload="metadata" playsinline>' .
|
||||
'<source src="' . esc_url($url) . '">' .
|
||||
'Your browser does not support video playback.' .
|
||||
'</video></div>';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user