Skip to content

Commit 00fab3d

Browse files
committed
Sync: IDC: 3rd Party: Hook domain mapping plugins to sync filters
1 parent b2061df commit 00fab3d

1 file changed

Lines changed: 52 additions & 27 deletions

File tree

3rd-party/domain-mapping.php

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
11
<?php
22

33
if ( Jetpack_Constants::is_defined( 'SUNRISE' ) ) :
4-
function jetpack_domain_mapping_check_compatible_plugins() {
5-
// Once we've satisfied a condition for adding domain mapping compatibility, then bail
6-
$hooked = jetpack_domain_mapping_maybe_support_wordpress_mu_domain_mapping();
74

8-
if ( ! $hooked ) {
9-
jetpack_domain_mapping_maybe_add_wpmu_dev_domain_mapping_support();
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+
* This method will test for a constant and function that are known to be used with Donncha's WordPress MU
14+
* Domain Mapping plugin. If conditions are met, we hook the domain_mapping_siteurl() function to Jetpack sync
15+
* filters for home_url and site_url callables.
16+
*
17+
* @return bool
18+
*/
19+
static function hook_wordpress_mu_domain_mapping() {
20+
if ( ! Jetpack_Constants::is_defined( 'DOMAIN_MAPPING' ) || function_exists( 'domain_mapping_siteurl' ) ) {
21+
return false;
22+
}
23+
24+
add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' );
25+
add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' );
26+
27+
return true;
1028
}
11-
}
12-
add_action( 'plugins_loaded', 'jetpack_domain_mapping_compatibility' );
1329

14-
// Compatibility with Donncha's WordPress MU Domain Mapping plugin
15-
function jetpack_domain_mapping_maybe_support_wordpress_mu_domain_mapping() {
16-
if ( ! Jetpack_Constants::is_defined( 'DOMAIN_MAPPING' ) || function_exists( 'domain_mapping_siteurl' ) ) {
17-
return false;
30+
/**
31+
* This method will test for a class and method known to be used in WPMU Dev's domain mapping plugin. If the
32+
* method exists, then we'll hook the swap_to_mapped_url() to our Jetpack sync fitlers for home_url and site_url.
33+
*
34+
* @return bool
35+
*/
36+
static function hook_wpmu_dev_domain_mapping() {
37+
if ( ! class_exists( 'domain_map' ) || ! method_exists( 'domain_map', 'utils' ) ) {
38+
return false;
39+
}
40+
41+
$utils = domain_map::utils();
42+
add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) );
43+
add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) );
44+
45+
return true;
1846
}
19-
20-
add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' );
21-
add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' );
22-
23-
return true;
2447
}
2548

26-
27-
// Compatibility with WPMU DEV's Domain Mapping plugin
28-
function jetpack_domain_mapping_maybe_add_wpmu_dev_domain_mapping_support() {
29-
if ( ! class_exists( 'domain_map' ) || ! method_exists( 'domain_map', 'utils' ) ) {
30-
return false;
31-
}
32-
33-
$utils = domain_map::utils();
34-
add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) );
35-
add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) );
49+
/**
50+
* This function is called on the plugins_loaded action and will loop through the methods of
51+
* Jetpack_3rd_Party_Domain_Mapping to try and hook a domain mapping plugin to the Jetpack sync
52+
* filters for the home_url and site_url callables.
53+
*/
54+
function jetpack_domain_mapping_hook_compatible_plugins() {
55+
$methods = get_class_methods( 'Jetpack_3rd_Party_Domain_Mapping' );
56+
do {
57+
$method = array_pop( $methods );
58+
$hooked = call_user_func( 'Jetpack_3rd_Party_Domain_Mapping', $method );
59+
} while( ! $hooked && ! empty( $methods ) );
3660
}
37-
endif;
61+
add_action( 'plugins_loaded', 'jetpack_domain_mapping_hook_compatible_plugins' );
62+
endif;

0 commit comments

Comments
 (0)