Skip to content

Commit

Permalink
Send API requests only on the required pages
Browse files Browse the repository at this point in the history
  • Loading branch information
burhandodhy committed Mar 6, 2024
1 parent e4cf3cf commit a4e651e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions includes/class-bc-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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';
Expand All @@ -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();
}
Expand Down Expand Up @@ -342,7 +342,6 @@ public static function preload_params() {
$params['defaultAccountId'] = ! empty( $default_account['account_id'] ) ? $default_account['account_id'] : '';

return $params;

}

/**
Expand All @@ -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' ),
Expand All @@ -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 );
Expand Down Expand Up @@ -470,7 +473,6 @@ public static function mime_types( $mime_types ) {
}

return $mime_types;

}

/**
Expand Down

0 comments on commit a4e651e

Please sign in to comment.