/**
  * Delete video or playlist
  *
  * Process call to delete video or playlist which is sent to the Brightcove API
  *
  * @since 1.0
  *
  * @return void
  */
 public function bc_ajax_delete_video_or_playlist()
 {
     global $bc_accounts;
     // Call this to check if we are allowed to continue.
     $this->bc_helper_check_ajax();
     $type = sanitize_key($_POST['type']);
     $type_msg = '';
     $id = BC_Utility::sanitize_id($_POST['id']);
     // Get type brightcove-playlist or brightcove-video.
     if (!in_array($type, array('playlists', 'videos'))) {
         wp_send_json_error(esc_html__('Type is not specified!', 'brightcove'));
     }
     // Try to get the existing post based on id.
     if ('playlists' === $type) {
         // Get playlist.
         $type_msg = 'playlist';
     } elseif ('videos' === $type) {
         // Find existing video.
         $type_msg = 'video';
     } else {
         wp_send_json_error(esc_html__('Wrong type is specified!', 'brightcove'));
     }
     $hash = sanitize_text_field($_POST['account']);
     if (false === $bc_accounts->get_account_by_hash($hash)) {
         wp_send_json_error(__('No such account exists', 'brightcove'));
     }
     $bc_accounts->set_current_account($hash);
     // Remove from Brightcove.
     $delete_status = false;
     $delete_message = '';
     if ('videos' === $type) {
         $delete_status = $this->cms_api->video_delete($id);
         if (!$delete_status) {
             // We were not able to delete video from Brightcove.
             $delete_message = esc_html__('Unable to remove video from Brightcove!', 'brightcove');
         } else {
             $delete_message = esc_html__('Successfully deleted your video.', 'brightcove');
         }
     } elseif ('playlists' === $type) {
         $delete_status = $this->cms_api->playlist_delete($id);
         if (!$delete_status) {
             // We were not able to delete playlist from Brightcove.
             $delete_message = esc_html__('Unable to remove playlist from Brightcove!', 'brightcove');
         } else {
             $delete_message = esc_html__('Successfully deleted your playlist.', 'brightcove');
         }
     }
     BC_Utility::delete_cache_item('*');
     $bc_accounts->restore_default_account();
     if ($delete_status) {
         wp_send_json_success($delete_message);
     } else {
         wp_send_json_error($delete_message);
     }
 }
 /**
  * Check permission level for an account.
  *
  * @return array List of permission issues.
  */
 protected function check_permissions_level()
 {
     $permission_issues = array();
     $video_id = false;
     // Start enumerating permissions that we'll need to ensure the account is good.
     $cms_api = new BC_CMS_API();
     // Create a video
     $video_creation = $cms_api->video_add(__('Brightcove WordPress plugin test video', 'brightcove'));
     if (!$video_creation || is_wp_error($video_creation)) {
         $permission_issues[] = esc_html__('create videos', 'brightcove');
     } else {
         $video_id = $video_creation['id'];
         // Update a video
         $renamed_title = __('Brightcove WordPress plugin test video renamed', 'brightcove');
         $video_renamed = $cms_api->video_update($video_id, array('name' => $renamed_title));
         if (!$video_renamed || $renamed_title !== $video_renamed['name']) {
             $permission_issues[] = esc_html__('modify videos', 'brightcove');
         }
     }
     $playlist = $cms_api->playlist_add(__('Brightcove WordPress plugin test playlist', 'brightcove'));
     if (!$playlist || !is_array($playlist) || !isset($playlist['id'])) {
         $permission_issues[] = esc_html__('create playlists', 'brightcove');
     } else {
         // For use through other Playlist test API calls.
         $playlist_id = $playlist['id'];
         $update_data = array('video_ids' => array($video_id), 'type' => 'EXPLICIT');
         $updated_playlist = $cms_api->playlist_update($playlist_id, $update_data);
         if (!$updated_playlist || !is_array($updated_playlist) || !isset($updated_playlist['id'])) {
             $permission_issues[] = esc_html__('modify playlists', 'brightcove');
         }
         // Delete a playlist
         if (!$cms_api->playlist_delete($playlist_id)) {
             $permission_issues[] = esc_html__('delete playlists', 'brightcove');
         }
     }
     // Delete a video
     if (!$cms_api->video_delete($video_id)) {
         $permission_issues[] = esc_html__('delete videos', 'brightcove');
     }
     $player_api = new BC_Player_Management_API($this);
     // Fetch all players
     $players = $player_api->player_list();
     if (is_wp_error($players) || !is_array($players['items'])) {
         $permission_issues[] = esc_html__('fetch players', 'brightcove');
     }
     return $permission_issues;
 }