-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync: IDC: Add get_raw_url method to Jetpack_Sync_Functions #5852
Changes from all commits
c411790
9514416
b2895f9
0bb2aeb
07df0da
aecd3d5
6c37dc1
8d3a7fb
b9a8df6
7214ce7
8be4bea
e54dbeb
f6e22f5
e244dde
bfd6b46
1824c78
0404b78
15f0555
c448404
1e4a204
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
/** | ||
* Class Jetpack_3rd_Party_Domain_Mapping | ||
* | ||
* This class contains methods that are used to provide compatibility between Jetpack sync and domain mapping plugins. | ||
*/ | ||
class Jetpack_3rd_Party_Domain_Mapping { | ||
|
||
/** | ||
* @var Jetpack_3rd_Party_Domain_Mapping | ||
**/ | ||
private static $instance = null; | ||
|
||
/** | ||
* An array of methods that are used to hook the Jetpack sync filters for home_url and site_url to a mapping plugin. | ||
* | ||
* @var array | ||
*/ | ||
static $test_methods = array( | ||
'hook_wordpress_mu_domain_mapping', | ||
'hook_wpmu_dev_domain_mapping' | ||
); | ||
|
||
static function init() { | ||
if ( is_null( self::$instance ) ) { | ||
self::$instance = new Jetpack_3rd_Party_Domain_Mapping; | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
private function __construct() { | ||
add_action( 'plugins_loaded', array( $this, 'attempt_to_hook_domain_mapping_plugins' ) ); | ||
} | ||
|
||
/** | ||
* This function is called on the plugins_loaded action and will loop through the $test_methods | ||
* to try and hook a domain mapping plugin to the Jetpack sync filters for the home_url and site_url callables. | ||
*/ | ||
function attempt_to_hook_domain_mapping_plugins() { | ||
if ( ! Jetpack_Constants::is_defined( 'SUNRISE' ) ) { | ||
return; | ||
} | ||
|
||
$hooked = false; | ||
$count = count( self::$test_methods ); | ||
for ( $i = 0; $i < $count && ! $hooked; $i++ ) { | ||
$hooked = call_user_func( array( $this, self::$test_methods[ $i ] ) ); | ||
} | ||
} | ||
|
||
/** | ||
* This method will test for a constant and function that are known to be used with Donncha's WordPress MU | ||
* Domain Mapping plugin. If conditions are met, we hook the domain_mapping_siteurl() function to Jetpack sync | ||
* filters for home_url and site_url callables. | ||
* | ||
* @return bool | ||
*/ | ||
function hook_wordpress_mu_domain_mapping() { | ||
if ( ! Jetpack_Constants::is_defined( 'SUNRISE_LOADED' ) || ! $this->function_exists( 'domain_mapping_siteurl' ) ) { | ||
return false; | ||
} | ||
|
||
add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' ); | ||
add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' ); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* This method will test for a class and method known to be used in WPMU Dev's domain mapping plugin. If the | ||
* method exists, then we'll hook the swap_to_mapped_url() to our Jetpack sync filters for home_url and site_url. | ||
* | ||
* @return bool | ||
*/ | ||
function hook_wpmu_dev_domain_mapping() { | ||
if ( ! $this->class_exists( 'domain_map' ) || ! $this->method_exists( 'domain_map', 'utils' ) ) { | ||
return false; | ||
} | ||
|
||
$utils = $this->get_domain_mapping_utils_instance(); | ||
add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) ); | ||
add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) ); | ||
|
||
return true; | ||
} | ||
|
||
/* | ||
* Utility Methods | ||
* | ||
* These methods are very minimal, and in most cases, simply pass on arguments. Why create them you ask? | ||
* So that we can test. | ||
*/ | ||
|
||
public function method_exists( $class, $method ) { | ||
return method_exists( $class, $method ); | ||
} | ||
|
||
public function class_exists( $class ) { | ||
return class_exists( $class ); | ||
} | ||
|
||
public function function_exists( $function ) { | ||
return function_exists( $function ); | ||
} | ||
|
||
public function get_domain_mapping_utils_instance() { | ||
return domain_map::utils(); | ||
} | ||
} | ||
|
||
Jetpack_3rd_Party_Domain_Mapping::init(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,7 @@ public function maybe_sync_callables() { | |
return; | ||
} | ||
|
||
$callable_checksums = (array) get_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() ); | ||
$callable_checksums = (array) Jetpack_Options::get_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this causing some misbehaviours? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From memory, I noticed that the callables weren't syncing as often as I expected them to. Once I made this change, it cleared up. |
||
|
||
// only send the callables that have changed | ||
foreach ( $callables as $name => $value ) { | ||
|
@@ -166,7 +166,7 @@ public function maybe_sync_callables() { | |
$callable_checksums[ $name ] = $checksum; | ||
} | ||
} | ||
update_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums ); | ||
Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums ); | ||
} | ||
|
||
public function expand_callables( $args ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool!