From 715597f92d2ad62c16f942e48f94ebc78d15585e Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Fri, 16 Jun 2023 16:05:07 -0500 Subject: [PATCH 1/5] Bugfix: do not instantiate BC_Accounts if no accounts were set --- includes/class-bc-setup.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-bc-setup.php b/includes/class-bc-setup.php index 32ac7a98..3f778c00 100644 --- a/includes/class-bc-setup.php +++ b/includes/class-bc-setup.php @@ -48,7 +48,7 @@ public static function action_init() { // Preload Errors Class First. new BC_Errors(); - $bc_accounts = new BC_Accounts(); + $bc_accounts = ! get_option( '_brightcove_accounts' ) ? new BC_Accounts() : false; // Load Administrative Resources. if ( BC_Utility::current_user_can_brightcove() ) { @@ -334,8 +334,8 @@ public static function preload_params() { $params['mimeTypes'] = BC_Utility::get_all_brightcove_mimetypes(); $default_account = $bc_accounts->get_account_details_for_user(); - $params['defaultAccount'] = $default_account['hash']; - $params['defaultAccountId'] = $default_account['account_id']; + $params['defaultAccount'] = ! empty ( $default_account['hash'] ) ? $default_account['hash'] : ''; + $params['defaultAccountId'] = ! empty ( $default_account['account_id'] ) ? $default_account['account_id'] : ''; return $params; From 9e93695c987e77df6d6b0a00b40721bc5a93fff3 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Fri, 16 Jun 2023 16:10:12 -0500 Subject: [PATCH 2/5] PHPCS Lint --- brightcove-video-connect.php | 1 - includes/class-bc-setup.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/brightcove-video-connect.php b/brightcove-video-connect.php index bd8bd7ea..9f377afe 100644 --- a/brightcove-video-connect.php +++ b/brightcove-video-connect.php @@ -52,7 +52,6 @@ function brightcove_activate() { * Uninstall routines should be in uninstall.php */ function brightcove_deactivate() { - BC_Utility::deactivate(); } diff --git a/includes/class-bc-setup.php b/includes/class-bc-setup.php index 3f778c00..d3faaf7e 100644 --- a/includes/class-bc-setup.php +++ b/includes/class-bc-setup.php @@ -334,8 +334,8 @@ public static function preload_params() { $params['mimeTypes'] = BC_Utility::get_all_brightcove_mimetypes(); $default_account = $bc_accounts->get_account_details_for_user(); - $params['defaultAccount'] = ! empty ( $default_account['hash'] ) ? $default_account['hash'] : ''; - $params['defaultAccountId'] = ! empty ( $default_account['account_id'] ) ? $default_account['account_id'] : ''; + $params['defaultAccount'] = ! empty( $default_account['hash'] ) ? $default_account['hash'] : ''; + $params['defaultAccountId'] = ! empty( $default_account['account_id'] ) ? $default_account['account_id'] : ''; return $params; From e5d96ee8d5931cb5a299570cc1d2c3d67c8d9228 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 20 Jun 2023 13:54:40 -0500 Subject: [PATCH 3/5] Do not load Brightcove configured dependent code if no brightcove account has been set --- includes/class-bc-setup.php | 181 ++++++++++++++++++---------------- includes/class-bc-utility.php | 9 ++ 2 files changed, 105 insertions(+), 85 deletions(-) diff --git a/includes/class-bc-setup.php b/includes/class-bc-setup.php index d3faaf7e..b1c77ca8 100644 --- a/includes/class-bc-setup.php +++ b/includes/class-bc-setup.php @@ -48,29 +48,32 @@ public static function action_init() { // Preload Errors Class First. new BC_Errors(); - $bc_accounts = ! get_option( '_brightcove_accounts' ) ? new BC_Accounts() : false; + $bc_accounts = new BC_Accounts(); // Load Administrative Resources. if ( BC_Utility::current_user_can_brightcove() ) { - - require_once BRIGHTCOVE_PATH . 'includes/admin/api/class-bc-admin-media-api.php'; require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-settings-page.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-labels-page.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-playlists-page.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-videos-page.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-sources.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-user-profile.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-templates.php'; - - // Load Brightcove API resources. - new BC_Admin_Media_API(); + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-sources.php'; new BC_Admin_Settings_Page(); - new BC_Admin_Labels_Page(); - new BC_Admin_Playlists_Page(); - new BC_Admin_Videos_Page(); - new BC_Admin_Sources(); - new BC_Admin_Templates(); - new BC_Admin_User_Profile(); + new BC_Admin_Sources(); + + if ( get_option( '_brightcove_accounts' ) ) { + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-labels-page.php'; + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-playlists-page.php'; + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-videos-page.php'; + + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-user-profile.php'; + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-templates.php'; + require_once BRIGHTCOVE_PATH . 'includes/admin/api/class-bc-admin-media-api.php'; + add_action( 'admin_enqueue_scripts', array( 'BC_Setup', 'brightcove_enqueue_assets' ) ); + // Load Brightcove API resources. + new BC_Admin_Media_API(); + new BC_Admin_Labels_Page(); + new BC_Admin_Playlists_Page(); + new BC_Admin_Videos_Page(); + new BC_Admin_Templates(); + new BC_Admin_User_Profile(); + } } new BC_Playlists(); @@ -341,77 +344,85 @@ public static function preload_params() { } + /** + * + * + * @return void + */ + public static function brightcove_enqueue_assets() { + global $wp_version; + + $suffix = BC_Utility::get_suffix(); + + $player_api = new BC_Player_Management_API2(); + $players = $player_api->get_all_players(); + + $experiences_api = new BC_Experiences_API(); + $experiences = $experiences_api->get_experiences(); + + $js_variable = array( + 'path' => esc_url( BRIGHTCOVE_URL . 'assets/js/src/' ), + 'preload' => self::preload_params(), + 'wp_version' => $wp_version, + 'languages' => BC_Utility::languages(), + 'players' => $players, + 'experiences' => $experiences, + 'str_badformat' => esc_html__( 'This file is not the proper format. Please use .vtt files, for more information visit', 'brightcove' ), + 'badformat_link' => esc_url( 'https://support.brightcove.com/en/video-cloud/docs/adding-captions-videos#captionsfile' ), + 'str_addcaption' => esc_html__( 'Add Another Caption', 'brightcove' ), + 'str_addremote' => esc_html__( 'Add another remote file', 'brightcove' ), + 'str_selectfile' => esc_html__( 'Select File', 'brightcove' ), + 'str_useremote' => esc_html__( 'Use a remote file instead', 'brightcove' ), + 'str_apifailure' => esc_html__( "Sorry! We weren't able to reach the Brightcove API even after trying a few times. Please try refreshing the page.", 'brightcove' ), + 'posts_per_page' => absint( apply_filters( 'brightcove_posts_per_page', 100 ) ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page + ); + + wp_register_script( 'brightcove', '//sadmin.brightcove.com/js/BrightcoveExperiences.js', array(), BRIGHTCOVE_VERSION, false ); + + wp_enqueue_script( 'tinymce_preview', esc_url( BRIGHTCOVE_URL . 'assets/js/src/tinymce.js' ), array( 'mce-view' ), BRIGHTCOVE_VERSION, true ); + wp_localize_script( + 'tinymce_preview', + 'bctiny', + array( + 'wp_version' => $wp_version, + ) + ); + + $dependencies = array( + 'jquery-ui-autocomplete', + 'jquery', + 'backbone', + 'wp-backbone', + 'media', + 'media-editor', + 'media-grid', + 'media-models', + 'media-upload', + 'media-views', + 'plupload-all', + 'brightcove', + 'wp-mediaelement', + 'tinymce_preview', + 'jquery-ui-datepicker', + ); + + wp_register_script( 'brightcove-admin', esc_url( BRIGHTCOVE_URL . 'assets/js/brightcove-admin' . $suffix . '.js' ), $dependencies, BRIGHTCOVE_VERSION, true ); + wp_localize_script( 'brightcove-admin', 'wpbc', $js_variable ); + wp_enqueue_script( 'brightcove-admin' ); + + if ( isset( $GLOBALS['post_ID'] ) ) { + wp_enqueue_media( array( 'post' => $GLOBALS['post_ID'] ) ); + } else { + wp_enqueue_media(); + } + } + /** * Enqueue the admin scripts and styles. */ public static function admin_enqueue_scripts() { - - global $wp_version; - // Use minified libraries if SCRIPT_DEBUG is turned off. - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; - - $player_api = new BC_Player_Management_API2(); - $players = $player_api->get_all_players(); - - $experiences_api = new BC_Experiences_API(); - $experiences = $experiences_api->get_experiences(); - - $js_variable = array( - 'path' => esc_url( BRIGHTCOVE_URL . 'assets/js/src/' ), - 'preload' => self::preload_params(), - 'wp_version' => $wp_version, - 'languages' => BC_Utility::languages(), - 'players' => $players, - 'experiences' => $experiences, - 'str_badformat' => esc_html__( 'This file is not the proper format. Please use .vtt files, for more information visit', 'brightcove' ), - 'badformat_link' => esc_url( 'https://support.brightcove.com/en/video-cloud/docs/adding-captions-videos#captionsfile' ), - 'str_addcaption' => esc_html__( 'Add Another Caption', 'brightcove' ), - 'str_addremote' => esc_html__( 'Add another remote file', 'brightcove' ), - 'str_selectfile' => esc_html__( 'Select File', 'brightcove' ), - 'str_useremote' => esc_html__( 'Use a remote file instead', 'brightcove' ), - 'str_apifailure' => esc_html__( "Sorry! We weren't able to reach the Brightcove API even after trying a few times. Please try refreshing the page.", 'brightcove' ), - 'posts_per_page' => absint( apply_filters( 'brightcove_posts_per_page', 100 ) ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page - ); - - wp_register_script( 'brightcove', '//sadmin.brightcove.com/js/BrightcoveExperiences.js', array(), BRIGHTCOVE_VERSION, false ); - - wp_enqueue_script( 'tinymce_preview', esc_url( BRIGHTCOVE_URL . 'assets/js/src/tinymce.js' ), array( 'mce-view' ), BRIGHTCOVE_VERSION, true ); - wp_localize_script( - 'tinymce_preview', - 'bctiny', - array( - 'wp_version' => $wp_version, - ) - ); - - $dependencies = array( - 'jquery-ui-autocomplete', - 'jquery', - 'backbone', - 'wp-backbone', - 'media', - 'media-editor', - 'media-grid', - 'media-models', - 'media-upload', - 'media-views', - 'plupload-all', - 'brightcove', - 'wp-mediaelement', - 'tinymce_preview', - 'jquery-ui-datepicker', - ); - - wp_register_script( 'brightcove-admin', esc_url( BRIGHTCOVE_URL . 'assets/js/brightcove-admin' . $suffix . '.js' ), $dependencies, BRIGHTCOVE_VERSION, true ); - wp_localize_script( 'brightcove-admin', 'wpbc', $js_variable ); - wp_enqueue_script( 'brightcove-admin' ); - - if ( isset( $GLOBALS['post_ID'] ) ) { - wp_enqueue_media( array( 'post' => $GLOBALS['post_ID'] ) ); - } else { - wp_enqueue_media(); - } + $suffix = BC_Utility::get_suffix(); wp_register_style( 'brightcove-video-connect', esc_url( BRIGHTCOVE_URL . 'assets/css/brightcove_video_connect' . $suffix . '.css' ), array(), BRIGHTCOVE_VERSION ); wp_enqueue_style( 'brightcove-video-connect' ); @@ -424,7 +435,7 @@ public static function admin_enqueue_scripts() { */ public static function frontend_enqueue_scripts() { // Use minified libraries if SCRIPT_DEBUG is turned off. - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; + $suffix = BC_Utility::get_suffix(); wp_enqueue_style( 'brightcove-pip-css', 'https://players.brightcove.net/videojs-pip/1/videojs-pip.css', [], BRIGHTCOVE_VERSION ); wp_register_style( 'brightcove-playlist', BRIGHTCOVE_URL . 'assets/css/brightcove_playlist' . $suffix . '.css', array(), BRIGHTCOVE_VERSION ); diff --git a/includes/class-bc-utility.php b/includes/class-bc-utility.php index 5006a953..c195b8f4 100644 --- a/includes/class-bc-utility.php +++ b/includes/class-bc-utility.php @@ -1525,4 +1525,13 @@ public static function compare_player_update_date( $player1, $player2 ) { public static function build_brightcove_src( $account_id, $extra_params = '' ) { return 'https://players.brightcove.net/' . trailingslashit( $account_id ) . $extra_params; } + + /** + * Utility function to get suffix for assets. For development purposes. + * + * @return string + */ + public static function get_suffix() { + return ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; + } } From fc0314f97b0f0893d4de909ffc8a44d421565c0c Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 20 Jun 2023 14:01:59 -0500 Subject: [PATCH 4/5] PHPCS lint --- includes/class-bc-setup.php | 148 ++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/includes/class-bc-setup.php b/includes/class-bc-setup.php index b1c77ca8..a76030dc 100644 --- a/includes/class-bc-setup.php +++ b/includes/class-bc-setup.php @@ -53,9 +53,9 @@ public static function action_init() { // Load Administrative Resources. if ( BC_Utility::current_user_can_brightcove() ) { require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-settings-page.php'; - require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-sources.php'; + require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-sources.php'; new BC_Admin_Settings_Page(); - new BC_Admin_Sources(); + new BC_Admin_Sources(); if ( get_option( '_brightcove_accounts' ) ) { require_once BRIGHTCOVE_PATH . 'includes/admin/class-bc-admin-labels-page.php'; @@ -344,78 +344,78 @@ public static function preload_params() { } - /** - * - * - * @return void - */ - public static function brightcove_enqueue_assets() { - global $wp_version; - - $suffix = BC_Utility::get_suffix(); - - $player_api = new BC_Player_Management_API2(); - $players = $player_api->get_all_players(); - - $experiences_api = new BC_Experiences_API(); - $experiences = $experiences_api->get_experiences(); - - $js_variable = array( - 'path' => esc_url( BRIGHTCOVE_URL . 'assets/js/src/' ), - 'preload' => self::preload_params(), - 'wp_version' => $wp_version, - 'languages' => BC_Utility::languages(), - 'players' => $players, - 'experiences' => $experiences, - 'str_badformat' => esc_html__( 'This file is not the proper format. Please use .vtt files, for more information visit', 'brightcove' ), - 'badformat_link' => esc_url( 'https://support.brightcove.com/en/video-cloud/docs/adding-captions-videos#captionsfile' ), - 'str_addcaption' => esc_html__( 'Add Another Caption', 'brightcove' ), - 'str_addremote' => esc_html__( 'Add another remote file', 'brightcove' ), - 'str_selectfile' => esc_html__( 'Select File', 'brightcove' ), - 'str_useremote' => esc_html__( 'Use a remote file instead', 'brightcove' ), - 'str_apifailure' => esc_html__( "Sorry! We weren't able to reach the Brightcove API even after trying a few times. Please try refreshing the page.", 'brightcove' ), - 'posts_per_page' => absint( apply_filters( 'brightcove_posts_per_page', 100 ) ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page - ); - - wp_register_script( 'brightcove', '//sadmin.brightcove.com/js/BrightcoveExperiences.js', array(), BRIGHTCOVE_VERSION, false ); - - wp_enqueue_script( 'tinymce_preview', esc_url( BRIGHTCOVE_URL . 'assets/js/src/tinymce.js' ), array( 'mce-view' ), BRIGHTCOVE_VERSION, true ); - wp_localize_script( - 'tinymce_preview', - 'bctiny', - array( - 'wp_version' => $wp_version, - ) - ); - - $dependencies = array( - 'jquery-ui-autocomplete', - 'jquery', - 'backbone', - 'wp-backbone', - 'media', - 'media-editor', - 'media-grid', - 'media-models', - 'media-upload', - 'media-views', - 'plupload-all', - 'brightcove', - 'wp-mediaelement', - 'tinymce_preview', - 'jquery-ui-datepicker', - ); - - wp_register_script( 'brightcove-admin', esc_url( BRIGHTCOVE_URL . 'assets/js/brightcove-admin' . $suffix . '.js' ), $dependencies, BRIGHTCOVE_VERSION, true ); - wp_localize_script( 'brightcove-admin', 'wpbc', $js_variable ); - wp_enqueue_script( 'brightcove-admin' ); - - if ( isset( $GLOBALS['post_ID'] ) ) { - wp_enqueue_media( array( 'post' => $GLOBALS['post_ID'] ) ); - } else { - wp_enqueue_media(); - } - } + /** + * + * + * @return void + */ + public static function brightcove_enqueue_assets() { + global $wp_version; + + $suffix = BC_Utility::get_suffix(); + + $player_api = new BC_Player_Management_API2(); + $players = $player_api->get_all_players(); + + $experiences_api = new BC_Experiences_API(); + $experiences = $experiences_api->get_experiences(); + + $js_variable = array( + 'path' => esc_url( BRIGHTCOVE_URL . 'assets/js/src/' ), + 'preload' => self::preload_params(), + 'wp_version' => $wp_version, + 'languages' => BC_Utility::languages(), + 'players' => $players, + 'experiences' => $experiences, + 'str_badformat' => esc_html__( 'This file is not the proper format. Please use .vtt files, for more information visit', 'brightcove' ), + 'badformat_link' => esc_url( 'https://support.brightcove.com/en/video-cloud/docs/adding-captions-videos#captionsfile' ), + 'str_addcaption' => esc_html__( 'Add Another Caption', 'brightcove' ), + 'str_addremote' => esc_html__( 'Add another remote file', 'brightcove' ), + 'str_selectfile' => esc_html__( 'Select File', 'brightcove' ), + 'str_useremote' => esc_html__( 'Use a remote file instead', 'brightcove' ), + 'str_apifailure' => esc_html__( "Sorry! We weren't able to reach the Brightcove API even after trying a few times. Please try refreshing the page.", 'brightcove' ), + 'posts_per_page' => absint( apply_filters( 'brightcove_posts_per_page', 100 ) ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page + ); + + wp_register_script( 'brightcove', '//sadmin.brightcove.com/js/BrightcoveExperiences.js', array(), BRIGHTCOVE_VERSION, false ); + + wp_enqueue_script( 'tinymce_preview', esc_url( BRIGHTCOVE_URL . 'assets/js/src/tinymce.js' ), array( 'mce-view' ), BRIGHTCOVE_VERSION, true ); + wp_localize_script( + 'tinymce_preview', + 'bctiny', + array( + 'wp_version' => $wp_version, + ) + ); + + $dependencies = array( + 'jquery-ui-autocomplete', + 'jquery', + 'backbone', + 'wp-backbone', + 'media', + 'media-editor', + 'media-grid', + 'media-models', + 'media-upload', + 'media-views', + 'plupload-all', + 'brightcove', + 'wp-mediaelement', + 'tinymce_preview', + 'jquery-ui-datepicker', + ); + + wp_register_script( 'brightcove-admin', esc_url( BRIGHTCOVE_URL . 'assets/js/brightcove-admin' . $suffix . '.js' ), $dependencies, BRIGHTCOVE_VERSION, true ); + wp_localize_script( 'brightcove-admin', 'wpbc', $js_variable ); + wp_enqueue_script( 'brightcove-admin' ); + + if ( isset( $GLOBALS['post_ID'] ) ) { + wp_enqueue_media( array( 'post' => $GLOBALS['post_ID'] ) ); + } else { + wp_enqueue_media(); + } + } /** * Enqueue the admin scripts and styles. From 0d7a3242c52292ad5e530d42bd281715d8dcb2eb Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 20 Jun 2023 15:18:02 -0500 Subject: [PATCH 5/5] Add documentation --- includes/class-bc-setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-bc-setup.php b/includes/class-bc-setup.php index a76030dc..bc4a9cbb 100644 --- a/includes/class-bc-setup.php +++ b/includes/class-bc-setup.php @@ -345,7 +345,7 @@ public static function preload_params() { } /** - * + * Enqueue brightcove functionality dependent assets. * * @return void */