diff --git a/inc/admin-pages/class-addons-admin-page.php b/inc/admin-pages/class-addons-admin-page.php deleted file mode 100644 index 3294bbf..0000000 --- a/inc/admin-pages/class-addons-admin-page.php +++ /dev/null @@ -1,553 +0,0 @@ - 'capability_here' - * To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here' - * To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here' - * - * @since 2.0.0 - * @var array - */ - protected $supported_panels = array( - 'network_admin_menu' => 'wu_read_settings', - ); - - /** - * Should we hide admin notices on this page? - * - * @since 2.0.0 - * @var boolean - */ - protected $hide_admin_notices = false; - - /** - * Should we force the admin menu into a folded state? - * - * @since 2.0.0 - * @var boolean - */ - protected $fold_menu = false; - - /** - * Holds the section slug for the URLs. - * - * @since 2.0.0 - * @var string - */ - protected $section_slug = 'tab'; - - /** - * Defines if the step links on the side are clickable or not. - * - * @since 2.0.0 - * @var boolean - */ - protected $clickable_navigation = true; - - /** - * Caches the list of add-ons. - * - * @since 2.0.0 - * @var null|array - */ - protected $addons; - - /** - * Allow child classes to add hooks to be run once the page is loaded. - * - * @see https://codex.wordpress.org/Plugin_API/Action_Reference/load-(page) - * @since 1.8.2 - * @return void - */ - public function init() { - - parent::init(); - - add_action('wp_ajax_serve_addons_list', array($this, 'serve_addons_list')); - - } // end init; - - /** - * Register forms - * - * @since 2.0.0 - * @return void - */ - public function register_forms() { - - wu_register_form('addon_more_info', array( - 'render' => array($this, 'display_more_info'), - 'handler' => array($this, 'install_addon'), - )); - - } // end register_forms; - - /** - * Displays the more info tab. - * - * @since 2.0.0 - * @return void - */ - public function display_more_info() { - - $addon_slug = wu_request('addon'); - - $addon = wu_get_isset($this->get_addons_list(), $addon_slug); - - $upgrade_url = wu_network_admin_url('wp-ultimo-pricing', array( - 'checkout' => 'true', - 'plan_id' => '4675', - 'plan_name' => 'wpultimo', - 'billing_cycle' => 'annual', - 'pricing_id' => '3849', - 'currency' => 'usd', - )); - - wu_get_template('base/addons/details', array( - 'upgrade_url' => $upgrade_url, - 'addon' => (object) $addon, - 'addon_slug' => $addon_slug, - 'license' => \WP_Ultimo\License::get_instance(), - )); - - do_action('wu_form_scripts', false); - - } // end display_more_info; - - /** - * Installs a given add-on. - * - * @since 2.0.0 - * @return void - */ - public function install_addon() { - - if (!current_user_can('manage_network_plugins')) { - - $error = new \WP_Error('error', __('You do not have enough permissions to perform this task.', 'wp-ultimo')); - - wp_send_json_error($error); - - } // end if; - - $addon_slug = wu_request('addon'); - - $addon = wu_get_isset($this->get_addons_list(), $addon_slug); - - $download_url = add_query_arg(array( - 'action' => 'download', - 'slug' => $addon_slug, - 'beta_program' => 2, - 'license_key' => rawurlencode((string) \WP_Ultimo\License::get_instance()->get_license_key()), - ), 'https://versions.nextpress.co/updates/'); - - /** - * We check if the URL is one of our websites - */ - $allowed_sites = array( - 'http://nextpress.co', 'https://nextpress.co', // New Domain - 'http://versions.nextpress.co', 'https://versions.nextpress.co', // New Domain - 'http://weare732.com', 'https://weare732.com' // Old Updates Domain - ); - - if (defined('WP_DEBUG') && WP_DEBUG) { - - $allowed_sites[] = 'http://localhost'; - $allowed_sites[] = 'http://wp-ultimo.local'; - - } // end if; - - $allowed = false; - - foreach ($allowed_sites as $allowed_site) { - - if (strncmp($download_url, $allowed_site, strlen($allowed_site)) === 0) { - - $allowed = true; - - break; - - } // end if; - - } // end foreach; - - if ($allowed) { - - // includes necessary for Plugin_Upgrader and Plugin_Installer_Skin - include_once(ABSPATH . 'wp-admin/includes/file.php'); - include_once(ABSPATH . 'wp-admin/includes/misc.php'); - include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); - - $skin = new \Automatic_Upgrader_Skin(array()); - - $upgrader = new \Plugin_Upgrader($skin); - - add_filter('https_ssl_verify', '__return_false', 2000); - - $results = $upgrader->install($download_url); - - remove_filter('https_ssl_verify', '__return_false', 2000); - - if (is_wp_error($results)) { - - wp_send_json_error($results); - - } // end if; - - $messages = $upgrader->skin->get_upgrade_messages(); - - if (!in_array($upgrader->strings['process_success'], $messages, true)) { - - $error = new \WP_Error('error', array_pop($messages)); - - wp_send_json_error($error); - - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg(array( - 's' => urlencode((string) $addon['name']), - ), network_admin_url('plugins.php')), - )); - - } else { - - $error = new \WP_Error('insecure-url', __('You are trying to download an add-on from an insecure URL', 'wp-ultimo')); - - wp_send_json_error($error); - - } // end if; - - } // end install_addon; - - /** - * Enqueue the necessary scripts. - * - * @since 2.0.0 - * @return void - */ - public function register_scripts() { - - wp_enqueue_style('theme'); - - wp_register_script('wu-addons', wu_get_asset('addons.js', 'js'), array('jquery', 'wu-vue', 'underscore'), wu_get_version(), true); - - wp_localize_script('wu-addons', 'wu_addons', array( - 'search' => wu_request('s', ''), - 'category' => wu_request('tab', 'all'), - 'i18n' => array( - 'all' => __('All Add-ons', 'wp-ultimo'), - ), - )); - - wp_enqueue_script('wu-addons'); - - } // end register_scripts; - - /** - * Fetches the list of add-ons available. - * - * @since 2.0.0 - * @return array - */ - protected function get_addons_list() { - /* - * Checks if we have a cached version. - */ - if (is_array($this->addons)) { - - return $this->addons; - - } // end if; - - /* - * Check for local cache. - */ - if (!wu_is_debug()) { - - $addons_list = get_site_transient('wu-addons-list'); - - if (is_array($addons_list) && !empty($addons_list)) { - - $this->addons = $addons_list; - - return $this->addons; - - } // end if; - - } // end if; - - $base_url = 'https://versions.nextpress.co/updates/'; - - $remote_url = add_query_arg(array( - 'slug' => 'wp-ultimo', - 'action' => 'addons', - 'installed_version' => wu_get_version(), - ), $base_url); - - if (defined('WP_ULTIMO_DEVELOPER_KEY') && WP_ULTIMO_DEVELOPER_KEY) { - - $remote_url = add_query_arg('developer_key', WP_ULTIMO_DEVELOPER_KEY, $remote_url); - - } // end if; - - $response = wp_remote_get($remote_url, array( - 'sslverify' => false, - )); - - if (is_wp_error($response)) { - - return array(); - - } // end if; - - $data = wp_remote_retrieve_body($response); - - $data = json_decode($data, true); - - if (!is_array($data)) { - - return array(); - - } // end if; - - /* - * Adds missing keys - */ - foreach ($data as $slug => $item) { - /* - * Checks if this is a free add-on. - */ - $item['free'] = wu_get_isset($item, 'free', false); - - /* - * Checks if the plugin is installed. - */ - $item['installed'] = $this->is_plugin_installed($slug); - - $this->addons[$slug] = $item; - - } // end foreach; - - set_transient('wu-addons-list', $this->addons, 2 * DAY_IN_SECONDS); - - return $this->addons; - - } // end get_addons_list; - - /** - * Checks if a given plugin is installed. - * - * @since 2.0.0 - * @param string $plugin_slug The plugin slug to check. - * @return boolean - */ - public function is_plugin_installed($plugin_slug) { - - $plugin_keys = array_keys(get_plugins()); - - $installed_plugins = implode(' - ', $plugin_keys); - - return stristr($installed_plugins, $plugin_slug) !== false; - - } // end is_plugin_installed; - - /** - * Gets the list of addons from the remote server. - * - * @since 2.0.0 - * @return void - */ - public function serve_addons_list() { - - $addons_list = $this->get_addons_list(); - - wp_send_json_success($addons_list); - - } // end serve_addons_list; - - /** - * Returns the title of the page. - * - * @since 2.0.0 - * @return string Title of the page. - */ - public function get_title() { - - return __('Add-ons', 'wp-ultimo'); - - } // end get_title; - - /** - * Returns the title of menu for this page. - * - * @since 2.0.0 - * @return string Menu label of the page. - */ - public function get_menu_title() { - - return __('Add-ons', 'wp-ultimo'); - - } // end get_menu_title; - - /** - * Every child class should implement the output method to display the contents of the page. - * - * @since 1.8.2 - * @return void - */ - public function output() { - - $more_info_url = wu_get_form_url('addon_more_info', array( - 'width' => 768, - 'addon' => 'ADDON_SLUG', - )); - - wu_get_template('base/addons', array( - 'screen' => get_current_screen(), - 'page' => $this, - 'classes' => '', - 'sections' => $this->get_sections(), - 'current_section' => $this->get_current_section(), - 'clickable_navigation' => $this->clickable_navigation, - 'more_info_url' => $more_info_url, - 'license' => \WP_Ultimo\License::get_instance(), - )); - - } // end output; - - /** - * Returns the list of settings sections. - * - * @since 2.0.0 - * @return array - */ - public function get_sections() { - - return array( - 'all' => array( - 'title' => __('All Add-ons', 'wp-ultimo'), - 'icon' => 'dashicons-wu-grid', - ), - 'premium' => array( - 'title' => __('Premium', 'wp-ultimo'), - 'icon' => 'dashicons-wu-rocket', - ), - 'free' => array( - 'title' => __('Free', 'wp-ultimo'), - 'icon' => 'dashicons-wu-pin', - ), - 'gateways' => array( - 'title' => __('Gateways', 'wp-ultimo'), - 'icon' => 'dashicons-wu-credit-card', - ), - 'growth' => array( - 'title' => __('Growth & Scaling', 'wp-ultimo'), - 'icon' => 'dashicons-wu-line-graph', - ), - 'integrations' => array( - 'title' => __('Integrations', 'wp-ultimo'), - 'icon' => 'dashicons-wu-power-plug', - ), - 'customization' => array( - 'title' => __('Customization', 'wp-ultimo'), - 'icon' => 'dashicons-wu-edit', - ), - 'admin theme' => array( - 'title' => __('Admin Themes', 'wp-ultimo'), - 'icon' => 'dashicons-wu-palette', - ), - 'monetization' => array( - 'title' => __('Monetization', 'wp-ultimo'), - 'icon' => 'dashicons-wu-credit', - ), - 'migrators' => array( - 'title' => __('Migrators', 'wp-ultimo'), - 'icon' => 'dashicons-wu-publish', - ), - 'separator' => array( - 'separator' => true, - ), - 'marketplace' => array( - 'title' => __('Marketplace', 'wp-ultimo'), - 'icon' => 'dashicons-wu-shop', - ), - ); - - } // end get_sections; - - /** - * Default handler for step submission. Simply redirects to the next step. - * - * @since 2.0.0 - * @return void - */ - public function default_handler() { - - WP_Ultimo()->settings->save_settings($_POST); - - wp_redirect(add_query_arg('updated', 1, wu_get_current_url())); - - exit; - - } // end default_handler; - -} // end class Addons_Admin_Page; diff --git a/inc/admin-pages/class-migration-alert-admin-page.php b/inc/admin-pages/class-migration-alert-admin-page.php index e0f5bb3..a9a993b 100644 --- a/inc/admin-pages/class-migration-alert-admin-page.php +++ b/inc/admin-pages/class-migration-alert-admin-page.php @@ -12,12 +12,6 @@ namespace WP_Ultimo\Admin_Pages; // Exit if accessed directly defined('ABSPATH') || exit; -use \WP_Ultimo\License; -use \WP_Ultimo\Installers\Migrator; -use \WP_Ultimo\Installers\Core_Installer; -use \WP_Ultimo\Installers\Default_Content_Installer; -use \WP_Ultimo\Logger; - /** * WP Multisite WaaS Dashboard Admin Page. */ diff --git a/inc/admin-pages/class-rollback-admin-page.php b/inc/admin-pages/class-rollback-admin-page.php deleted file mode 100644 index 7bf8f30..0000000 --- a/inc/admin-pages/class-rollback-admin-page.php +++ /dev/null @@ -1,170 +0,0 @@ - 'capability_here' - * To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here' - * To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here' - * - * @since 2.0.0 - * @var array - */ - protected $supported_panels = array( - 'network_admin_menu' => 'manage_network', - ); - - /** - * Creates the page with the necessary hooks. - * - * @since 1.8.2 - */ - public function __construct() { - - if (WP_Ultimo()->is_loaded() === false) { - - $this->highlight_menu_slug = 'wp-ultimo-setup'; - - } // end if; - - parent::__construct(); - - } // end __construct; - - /** - * Returns the title of the page. - * - * @since 2.0.0 - * @return string Title of the page. - */ - public function get_title() { - - return __('Rollback', 'wp-ultimo'); - - } // end get_title; - - /** - * Returns the title of menu for this page. - * - * @since 2.0.0 - * @return string Menu label of the page. - */ - public function get_menu_title() { - - return __('Rollback', 'wp-ultimo'); - - } // end get_menu_title; - - /** - * Allows admins to rename the sub-menu (first item) for a top-level page. - * - * @since 2.0.0 - * @return string False to use the title menu or string with sub-menu title. - */ - public function get_submenu_title() { - - return __('Rollback', 'wp-ultimo'); - - } // end get_submenu_title; - - /** - * Registers the necessary scripts. - * - * @since 2.0.0 - * @return void - */ - public function register_scripts() { - /* - * If Ultimo is not yet loaded, we need to register vue. - */ - if (WP_Ultimo()->is_loaded() === false) { - - wp_register_script('wu-vue', wu_get_asset('lib/vue.js', 'js'), false, wu_get_version()); - - } // end if; - - wp_enqueue_script('wu-vue'); - - } // end register_scripts; - - /** - * Every child class should implement the output method to display the contents of the page. - * - * @since 1.8.2 - * @return void - */ - public function output() { - - wu_get_template('rollback/rollback', array( - 'n' => \WP_Ultimo\License::get_instance()->get_license_key(), - 'versions' => \WP_Ultimo\Rollback\Rollback::get_instance()->get_available_versions(), - 'page' => $this, - )); - - } // end output; - -} // end class Rollback_Admin_Page; diff --git a/inc/admin-pages/class-settings-admin-page.php b/inc/admin-pages/class-settings-admin-page.php index ca2335a..3f9b6ba 100644 --- a/inc/admin-pages/class-settings-admin-page.php +++ b/inc/admin-pages/class-settings-admin-page.php @@ -135,21 +135,11 @@ class Settings_Admin_Page extends Wizard_Admin_Page { parent::register_widgets(); - wu_register_settings_side_panel('general', array( - 'title' => __('Add-ons', 'wp-ultimo'), - 'render' => array($this, 'render_addons_side_panel'), - )); - wu_register_settings_side_panel('login-and-registration', array( 'title' => __('Checkout Forms', 'wp-ultimo'), 'render' => array($this, 'render_checkout_forms_side_panel'), )); - wu_register_settings_side_panel('integrations', array( - 'title' => __('Add-ons', 'wp-ultimo'), - 'render' => array($this, 'render_addons_side_panel'), - )); - wu_register_settings_side_panel('sites', array( 'title' => __('Template Previewer', 'wp-ultimo'), 'render' => array($this, 'render_site_template_side_panel'), @@ -165,11 +155,6 @@ class Settings_Admin_Page extends Wizard_Admin_Page { 'render' => array($this, 'render_invoice_side_panel'), )); - wu_register_settings_side_panel('payment-gateways', array( - 'title' => __('Additional Gateways', 'wp-ultimo'), - 'render' => array($this, 'render_gateways_addons_side_panel'), - )); - wu_register_settings_side_panel('emails', array( 'title' => __('System Emails', 'wp-ultimo'), 'render' => array($this, 'render_system_emails_side_panel'), @@ -180,172 +165,8 @@ class Settings_Admin_Page extends Wizard_Admin_Page { 'render' => array($this, 'render_email_template_side_panel'), )); - wu_register_settings_side_panel('all', array( - 'title' => __('Your License', 'wp-ultimo'), - 'render' => array($this, 'render_account_side_panel'), - 'show' => array(\WP_Ultimo\License::get_instance(), 'is_not_whitelabel'), - )); - } // end register_widgets; - // phpcs:disable - - /** - * Renders the addons side panel - * - * @since 2.0.0 - * @return void - */ - public function render_addons_side_panel() { ?> - -
- - get_customer(); - - $license = \WP_Ultimo\License::get_instance()->get_license(); - - ?> - - - - - - - - 'manage_network', ); - /** - * The customer license, if it exists. - * - * @since 2.0.0 - * @var object - */ - public $license; - - /** - * The customer object, if it exists. - * - * @since 2.0.0 - * @var object - */ - public $customer; - /** * Is this an old install migrating. * @@ -202,10 +185,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page { parent::page_loaded(); - $this->license = \WP_Ultimo\License::get_instance()->get_license(); - - $this->customer = \WP_Ultimo\License::get_instance()->get_customer(); - $this->set_settings(); } // end page_loaded; @@ -354,8 +333,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page { */ public function get_sections() { - $allowed = \WP_Ultimo\License::get_instance()->allowed(); - $sections = array( 'welcome' => array( 'title' => __('Welcome', 'wp-ultimo'), @@ -434,7 +411,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page { $message_lines = array( 'Hi there,', sprintf('My name is %s.', $user->display_name), - sprintf('License Key: %s', License::get_instance()->get_license_key()), 'I tried to migrate my network from version 1 to version 2, but was not able to do it successfully...', 'Here are the error messages I got:', sprintf('```%s%s%s```', PHP_EOL, implode(PHP_EOL, $errors), PHP_EOL), @@ -603,64 +579,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page { } // end get_payment_settings; - /** - * Shows the description and possible error. - * - * @since 2.0.0 - * @return string - */ - public function _desc_and_validation_error() { - - ob_start(); - - echo __('Your license key starts with "sk_".', 'wp-ultimo'); - - $error = wu_request('error', false); - - if ($error) : - - // phpcs:disable ?> - - - - — - - - -allowed()) : // phpcs:ignore ?> - - - Settings Page.', 'wp-ultimo'), $this->customer->first, wu_network_admin_url('wp-ultimo-settings')); ?> - - - get_customer(); - $license = \WP_Ultimo\License::get_instance()->get_license(); - - if (!empty($customer) && !empty($license)) { - - $array_license_data = array( - 'username' => array( - 'tooltip' => '', - 'title' => 'Username', - 'value' => vsprintf('%s %s', array( $customer->first, $customer->last ) ), - ), - 'email' => array( - 'tooltip' => '', - 'title' => 'E-mail', - 'value' => $customer->email, - ), - 'license-key' => array( - 'tooltip' => '', - 'title' => 'License Key', - 'value' => substr_replace((string) $license->secret_key, str_repeat('*', 16), 4, 24), - ), - ); - - } // end if; - return apply_filters('wu_system_info_data', array( 'WordPress and System Settings' => array( 'wp-ultimo-version' => array( @@ -591,8 +565,6 @@ class System_Info_Admin_Page extends Base_Admin_Page { $wpultimo_settings ), 'Defined Constants' => $array_constants, - - 'License' => $array_license_data )); } // end get_data; diff --git a/inc/class-core-updates.php b/inc/class-core-updates.php deleted file mode 100644 index d3198cf..0000000 --- a/inc/class-core-updates.php +++ /dev/null @@ -1,348 +0,0 @@ -version = class_exists(\WP_Ultimo::class) ? \WP_Ultimo::VERSION : ''; - - /** - * As WP Multisite WaaS needs to load in wp-ultimo/ directory to work with Sunrise - * we can assume the plugin as wp-ultimo/wp-ultimo.php. if it's a mu-plugin - * we will assume as wp-ultimo.php. - * - * At this point WPMU_PLUGIN_DIR is not defined yet. - */ - $is_mu = strpos(__DIR__, '/mu-plugins/wp-multisite-waas/') !== false; - $this->plugin_id = $is_mu ? 'wp-multisite-waas.php' : 'wp-multisite-waas/wp-multisite-waas.php'; - $this->plugin_slug = 'wp-multisite-waas/wp-multisite-waas.php'; - - /** - * Check for a WP Multisite WaaS Core Updates. - */ - add_action('upgrader_process_complete', array($this, 'maybe_add_core_update_hooks'), 10, 2); - - /** - * Update process hooks. - */ - add_filter('plugins_api', array($this, 'get_plugin_info'), 20, 3); - add_filter('site_transient_update_plugins', array($this, 'check_for_update')); - add_action('upgrader_process_complete', array($this, 'purge_update_cache'), 10, 2); - - } // end init; - - /** - * Checks if a WP Multisite WaaS core update is being performed and triggers an action if that's the case. - * - * @since 2.0.0 - * - * @param \WP_Upgrader $u The upgrader instance. - * @param array $i Upgrade info. - * @return void - */ - public function maybe_add_core_update_hooks($u, $i) { - - $is_a_wp_ultimo_update = false; - - if (!empty($u->result) && in_array('wp-multisite-waas.php', $u->result['source_files'], true)) { - - $is_a_wp_ultimo_update = true; - - } elseif (isset($i['plugins']) && is_array($i['plugins'])) { - - if (in_array('wp-multisite-waas/wp-multisite-waas.php', $i['plugins'], true)) { - - $is_a_wp_ultimo_update = true; - - } // end if; - - } // end if; - - if ($is_a_wp_ultimo_update) { - - function_exists('wu_log_add') && wu_log_add('wp-ultimo-core', __('Updating WP Multisite WaaS Core...', 'wp-ultimo')); - - try { - - /** - * Triggers an action that be used to perform - * tasks on a core update. - * - * @since 2.0.0 - */ - do_action('wu_core_update'); - - } catch (\Throwable $exception) { - - // Nothing to do in here. - - } // end try; - - } // end if; - - } // end maybe_add_core_update_hooks; - - /** - * Override the WordPress request to return the correct plugin info. - * - * @see https://developer.wordpress.org/reference/hooks/plugins_api/ - * - * @since 2.4.0 - * - * @param false|object|array $result The result object or array. Default false. - * @param string $action The type of information being requested from the Plugin Install API. - * @param object $args Plugin API arguments. - * @return false|object|array - */ - public function get_plugin_info($result, $action, $args) { - - if ('plugin_information' !== $action) { - - return $result; - - } // end if; - - if ($this->plugin_slug !== $args->slug) { - - return $result; - - } // end if; - - $remote = $this->info_request(); - - if (!$remote || !$remote->success || empty($remote->update)) { - - return false; - - } // end if; - - $plugin_data = get_plugin_data(__FILE__); - - $result = $remote->update; - $result->name = $plugin_data['Name']; - $result->slug = $this->plugin_slug; - $result->sections = (array) $result->sections; - - return $result; - - } // end get_plugin_info; - - /** - * Override the WordPress request to check if an update is available. - * - * @see https://make.wordpress.org/core/2020/07/30/recommended-usage-of-the-updates-api-to-support-the-auto-updates-ui-for-plugins-and-themes-in-wordpress-5-5/ - * - * @since 2.4.0 - * - * @param object $transient The transient data. - * @return object - */ - public function check_for_update($transient) { - - if (empty($transient->checked)) { - - return $transient; - - } // end if; - - $res = (object) array( - 'id' => $this->plugin_id, - 'slug' => $this->plugin_slug, - 'plugin' => $this->plugin_id, - 'new_version' => $this->version, - 'url' => $this->plugin_url, - 'package' => '', - 'icons' => array(), - 'banners' => array(), - 'banners_rtl' => array(), - 'tested' => '', - 'requires_php' => '', - 'compatibility' => new \stdClass(), - ); - - $remote = $this->info_request(); - - if ( - $remote && $remote->success && !empty($remote->update) - && version_compare($this->version, $remote->update->version, '<') - ) { - - $res->new_version = $remote->update->version; - $res->package = property_exists($remote->update, 'download_url') ? $remote->update->download_url : ''; - - $transient->response[$res->plugin] = $res; - - } else { - - $transient->no_update[$res->plugin] = $res; - - } // end if; - - return $transient; - - } // end check_for_update; - - /** - * When the update is complete, purge the cache. - * - * @see https://developer.wordpress.org/reference/hooks/upgrader_process_complete/ - * - * @since 2.4.0 - * - * @param WP_Upgrader $upgrader The upgrader instance. - * @param array $options Upgrade info. - * @return void - */ - public function purge_update_cache($upgrader, $options) { - - if ( - $this->cache_allowed - && 'update' === $options['action'] - && 'plugin' === $options['type'] - && !empty($options['plugins']) - ) { - - foreach ($options['plugins'] as $plugin) { - - if ($plugin === $this->plugin_id) { - - delete_transient($this->cache_key); - - } // end if; - - } // end foreach; - - } // end if; - - } // end purge_update_cache; - - /** - * Fetch the update info from the remote server. - * - * @since 2.4.0 - * - * @return object|bool - */ - protected function info_request() { - - $license = \WP_Ultimo\License::get_instance(); - - $license_key = $license->get_license_key(); - - $remote = get_transient($this->cache_key); - - if (false !== $remote && $this->cache_allowed) { - - if ('error' === $remote) { - - return false; - - } // end if; - - return json_decode($remote); - - } // end if; - - // WP Ultimo endpoint - $api_url = 'https://licenses.nextpress.us/api/meta/wp-ultimo/'; - - if ($license_key) { - - $api_url = add_query_arg(array( - 'license_key' => rawurlencode($license_key), - ), $api_url); - - } // end if; - - $remote = wp_remote_get( - $api_url, - array( - 'timeout' => 5, - ) - ); - - if ( - is_wp_error($remote) - || 200 !== wp_remote_retrieve_response_code($remote) - || empty(wp_remote_retrieve_body($remote)) - ) { - - set_transient($this->cache_key, 'error', MINUTE_IN_SECONDS * 10); - - return false; - - } // end if; - - $payload = wp_remote_retrieve_body($remote); - - $response = new \stdClass(); - $response->success = true; - $response->update = json_decode($payload); - - set_transient($this->cache_key, json_encode($response), DAY_IN_SECONDS); - - return $response; - - } // end info_request; - -} // end class Core_Updates; diff --git a/inc/class-license.php b/inc/class-license.php deleted file mode 100644 index 4184270..0000000 --- a/inc/class-license.php +++ /dev/null @@ -1,692 +0,0 @@ -register_forms(); - - $this->setup_activator(); - - } // end init; - /** - * Request a support signature to the API. - * - * This confirms ownership of the license and allows us - * to display past conversations with confidence that the - * customer is who they say they is. - * - * @since 2.0.7 - * @return string|\WP_Error - */ - public function request_support_signature() { - - $signature_url = wu_with_license_key('https://api.wpultimo.com/signature'); - - $response = wp_remote_get($signature_url); - - if (is_wp_error($response)) { - - return $response; - - } // end if; - - $body = wp_remote_retrieve_body($response); - - $data = (array) json_decode($body, true); - - $signature = wu_get_isset($data, 'signature', 'no_signature'); - - return $signature; - - } // end request_support_signature; - - /** - * Registers the form and handler to license activation. - * - * @since 2.0.0 - * @return void - */ - public function register_forms() { - - if (function_exists('wu_register_form')) { - - add_filter('removable_query_args', array($this, 'add_activation_to_removable_query_list')); - - add_action('load-wp-ultimo_page_wp-ultimo-settings', array($this, 'add_successful_activation_message')); - - wu_register_form('license_activation', array( - 'render' => array($this, 'render_activation_form'), - 'handler' => array($this, 'handle_activation_form'), - )); - - wu_register_form('license_deactivation', array( - 'render' => array($this, 'render_deactivation_form'), - 'handler' => array($this, 'handle_deactivation_form'), - )); - - } // end if; - - } // end register_forms; - - /** - * Adds our query arg to the removable list. - * - * @since 2.0.0 - * - * @param array $args The current list of removable query args. - * @return array - */ - public function add_activation_to_removable_query_list($args) { - - $args[] = 'wp-ultimo-activation'; - - return $args; - - } // end add_activation_to_removable_query_list; - - /** - * Adds a successful message when activation is successful. - * - * @since 2.0.0 - * @return void - */ - public function add_successful_activation_message() { - - if (wu_request('wp-ultimo-activation') === 'success') { - - WP_Ultimo()->notices->add(__('WP Multisite WaaS successfully activated!', 'wp-ultimo'), 'success', 'network-admin', false, array()); - - } // end if; - - } // end add_successful_activation_message; - - /** - * Render the license activation form. - * - * @since 2.0.0 - * @return void - */ - public function render_activation_form() { - - $fields = array( - 'license_key' => array( - 'type' => 'text', - 'title' => __('Your License Key', 'wp-ultimo'), - 'desc' => __('Enter your license key here. You received your license key via email when you completed your purchase. Your license key usually starts with "sk_".', 'wp-ultimo'), - 'placeholder' => __('e.g. sk_******************', 'wp-ultimo'), - ), - 'submit_button' => array( - 'type' => 'submit', - 'title' => __('Activate', 'wp-ultimo'), - 'placeholder' => __('Activate', 'wp-ultimo'), - 'value' => 'save', - 'classes' => 'button button-primary wu-w-full', - 'wrapper_classes' => 'wu-items-end', - 'html_attr' => array( - 'v-bind:disabled' => '!confirmed', - ), - ), - ); - - $form = new \WP_Ultimo\UI\Form('total-actions', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - )); - - $form->render(); - - } // end render_activation_form; - - /** - * Handle license activation form submission. - * - * @since 2.0.0 - * @return void - */ - public function handle_activation_form() { - - $license = License::get_instance(); - - $activation_results = $license->activate(wu_request('license_key')); - - if (isset($activation_results->error)) { - - $activation_results = new \WP_Error('error', $activation_results->error); - - } // end if; - - if (is_wp_error($activation_results)) { - - wp_send_json_error($activation_results); - - } // end if; - - wp_send_json_success(array( - 'redirect_url' => add_query_arg('wp-ultimo-activation', 'success', wu_get_current_url()), - )); - - } // end handle_activation_form; - - /** - * Render the license activation form. - * - * @since 2.0.0 - * @return void - */ - public function render_deactivation_form() { - - $fields = array( - 'confirm' => array( - 'type' => 'toggle', - 'title' => __('Confirm the remove of your license key', 'wp-ultimo'), - 'desc' => __('This action can not be undone.', 'wp-ultimo'), - 'html_attr' => array( - 'v-model' => 'confirmed', - ), - ), - 'submit_button' => array( - 'type' => 'submit', - 'title' => __('Remove License', 'wp-ultimo'), - 'value' => 'save', - 'classes' => 'button button-primary wu-w-full', - 'wrapper_classes' => 'wu-items-end', - 'html_attr' => array( - 'v-bind:disabled' => '!confirmed', - ), - ), - ); - - $form = new \WP_Ultimo\UI\Form('total-actions', $fields, array( - 'views' => 'admin-pages/fields', - 'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', - 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', - 'html_attr' => array( - 'data-wu-app' => 'true', - 'data-state' => wu_convert_to_state(array( - 'confirmed' => false, - )), - ), - )); - - $form->render(); - - } // end render_deactivation_form; - - /** - * Handle license activation form submission. - * - * @since 2.0.0 - * @return void - */ - public function handle_deactivation_form() { - - $license = License::get_instance(); - - if (!$this->deactivate()) { - - $activation_results = new \WP_Error('error', __('Error deactivating license.', 'wp-ultimo')); - - wp_send_json_error($activation_results); - - } // end if; - - wp_send_json_success(array( - 'redirect_url' => wu_get_current_url(), - )); - - } // end handle_deactivation_form; - - /** - * Sets up the activator instance. - * - * @since 2.0.0 - * @return void - */ - protected function setup_activator() { - - if (!defined('WP_ULTIMO_PLUGIN_DIR') || defined('WP_TESTS_MULTISITE')) { - - return; - - } // end if; - - if (!(is_main_site()) && !is_network_admin()) { - - return; - - } // end if; - - if (!$this->allowed() && defined('WP_ULTIMO_LICENSE_KEY') && WP_ULTIMO_LICENSE_KEY) { - /** - * Checks if init has run. If so, delay execution. - * - * @since 2.0.11 - */ - $action = did_action('init') ? 'shutdown' : 'init'; - - add_action($action, function() { - - $this->activate(WP_ULTIMO_LICENSE_KEY); - - }); - - } // end if; - - } // end setup_activator; - /** - * Tries to perform a license activation. - * - * @since 2.0.0 - * - * @param string $license_key The customer license key. - * @return bool|\WP_Error - */ - public function activate($license_key) { - - if (!$license_key) { - - return new \WP_Error('missing-license', __('License key is required.', 'wp-ultimo')); - - } // end if; - - try { - - $response = $this->license_api_request('/activate', array( - 'license_key' => $license_key, - 'instance_name' => defined('DOMAIN_CURRENT_SITE') ? DOMAIN_CURRENT_SITE : get_home_url(wu_get_main_site_id()), - ), 'POST'); - - if ($response->error) { - - return new \WP_Error('invalid-license', $response->error); - - } // end if; - - wu_save_option($this->option_key, $response); - - } catch (\Throwable $e) { - - wu_log_add('license', $e->getMessage(), LogLevel::ERROR); - - return new \WP_Error('general-error', __('An unexpected error occurred.', 'wp-ultimo')); - - } // end try; - - return true; - - } // end activate; - - /** - * Deactivated the current license. - * - * @since 2.0.11 - * @return bool - */ - public function deactivate(): bool { - - try { - - $license = wu_get_option($this->option_key); - - if (!$license) { - - return false; - - } // end if; - - $response = $this->license_api_request('/deactivate', array( - 'license_key' => $license->secret_key, - 'instance_id' => $license->instance, - ), 'POST'); - - wu_save_option($this->option_key, false); - - } catch (\Throwable $e) { - - return false; - - } // end try; - - return true; - - } // end deactivate; - - /** - * Checks if this copy of the plugin was activated. - * - * @since 2.0.0 - * - * @todo: Check if we should use the plan here and if we should use the product ID. - * - * @param string $plan Plan to check against. - * @return bool - */ - public function allowed($plan = 'wpultimo') { - - $license = $this->get_license(); - - if ($this->get_license() === false) { - - return false; - - } // end if; - - return $license->valid; - - } // end allowed; - - /** - * Returns the customer of the current license. - * - * @since 2.0.0 - * @return object|false - */ - public function get_customer() { - - $license = $this->get_license(); - - if ($license === false) { - - return false; - - } // end if; - - return $license->customer; - - } // end get_customer; - - /** - * Returns the license object. - * - * @since 2.0.0 - * @return object|false - */ - public function get_license() { - - $license = wu_get_option($this->option_key, null) ?? $this->get_fs_license(); - - if (!$license) { - - return false; - - } // end if; - - if ($license->timestamp + 86400 < time()) { - - try { - - $validated_license = $this->license_api_request('/validate', array( - 'license_key' => $license->secret_key, - 'instance_id' => $license->instance, - ), 'POST'); - - } catch (\Throwable $e) { - - wu_log_add('license', $e->getMessage(), LogLevel::ERROR); - - return false; - - } // end try; - - $validated_license->secret_key = $license->secret_key; - $validated_license->instance = $license->instance; - - wu_save_option($this->option_key, $validated_license); - - $license = $validated_license; - - } // end if; - - return $license; - - } // end get_license; - - /** - * Returns a license based om freemius license. - * - * @return object|false - */ - protected function get_fs_license() { - - $account = get_blog_option(get_main_site_id(), 'fs_accounts'); - - if (empty($account) || !isset($account['sites']) || !isset($account['sites']['wp-ultimo'])) { - - return false; - - } // end if; - - $account_site = get_object_vars($account['sites']['wp-ultimo']); - $license_id = $account_site['license_id']; - $fs_accounts = get_site_option('fs_accounts', array()); - $fs_id = 2963; - - if (empty($fs_accounts) || !isset($fs_accounts['all_licenses']) || !isset($fs_accounts['all_licenses'][$fs_id])) { - - return false; - - } // end if; - - $licenses = $fs_accounts['all_licenses'][$fs_id]; - - foreach ($licenses as $fs_license) { - - $fs_license = get_object_vars($fs_license); - - if ($fs_license['id'] === $license_id) { - - $license = new \stdClass(); - - $license->timestamp = 0; - $license->secret_key = $fs_license['secret_key']; - $license->instance = $fs_license['id']; - - return $license; - - } // end if; - - } // end foreach; - - return false; - - } // end get_fs_license; - /** - * Returns the license key used to activate this copy. - * - * @since 2.0.0 - * @return string|false - */ - public function get_license_key() { - - $license = $this->get_license(); - - return $license && $license->secret_key ? $license->secret_key : false; - - } // end get_license_key; - - /** - * Checks if the white-label mode was activated. - * - * @since 2.0.0 - * @return boolean - */ - public function is_whitelabel() { - - $license = $this->get_license(); - - return $license ? $license->is_whitelabeled : false; - - } // end is_whitelabel; - - /** - * Inverse of the is_whitelabel. Used in callbacks. - * - * @since 2.0.0 - * @return boolean - */ - public function is_not_whitelabel() { - - return !$this->is_whitelabel(); - - } // end is_not_whitelabel; - /** - * Returns the license key set as constant if it exists. - * - * @since 2.0.0 - * @return false|string - */ - public function has_license_key_defined_as_constant() { - - return defined('WP_ULTIMO_LICENSE_KEY') ? WP_ULTIMO_LICENSE_KEY : false; - - } // end has_license_key_defined_as_constant; - - /** - * Sends a request to license API - * - * @since 2.4.0 - * @param string $endpoint Endpoint to send the call to. - * @param array $data Array containing the params to the call. - * @param string $method HTTP method to use. - * @return object - */ - protected function license_api_request(string $endpoint, array $data, $method = 'GET') { - - $data['version'] = wu_get_isset($data, 'version', wu_get_version()); - - $url = 'https://licenses.nextpress.us/api/licenses' . $endpoint; - - $post_fields = array( - 'blocking' => true, - 'timeout' => 10, - 'method' => $method, - 'body' => $data, - 'headers' => array( - 'Content-Type' => 'application/x-www-form-urlencoded', - 'Accept' => 'application/json', - ), - ); - - if ($method === 'GET') { - - $url = add_query_arg($data, $url); - $post_fields['body'] = null; - - } // end if; - - $response = wp_remote_request($url, $post_fields); - - if (is_wp_error($response)) { - - throw new \Exception($response->get_error_message()); - - } // end if; - - $body = json_decode(wp_remote_retrieve_body($response)); - - if (json_last_error() !== JSON_ERROR_NONE) { - - throw new \Exception(json_last_error_msg()); - - } // end if; - - return $this->build_license_from_response($body); - - } // end license_api_request; - - /** - * Build a license object from the API response. - * - * @since 2.4.0 - * - * @param object $response Response from the API. - * @return object - */ - protected function build_license_from_response(object $response): object { - - $status = array( - 'active', - 'trial', - 'lifetime', - 'golden-ticket', - ); - - $license = new \stdClass(); - $license->is_whitelabeled = false; - $license->timestamp = time(); - $license->secret_key = property_exists($response, 'key') ? $response->key : null; - $license->valid = property_exists($response, 'status') ? in_array($response->status, $status, true) : false; - $license->instance = property_exists($response, 'instance') ? $response->instance : null; - $license->error = property_exists($response, 'error') ? $response->error : null; - - $name = explode(' ', property_exists($response, 'customer') ? $response->customer->name : '', 2); - - $license->customer = new \stdClass(); - $license->customer->email = property_exists($response, 'customer') ? $response->customer->email : null; - $license->customer->first = $name[0]; - $license->customer->last = isset($name[1]) ? $name[1] : ''; - - if (!$license->valid) { - - $response->status = property_exists($response, 'status') ? $response->status : null; - - switch ($response->status) { - case 'expired': - $license->error = __('License key expired', 'wp-ultimo'); - break; - case 'limit-quota': - $license->error = __('License key limit reached', 'wp-ultimo'); - break; - default: - $license->error = __('Invalid license key', 'wp-ultimo'); - break; - } - - } // end if; - - return $license; - - } // end build_license_from_response; - -} // end class License; diff --git a/inc/class-sunrise.php b/inc/class-sunrise.php index 8895f4e..9ef6647 100644 --- a/inc/class-sunrise.php +++ b/inc/class-sunrise.php @@ -177,11 +177,6 @@ class Sunrise { */ \WP_Ultimo\Sunrise::load_dependencies(); - /* - * Handles WP Multisite WaaS core updates - */ - \WP_Ultimo\Core_Updates::get_instance(); - /* * Adds backwards compatibility code for the domain mapping. */ diff --git a/inc/class-unsupported.php b/inc/class-unsupported.php deleted file mode 100644 index deec84f..0000000 --- a/inc/class-unsupported.php +++ /dev/null @@ -1,388 +0,0 @@ - array('plugins_loaded', 'wu_wc_init', 10, true), - '\WU_Multiple_Logins' => false, - '\WP_Ultimo_Blocks' => array('plugins_loaded', 'wp_ultimo_blocks_init', 20, false), - '\WU_Ultimo_Domain_Seller' => array('plugins_loaded', 'wu_domain_seller_init', 1, false), - '\WP_Ultimo_PS_Migrator' => array('plugins_loaded', 'wu_ps_migrator_init', 1, false), - ); - - /** - * List of supported add-ons with upgrades available. - * - * @since 2.0.5 - */ - $supported_but_upgradable = array( - '\WP_Ultimo_PTM', - ); - - foreach ($unsupported_v1_addons as $base_class => $init_info) { - - if (class_exists($base_class)) { - - list($hook, $function, $priority, $upgradeable) = $init_info; - - self::$unloaded[] = $base_class; - - if ($hook) { - - remove_action($hook, $function, $priority); - - } // end if; - - if ($upgradeable) { - - self::$to_upgrade[] = $base_class; - - } // end if; - - } // end if; - - } // end foreach; - - foreach ($supported_but_upgradable as $base_class) { - - if (class_exists($base_class)) { - - self::$upgradeable[] = $base_class; - - self::$to_upgrade[] = $base_class; - - } // end if; - - } // end foreach; - - } // end unload_unsupported_addons; - - /** - * Install the newer version of the plugin updater for add-ons that can already be updated. - * - * @since 2.0.5 - * @return void - */ - public static function force_updater() { - - global $pagenow; - - if ($pagenow !== 'plugins.php') { - - return; - - } - - if (WP_Ultimo()->is_loaded() === false || !is_network_admin()) { - - return; - - } // end if; - - $license_key = \WP_Ultimo\License::get_instance()->get_license_key(); - - if (!$license_key) { - - return; - - } // end if; - - foreach (self::$to_upgrade as $addon_to_upgrade) { - - $info = self::replace_with($addon_to_upgrade); - - if ($info && wu_get_isset($info, 'slug', false)) { - - try { - - $url = add_query_arg(array( - 'action' => 'get_metadata', - 'slug' => $info['slug'], - 'beta_program' => 2, - ), 'https://versions.nextpress.co/updates/'); - - $url = wu_with_license_key($url); - - $guess_plugin_path = WP_PLUGIN_DIR . '/' . $info['slug'] . '/' . $info['slug'] . '.php'; - - if (file_exists($guess_plugin_path)) { - - $checker = \Puc_v4_Factory::buildUpdateChecker($url, $guess_plugin_path, $info['slug']); - - } // end if; - - } catch (\Throwable $exception) { - - // Nothing to do. - - } // end try; - - } // end if; - - } // end foreach; - - } // end force_updater; - - /** - * Maybe add necessary admin notices about installing WP Multisite WaaS version 2. - * - * @since 2.0.5 - * @return void - */ - public static function maybe_add_notices() { - - if (wu_request('page') === 'wp-ultimo-setup') { - - return; - - } // end if; - - $message = array(); - - $plugins_page_a = sprintf('%s', network_admin_url('plugins.php'), __('plugins', 'wp-ultimo')); - - /** - * Firstly, lets check if we already run the migration. - * We found some cases that the migration not worked as expected and the option checked in Migrator::is_migration_done() - * is not added. So for this verification we also need to see if we already run the setup. - */ - if (Migrator::is_migration_done() === false && Requirements::run_setup() === false) { - - $message[] = '' . __('It seems that you have not run the WP Multisite WaaS upgrader yet. That is the first thing we need to do.', 'wp-ultimo') . '
'; - - $message[] = sprintf('%s', network_admin_url('admin.php?page=wp-ultimo-setup'), __('Visit the Installer to finish the upgrade →', 'wp-ultimo')); - - } // end if; - - if (count(self::$unloaded) > 0) { - - if ($message) { - - $message[] = '' . __('To make sure you do not experience any crashes on your network, we checked the add-ons installed and deactivated the ones that could cause problems in their currently installed version - or that are no longer supported.', 'wp-ultimo') . '
' . __('These add-ons include:', 'wp-ultimo') . '
' . __('Other add-ons that you have installed at the moment are still supported, but have new versions with full compatibility with version 2.0:', 'wp-ultimo') . '
' . __('Thanks for updating to WP Multisite WaaS version 2.0!', 'wp-ultimo') . '
'), $message); - - $message = implode('', $message); - - if (WP_Ultimo()->is_loaded()) { - - WP_Ultimo()->notices->add($message, 'warning', 'network-admin'); - - } else { - - self::fallback_admin_notice_display($message, 'warning'); - - } // end if; - - } // end maybe_add_notices; - - /** - * A fallback way to display admin notices when WP Multisite WaaS is not fully loaded yet. - * - * @since 2.0.5 - * - * @param string $message The message to display. - * @param string $type The type of notice. Defaults to warning. - * @return void - */ - public static function fallback_admin_notice_display($message, $type = 'warning') { - - printf('