class-fs-site.php
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 | * @since 1.0.3 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | class FS_Site extends FS_Scope_Entity { |
| 14 | /** |
| 15 | * @var number |
| 16 | */ |
| 17 | public $site_id; |
| 18 | /** |
| 19 | * @var int |
| 20 | */ |
| 21 | public $blog_id; |
| 22 | /** |
| 23 | * @var number |
| 24 | */ |
| 25 | public $plugin_id; |
| 26 | /** |
| 27 | * @var number |
| 28 | */ |
| 29 | public $user_id; |
| 30 | /** |
| 31 | * @var string |
| 32 | */ |
| 33 | public $title; |
| 34 | /** |
| 35 | * @var string |
| 36 | */ |
| 37 | public $url; |
| 38 | /** |
| 39 | * @var string |
| 40 | */ |
| 41 | public $version; |
| 42 | /** |
| 43 | * @var string E.g. en-GB |
| 44 | */ |
| 45 | public $language; |
| 46 | /** |
| 47 | * @var string Platform version (e.g WordPress version). |
| 48 | */ |
| 49 | public $platform_version; |
| 50 | /** |
| 51 | * Freemius SDK version |
| 52 | * |
| 53 | * @author Leo Fajardo (@leorw) |
| 54 | * @since 1.2.2 |
| 55 | * |
| 56 | * @var string SDK version (e.g.: 1.2.2) |
| 57 | */ |
| 58 | public $sdk_version; |
| 59 | /** |
| 60 | * @var string Programming language version (e.g PHP version). |
| 61 | */ |
| 62 | public $programming_language_version; |
| 63 | /** |
| 64 | * @var number|null |
| 65 | */ |
| 66 | public $plan_id; |
| 67 | /** |
| 68 | * @var number|null |
| 69 | */ |
| 70 | public $license_id; |
| 71 | /** |
| 72 | * @var number|null |
| 73 | */ |
| 74 | public $trial_plan_id; |
| 75 | /** |
| 76 | * @var string|null |
| 77 | */ |
| 78 | public $trial_ends; |
| 79 | /** |
| 80 | * @since 1.0.9 |
| 81 | * |
| 82 | * @var bool |
| 83 | */ |
| 84 | public $is_premium = false; |
| 85 | /** |
| 86 | * @author Leo Fajardo (@leorw) |
| 87 | * |
| 88 | * @since 1.2.1.5 |
| 89 | * @deprecated Since 2.5.1 |
| 90 | * @todo Remove after a few releases. |
| 91 | * |
| 92 | * @var bool |
| 93 | */ |
| 94 | public $is_disconnected = false; |
| 95 | /** |
| 96 | * @since 2.0.0 |
| 97 | * |
| 98 | * @var bool |
| 99 | */ |
| 100 | public $is_active = true; |
| 101 | /** |
| 102 | * @since 2.0.0 |
| 103 | * |
| 104 | * @var bool |
| 105 | */ |
| 106 | public $is_uninstalled = false; |
| 107 | /** |
| 108 | * @author Edgar Melkonyan |
| 109 | * |
| 110 | * @since 2.4.2 |
| 111 | * |
| 112 | * @var bool |
| 113 | */ |
| 114 | public $is_beta; |
| 115 | |
| 116 | /** |
| 117 | * @param stdClass|bool $site |
| 118 | */ |
| 119 | function __construct( $site = false ) { |
| 120 | parent::__construct( $site ); |
| 121 | |
| 122 | if ( is_object( $site ) ) { |
| 123 | $this->plan_id = $site->plan_id; |
| 124 | } |
| 125 | |
| 126 | if ( ! is_bool( $this->is_disconnected ) ) { |
| 127 | $this->is_disconnected = false; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static function get_type() { |
| 132 | return 'install'; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @author Vova Feldman (@svovaf) |
| 137 | * @since 2.0.0 |
| 138 | * |
| 139 | * @param string $url |
| 140 | * |
| 141 | * @return bool |
| 142 | */ |
| 143 | static function is_localhost_by_address( $url ) { |
| 144 | if ( false !== strpos( $url, '127.0.0.1' ) || |
| 145 | false !== strpos( $url, 'localhost' ) |
| 146 | ) { |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | if ( ! fs_starts_with( $url, 'http' ) ) { |
| 151 | $url = 'http://' . $url; |
| 152 | } |
| 153 | |
| 154 | $url_parts = parse_url( $url ); |
| 155 | |
| 156 | $subdomain = $url_parts['host']; |
| 157 | |
| 158 | return ( |
| 159 | // Starts with. |
| 160 | fs_starts_with( $subdomain, 'local.' ) || |
| 161 | fs_starts_with( $subdomain, 'dev.' ) || |
| 162 | fs_starts_with( $subdomain, 'test.' ) || |
| 163 | fs_starts_with( $subdomain, 'stage.' ) || |
| 164 | fs_starts_with( $subdomain, 'staging.' ) || |
| 165 | |
| 166 | // Ends with. |
| 167 | fs_ends_with( $subdomain, '.dev' ) || |
| 168 | fs_ends_with( $subdomain, '.test' ) || |
| 169 | fs_ends_with( $subdomain, '.staging' ) || |
| 170 | fs_ends_with( $subdomain, '.local' ) || |
| 171 | fs_ends_with( $subdomain, '.example' ) || |
| 172 | fs_ends_with( $subdomain, '.invalid' ) || |
| 173 | // GoDaddy test/dev. |
| 174 | fs_ends_with( $subdomain, '.myftpupload.com' ) || |
| 175 | // ngrok tunneling. |
| 176 | fs_ends_with( $subdomain, '.ngrok.io' ) || |
| 177 | // wpsandbox. |
| 178 | fs_ends_with( $subdomain, '.wpsandbox.pro' ) || |
| 179 | // SiteGround staging. |
| 180 | fs_starts_with( $subdomain, 'staging' ) || |
| 181 | // WPEngine staging. |
| 182 | fs_ends_with( $subdomain, '.staging.wpengine.com' ) || |
| 183 | fs_ends_with( $subdomain, '.dev.wpengine.com' ) || |
| 184 | fs_ends_with( $subdomain, '.wpengine.com' ) || |
| 185 | fs_ends_with( $subdomain, '.wpenginepowered.com' ) || |
| 186 | // Pantheon |
| 187 | ( fs_ends_with( $subdomain, 'pantheonsite.io' ) && |
| 188 | ( fs_starts_with( $subdomain, 'test-' ) || fs_starts_with( $subdomain, 'dev-' ) ) ) || |
| 189 | // Cloudways |
| 190 | fs_ends_with( $subdomain, '.cloudwaysapps.com' ) || |
| 191 | // Kinsta |
| 192 | ( |
| 193 | ( fs_starts_with( $subdomain, 'stg-' ) || fs_starts_with( $subdomain, 'staging-' ) || fs_starts_with( $subdomain, 'env-' ) ) && |
| 194 | ( fs_ends_with( $subdomain, '.kinsta.com' ) || fs_ends_with( $subdomain, '.kinsta.cloud' ) ) |
| 195 | ) || |
| 196 | // DesktopServer |
| 197 | fs_ends_with( $subdomain, '.dev.cc' ) || |
| 198 | // Pressable |
| 199 | fs_ends_with( $subdomain, '.mystagingwebsite.com' ) || |
| 200 | // WPMU DEV |
| 201 | ( fs_ends_with( $subdomain, '.tempurl.host' ) || fs_ends_with( $subdomain, '.wpmudev.host' ) ) || |
| 202 | // Vendasta |
| 203 | ( fs_ends_with( $subdomain, '.websitepro-staging.com' ) || fs_ends_with( $subdomain, '.websitepro.hosting' ) ) || |
| 204 | // InstaWP |
| 205 | ( fs_ends_with( $subdomain, '.instawp.co' ) || fs_ends_with( $subdomain, '.instawp.link' ) || fs_ends_with( $subdomain, '.instawp.xyz' ) ) || |
| 206 | // 10Web Hosting |
| 207 | ( fs_ends_with( $subdomain, '-dev.10web.site' ) || fs_ends_with( $subdomain, '-dev.10web.cloud' ) ) |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * @author Leo Fajardo (@leorw) |
| 213 | * @since 2.9.1 |
| 214 | * |
| 215 | * @param string $host |
| 216 | * |
| 217 | * @return bool |
| 218 | */ |
| 219 | static function is_playground_wp_environment_by_host( $host ) { |
| 220 | // Services aimed at providing a WordPress sandbox environment. |
| 221 | $sandbox_wp_environment_domains = array( |
| 222 | // InstaWP |
| 223 | 'instawp.co', |
| 224 | 'instawp.link', |
| 225 | 'instawp.xyz', |
| 226 | |
| 227 | // TasteWP |
| 228 | 'tastewp.com', |
| 229 | |
| 230 | // WordPress Playground |
| 231 | 'playground.wordpress.net', |
| 232 | ); |
| 233 | |
| 234 | foreach ( $sandbox_wp_environment_domains as $domain) { |
| 235 | if ( |
| 236 | ( $host === $domain ) || |
| 237 | fs_ends_with( $host, '.' . $domain ) || |
| 238 | fs_ends_with( $host, '-' . $domain ) |
| 239 | ) { |
| 240 | return true; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | function is_localhost() { |
| 248 | return ( WP_FS__IS_LOCALHOST_FOR_SERVER || self::is_localhost_by_address( $this->url ) ); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Check if site in trial. |
| 253 | * |
| 254 | * @author Vova Feldman (@svovaf) |
| 255 | * @since 1.0.9 |
| 256 | * |
| 257 | * @return bool |
| 258 | */ |
| 259 | function is_trial() { |
| 260 | return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME ); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Check if user already utilized the trial with the current install. |
| 265 | * |
| 266 | * @author Vova Feldman (@svovaf) |
| 267 | * @since 1.0.9 |
| 268 | * |
| 269 | * @return bool |
| 270 | */ |
| 271 | function is_trial_utilized() { |
| 272 | return is_numeric( $this->trial_plan_id ); |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * @author Edgar Melkonyan |
| 277 | * |
| 278 | * @return bool |
| 279 | */ |
| 280 | function is_beta() { |
| 281 | return ( isset( $this->is_beta ) && true === $this->is_beta ); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * @author Leo Fajardo (@leorw) |
| 286 | * @since 2.5.1 |
| 287 | * |
| 288 | * @param string $site_url |
| 289 | * |
| 290 | * @return bool |
| 291 | */ |
| 292 | function is_clone( $site_url ) { |
| 293 | $clone_install_url = trailingslashit( fs_strip_url_protocol( $this->url ) ); |
| 294 | |
| 295 | return ( $clone_install_url !== $site_url ); |
| 296 | } |
| 297 | } |