/**
  * @author Vova Feldman (@svovaf)
  * @since  1.0.7
  *
  * @param string $ids
  */
 function remove_sticky($ids)
 {
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     foreach ($ids as $id) {
         // Remove from sticky storage.
         $this->_sticky_storage->remove($id);
         // Remove from current admin messages.
         if (isset($this->_admin_messages['all_admin_notices']) && isset($this->_admin_messages['all_admin_notices'][$id])) {
             unset($this->_admin_messages['all_admin_notices'][$id]);
         }
         if (isset($this->_admin_messages['admin_notices']) && isset($this->_admin_messages['admin_notices'][$id])) {
             unset($this->_admin_messages['admin_notices'][$id]);
         }
     }
 }
示例#2
0
 /**
  * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
  * 2. If had any HTTP issue, return `false`.
  * 3. If there was an API error, return the API result.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.1.7.4
  *
  * @param string|bool $email
  * @param string|bool $first
  * @param string|bool $last
  * @param string|bool $license_key
  * @param bool        $is_uninstall       If "true", this means that the module is currently being uninstalled.
  *                                        In this case, the user and site info will be sent to the server but no
  *                                        data will be saved to the WP installation's database.
  *
  * @return mixed
  *
  * @use    WP_Error
  */
 function opt_in($email = false, $first = false, $last = false, $license_key = false, $is_uninstall = false)
 {
     $this->_logger->entrance();
     if (false === $email) {
         $current_user = self::_get_current_wp_user();
         $email = $current_user->user_email;
     }
     /**
      * @since 1.2.1 If activating with license key, ignore the context-user
      *              since the user will be automatically loaded from the license.
      */
     if (empty($license_key)) {
         // Clean up pending license if opt-ing in again.
         $this->_storage->remove('pending_license_key');
         if (!$is_uninstall) {
             $fs_user = Freemius::_get_user_by_email($email);
             if (is_object($fs_user) && !$this->is_pending_activation()) {
                 return $this->install_with_current_user(false);
             }
         }
     }
     $user_info = array();
     if (!empty($email)) {
         $user_info['user_email'] = $email;
     }
     if (!empty($first)) {
         $user_info['user_firstname'] = $first;
     }
     if (!empty($last)) {
         $user_info['user_lastname'] = $last;
     }
     $params = $this->get_opt_in_params($user_info);
     if (is_string($license_key)) {
         $params['license_key'] = $license_key;
     }
     if ($is_uninstall) {
         $params['uninstall_params'] = array('reason_id' => $this->_storage->uninstall_reason->id, 'reason_info' => $this->_storage->uninstall_reason->info);
     }
     $params['format'] = 'json';
     $url = WP_FS__ADDRESS . '/action/service/user/install/';
     if (isset($_COOKIE['XDEBUG_SESSION'])) {
         $url = add_query_arg('XDEBUG_SESSION', 'PHPSTORM', $url);
     }
     $response = wp_remote_post($url, array('method' => 'POST', 'body' => $params, 'timeout' => 15));
     if ($response instanceof WP_Error) {
         if ('https://' === substr($url, 0, 8) && isset($response->errors) && isset($response->errors['http_request_failed']) && false !== strpos($response->errors['http_request_failed'][0], 'sslv3 alert handshake')) {
             // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
             $url = 'http://' . substr($url, 8);
             $response = wp_remote_post($url, array('method' => 'POST', 'body' => $params, 'timeout' => 15));
         }
         if ($response instanceof WP_Error) {
             return false;
         }
     }
     if (is_wp_error($response)) {
         return false;
     }
     // Module is being uninstalled, don't handle the returned data.
     if ($is_uninstall) {
         return true;
     }
     $decoded = @json_decode($response['body']);
     if (empty($decoded)) {
         return false;
     }
     if ($this->is_api_error($decoded)) {
         return $is_uninstall ? $decoded : $this->apply_filters('after_install_failure', $decoded, $params);
     } else {
         if (isset($decoded->pending_activation) && $decoded->pending_activation) {
             // Pending activation, add message.
             return $this->set_pending_confirmation(true, false, $license_key);
         } else {
             if (isset($decoded->install_secret_key)) {
                 return $this->install_with_new_user($decoded->user_id, $decoded->user_public_key, $decoded->user_secret_key, $decoded->install_id, $decoded->install_public_key, $decoded->install_secret_key, false);
             }
         }
     }
     return $decoded;
 }
 /**
  * @author Vova Feldman (@svovaf)
  * @since  1.1.7.3
  */
 private function clear_install_sync_cron()
 {
     $this->_logger->entrance();
     if (!$this->is_install_sync_scheduled()) {
         return;
     }
     $this->_storage->remove('install_sync_cron');
     wp_clear_scheduled_hook($this->get_action_tag('install_sync'));
 }