| @@ 73-125 (lines=53) @@ | ||
| 70 | * |
|
| 71 | * @return bool|WP_Error |
|
| 72 | */ |
|
| 73 | public static function is_usable_domain( $domain, $extra = array() ) { |
|
| 74 | ||
| 75 | // If it's empty, just fail out. |
|
| 76 | if ( ! $domain ) { |
|
| 77 | return new WP_Error( 'fail_domain_empty', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is empty.', 'jetpack' ), $domain ) ); |
|
| 78 | } |
|
| 79 | ||
| 80 | /** |
|
| 81 | * Skips the usuable domain check when connecting a site. |
|
| 82 | * |
|
| 83 | * Allows site administrators with domains that fail gethostname-based checks to pass the request to WP.com |
|
| 84 | * |
|
| 85 | * @since 4.1.0 |
|
| 86 | * |
|
| 87 | * @param bool If the check should be skipped. Default false. |
|
| 88 | */ |
|
| 89 | if ( apply_filters( 'jetpack_skip_usuable_domain_check', false ) ) { |
|
| 90 | return true; |
|
| 91 | } |
|
| 92 | ||
| 93 | // None of the explicit localhosts. |
|
| 94 | $forbidden_domains = array( |
|
| 95 | 'wordpress.com', |
|
| 96 | 'localhost', |
|
| 97 | 'localhost.localdomain', |
|
| 98 | '127.0.0.1', |
|
| 99 | 'local.wordpress.test', // VVV |
|
| 100 | 'local.wordpress-trunk.test', // VVV |
|
| 101 | 'src.wordpress-develop.test', // VVV |
|
| 102 | 'build.wordpress-develop.test', // VVV |
|
| 103 | ); |
|
| 104 | if ( in_array( $domain, $forbidden_domains ) ) { |
|
| 105 | return new WP_Error( 'fail_domain_forbidden', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is in the forbidden array.', 'jetpack' ), $domain ) ); |
|
| 106 | } |
|
| 107 | ||
| 108 | // No .test or .local domains |
|
| 109 | if ( preg_match( '#\.(test|local)$#i', $domain ) ) { |
|
| 110 | return new WP_Error( 'fail_domain_tld', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it uses an invalid top level domain.', 'jetpack' ), $domain ) ); |
|
| 111 | } |
|
| 112 | ||
| 113 | // No WPCOM subdomains |
|
| 114 | if ( preg_match( '#\.wordpress\.com$#i', $domain ) ) { |
|
| 115 | return new WP_Error( 'fail_subdomain_wpcom', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is a subdomain of WordPress.com.', 'jetpack' ), $domain ) ); |
|
| 116 | } |
|
| 117 | ||
| 118 | // If PHP was compiled without support for the Filter module (very edge case) |
|
| 119 | if ( ! function_exists( 'filter_var' ) ) { |
|
| 120 | // Just pass back true for now, and let wpcom sort it out. |
|
| 121 | return true; |
|
| 122 | } |
|
| 123 | ||
| 124 | return true; |
|
| 125 | } |
|
| 126 | } |
|
| 127 | ||
| @@ 429-481 (lines=53) @@ | ||
| 426 | * |
|
| 427 | * @return bool|WP_Error |
|
| 428 | */ |
|
| 429 | public function is_usable_domain( $domain, $extra = array() ) { |
|
| 430 | ||
| 431 | // If it's empty, just fail out. |
|
| 432 | if ( ! $domain ) { |
|
| 433 | return new WP_Error( 'fail_domain_empty', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is empty.', 'jetpack' ), $domain ) ); |
|
| 434 | } |
|
| 435 | ||
| 436 | /** |
|
| 437 | * Skips the usuable domain check when connecting a site. |
|
| 438 | * |
|
| 439 | * Allows site administrators with domains that fail gethostname-based checks to pass the request to WP.com |
|
| 440 | * |
|
| 441 | * @since 4.1.0 |
|
| 442 | * |
|
| 443 | * @param bool If the check should be skipped. Default false. |
|
| 444 | */ |
|
| 445 | if ( apply_filters( 'jetpack_skip_usuable_domain_check', false ) ) { |
|
| 446 | return true; |
|
| 447 | } |
|
| 448 | ||
| 449 | // None of the explicit localhosts. |
|
| 450 | $forbidden_domains = array( |
|
| 451 | 'wordpress.com', |
|
| 452 | 'localhost', |
|
| 453 | 'localhost.localdomain', |
|
| 454 | '127.0.0.1', |
|
| 455 | 'local.wordpress.test', // VVV |
|
| 456 | 'local.wordpress-trunk.test', // VVV |
|
| 457 | 'src.wordpress-develop.test', // VVV |
|
| 458 | 'build.wordpress-develop.test', // VVV |
|
| 459 | ); |
|
| 460 | if ( in_array( $domain, $forbidden_domains ) ) { |
|
| 461 | return new WP_Error( 'fail_domain_forbidden', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is in the forbidden array.', 'jetpack' ), $domain ) ); |
|
| 462 | } |
|
| 463 | ||
| 464 | // No .test or .local domains |
|
| 465 | if ( preg_match( '#\.(test|local)$#i', $domain ) ) { |
|
| 466 | return new WP_Error( 'fail_domain_tld', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it uses an invalid top level domain.', 'jetpack' ), $domain ) ); |
|
| 467 | } |
|
| 468 | ||
| 469 | // No WPCOM subdomains |
|
| 470 | if ( preg_match( '#\.WordPress\.com$#i', $domain ) ) { |
|
| 471 | return new WP_Error( 'fail_subdomain_wpcom', sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is a subdomain of WordPress.com.', 'jetpack' ), $domain ) ); |
|
| 472 | } |
|
| 473 | ||
| 474 | // If PHP was compiled without support for the Filter module (very edge case) |
|
| 475 | if ( ! function_exists( 'filter_var' ) ) { |
|
| 476 | // Just pass back true for now, and let wpcom sort it out. |
|
| 477 | return true; |
|
| 478 | } |
|
| 479 | ||
| 480 | return true; |
|
| 481 | } |
|
| 482 | } |
|
| 483 | ||