er->ID, 'user_roles' => implode( ',', $user->roles ), ), null, 'wpcom' ); // silently fail...might be helpful to track it? if ( is_wp_error( $wpcom_response ) ) { return array(); } $envelopes = json_decode( $wpcom_response['body'] ); if ( ! is_array( $envelopes ) ) { return array(); } $expiration = isset( $envelopes[0] ) ? $envelopes[0]->ttl : 300; // Do not cache if expiration is 0 or we're not using the cache. if ( 0 !== $expiration && $use_cache ) { $envelopes['last_response_time'] = time(); set_transient( 'jetpack_jitm_' . substr( md5( $path ), 0, 31 ), $envelopes, $expiration ); } } $hidden_jitms = \Jetpack_Options::get_option( 'hide_jitm' ); unset( $envelopes['last_response_time'] ); /** * Allow adding your own custom JITMs after a set of JITMs has been received. * * @since 1.1.0 * @since-jetpack 6.9.0 * @since-jetpack 8.3.0 - Added Message path. * * @param array $envelopes array of existing JITMs. * @param string $message_path The message path to ask for. */ $envelopes = apply_filters( 'jetpack_jitm_received_envelopes', $envelopes, $message_path ); foreach ( $envelopes as $idx => &$envelope ) { $dismissed_feature = isset( $hidden_jitms[ $envelope->feature_class ] ) && is_array( $hidden_jitms[ $envelope->feature_class ] ) ? $hidden_jitms[ $envelope->feature_class ] : null; // If the this feature class has been dismissed and the request has not passed the ttl, skip it as it's been dismissed. if ( is_array( $dismissed_feature ) && ( time() - $dismissed_feature['last_dismissal'] < $envelope->expires || $dismissed_feature['number'] >= $envelope->max_dismissal ) ) { unset( $envelopes[ $idx ] ); continue; } $this->tracking->record_user_event( 'jitm_view_client', array( 'jitm_id' => $envelope->id, 'jitm_message_path' => $message_path, ) ); $url_params = array( 'u' => $user->ID, ); // Get affiliate code and add it to the array of URL parameters. $aff = Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ); if ( '' !== $aff ) { $url_params['aff'] = $aff; } // Check if the current user has connected their WP.com account // and if not add this information to the the array of URL parameters. if ( ! ( new Manager() )->is_user_connected( $user->ID ) ) { $url_params['query'] = 'unlinked=1'; } $envelope->url = esc_url( Redirect::get_url( "jitm-$envelope->id", $url_params ) ); $stats = new A8c_Mc_Stats(); $envelope->jitm_stats_url = $stats->build_stats_url( array( 'x_jetpack-jitm' => $envelope->id ) ); // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase // $CTA is not valid per PHPCS, but it is part of the return from WordPress.com, so allowing. if ( $envelope->CTA->hook ) { $envelope->url = apply_filters( 'jitm_' . $envelope->CTA->hook, $envelope->url ); unset( $envelope->CTA->hook ); } // phpcs:enable if ( isset( $envelope->content->hook ) ) { $envelope->content = apply_filters( 'jitm_' . $envelope->content->hook, $envelope->content ); unset( $envelope->content->hook ); } // No point in showing an empty message. if ( empty( $envelope->content->message ) ) { unset( $envelopes[ $idx ] ); continue; } $envelope->content->icon = $this->generate_icon( $envelope->content->icon, $full_jp_logo_exists ); $envelope->message_path = esc_attr( $message_path ); $stats->add( 'jitm', $envelope->id . '-viewed' ); $stats->do_server_side_stats(); } return $envelopes; } }