← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/modules/class-callables.php
+29
-11
13.5.2
→
16.3-beta
View file →
| @@ -12,8 +12,12 @@ | ||
| 12 | 12 | use Automattic\Jetpack\Sync\Defaults; |
| 13 | 13 | use Automattic\Jetpack\Sync\Functions; |
| 14 | 14 | use Automattic\Jetpack\Sync\Settings; |
| 15 | 15 | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 16 | 20 | /** |
| 17 | 21 | * Class to handle sync for callables. |
| 18 | 22 | */ |
| 19 | 23 | class Callables extends Module { |
| @@ -53,8 +57,9 @@ | ||
| 53 | 57 | 'siteurl', |
| 54 | 58 | 'jetpack_sync_error_idc', |
| 55 | 59 | 'paused_plugins', |
| 56 | 60 | 'paused_themes', |
| 61 | + 'blog_public', // Callable is jetpack_site_visibility; privacy has to travel as fast as the option. | |
| 57 | 62 | |
| 58 | 63 | ); |
| 59 | 64 | |
| 60 | 65 | const ALWAYS_SEND_UPDATES_TO_THESE_OPTIONS_NEXT_TICK = array( |
| @@ -80,8 +85,9 @@ | ||
| 80 | 85 | // @TODO: Audit the other option names for differences between the option names and callable names. |
| 81 | 86 | 'home' => 'home_url', |
| 82 | 87 | 'siteurl' => 'site_url', |
| 83 | 88 | 'jetpack_active_modules' => 'active_modules', |
| 89 | + 'blog_public' => 'jetpack_site_visibility', | |
| 84 | 90 | ); |
| 85 | 91 | |
| 86 | 92 | /** |
| 87 | 93 | * Sync module name. |
| @@ -159,8 +165,11 @@ | ||
| 159 | 165 | // get_plugins and wp_version |
| 160 | 166 | // gets fired when new code gets installed, updates etc. |
| 161 | 167 | add_action( 'upgrader_process_complete', array( $this, 'unlock_plugin_action_link_and_callables' ) ); |
| 162 | 168 | add_action( 'update_option_active_plugins', array( $this, 'unlock_plugin_action_link_and_callables' ) ); |
| 169 | + // Deleting an inactive plugin fires neither of the above, so without this the synced | |
| 170 | + // get_plugins callable stays stale until the periodic re-check happens to run. | |
| 171 | + add_action( 'deleted_plugin', array( $this, 'unlock_plugin_action_link_and_callables' ) ); | |
| 163 | 172 | } |
| 164 | 173 | |
| 165 | 174 | /** |
| 166 | 175 | * Initialize callables action listeners for full sync. |
| @@ -290,19 +299,25 @@ | ||
| 290 | 299 | * |
| 291 | 300 | * @access public |
| 292 | 301 | * |
| 293 | 302 | * @param array $config Full sync configuration for this sync module. |
| 303 | + * @param array $status This Module Full Sync Status. | |
| 294 | 304 | * @param int $send_until The timestamp until the current request can send. |
| 295 | - * @param array $status This Module Full Sync Status. | |
| 305 | + * @param int $started The timestamp when the full sync started. | |
| 296 | 306 | * |
| 297 | 307 | * @return array This Module Full Sync Status. |
| 298 | 308 | */ |
| 299 | - public function send_full_sync_actions( $config, $send_until, $status ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 309 | + public function send_full_sync_actions( $config, $status, $send_until, $started ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 300 | 310 | // we call this instead of do_action when sending immediately. |
| 301 | - $this->send_action( 'jetpack_full_sync_callables', array( true ) ); | |
| 311 | + $result = $this->send_action( 'jetpack_full_sync_callables', array( true ) ); | |
| 302 | 312 | |
| 303 | - // The number of actions enqueued, and next module state (true == done). | |
| 304 | - return array( 'finished' => true ); | |
| 313 | + if ( is_wp_error( $result ) ) { | |
| 314 | + $status['error'] = true; | |
| 315 | + return $status; | |
| 316 | + } | |
| 317 | + $status['finished'] = true; | |
| 318 | + $status['sent'] = $status['total']; | |
| 319 | + return $status; | |
| 305 | 320 | } |
| 306 | 321 | |
| 307 | 322 | /** |
| 308 | 323 | * Retrieve an estimated number of actions that will be enqueued. |
| @@ -309,9 +324,9 @@ | ||
| 309 | 324 | * |
| 310 | 325 | * @access public |
| 311 | 326 | * |
| 312 | 327 | * @param array $config Full sync configuration for this sync module. |
| 313 | - * @return array Number of items yet to be enqueued. | |
| 328 | + * @return int Number of items yet to be enqueued. | |
| 314 | 329 | */ |
| 315 | 330 | public function estimate_full_sync_actions( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 316 | 331 | return 1; |
| 317 | 332 | } |
| @@ -378,14 +393,17 @@ | ||
| 378 | 393 | $current_screeen = get_current_screen(); |
| 379 | 394 | |
| 380 | 395 | $plugins_action_links = array(); |
| 381 | 396 | // Is the transient lock in place? |
| 382 | - $plugins_lock = get_transient( 'jetpack_plugin_api_action_links_refresh', false ); | |
| 397 | + $plugins_lock = get_transient( 'jetpack_plugin_api_action_links_refresh' ); | |
| 383 | 398 | if ( ! empty( $plugins_lock ) && ( isset( $current_screeen->id ) && 'plugins' !== $current_screeen->id ) ) { |
| 384 | 399 | return; |
| 385 | 400 | } |
| 386 | - $plugins = array_keys( Functions::get_plugins() ); | |
| 387 | - foreach ( $plugins as $plugin_file ) { | |
| 401 | + $plugins = Functions::get_plugins(); | |
| 402 | + if ( ! is_array( $plugins ) ) { | |
| 403 | + return; | |
| 404 | + } | |
| 405 | + foreach ( $plugins as $plugin_file => $plugin_data ) { | |
| 388 | 406 | /** |
| 389 | 407 | * Plugins often like to unset things but things break if they are not able to. |
| 390 | 408 | */ |
| 391 | 409 | $action_links = array( |
| @@ -395,15 +413,15 @@ | ||
| 395 | 413 | 'delete' => '', |
| 396 | 414 | 'edit' => '', |
| 397 | 415 | ); |
| 398 | 416 | /** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */ |
| 399 | - $action_links = apply_filters( 'plugin_action_links', $action_links, $plugin_file, null, 'all' ); | |
| 417 | + $action_links = apply_filters( 'plugin_action_links', $action_links, $plugin_file, $plugin_data, 'all' ); | |
| 400 | 418 | // Verify $action_links is still an array. |
| 401 | 419 | if ( ! is_array( $action_links ) ) { |
| 402 | 420 | $action_links = array(); |
| 403 | 421 | } |
| 404 | 422 | /** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */ |
| 405 | - $action_links = apply_filters( "plugin_action_links_{$plugin_file}", $action_links, $plugin_file, null, 'all' ); | |
| 423 | + $action_links = apply_filters( "plugin_action_links_{$plugin_file}", $action_links, $plugin_file, $plugin_data, 'all' ); | |
| 406 | 424 | // Verify $action_links is still an array to resolve warnings from filters not returning an array. |
| 407 | 425 | if ( is_array( $action_links ) ) { |
| 408 | 426 | $action_links = array_filter( $action_links ); |
| 409 | 427 | } else { |