public function subscribe_if_not_subscribed()
 {
     global $bc_accounts;
     $accounts = $bc_accounts->get_sanitized_all_accounts();
     $completed_accounts = array();
     foreach ($accounts as $account => $account_data) {
         // We may have multiple accounts for an account_id, prevent syncing that account more than once.
         if (!in_array($account_data['account_id'], $completed_accounts)) {
             $completed_accounts[] = $account_data['account_id'];
             $bc_accounts->set_current_account($account);
             $subscriptions = $this->cms_api->get_subscriptions();
             if (is_array($subscriptions)) {
                 foreach ($subscriptions as $subscription) {
                     if ($bc_accounts->get_account_id() === $subscription['service_account'] && isset($subscription['id']) && false !== strpos($subscription['endpoint'], get_admin_url())) {
                         $this->cms_api->remove_subscription($subscription['id']);
                     }
                 }
             }
             $subscription_status = $this->cms_api->add_subscription();
             if (is_wp_error($subscription_status)) {
                 $bc_accounts->restore_default_account();
                 return false;
             }
             if (isset($subscription_status['id']) && $subscription_status['service_account'] === $bc_accounts->get_account_id()) {
                 $subscription_id = BC_Utility::sanitize_subscription_id($subscription_status['id']);
                 update_option($this->get_option_key_for($bc_accounts->get_account_id()), $subscription_id);
             }
             $bc_accounts->restore_default_account();
         }
     }
 }
 /**
  * Retrieve all players and create/update when necessary
  *
  * @return bool
  */
 public function sync_players($retry = false)
 {
     $force_sync = false;
     if (defined('BRIGHTCOVE_FORCE_SYNC') && BRIGHTCOVE_FORCE_SYNC) {
         $force_sync = true;
     }
     $players = $this->players_api->player_list();
     if (!is_array($players)) {
         if (!$retry) {
             return $this->sync_players(true);
         } else {
             return false;
             // Something happened we retried, we failed.
         }
     }
     $players = $this->sort_api_response($players);
     if ($force_sync || BC_Utility::hash_changed('players', $players, $this->cms_api->account_id)) {
         $player_ids_to_keep = array();
         // for deleting outdated players
         /* process all players */
         foreach ($players as $player) {
             $this->add_or_update_wp_player($player);
             $player_ids_to_keep[] = BC_Utility::sanitize_subscription_id($player['id']);
         }
         BC_Utility::remove_deleted_players($player_ids_to_keep);
         BC_Utility::store_hash('players', $players, $this->cms_api->account_id);
     }
     return true;
 }