From 7e3a62d1a0ac7278fb19a5fabfe9e2c06bc021a8 Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Fri, 7 Oct 2022 11:45:36 +0700 Subject: [PATCH] * The video player front-end javascript files are now only included on pages that use the player. If you run into issues with this, you can set a toggle in the settings to always include the scripts. Note that for Elementor users, the player scripts are always included because there isn't a reliable mechanism to tell if a player is being used on a page before it's too late to enqueue the scripts. You can blame Elementor for this. * The elementor video player widget was removed from the previous version on accident, it has been included again. * Fix for asset tool * Fix for `block_categories` deprecation warning (thanks @joshuafredrickson) --- .github/workflows/deploy.yml | 4 ---- .../Elementor/MediaCloudVideoWidget.php | 8 +++---- .../Video/Player/Tool/VideoPlayerTool.php | 21 ++++++++++++++----- .../Video/Player/VideoPlayerShortcode.php | 2 ++ .../Video/Player/VideoPlayerToolSettings.php | 2 ++ config/video-player.config.php | 6 ++++++ ilab-media-tools.php | 4 ++-- readme.txt | 14 +++++++++++-- 8 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 68a97467..208d4bfa 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,10 +9,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - name: Build - run: | - npm install - npm run build - name: WordPress Plugin Deploy id: deploy uses: 10up/action-wordpress-plugin-deploy@stable diff --git a/classes/Tools/Video/Player/Elementor/MediaCloudVideoWidget.php b/classes/Tools/Video/Player/Elementor/MediaCloudVideoWidget.php index 6b69d5e7..b59caf26 100644 --- a/classes/Tools/Video/Player/Elementor/MediaCloudVideoWidget.php +++ b/classes/Tools/Video/Player/Elementor/MediaCloudVideoWidget.php @@ -17,14 +17,14 @@ use Elementor\Widget_Base; use MediaCloud\Plugin\Tools\ToolsManager; use MediaCloud\Plugin\Tools\Video\Driver\Mux\Models\MuxAsset; -use MediaCloud\Plugin\Tools\Video\Driver\Mux\MuxToolProSettings; -use MediaCloud\Plugin\Tools\Video\Driver\Mux\MuxToolSettings; use MediaCloud\Plugin\Tools\Video\Player\Tool\VideoPlayerTool; use function MediaCloud\Plugin\Utilities\arrayPath; -use function MediaCloud\Plugin\Utilities\gen_uuid; -use function MediaCloud\Plugin\Utilities\vomit; class MediaCloudVideoWidget extends Widget_Base { + public function __construct($data = [], $args = null) { + parent::__construct($data, $args); + } + public function get_name() { return "mux-video"; } diff --git a/classes/Tools/Video/Player/Tool/VideoPlayerTool.php b/classes/Tools/Video/Player/Tool/VideoPlayerTool.php index b9376603..89119b68 100644 --- a/classes/Tools/Video/Player/Tool/VideoPlayerTool.php +++ b/classes/Tools/Video/Player/Tool/VideoPlayerTool.php @@ -22,7 +22,6 @@ use MediaCloud\Plugin\Tools\Video\Driver\Mux\Models\MuxAsset; use MediaCloud\Plugin\Tools\Video\Player\Elementor\MediaCloudVideoWidget; use MediaCloud\Plugin\Tools\Video\Player\VideoPlayerShortcode; -use MediaCloud\Plugin\Tools\Video\Player\VideoPlayerToolProSettings; use MediaCloud\Plugin\Tools\Video\Player\VideoPlayerToolSettings; use MediaCloud\Plugin\Utilities\UI\CSSColorParser; use function MediaCloud\Plugin\Utilities\arrayPath; @@ -37,6 +36,8 @@ class VideoPlayerTool extends Tool { /** @var null|VideoPlayerShortcode */ protected $shortCode = null; + protected static $enqueued = false; + public function __construct($toolName, $toolInfo, $toolManager) { $this->settings = VideoPlayerToolSettings::instance(); @@ -56,7 +57,11 @@ public function setup() { add_filter('render_block', [$this, 'filterBlocks'], PHP_INT_MAX - 1, 2); - static::enqueuePlayer(is_admin()); + if (is_admin() || !empty($this->settings->alwaysIncludeJS) || class_exists('Elementor\Plugin')) { + static::enqueuePlayer(is_admin()); + } else if (isset($_GET['elementor-preview'])) { + static::enqueuePlayer(false); + } if (is_admin()) { add_action('admin_enqueue_scripts', function(){ @@ -219,6 +224,12 @@ private function initShortcodeOverride() { //region Player public static function enqueuePlayer($admin = false) { + if (static::$enqueued) { + return; + } + + static::$enqueued = true; + add_action((!empty($admin)) ? 'admin_enqueue_scripts' : 'wp_enqueue_scripts', function() { wp_enqueue_script('mux_video_player_hlsjs', ILAB_PUB_JS_URL . '/mux-hls.js', null, null, true); }); @@ -229,10 +240,9 @@ public static function enqueuePlayer($admin = false) { protected function initBlocks() { add_action('init', function() { register_block_type( ILAB_BLOCKS_DIR . '/mediacloud-video-block' ); -// register_block_type( ILAB_BLOCKS_DIR . '/mediacloud-video-block/build' ); }); - add_filter('block_categories', function($categories, $post) { + add_filter('block_categories_all', function($categories, $post) { foreach($categories as $category) { if ($category['slug'] === 'mediacloud') { return $categories; @@ -313,6 +323,8 @@ protected function filterVideoBlock($block_content, $block) { $asset = MuxAsset::assetForAttachment($attachmentId); } + static::enqueuePlayer(is_admin()); + if ($asset && !empty($asset->transferData)) { if ($asset->transferData['source'] === 's3') { /** @var StorageTool $storageTool */ @@ -369,7 +381,6 @@ protected function filterVideoBlock($block_content, $block) { $classes .= " {$this->settings->playerCSSClasses}"; } -// $styles = !empty($styles) ? "style='${styles}'" : ""; $block_content = str_replace('