From 0eb2c227027a1f9a0d1a2b845333f70bd59d39c0 Mon Sep 17 00:00:00 2001 From: edgar-melkonyan Date: Fri, 11 Dec 2020 20:51:30 +0400 Subject: [PATCH 1/2] [class] [freemius] Get and store whitelisted_domains data when a sync event is happening. --- includes/class-freemius.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/class-freemius.php b/includes/class-freemius.php index 5d4b50fd8..3b9206e9e 100755 --- a/includes/class-freemius.php +++ b/includes/class-freemius.php @@ -20346,6 +20346,14 @@ private function _sync_plugin_license( $is_site_level_sync = ( $is_context_single_site || fs_is_blog_admin() || ! $this->_is_network_active ); + // Get whitelisted domains. + $whitelisted_domains = $this->get_user_localhost_sites(); + + // Store whitelisted domains to $_accounts. + if (is_object($whitelisted_domains)) { + self::$_accounts->set_option( 'whitelisted_domains', $whitelisted_domains->localhost_sites ); + } + if ( ! $send_installs_update ) { $site = $this->_site; } else { @@ -25335,5 +25343,15 @@ function add_show_pending( $path ) { return $path . ( false !== strpos( $path, '?' ) ? '&' : '?' ) . 'show_pending=true'; } + /** + * @author Edgar Melkonyan + * + * @return stdClass|false + */ + function get_user_localhost_sites() + { + return $this->get_api_plugin_scope()->get("/users/{$this->_user->id}/localhost_site"); + } + #endregion } From f2a4700b68ab80416651f20279c329f9926011fa Mon Sep 17 00:00:00 2001 From: edgar-melkonyan Date: Fri, 11 Dec 2020 20:52:38 +0400 Subject: [PATCH 2/2] [class] [fs] [site] Updated is_localhost_by_address(), to check if a subdomain is in the whitelisted domains list. --- includes/entities/class-fs-site.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/entities/class-fs-site.php b/includes/entities/class-fs-site.php index fd9747668..471ca5964 100755 --- a/includes/entities/class-fs-site.php +++ b/includes/entities/class-fs-site.php @@ -145,6 +145,19 @@ static function is_localhost_by_address( $url ) { $subdomain = $url_parts['host']; + // Get whitelisted domains list. + $accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true ); + $whitelisted_domains = $accounts->get_option('whitelisted_domains'); + + if (null !== $whitelisted_domains) { + // Checking if a subdomain is in the whitelisted domains list. + foreach ($whitelisted_domains as $whitelisted_domain) { + if ($subdomain === $whitelisted_domain->domain) { + return true; + } + } + } + return ( // Starts with. fs_starts_with( $subdomain, 'local.' ) ||