<?php if ($fs->enable_anonymous()) { ?> <a href="<?php echo wp_nonce_url($fs->_get_admin_page_url('', array('fs_action' => $slug . '_skip_activation')), $slug . '_skip_activation'); ?> " class="button button-secondary" tabindex="2"><?php _efs('skip'); ?> </a> <?php } ?> <?php $fs_user = Freemius::_get_user_by_email($current_user->user_email); ?> <?php if (is_object($fs_user)) { ?> <form action="" method="POST"> <input type="hidden" name="fs_action" value="<?php echo $slug; ?> _activate_existing"> <?php wp_nonce_field('activate_existing_' . $fs->get_public_key()); ?> <button class="button button-primary" tabindex="1" type="submit"><?php _efs('opt-in-connect');
/** * 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.4 * * @param string|bool $email * @param string|bool $first * @param string|bool $last * * @return bool Is successful opt-in (or set to pending). */ function opt_in($email = false, $first = false, $last = false) { $this->_logger->entrance(); if (false === $email) { $current_user = self::_get_current_wp_user(); $email = $current_user->user_email; } $fs_user = Freemius::_get_user_by_email($email); if (is_object($fs_user) && !$this->is_pending_activation()) { $this->install_with_current_user(false); return true; } $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); $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; } $decoded = @json_decode($response['body']); if (empty($decoded)) { return false; } if (isset($decoded->error)) { return false; } else { if (isset($decoded->pending_activation) && $decoded->pending_activation) { // Pending activation, add message. $this->set_pending_confirmation(false, false); return true; } else { if (isset($decoded->install_secret_key)) { $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 true; } } } return false; }