| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* simple wrapper that allows enumerating cached static instances |
| 5 |
* of sync modules |
| 6 |
*/ |
| 7 |
|
| 8 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module.php'; |
| 9 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-posts.php'; |
| 10 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-comments.php'; |
| 11 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-constants.php'; |
| 12 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-callables.php'; |
| 13 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-options.php'; |
| 14 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-network-options.php'; |
| 15 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-updates.php'; |
| 16 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-users.php'; |
| 17 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-themes.php'; |
| 18 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-attachments.php'; |
| 19 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-meta.php'; |
| 20 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-terms.php'; |
| 21 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-plugins.php'; |
| 22 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-protect.php'; |
| 23 |
require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-full-sync.php'; |
| 24 |
|
| 25 |
class Jetpack_Sync_Modules { |
| 26 |
|
| 27 |
private static $default_sync_modules = array( |
| 28 |
'Jetpack_Sync_Module_Constants', |
| 29 |
'Jetpack_Sync_Module_Callables', |
| 30 |
'Jetpack_Sync_Module_Options', |
| 31 |
'Jetpack_Sync_Module_Network_Options', |
| 32 |
'Jetpack_Sync_Module_Terms', |
| 33 |
'Jetpack_Sync_Module_Themes', |
| 34 |
'Jetpack_Sync_Module_Users', |
| 35 |
'Jetpack_Sync_Module_Posts', |
| 36 |
'Jetpack_Sync_Module_Comments', |
| 37 |
'Jetpack_Sync_Module_Updates', |
| 38 |
'Jetpack_Sync_Module_Attachments', |
| 39 |
'Jetpack_Sync_Module_Meta', |
| 40 |
'Jetpack_Sync_Module_Plugins', |
| 41 |
'Jetpack_Sync_Module_Protect', |
| 42 |
'Jetpack_Sync_Module_Full_Sync', |
| 43 |
); |
| 44 |
|
| 45 |
private static $initialized_modules = null; |
| 46 |
|
| 47 |
public static function get_modules() { |
| 48 |
if ( null === self::$initialized_modules ) { |
| 49 |
self::$initialized_modules = self::initialize_modules(); |
| 50 |
} |
| 51 |
|
| 52 |
return self::$initialized_modules; |
| 53 |
} |
| 54 |
|
| 55 |
public static function set_defaults() { |
| 56 |
foreach ( self::get_modules() as $module ) { |
| 57 |
$module->set_defaults(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public static function get_module( $module_name ) { |
| 62 |
foreach ( self::get_modules() as $module ) { |
| 63 |
if ( $module->name() === $module_name ) { |
| 64 |
return $module; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
static function initialize_modules() { |
| 72 |
/** |
| 73 |
* Filters the list of class names of sync modules. |
| 74 |
* If you add to this list, make sure any classes implement the |
| 75 |
* Jetpack_Sync_Module interface. |
| 76 |
* |
| 77 |
* @since 4.2.0 |
| 78 |
*/ |
| 79 |
$modules = apply_filters( 'jetpack_sync_modules', self::$default_sync_modules ); |
| 80 |
|
| 81 |
return array_map( array( 'Jetpack_Sync_Modules', 'initialize_module' ), $modules ); |
| 82 |
} |
| 83 |
|
| 84 |
static function initialize_module( $module_name ) { |
| 85 |
$module = new $module_name; |
| 86 |
$module->set_defaults(); |
| 87 |
|
| 88 |
return $module; |
| 89 |
} |
| 90 |
} |
| 91 |
|