/** * 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(); // Clear user and site. $this->_site = null; $this->_user = null; if (fs_redirect($this->get_activation_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', $this->_slug), '<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', $this->_slug), '<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', $this->_slug), '<b>' . $this->_user->email . '</b>'), 'ownership_changed', __fs('congrats', $this->_slug) . '!'); } 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', $this->_slug) . ' ' . sprintf(__fs('user-exist-message_ownership', $this->_slug), '<b>' . $new_email . '</b>') . sprintf('<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s ➜</button></a>', $this->get_account_url('change_owner', array('state' => 'init', 'candidate_email' => $new_email)), __fs('change-ownership', $this->_slug)), __fs('oops', $this->_slug) . '...', 'error'); break; } } else { $this->_admin_notices->add(__fs('email-updated-message', $this->_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(__fs('name-update-failed-message', $this->_slug), __fs('oops', $this->_slug) . '...', 'error'); } else { $this->_admin_notices->add(__fs('name-updated-message', $this->_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': if ($plugin_id == $this->get_id()) { $this->_cancel_trial(); } else { if ($this->is_addon_activated($plugin_id)) { $fs_addon = self::get_instance_by_id($plugin_id); $fs_addon->_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', $this->_slug), '<b>' . str_replace('_', ' ', $p) . '</b>')); return; } } } }
/** * 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; } } } }
function fs_request_is_action($action, $action_key = 'action') { return strtolower($action) === fs_get_action($action_key); }
/** * 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; } } } }