PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.3.4
Jetpack – WP Security, Backup, Speed, & Growth v7.3.4
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / 3rd-party / domain-mapping.php
domain-mapping.php
114 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Jetpack_3rd_Party_Domain_Mapping
5 *
6 * This class contains methods that are used to provide compatibility between Jetpack sync and domain mapping plugins.
7 */
8 class Jetpack_3rd_Party_Domain_Mapping {
9
10 /**
11 * @var Jetpack_3rd_Party_Domain_Mapping
12 **/
13 private static $instance = null;
14
15 /**
16 * An array of methods that are used to hook the Jetpack sync filters for home_url and site_url to a mapping plugin.
17 *
18 * @var array
19 */
20 static $test_methods = array(
21 'hook_wordpress_mu_domain_mapping',
22 'hook_wpmu_dev_domain_mapping'
23 );
24
25 static function init() {
26 if ( is_null( self::$instance ) ) {
27 self::$instance = new Jetpack_3rd_Party_Domain_Mapping;
28 }
29
30 return self::$instance;
31 }
32
33 private function __construct() {
34 add_action( 'plugins_loaded', array( $this, 'attempt_to_hook_domain_mapping_plugins' ) );
35 }
36
37 /**
38 * This function is called on the plugins_loaded action and will loop through the $test_methods
39 * to try and hook a domain mapping plugin to the Jetpack sync filters for the home_url and site_url callables.
40 */
41 function attempt_to_hook_domain_mapping_plugins() {
42 if ( ! Jetpack_Constants::is_defined( 'SUNRISE' ) ) {
43 return;
44 }
45
46 $hooked = false;
47 $count = count( self::$test_methods );
48 for ( $i = 0; $i < $count && ! $hooked; $i++ ) {
49 $hooked = call_user_func( array( $this, self::$test_methods[ $i ] ) );
50 }
51 }
52
53 /**
54 * This method will test for a constant and function that are known to be used with Donncha's WordPress MU
55 * Domain Mapping plugin. If conditions are met, we hook the domain_mapping_siteurl() function to Jetpack sync
56 * filters for home_url and site_url callables.
57 *
58 * @return bool
59 */
60 function hook_wordpress_mu_domain_mapping() {
61 if ( ! Jetpack_Constants::is_defined( 'SUNRISE_LOADED' ) || ! $this->function_exists( 'domain_mapping_siteurl' ) ) {
62 return false;
63 }
64
65 add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' );
66 add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' );
67
68 return true;
69 }
70
71 /**
72 * This method will test for a class and method known to be used in WPMU Dev's domain mapping plugin. If the
73 * method exists, then we'll hook the swap_to_mapped_url() to our Jetpack sync filters for home_url and site_url.
74 *
75 * @return bool
76 */
77 function hook_wpmu_dev_domain_mapping() {
78 if ( ! $this->class_exists( 'domain_map' ) || ! $this->method_exists( 'domain_map', 'utils' ) ) {
79 return false;
80 }
81
82 $utils = $this->get_domain_mapping_utils_instance();
83 add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) );
84 add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) );
85
86 return true;
87 }
88
89 /*
90 * Utility Methods
91 *
92 * These methods are very minimal, and in most cases, simply pass on arguments. Why create them you ask?
93 * So that we can test.
94 */
95
96 public function method_exists( $class, $method ) {
97 return method_exists( $class, $method );
98 }
99
100 public function class_exists( $class ) {
101 return class_exists( $class );
102 }
103
104 public function function_exists( $function ) {
105 return function_exists( $function );
106 }
107
108 public function get_domain_mapping_utils_instance() {
109 return domain_map::utils();
110 }
111 }
112
113 Jetpack_3rd_Party_Domain_Mapping::init();
114