diff --git a/includes/class-bc-setup.php b/includes/class-bc-setup.php index 582b198f..7957e830 100644 --- a/includes/class-bc-setup.php +++ b/includes/class-bc-setup.php @@ -270,7 +270,6 @@ public static function add_brightcove_media_modal_container() { * @return array|false */ public static function preload_params() { - global $bc_accounts; $tags = new BC_Tags(); @@ -283,8 +282,7 @@ public static function preload_params() { if ( BC_Utility::current_user_can_brightcove() ) { - $cms_api = new BC_CMS_API(); - $admin_media_api = new BC_Admin_Media_API(); + $cms_api = new BC_CMS_API(); if ( false !== strpos( $uri, BC_Admin_Menu::get_playlists_page_uri_component() ) ) { $type = 'playlists'; @@ -298,7 +296,9 @@ public static function preload_params() { $params['nonce'] = wp_create_nonce( '_bc_ajax_search_nonce' ); $params['tags'] = $tags->get_tags(); $params['folders'] = array(); - if ( BC_Utility::current_user_can_brightcove() ) { + + $current_page = get_current_screen(); + if ( BC_Utility::current_user_can_brightcove() && ( 'post' === $current_page->id || false !== strpos( $current_page->id, 'brightcove_page' ) ) ) { $params['folders'] = $cms_api->fetch_folders(); $params['labels'] = $cms_api->get_account_labels(); } @@ -342,7 +342,6 @@ public static function preload_params() { $params['defaultAccountId'] = ! empty( $default_account['account_id'] ) ? $default_account['account_id'] : ''; return $params; - } /** @@ -355,19 +354,11 @@ public static function brightcove_enqueue_assets() { $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' ), @@ -378,6 +369,18 @@ public static function brightcove_enqueue_assets() { 'posts_per_page' => absint( apply_filters( 'brightcove_posts_per_page', 100 ) ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page ); + $current_page = get_current_screen(); + if ( 'post' === $current_page->id ) { + $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['experiences'] = $experiences; + $js_variable['players'] = $players; + } + 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 ); @@ -470,7 +473,6 @@ public static function mime_types( $mime_types ) { } return $mime_types; - } /**