← All changes
|
jetpack_vendor/automattic/jetpack-jitm/src/class-post-connection-jitm.php
+29
-12
13.0.2
→
16.3
View file →
| @@ -14,8 +14,12 @@ | ||
| 14 | 14 | use Automattic\Jetpack\Partner; |
| 15 | 15 | use Automattic\Jetpack\Redirect; |
| 16 | 16 | use Automattic\Jetpack\Tracking; |
| 17 | 17 | |
| 18 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 19 | + exit( 0 ); | |
| 20 | +} | |
| 21 | + | |
| 18 | 22 | /** |
| 19 | 23 | * Jetpack just in time messaging through out the admin |
| 20 | 24 | * |
| 21 | 25 | * @since 1.1.0 |
| @@ -26,9 +30,9 @@ | ||
| 26 | 30 | |
| 27 | 31 | /** |
| 28 | 32 | * Tracking object. |
| 29 | 33 | * |
| 30 | - * @var Automattic\Jetpack\Tracking | |
| 34 | + * @var \Automattic\Jetpack\Tracking | |
| 31 | 35 | * |
| 32 | 36 | * @access private |
| 33 | 37 | */ |
| 34 | 38 | public $tracking; |
| @@ -42,11 +46,11 @@ | ||
| 42 | 46 | |
| 43 | 47 | /** |
| 44 | 48 | * A special filter for WooCommerce, to set a message based on local state. |
| 45 | 49 | * |
| 46 | - * @param string $content The current message. | |
| 50 | + * @param object $content The current message. | |
| 47 | 51 | * |
| 48 | - * @return array The new message. | |
| 52 | + * @return object The new message. | |
| 49 | 53 | */ |
| 50 | 54 | public static function jitm_woocommerce_services_msg( $content ) { |
| 51 | 55 | if ( ! function_exists( 'wc_get_base_location' ) ) { |
| 52 | 56 | return $content; |
| @@ -112,9 +116,9 @@ | ||
| 112 | 116 | add_query_arg( |
| 113 | 117 | array( |
| 114 | 118 | 'creative-mail-action' => 'install', |
| 115 | 119 | ), |
| 116 | - admin_url( 'edit.php?post_type=feedback' ) | |
| 120 | + admin_url( 'admin.php?page=jetpack-forms-admin' ) | |
| 117 | 121 | ), |
| 118 | 122 | 'creative-mail-install' |
| 119 | 123 | ); |
| 120 | 124 | } |
| @@ -129,9 +133,9 @@ | ||
| 129 | 133 | add_query_arg( |
| 130 | 134 | array( |
| 131 | 135 | 'creative-mail-action' => 'activate', |
| 132 | 136 | ), |
| 133 | - admin_url( 'edit.php?post_type=feedback' ) | |
| 137 | + admin_url( 'admin.php?page=jetpack-forms-admin' ) | |
| 134 | 138 | ), |
| 135 | 139 | 'creative-mail-install' |
| 136 | 140 | ); |
| 137 | 141 | } |
| @@ -224,12 +228,16 @@ | ||
| 224 | 228 | return true; |
| 225 | 229 | } |
| 226 | 230 | |
| 227 | 231 | /** |
| 228 | - * Asks the wpcom API for the current message to display keyed on query string and message path | |
| 232 | + * Asks the wpcom API for the current message to display keyed on query string and message path. | |
| 229 | 233 | * |
| 234 | + * For sites running on the Dotcom Simple codebase, the network request is bypassed | |
| 235 | + * via Client::wpcom_json_api_request_as_blog allowing for the JITM\Engine to be called | |
| 236 | + * directly. | |
| 237 | + * | |
| 230 | 238 | * @param string $message_path The message path to ask for. |
| 231 | - * @param string $query The query string originally from the front end. | |
| 239 | + * @param array $query Query parameters as an associative array. | |
| 232 | 240 | * @param bool $full_jp_logo_exists If there is a full Jetpack logo already on the page. |
| 233 | 241 | * |
| 234 | 242 | * @return array The JITM's to show, or an empty array if there is nothing to show |
| 235 | 243 | */ |
| @@ -272,10 +280,12 @@ | ||
| 272 | 280 | ), |
| 273 | 281 | sprintf( '/sites/%d/jitm/%s', $site_id, $message_path ) |
| 274 | 282 | ); |
| 275 | 283 | |
| 284 | + $cache_key = 'jetpack_jitm_' . substr( md5( $path ), 0, 31 ); | |
| 285 | + | |
| 276 | 286 | // Attempt to get from cache. |
| 277 | - $envelopes = get_transient( 'jetpack_jitm_' . substr( md5( $path ), 0, 31 ) ); | |
| 287 | + $envelopes = get_transient( $cache_key ); | |
| 278 | 288 | |
| 279 | 289 | // If something is in the cache and it was put in the cache after the last sync we care about, use it. |
| 280 | 290 | $use_cache = false; |
| 281 | 291 | |
| @@ -291,10 +301,18 @@ | ||
| 291 | 301 | $use_cache = true; |
| 292 | 302 | } |
| 293 | 303 | |
| 294 | 304 | if ( $use_cache ) { |
| 295 | - $last_sync = (int) get_transient( 'jetpack_last_plugin_sync' ); | |
| 296 | - $from_cache = $envelopes && $last_sync > 0 && $last_sync < $envelopes['last_response_time']; | |
| 305 | + $last_sync = (int) get_transient( 'jetpack_last_plugin_sync' ); | |
| 306 | + // The sync timestamp indicates when a plugin change was last sent to Jetpack, however, | |
| 307 | + // it's stored in a transient and doesn't stay forever. Therefore, an admin who last changed | |
| 308 | + // a plugin a month ago is likely to have $last_sync=0. | |
| 309 | + // | |
| 310 | + // If the sync timestamp is missing (value 0): use the cache. | |
| 311 | + // If the timestamp exists and is older than the cached envelope: use the cache. | |
| 312 | + // If the timestamp exists and is newer: bypass and refresh. | |
| 313 | + // (This case means the JITM was created before the last plugin activate/deactivate and is invalid). | |
| 314 | + $from_cache = $envelopes && ( 0 === $last_sync || $last_sync < $envelopes['last_response_time'] ); | |
| 297 | 315 | } else { |
| 298 | 316 | $from_cache = false; |
| 299 | 317 | } |
| 300 | 318 | |
| @@ -326,10 +344,9 @@ | ||
| 326 | 344 | |
| 327 | 345 | // Do not cache if expiration is 0 or we're not using the cache. |
| 328 | 346 | if ( 0 !== $expiration && $use_cache ) { |
| 329 | 347 | $envelopes['last_response_time'] = time(); |
| 330 | - | |
| 331 | - set_transient( 'jetpack_jitm_' . substr( md5( $path ), 0, 31 ), $envelopes, $expiration ); | |
| 348 | + set_transient( $cache_key, $envelopes, $expiration ); | |
| 332 | 349 | } |
| 333 | 350 | } |
| 334 | 351 | |
| 335 | 352 | $hidden_jitms = \Jetpack_Options::get_option( 'hide_jitm' ); |