/**
  * Handles video uploads
  *
  * Handles videos uploaded via WordPress.
  *
  * @since 1.0
  *
  * @return void
  */
 public function brightcove_media_upload()
 {
     global $bc_accounts;
     foreach (array('nonce', 'tags', 'name', 'account') as $parameter) {
         if (!isset($_POST[$parameter])) {
             wp_send_json_error();
         }
     }
     if (!wp_verify_nonce($_POST['nonce'], '_bc_ajax_search_nonce')) {
         wp_send_json_error();
     }
     $account_hash = sanitize_text_field($_POST['account']);
     $account = $bc_accounts->set_current_account($account_hash);
     $tags = sanitize_text_field($_POST['tags']);
     $name = sanitize_text_field($_POST['name']);
     if (!is_array($account) || !is_string($name) || '' === $name) {
         $bc_accounts->restore_default_account();
         wp_send_json_error();
     }
     $ingestion_request_status = $this->video_upload->process_uploaded_video($_FILES, $account_hash, $tags, $name);
     $bc_accounts->restore_default_account();
     if (is_wp_error($ingestion_request_status)) {
         wp_send_json_error($ingestion_request_status->get_error_message());
     }
     $this->videos->add_or_update_wp_video($ingestion_request_status['videoDetails'], true);
     wp_send_json_success($ingestion_request_status);
 }
 /**
  * Function for processing a callback notification from Brightcove
  *
  * Valid callback URI: /wp-admin/admin-post.php?bc_auth=4455f75b
  * Valid callback JSON:
  * {"timestamp":1427307045995,"account_id":"4089003419001","event":"video-change","video":"4133902975001","version":0}
  **/
 public function video_notification()
 {
     if (!isset($_GET['bc_auth'])) {
         return;
     }
     $auth = $_GET['bc_auth'];
     $json = file_get_contents('php://input');
     $decoded = json_decode($json, true);
     if (!is_array($decoded)) {
         return;
     }
     if (!isset($decoded['account_id']) || !isset($decoded['video'])) {
         return;
     }
     $account_id = BC_Utility::sanitize_id($decoded['account_id']);
     $valid_auth = BC_Utility::get_auth_key_for_id($account_id);
     if ($valid_auth !== $auth) {
         // Someone was spoofing callbacks?
         return;
     }
     $video_id = BC_Utility::sanitize_id($decoded['video']);
     if (!$video_id) {
         wp_send_json_error('missing video id');
         // Some sort of error occurred with the callback and we have no video_id.
     }
     global $bc_accounts;
     if (!$bc_accounts->set_current_account_by_id($account_id)) {
         wp_send_json_error('bad account id');
         // Bad account id in callback
     }
     $cms_api = new BC_CMS_API();
     $video_details = $cms_api->video_get($video_id);
     if (false === $video_details) {
         wp_send_json_error('video does not exist');
     }
     $videos = new BC_Videos();
     $video_update = $videos->add_or_update_wp_video($video_details);
     $bc_accounts->restore_default_account();
     $this->trigger_background_fetch();
     if ($video_update) {
         wp_send_json_success('video successfully updated');
     } else {
         wp_send_json_error('unable to update video');
     }
 }