/**
  * Take an uploaded file, and a supplied name and create a video ID and
  * ingestion request for them.
  * @param $name video name
  * @return bool|string|WP_Error
  */
 public function process_uploaded_video($files, $account_hash, $tags, $name)
 {
     global $bc_accounts;
     $status = array('upload' => 'fail', 'ingest' => 'fail', 'url' => '');
     $account = $bc_accounts->get_account_by_hash($account_hash);
     if (!$account) {
         return new WP_Error('invalid-account', esc_html__('Invalid account', 'brightcove'));
     }
     if (isset($files) && isset($files['file'])) {
         $cms_api = $this->cms_api;
         // check that file is supported by WP
         if ($this->check_allowed_file($files['file']) === false) {
             $error_message = esc_html__('Video type is not supported', 'brightcove');
             BC_Logging::log(sprintf('VIDEO UPLOAD: %s', $error_message));
             return new WP_Error('video_upload_error', $error_message);
         }
         $uploaded = wp_handle_upload($files['file'], array('test_form' => false));
         if (isset($uploaded['error'])) {
             $error_message = esc_html__($uploaded['error'], 'brightcove');
             BC_Logging::log(sprintf('VIDEO UPLOAD ERROR: %s', $error_message));
             return new WP_Error('video_upload_error', $error_message);
         } else {
             $status['upload'] = 'success';
             $status['url'] = $uploaded['url'];
         }
         $tags_array = $this->process_tags($tags);
         $data = array();
         if (false !== $tags_array) {
             $data['tags'] = $tags_array;
         }
         $video_id_creation_result = $cms_api->video_add($name, $data);
         if (false === $video_id_creation_result) {
             return new WP_Error(esc_html__('Unable to create a video on brightcove side', 'brightcove'));
         }
         if (is_wp_error($video_id_creation_result)) {
             return $video_id_creation_result;
         }
         if (isset($video_id_creation_result['created_at'])) {
             $video_id = BC_Utility::sanitize_and_generate_meta_video_id($video_id_creation_result['id']);
             $status['video_id'] = $video_id_creation_result['id'];
             BC_Utility::add_pending_upload($video_id, $uploaded['file']);
             $video_ingestion_request_result = $cms_api->video_upload($video_id_creation_result['id'], $uploaded['url']);
             if (is_array($video_ingestion_request_result) && isset($video_ingestion_request_result['id'])) {
                 $status['ingest'] = 'success';
                 $status['ingestId'] = $video_ingestion_request_result['id'];
             }
             $status['videoDetails'] = $video_id_creation_result;
         }
     }
     return $status;
 }