PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 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 All 506 releases
← All changes | jetpack_vendor/automattic/jetpack-sync/src/class-main.php +49 -1 12.3.2 → 16.3-a.7 View file →
@@ -7,8 +7,9 @@
7 7
8 8 namespace Automattic\Jetpack\Sync;
9 9
10 10 use Automattic\Jetpack\Sync\Actions as Sync_Actions;
11 +use Automattic\Jetpack\Sync\Queue\Queue_Storage_Table;
11 12
12 13 /**
13 14 * Jetpack Sync main class.
14 15 */
@@ -19,8 +20,11 @@
19 20 *
20 21 * @action plugins_loaded
21 22 */
22 23 public static function configure() {
24 + // Activity Log custom events must register even when Sync is disabled, e.g. on WordPress.com Simple sites.
25 + Activity_Log_Event::init();
26 +
23 27 if ( Actions::sync_allowed() ) {
24 28 add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_early' ), 5 );
25 29 add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_late' ), 90 );
26 30 }
@@ -33,13 +37,40 @@
33 37
34 38 // Any hooks below are special cases that need to be declared even if Sync is not allowed.
35 39 add_action( 'jetpack_site_registered', array( 'Automattic\\Jetpack\\Sync\\Actions', 'do_initial_sync' ), 10, 0 );
36 40
41 + // Sync clean up, when Jetpack is disconnected.
42 + add_action( 'jetpack_site_disconnected', array( __CLASS__, 'on_jetpack_site_disconnected' ), 1000 );
43 +
37 44 // Set up package version hook.
38 45 add_filter( 'jetpack_package_versions', __NAMESPACE__ . '\Package_Version::send_package_version_to_tracker' );
46 +
47 + // Add the custom capabilities for managing modules
48 + add_filter( 'map_meta_cap', array( __CLASS__, 'module_custom_caps' ), 10, 2 );
39 49 }
40 50
41 51 /**
52 + * Sets the Module custom capabilities.
53 + *
54 + * @param string[] $caps Array of the user's capabilities.
55 + * @param string $cap Capability name.
56 + * @return string[] The user's capabilities, adjusted as necessary.
57 + */
58 + public static function module_custom_caps( $caps, $cap ) {
59 + switch ( $cap ) {
60 + case 'jetpack_manage_modules':
61 + case 'jetpack_activate_modules':
62 + case 'jetpack_deactivate_modules':
63 + $caps = array( 'manage_options' );
64 + break;
65 + case 'jetpack_configure_modules':
66 + $caps = array( 'manage_options' );
67 + break;
68 + }
69 + return $caps;
70 + }
71 +
72 + /**
42 73 * Delete all sync related data on Identity Crisis disconnect.
43 74 */
44 75 public static function on_jetpack_idc_disconnect() {
45 76 Sender::get_instance()->uninstall();
@@ -45,8 +76,26 @@
45 76 Sender::get_instance()->uninstall();
46 77 }
47 78
48 79 /**
80 + * Sync cleanup on shutdown.
81 + */
82 + public static function on_jetpack_site_disconnected() {
83 + add_action( 'shutdown', array( __CLASS__, 'sync_cleanup' ), 10000 );
84 + }
85 +
86 + /**
87 + * Delete all sync related data on Site disconnect / clean up custom table.
88 + * Needs to happen on shutdown to prevent fatals.
89 + */
90 + public static function sync_cleanup() {
91 + Sender::get_instance()->uninstall();
92 +
93 + $table_storage = new Queue_Storage_Table( 'test_queue' );
94 + $table_storage->drop_table();
95 + }
96 +
97 + /**
49 98 * Sets the Sync data settings.
50 99 *
51 100 * @param array $data_settings An array containing the Sync data options. An empty array indicates that the default
52 101 * values will be used for all Sync data.
@@ -109,6 +158,5 @@
109 158
110 159 // Initialize health-related hooks after plugins have loaded.
111 160 Health::init();
112 161 }
113 -
114 162 }