diff options
Diffstat (limited to 'plugins/jetpack/modules/videopress/class.videopress-gutenberg.php')
-rw-r--r-- | plugins/jetpack/modules/videopress/class.videopress-gutenberg.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php b/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php index be0bd1db..55421ee9 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php +++ b/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php @@ -5,6 +5,8 @@ * @package Jetpack */ +use Automattic\Jetpack\Assets; + /** * Register a VideoPress extension to replace the default Core Video block. */ @@ -31,6 +33,7 @@ class VideoPress_Gutenberg { private function __construct() { add_action( 'init', array( $this, 'register_video_block_with_videopress' ) ); add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'set_extension_availability' ) ); + add_action( 'enqueue_block_editor_assets', array( $this, 'override_video_upload' ) ); } /** @@ -164,6 +167,30 @@ class VideoPress_Gutenberg { 1 ); } + + /** + * Replaces the video uploaded in the block editor. + * + * Enqueues a script that registers an API fetch middleware replacing the video uploads in Gutenberg so they are + * uploaded against the WP.com API media endpoint and thus transcoded by VideoPress. + */ + public function override_video_upload() { + // Bail if Jetpack or VideoPress is not active. + if ( ! Jetpack::is_active() || ! Jetpack::is_module_active( 'videopress' ) ) { + return; + } + + wp_enqueue_script( + 'jetpack-videopress-gutenberg-override-video-upload', + Assets::get_file_url_for_environment( + '_inc/build/videopress/js/gutenberg-video-upload.min.js', + 'modules/videopress/js/gutenberg-video-upload.js' + ), + array( 'wp-api-fetch', 'wp-polyfill', 'lodash' ), + JETPACK__VERSION, + false + ); + } } VideoPress_Gutenberg::init(); |