← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/modules/class-callables.php
+52
-14
12.3.2
→
16.3-a.7
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. |
| @@ -109,8 +115,30 @@ | ||
| 109 | 115 | $this->force_send_callables_on_next_tick = false; // Resets here as well mostly for tests. |
| 110 | 116 | } |
| 111 | 117 | |
| 112 | 118 | /** |
| 119 | + * Set module defaults at a later time. | |
| 120 | + * Reset the callable whitelist if needed to account for plugins adding the 'jetpack_sync_callable_whitelist' | |
| 121 | + * and 'jetpack_sync_multisite_callable_whitelist' filters late. | |
| 122 | + * | |
| 123 | + * @see Automattic\Jetpack\Sync\Modules::set_module_defaults | |
| 124 | + * @access public | |
| 125 | + */ | |
| 126 | + public function set_late_default() { | |
| 127 | + if ( is_multisite() ) { | |
| 128 | + $late_callables = array_merge( | |
| 129 | + apply_filters( 'jetpack_sync_callable_whitelist', array() ), | |
| 130 | + apply_filters( 'jetpack_sync_multisite_callable_whitelist', array() ) | |
| 131 | + ); | |
| 132 | + } else { | |
| 133 | + $late_callables = apply_filters( 'jetpack_sync_callable_whitelist', array() ); | |
| 134 | + } | |
| 135 | + if ( ! empty( $late_callables ) && is_array( $late_callables ) ) { | |
| 136 | + $this->callable_whitelist = array_merge( $this->callable_whitelist, $late_callables ); | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 113 | 141 | * Initialize callables action listeners. |
| 114 | 142 | * |
| 115 | 143 | * @access public |
| 116 | 144 | * |
| @@ -137,8 +165,11 @@ | ||
| 137 | 165 | // get_plugins and wp_version |
| 138 | 166 | // gets fired when new code gets installed, updates etc. |
| 139 | 167 | add_action( 'upgrader_process_complete', array( $this, 'unlock_plugin_action_link_and_callables' ) ); |
| 140 | 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' ) ); | |
| 141 | 172 | } |
| 142 | 173 | |
| 143 | 174 | /** |
| 144 | 175 | * Initialize callables action listeners for full sync. |
| @@ -268,19 +299,25 @@ | ||
| 268 | 299 | * |
| 269 | 300 | * @access public |
| 270 | 301 | * |
| 271 | 302 | * @param array $config Full sync configuration for this sync module. |
| 303 | + * @param array $status This Module Full Sync Status. | |
| 272 | 304 | * @param int $send_until The timestamp until the current request can send. |
| 273 | - * @param array $status This Module Full Sync Status. | |
| 305 | + * @param int $started The timestamp when the full sync started. | |
| 274 | 306 | * |
| 275 | 307 | * @return array This Module Full Sync Status. |
| 276 | 308 | */ |
| 277 | - 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 | |
| 278 | 310 | // we call this instead of do_action when sending immediately. |
| 279 | - $this->send_action( 'jetpack_full_sync_callables', array( true ) ); | |
| 311 | + $result = $this->send_action( 'jetpack_full_sync_callables', array( true ) ); | |
| 280 | 312 | |
| 281 | - // The number of actions enqueued, and next module state (true == done). | |
| 282 | - 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; | |
| 283 | 320 | } |
| 284 | 321 | |
| 285 | 322 | /** |
| 286 | 323 | * Retrieve an estimated number of actions that will be enqueued. |
| @@ -287,9 +324,9 @@ | ||
| 287 | 324 | * |
| 288 | 325 | * @access public |
| 289 | 326 | * |
| 290 | 327 | * @param array $config Full sync configuration for this sync module. |
| 291 | - * @return array Number of items yet to be enqueued. | |
| 328 | + * @return int Number of items yet to be enqueued. | |
| 292 | 329 | */ |
| 293 | 330 | public function estimate_full_sync_actions( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 294 | 331 | return 1; |
| 295 | 332 | } |
| @@ -347,9 +384,8 @@ | ||
| 347 | 384 | */ |
| 348 | 385 | public function set_plugin_action_links() { |
| 349 | 386 | if ( |
| 350 | 387 | ! class_exists( '\DOMDocument' ) || |
| 351 | - ! function_exists( 'libxml_use_internal_errors' ) || | |
| 352 | 388 | ! function_exists( 'mb_convert_encoding' ) |
| 353 | 389 | ) { |
| 354 | 390 | return; |
| 355 | 391 | } |
| @@ -357,14 +393,17 @@ | ||
| 357 | 393 | $current_screeen = get_current_screen(); |
| 358 | 394 | |
| 359 | 395 | $plugins_action_links = array(); |
| 360 | 396 | // Is the transient lock in place? |
| 361 | - $plugins_lock = get_transient( 'jetpack_plugin_api_action_links_refresh', false ); | |
| 397 | + $plugins_lock = get_transient( 'jetpack_plugin_api_action_links_refresh' ); | |
| 362 | 398 | if ( ! empty( $plugins_lock ) && ( isset( $current_screeen->id ) && 'plugins' !== $current_screeen->id ) ) { |
| 363 | 399 | return; |
| 364 | 400 | } |
| 365 | - $plugins = array_keys( Functions::get_plugins() ); | |
| 366 | - 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 ) { | |
| 367 | 406 | /** |
| 368 | 407 | * Plugins often like to unset things but things break if they are not able to. |
| 369 | 408 | */ |
| 370 | 409 | $action_links = array( |
| @@ -374,15 +413,15 @@ | ||
| 374 | 413 | 'delete' => '', |
| 375 | 414 | 'edit' => '', |
| 376 | 415 | ); |
| 377 | 416 | /** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */ |
| 378 | - $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' ); | |
| 379 | 418 | // Verify $action_links is still an array. |
| 380 | 419 | if ( ! is_array( $action_links ) ) { |
| 381 | 420 | $action_links = array(); |
| 382 | 421 | } |
| 383 | 422 | /** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */ |
| 384 | - $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' ); | |
| 385 | 424 | // Verify $action_links is still an array to resolve warnings from filters not returning an array. |
| 386 | 425 | if ( is_array( $action_links ) ) { |
| 387 | 426 | $action_links = array_filter( $action_links ); |
| 388 | 427 | } else { |
| @@ -404,9 +443,9 @@ | ||
| 404 | 443 | } |
| 405 | 444 | |
| 406 | 445 | $link_element = $link_elements->item( 0 ); |
| 407 | 446 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 408 | - if ( $link_element->hasAttribute( 'href' ) && $link_element->nodeValue ) { | |
| 447 | + if ( $link_element instanceof \DOMElement && $link_element->hasAttribute( 'href' ) && $link_element->nodeValue ) { | |
| 409 | 448 | $link_url = trim( $link_element->getAttribute( 'href' ) ); |
| 410 | 449 | |
| 411 | 450 | // Add the full admin path to the url if the plugin did not provide it. |
| 412 | 451 | $link_url_scheme = wp_parse_url( $link_url, PHP_URL_SCHEME ); |
| @@ -641,6 +680,5 @@ | ||
| 641 | 680 | } |
| 642 | 681 | |
| 643 | 682 | return 'CALLABLE-DOES-NOT-EXIST'; |
| 644 | 683 | } |
| 645 | - | |
| 646 | 684 | } |