示例#1
0
 private function authenticate($data)
 {
     check_admin_referer('authenticate-user');
     require_once $GLOBALS['ithemes_sync_path'] . '/server.php';
     $result = Ithemes_Sync_Server::authenticate($data['username'], $data['password']);
     if (is_wp_error($result)) {
         $heading = __('The user could not be synced.', 'it-l10n-ithemes-sync');
         $code = $result->get_error_code();
         if ('http_request_failed' == $code) {
             $message = sprintf(__('<p>The iThemes Sync server was unable to be contacted. WordPress returned the following error when trying to contact the server:</p><p>%1$s</p><p>If you continue to experience problems, please contact <a target="_blank" href="%2$s">iThemes support</a>.</p>', 'it-l10n-ithemes-sync'), $result->get_error_message(), 'http://ithemes.com/support/');
         } else {
             if ('ithemes-sync-server-failed-request' == $code) {
                 $message = sprintf(__('<p>The iThemes Sync server was unable to process the request at this time. Please try again in a few minutes.</p><p>If you continue to experience problems, please contact <a target="_blank" href="%s">iThemes support</a>.</p>', 'it-l10n-ithemes-sync'), 'http://ithemes.com/support/');
             } else {
                 $message = $result->get_error_message();
             }
         }
         $this->add_error_message($heading, $message);
         return;
     }
     if (empty($result['key'])) {
         $heading = __('The user could not be synced.', 'it-l10n-ithemes-sync');
         $message = __('The sync request failed due to a server communication error. The server sent a response that did not include a authentication key.', 'it-l10n-ithemes-sync');
         $this->add_error_message($heading, $message);
         return;
     }
     if (empty($result['user_id'])) {
         $heading = __('The user could not be synced.', 'it-l10n-ithemes-sync');
         $message = __('The sync request failed due to a server communication error. The server sent a response that did not include a user ID.', 'it-l10n-ithemes-sync');
         $this->add_error_message($heading, $message);
         return;
     }
     $add_result = $GLOBALS['ithemes-sync-settings']->add_authentication($result['user_id'], $data['username'], $result['key']);
     if (is_wp_error($add_result)) {
         $heading = __('The user could not be synced.', 'it-l10n-ithemes-sync');
         $message = $add_result->get_error_message();
         $this->add_error_message($heading, $message);
         return;
     }
     $heading = __('Woohoo! Your site has been synced.', 'it-l10n-ithemes-sync');
     $messages = array();
     if (0 == $result['quota']['available']) {
         $messages[] = sprintf(__('Your user has now used all of the sites available to be added to Sync. More information can be found on the <a href="%s" target="_blank">iThemes membership panel</a>.', 'it-l10n-ithemes-sync'), $this->sync_dashboard_url);
     } else {
         $messages[] = sprintf(_n('Your user can Sync 1 additional site.', 'Your user can sync %d additional sites.', $result['quota']['available'], 'it-l10n-ithemes-sync'), $result['quota']['available']);
     }
     $this->add_success_message($heading, $messages);
 }