Skip to content

Commit

Permalink
* The video player front-end javascript files are now only included o…
Browse files Browse the repository at this point in the history
…n 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)
  • Loading branch information
jawngee committed Oct 7, 2022
1 parent f262efc commit 7e3a62d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 17 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
21 changes: 16 additions & 5 deletions classes/Tools/Video/Player/Tool/VideoPlayerTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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(){
Expand Down Expand Up @@ -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);
});
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -369,7 +381,6 @@ protected function filterVideoBlock($block_content, $block) {
$classes .= " {$this->settings->playerCSSClasses}";
}

// $styles = !empty($styles) ? "style='${styles}'" : "";
$block_content = str_replace('<video ', "<video class='{$classes}' {$extras}", $block_content);

$source = "<source src='{$playlistUrl}' type='{$playlistMime}' />";
Expand Down
2 changes: 2 additions & 0 deletions classes/Tools/Video/Player/VideoPlayerShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace MediaCloud\Plugin\Tools\Video\Player;

use MediaCloud\Plugin\Tools\Video\Driver\Mux\Models\MuxAsset ;
use MediaCloud\Plugin\Tools\Video\Player\Tool\VideoPlayerTool ;
use MediaCloud\Plugin\Utilities\View ;
use function MediaCloud\Plugin\Utilities\arrayPath ;
use function MediaCloud\Plugin\Utilities\postIdExists ;
Expand Down Expand Up @@ -85,6 +86,7 @@ public function renderShortCode( $attrs )
$classes = "mux-player";
$extras = "";
$asset = MuxAsset::assetForAttachment( $attachmentId );
VideoPlayerTool::enqueuePlayer( is_admin() );
if ( !empty($this->settings->playerCSSClasses) ) {
$classes .= " {$this->settings->playerCSSClasses}";
}
Expand Down
2 changes: 2 additions & 0 deletions classes/Tools/Video/Player/VideoPlayerToolSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
* @package MediaCloud\Mux
*
* @property bool playerCSSClasses
* @property bool alwaysIncludeJS
*/
class VideoPlayerToolSettings extends ToolSettings {
/**
* Map of property names to setting names
* @var string[]
*/
protected $settingsMap = [
'alwaysIncludeJS' => ['media-cloud-mux-player-include-js', null, false],
'playerCSSClasses' => ['media-cloud-player-css-classes', null, false],
];
}
6 changes: 6 additions & 0 deletions config/video-player.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"options-page" => "media-cloud-player",
"options-group" => "media-cloud-player",
"groups" => [
"media-cloud-mux-player-include-js" => [
"title" => "Always Include Video Player JavaScript",
"description" => "When enabled, the javascript file for the video.js or HLS player will be included on every page. You may need to do this if you dynamically display videos.",
"type" => "checkbox",
"default" => false
],
"media-cloud-mux-player" => [
"title" => "Player Settings",
"doc_link" => 'https://support.mediacloud.press/articles/documentation/video-encoding/mux-player-settings',
Expand Down
4 changes: 2 additions & 2 deletions ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/interfacelab/ilab-media-tools
Description: Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site performance and simplifies workflows.
Author: interfacelab
Version: 4.4.3
Version: 4.4.4
Requires PHP: 7.4
Author URI: http://interfacelab.io
*/
Expand Down Expand Up @@ -95,7 +95,7 @@
}

// Version Defines
define( 'MEDIA_CLOUD_VERSION', '4.4.3' );
define( 'MEDIA_CLOUD_VERSION', '4.4.4' );
define( 'MEDIA_CLOUD_INFO_VERSION', '4.0.2' );
define( 'MCLOUD_IS_BETA', false );
// Debugging
Expand Down
14 changes: 12 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 4.9
Tested up to: 6.0.2
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Stable tag: 4.4.3
Stable tag: 4.4.4
Requires PHP: 7.4

Automatically store media on Amazon S3, Google Cloud Storage, DigitalOcean Spaces + others. Serve CSS/JS assets through CDNs. Integrate with Imgix.
Expand Down Expand Up @@ -105,7 +105,17 @@ Imgix is a content delivery network with a twist. In addition to distributing y

== Changelog ==

= 4.4.3 - 10/2/2022 =
= 4.4.4 - 10/7/2022 =

* 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)

= 4.4.3 - 10/5/2022 =

* Ability to specify colors for video.js player in the Video Player settings.

Expand Down

0 comments on commit 7e3a62d

Please sign in to comment.