Esempio n. 1
0
             * the SDK was downgraded to a lower SDK.
             */
            // Find the active plugin with the newest SDK version and update the newest reference.
            fs_fallback_to_newest_active_sdk();
        } else {
            if ($is_newest_sdk_plugin_activate && $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && ($fs_active_plugins->newest->in_activation || class_exists('Freemius') && (!defined('WP_FS__SDK_VERSION') || version_compare(WP_FS__SDK_VERSION, $this_sdk_version, '<')))) {
                if ($fs_active_plugins->newest->in_activation) {
                    // Plugin no more in activation.
                    $fs_active_plugins->newest->in_activation = false;
                    update_option('fs_active_plugins', $fs_active_plugins);
                }
                // Reorder plugins to load plugin with newest SDK first.
                if (fs_newest_sdk_plugin_first()) {
                    // Refresh page after re-order to make sure activated plugin loads newest SDK.
                    if (class_exists('Freemius')) {
                        if (fs_redirect($_SERVER['REQUEST_URI'])) {
                            exit;
                        }
                    }
                }
            }
        }
    }
}
if (class_exists('Freemius')) {
    // SDK was already loaded.
    return;
}
if (version_compare($this_sdk_version, $fs_active_plugins->newest->version, '<')) {
    $newest_sdk_starter = fs_normalize_path(WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php');
    if (file_exists($newest_sdk_starter)) {
Esempio n. 2
0
 /**
  * Forward page to activation page.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.3
  */
 function _redirect_on_activation_hook()
 {
     $url = $this->get_after_plugin_activation_redirect_url();
     if (is_string($url)) {
         fs_redirect($url);
         exit;
     }
 }
 /**
  * Forward page to activation page.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.3
  */
 function _redirect_on_activation_hook()
 {
     $url = false;
     $plugin_fs = false;
     if (!$this->is_addon()) {
         $first_time_path = $this->_menu->get_first_time_path();
         $plugin_fs = $this;
         $url = $plugin_fs->is_activation_mode() ? $plugin_fs->get_activation_url() : (empty($first_time_path) ? $this->_get_admin_page_url() : $first_time_path);
     } else {
         if ($this->is_parent_plugin_installed()) {
             $plugin_fs = self::get_parent_instance();
         }
         if (is_object($plugin_fs)) {
             if (!$plugin_fs->is_registered()) {
                 // Forward to parent plugin connect when parent not registered.
                 $url = $plugin_fs->get_activation_url();
             } else {
                 // Forward to account page.
                 $url = $plugin_fs->_get_admin_page_url('account');
             }
         }
     }
     if (is_string($url)) {
         fs_redirect($url);
         exit;
     }
 }
 function _redirect_on_clicked_menu_link()
 {
     $this->_logger->entrance();
     $page = strtolower(isset($_REQUEST['page']) ? $_REQUEST['page'] : '');
     $this->_logger->log('page = ' . $page);
     foreach ($this->_menu_items as $priority => $items) {
         foreach ($items as $item) {
             if (isset($item['url'])) {
                 if ($page === $item['menu_slug']) {
                     $this->_logger->log('Redirecting to ' . $item['url']);
                     fs_redirect($item['url']);
                 }
             }
         }
     }
 }
 /**
  * Handle account page updates / edits / actions.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.2
  *
  */
 private function _handle_account_edits()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     $plugin_id = fs_request_get('plugin_id', $this->get_id());
     $action = fs_get_action();
     switch ($action) {
         case 'delete_account':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->delete_account_event();
                 if (fs_redirect($this->_get_admin_page_url())) {
                     exit;
                 }
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->delete_account_event();
                     if (fs_redirect($this->_get_admin_page_url('account'))) {
                         exit;
                     }
                 }
             }
             return;
         case 'downgrade_account':
             check_admin_referer($action);
             $this->_downgrade_site();
             return;
         case 'activate_license':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->_activate_license();
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->_activate_license();
                 }
             }
             return;
         case 'deactivate_license':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->_deactivate_license();
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->_deactivate_license();
                 }
             }
             return;
         case 'check_updates':
             check_admin_referer($action);
             $this->_check_updates();
             return;
         case 'change_owner':
             $state = fs_request_get('state', 'init');
             switch ($state) {
                 case 'init':
                     $candidate_email = fs_request_get('candidate_email', '');
                     if ($this->init_change_owner($candidate_email)) {
                         $this->_admin_notices->add(sprintf(__fs('change-owner-request-sent-x'), '<b>' . $this->_user->email . '</b>'));
                     }
                     break;
                 case 'owner_confirmed':
                     $candidate_email = fs_request_get('candidate_email', '');
                     $this->_admin_notices->add(sprintf(__fs('change-owner-request_owner-confirmed'), '<b>' . $candidate_email . '</b>'));
                     break;
                 case 'candidate_confirmed':
                     if ($this->complete_change_owner()) {
                         $this->_admin_notices->add_sticky(sprintf(__fs('change-owner-request_candidate-confirmed'), '<b>' . $this->_user->email . '</b>'), 'ownership_changed', __fs('congrats') . '!');
                     } else {
                         // @todo Handle failed ownership change message.
                     }
                     break;
             }
             return;
         case 'update_email':
             check_admin_referer('update_email');
             $new_email = fs_request_get('fs_email_' . $this->_slug, '');
             $result = $this->_update_email($new_email);
             if (isset($result->error)) {
                 switch ($result->error->code) {
                     case 'user_exist':
                         $this->_admin_notices->add(__fs('user-exist-message') . ' ' . sprintf(__fs('user-exist-message_ownership'), '<b>' . $new_email . '</b>') . sprintf('<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>', $this->get_account_url('change_owner', array('state' => 'init', 'candidate_email' => $new_email)), __fs('change-ownership')), __fs('oops') . '...', 'error');
                         break;
                 }
             } else {
                 $this->_admin_notices->add(__fs('email-updated-message'));
             }
             return;
         case 'update_user_name':
             check_admin_referer('update_user_name');
             $result = $this->update_user_name();
             if (isset($result->error)) {
                 $this->_admin_notices->add(__fs('name-update-failed-message'), __fs('oops') . '...', 'error');
             } else {
                 $this->_admin_notices->add(__fs('name-updated-message'));
             }
             return;
             #region Actions that might be called from external links (e.g. email)
         #region Actions that might be called from external links (e.g. email)
         case 'cancel_trial':
             $this->_cancel_trial();
             return;
         case 'verify_email':
             $this->verify_email();
             return;
         case 'sync_user':
             $this->_handle_account_user_sync();
             return;
         case $this->_slug . '_sync_license':
             $this->_sync_license();
             return;
         case 'download_latest':
             $this->_download_latest_directly($plugin_id);
             return;
             #endregion
     }
     if (WP_FS__IS_POST_REQUEST) {
         $properties = array('site_secret_key', 'site_id', 'site_public_key');
         foreach ($properties as $p) {
             if ('update_' . $p === $action) {
                 check_admin_referer($action);
                 $this->_logger->log($action);
                 $site_property = substr($p, strlen('site_'));
                 $site_property_value = fs_request_get('fs_' . $p . '_' . $this->_slug, '');
                 $this->get_site()->{$site_property} = $site_property_value;
                 // Store account after modification.
                 $this->_store_site();
                 $this->do_action('account_property_edit', 'site', $site_property, $site_property_value);
                 $this->_admin_notices->add(sprintf(__fs('x-updated'), '<b>' . str_replace('_', ' ', $p) . '</b>'));
                 return;
             }
         }
     }
 }
 function rw_reset_account()
 {
     global $rw_fs;
     $rw_account = rw_account();
     $rw_api = rwapi();
     // Before making any changes, make sure site credentials are good.
     // Preserve previous credentials.
     $prev_site_id = $rw_account->site_id;
     $prev_site_public_key = $rw_account->site_public_key;
     $prev_site_secret_key = $rw_account->site_secret_key;
     // Get install information from request.
     $site_id = rw_request_get('site_id');
     $site_public_key = rw_request_get('site_public_key');
     $site_secret_key = rw_request_get('site_secret_key');
     $admin_notices = FS_Admin_Notice_Manager::instance(WP_RW__ID, 'Rating-Widget');
     if (!is_numeric($site_id)) {
         $admin_notices->add('Invalid site ID. Please contact our support for more details.');
         return false;
     }
     if (32 !== strlen($site_public_key)) {
         $admin_notices->add('Invalid public key. Please contact our support for more details.');
         return false;
     }
     if (20 > strlen($site_secret_key)) {
         $admin_notices->add('Invalid secret key. Please contact our support for more details.');
         return false;
     }
     // Override site details.
     $rw_account->set_site($site_id, $site_public_key, $site_secret_key, false);
     // Reload API with new account details.
     $rw_api->reload();
     if (!$rw_api->test()) {
         // Fallback to previous account.
         $rw_account->set_site($prev_site_id, $prev_site_public_key, $prev_site_secret_key, false);
         // Reload API with new account details.
         $rw_api->reload();
         $admin_notices->add('Invalid site credentials. Failed pining RatingWidget\'s API. Please contact our support for more details.');
         return false;
     }
     // Save new RW credentials.
     $rw_account->save();
     if ($rw_fs->is_registered()) {
         // Send uninstall event.
         $rw_fs->_uninstall_plugin_event(false);
         if ('true' === rw_request_get('delete_account')) {
             $rw_fs->delete_account_event(false);
         }
     }
     if (rw_migration_to_freemius()) {
         fs_redirect($rw_fs->_get_admin_page_url('account'));
         die;
     }
     return true;
 }
function fs_site_redirect($location = '')
{
    fs_redirect(fs_get_site_url($location));
    exit;
}
Esempio n. 8
0
 /**
  * Handle account page updates / edits / actions.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.2
  *
  */
 private function _handle_account_edits()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     $plugin_id = fs_request_get('plugin_id', $this->get_id());
     $action = fs_get_action();
     switch ($action) {
         case 'delete_account':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->delete_account_event();
                 if (fs_redirect($this->_get_admin_page_url())) {
                     exit;
                 }
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->delete_account_event();
                     if (fs_redirect($this->_get_admin_page_url('account'))) {
                         exit;
                     }
                 }
             }
             return;
         case 'downgrade_account':
             check_admin_referer($action);
             $this->_downgrade_site();
             return;
         case 'activate_license':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->_activate_license();
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->_activate_license();
                 }
             }
             return;
         case 'deactivate_license':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->_deactivate_license();
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->_deactivate_license();
                 }
             }
             return;
         case 'check_updates':
             check_admin_referer($action);
             $this->_check_updates();
             return;
         case 'update_email':
             check_admin_referer('update_email');
             $result = $this->_update_email();
             if (isset($result->error)) {
                 switch ($result->error->code) {
                     case 'user_exist':
                         $this->_admin_notices->add(__fs('user-exist-message'), __fs('oops') . '...', 'error');
                         break;
                 }
             } else {
                 $this->_admin_notices->add(__fs('email-updated-message'));
             }
             return;
         case 'update_user_name':
             check_admin_referer('update_user_name');
             $result = $this->_update_user_name();
             if (isset($result->error)) {
                 $this->_admin_notices->add(__fs('name-update-failed-message'), __fs('oops') . '...', 'error');
             } else {
                 $this->_admin_notices->add(__fs('name-updated-message'));
             }
             return;
             #region Actions that might be called from external links (e.g. email)
         #region Actions that might be called from external links (e.g. email)
         case 'cancel_trial':
             $this->_cancel_trial();
             return;
         case 'verify_email':
             $this->_verify_email();
             return;
         case 'sync_user':
             $this->_handle_account_user_sync();
             return;
         case $this->_slug . '_sync_license':
             $this->_sync_license();
             return;
         case 'download_latest':
             $this->_download_latest_directly($plugin_id);
             return;
             #endregion
     }
     if (WP_FS__IS_POST_REQUEST) {
         $properties = array('site_secret_key', 'site_id', 'site_public_key');
         foreach ($properties as $p) {
             if ('update_' . $p === $action) {
                 check_admin_referer($action);
                 $this->_logger->log($action);
                 $site_property = substr($p, strlen('site_'));
                 $site_property_value = fs_request_get('fs_' . $p . '_' . $this->_slug, '');
                 $this->get_site()->{$site_property} = $site_property_value;
                 // Store account after modification.
                 $this->_store_site();
                 $this->do_action('account_property_edit', 'site', $site_property, $site_property_value);
                 $this->_admin_notices->add(sprintf(__fs('x-updated'), '<b>' . str_replace('_', ' ', $p) . '</b>'));
                 return;
             }
         }
     }
 }
Esempio n. 9
0
 /**
  * Handle account page updates / edits / actions.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.2
  *
  */
 private function _handle_account_edits()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     $plugin_id = fs_request_get('plugin_id', $this->get_id());
     $action = fs_get_action();
     switch ($action) {
         case 'delete_account':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->delete_account_event();
                 if (fs_redirect($this->_get_admin_page_url())) {
                     exit;
                 }
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->delete_account_event();
                     if (fs_redirect($this->_get_admin_page_url('account'))) {
                         exit;
                     }
                 }
             }
             return;
         case 'downgrade_account':
             check_admin_referer($action);
             $this->_downgrade_site();
             return;
         case 'activate_license':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->_activate_license();
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->_activate_license();
                 }
             }
             return;
         case 'deactivate_license':
             check_admin_referer($action);
             if ($plugin_id == $this->get_id()) {
                 $this->_deactivate_license();
             } else {
                 if ($this->is_addon_activated($plugin_id)) {
                     $fs_addon = self::get_instance_by_id($plugin_id);
                     $fs_addon->_deactivate_license();
                 }
             }
             return;
         case 'check_updates':
             check_admin_referer($action);
             $this->_check_updates();
             return;
         case 'update_email':
             check_admin_referer('update_email');
             $result = $this->_update_email();
             if (isset($result->error)) {
                 switch ($result->error->code) {
                     case 'user_exist':
                         $this->_admin_notices->add(__('Sorry, we could not complete the email update. Another user with the same email is already registered.', WP_FS__SLUG), __('Oops...', WP_FS__SLUG), 'error');
                         break;
                 }
             } else {
                 $this->_admin_notices->add(__('Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', WP_FS__SLUG));
             }
             return;
         case 'update_user_name':
             check_admin_referer('update_user_name');
             $result = $this->_update_user_name();
             if (isset($result->error)) {
                 $this->_admin_notices->add(__('Please provide your full name.', WP_FS__SLUG), __('Oops...', WP_FS__SLUG), 'error');
             } else {
                 $this->_admin_notices->add(__('Your name was successfully updated.', WP_FS__SLUG));
             }
             return;
             #region Actions that might be called from external links (e.g. email)
         #region Actions that might be called from external links (e.g. email)
         case 'cancel_trial':
             $this->_cancel_trial();
             return;
         case 'verify_email':
             $this->_verify_email();
             return;
         case 'sync_user':
             $this->_handle_account_user_sync();
             return;
         case $this->_slug . '_sync_license':
             $this->_sync_license();
             return;
         case 'download_latest':
             $this->_download_latest_directly($plugin_id);
             return;
             #endregion
     }
     if (WP_FS__IS_POST_REQUEST) {
         $properties = array('site_secret_key', 'site_id', 'site_public_key');
         foreach ($properties as $p) {
             if ('update_' . $p === $action) {
                 check_admin_referer($action);
                 $this->_logger->log($action);
                 $site_property = substr($p, strlen('site_'));
                 $site_property_value = fs_request_get('fs_' . $p . '_' . $this->_slug, '');
                 $this->get_site()->{$site_property} = $site_property_value;
                 // Store account after modification.
                 $this->_store_site();
                 $this->do_action('account_property_edit', 'site', $site_property, $site_property_value);
                 $this->_admin_notices->add(sprintf(__('You have successfully updated your %s .', WP_FS__SLUG), '<b>' . str_replace('_', ' ', $p) . '</b>'));
                 return;
             }
         }
     }
 }