protected function is_valid_account($account_id, $client_id, $client_secret, $account_name, $check_access = true)
 {
     // Save current account as $old_account.
     $old_account = $this->current_account;
     $new_account = array('account_id' => $account_id, 'client_id' => $client_id, 'client_secret' => $client_secret, 'account_name' => $account_name);
     $new_account['hash'] = BC_Utility::get_hash_for_account($new_account);
     // Set new account as $account.
     $this->current_account = $new_account;
     $oauth = new BC_Oauth_API();
     // Obtain session token with oAuth.
     $valid_credentials = $oauth->is_valid_account_credentials();
     $errors = array();
     if (!$valid_credentials) {
         $errors[] = new WP_Error('account-invalid-credentials', esc_html__('Invalid account credentials', 'brightcove'));
     } else {
         if ($check_access) {
             $permission_issues = $this->check_permissions_level();
             if (count($permission_issues) > 0) {
                 $errors[] = new WP_Error('account-permission-issue', esc_html__("Supplied account doesn't have the following permissions: ", 'brightcove') . implode(', ', $permission_issues) . '. ' . esc_html__('Please use an account that has these permissions.', 'brightcove'));
             }
         }
     }
     // Restore current account transient (if exists).
     $this->current_account = $old_account;
     return !empty($errors) ? $errors : true;
 }
 /**
  * Adds the required oAuth token header to make an API call to the Brightcove APIs
  *
  * @since  1.0.0
  *
  * @param boolean $force_new_token Whether or not we should obtain a fresh OAuth token for the request.
  *
  * @return string String containing oAuth token
  */
 protected function get_authorization_header($force_new_token = false)
 {
     $oauth = new BC_Oauth_API();
     $token = $oauth->_request_access_token($force_new_token);
     if (is_wp_error($token)) {
         return $token;
     }
     return 'Bearer ' . $token;
 }
 protected function is_valid_account($account_id, $client_id, $client_secret, $account_name, $check_access = true)
 {
     // Save current account as $old_account.
     $old_account = $this->current_account;
     $new_account = array('account_id' => $account_id, 'client_id' => $client_id, 'client_secret' => $client_secret, 'account_name' => $account_name);
     $new_account['hash'] = BC_Utility::get_hash_for_account($new_account);
     // Set new account as $account.
     $this->current_account = $new_account;
     $oauth = new BC_Oauth_API();
     // Obtain session token with oAuth.
     $valid_credentials = $oauth->is_valid_account_credentials();
     $errors = array();
     if (!$valid_credentials) {
         $errors[] = new WP_Error('account-invalid-credentials', esc_html__('Invalid account credentials', 'brightcove'));
     } else {
         if ($check_access) {
             $errors = array_merge($errors, $this->check_permissions_level());
         }
     }
     // Restore current account transient (if exists).
     $this->current_account = $old_account;
     return !empty($errors) ? $errors : true;
 }