debug-bar
7 years ago
3rd-party.php
6 years ago
bbpress.php
6 years ago
beaverbuilder.php
8 years ago
bitly.php
9 years ago
buddypress.php
10 years ago
class-jetpack-bbpress-rest-api.php
6 years ago
class.jetpack-amp-support.php
6 years ago
class.jetpack-modules-overrides.php
8 years ago
debug-bar.php
8 years ago
domain-mapping.php
6 years ago
polldaddy.php
9 years ago
qtranslate-x.php
8 years ago
vaultpress.php
6 years ago
woocommerce-services.php
6 years ago
woocommerce.php
6 years ago
wpml.php
8 years ago
domain-mapping.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | use Automattic\Jetpack\Constants; |
| 4 | |
| 5 | /** |
| 6 | * Class Jetpack_3rd_Party_Domain_Mapping |
| 7 | * |
| 8 | * This class contains methods that are used to provide compatibility between Jetpack sync and domain mapping plugins. |
| 9 | */ |
| 10 | class Jetpack_3rd_Party_Domain_Mapping { |
| 11 | |
| 12 | /** |
| 13 | * @var Jetpack_3rd_Party_Domain_Mapping |
| 14 | **/ |
| 15 | private static $instance = null; |
| 16 | |
| 17 | /** |
| 18 | * An array of methods that are used to hook the Jetpack sync filters for home_url and site_url to a mapping plugin. |
| 19 | * |
| 20 | * @var array |
| 21 | */ |
| 22 | static $test_methods = array( |
| 23 | 'hook_wordpress_mu_domain_mapping', |
| 24 | 'hook_wpmu_dev_domain_mapping' |
| 25 | ); |
| 26 | |
| 27 | static function init() { |
| 28 | if ( is_null( self::$instance ) ) { |
| 29 | self::$instance = new Jetpack_3rd_Party_Domain_Mapping; |
| 30 | } |
| 31 | |
| 32 | return self::$instance; |
| 33 | } |
| 34 | |
| 35 | private function __construct() { |
| 36 | add_action( 'plugins_loaded', array( $this, 'attempt_to_hook_domain_mapping_plugins' ) ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * This function is called on the plugins_loaded action and will loop through the $test_methods |
| 41 | * to try and hook a domain mapping plugin to the Jetpack sync filters for the home_url and site_url callables. |
| 42 | */ |
| 43 | function attempt_to_hook_domain_mapping_plugins() { |
| 44 | if ( ! Constants::is_defined( 'SUNRISE' ) ) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | $hooked = false; |
| 49 | $count = count( self::$test_methods ); |
| 50 | for ( $i = 0; $i < $count && ! $hooked; $i++ ) { |
| 51 | $hooked = call_user_func( array( $this, self::$test_methods[ $i ] ) ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * This method will test for a constant and function that are known to be used with Donncha's WordPress MU |
| 57 | * Domain Mapping plugin. If conditions are met, we hook the domain_mapping_siteurl() function to Jetpack sync |
| 58 | * filters for home_url and site_url callables. |
| 59 | * |
| 60 | * @return bool |
| 61 | */ |
| 62 | function hook_wordpress_mu_domain_mapping() { |
| 63 | if ( ! Constants::is_defined( 'SUNRISE_LOADED' ) || ! $this->function_exists( 'domain_mapping_siteurl' ) ) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' ); |
| 68 | add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' ); |
| 69 | |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * This method will test for a class and method known to be used in WPMU Dev's domain mapping plugin. If the |
| 75 | * method exists, then we'll hook the swap_to_mapped_url() to our Jetpack sync filters for home_url and site_url. |
| 76 | * |
| 77 | * @return bool |
| 78 | */ |
| 79 | function hook_wpmu_dev_domain_mapping() { |
| 80 | if ( ! $this->class_exists( 'domain_map' ) || ! $this->method_exists( 'domain_map', 'utils' ) ) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | $utils = $this->get_domain_mapping_utils_instance(); |
| 85 | add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) ); |
| 86 | add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) ); |
| 87 | |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Utility Methods |
| 93 | * |
| 94 | * These methods are very minimal, and in most cases, simply pass on arguments. Why create them you ask? |
| 95 | * So that we can test. |
| 96 | */ |
| 97 | |
| 98 | public function method_exists( $class, $method ) { |
| 99 | return method_exists( $class, $method ); |
| 100 | } |
| 101 | |
| 102 | public function class_exists( $class ) { |
| 103 | return class_exists( $class ); |
| 104 | } |
| 105 | |
| 106 | public function function_exists( $function ) { |
| 107 | return function_exists( $function ); |
| 108 | } |
| 109 | |
| 110 | public function get_domain_mapping_utils_instance() { |
| 111 | return domain_map::utils(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | Jetpack_3rd_Party_Domain_Mapping::init(); |
| 116 |