Skip to content

Commit

Permalink
JITMs: update pre-connection messages for launch (#19618)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeherve authored Apr 26, 2021
1 parent 871d75b commit 7e18142
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 73 deletions.
4 changes: 4 additions & 0 deletions projects/packages/jitm/changelog/update-pre-connection-jitms
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Always display pre-connection JITMs, without the need to set a filter.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Avoid wrapping text in the main CTA button
6 changes: 0 additions & 6 deletions projects/packages/jitm/src/class-pre-connection-jitm.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ private function validate_messages( $messages ) {
* @return array The JITMs to show, or an empty array if there is nothing to show
*/
public function get_messages( $message_path, $query, $full_jp_logo_exists ) {
/** This filter is documented in class.jetpack-connection-banner.php */
if ( ! apply_filters( 'jetpack_pre_connection_prompt_helpers', false ) ) {
// If filter jetpack_pre_connection_prompt_helpers is not set, return an empty array.
return array();
}

if ( ! current_user_can( 'install_plugins' ) ) {
return array();
}
Expand Down
1 change: 1 addition & 0 deletions projects/packages/jitm/src/css/jetpack-admin-jitm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $blue-medium-dark: #2271b1;
font-size: 11px;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;

&:disabled {
color: lighten( $gray, 30% );
Expand Down
57 changes: 6 additions & 51 deletions projects/packages/jitm/tests/php/test_pre_connection_jitm.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,10 @@ public function tear_down() {
Monkey\tearDown();
}

/**
* The pre-connection JITMs are disabled by default by the `jetpack_pre_connection_prompt_helpers` filter's default value.
*/
public function test_get_messages_prompt_helpers_default() {
Filters\expectApplied( 'jetpack_pre_connection_prompt_helpers' )
->once()
->with( false );

Functions\expect( 'current_user_can' )
->atMost()
->once()
->andReturn( true );

Filters\expectApplied( 'jetpack_pre_connection_jitms' )
->atMost()
->once()
->with( array() )
->andReturn( $this->test_jitms );

$this->assertEmpty( $this->jitm_instance->get_messages( '/wp:plugins:admin_notices/', '', false ) );
}

/**
* The pre-connection JITMs are disabled when the current user does not have the 'install_plugins' capability.
*/
public function test_get_messages_user_cannot_install_plugins() {
Filters\expectApplied( 'jetpack_pre_connection_prompt_helpers' )
->atMost()
->once()
->with( false )
->andReturns( true );

Functions\expect( 'current_user_can' )
->once()
->andReturn( false );
Expand All @@ -109,16 +81,10 @@ public function test_get_messages_user_cannot_install_plugins() {
}

/**
* The pre-connection JITMs are empty by default. The default value of the 'jetpack_pre_connection_jitms' filter is
* The pre-connection JITMs are empty by default. The default value of the 'jetpack_pre_connection_jitms' filter is
* an empty array.
*/
public function test_get_messages_jitms_filter_default() {
Filters\expectApplied( 'jetpack_pre_connection_prompt_helpers' )
->atMost()
->once()
->with( false )
->andReturns( true );

Functions\expect( 'current_user_can' )
->atMost()
->once()
Expand All @@ -136,12 +102,6 @@ public function test_get_messages_jitms_filter_default() {
* returns anything other than an array.
*/
public function test_get_messages_filter_returns_string() {
Filters\expectApplied( 'jetpack_pre_connection_prompt_helpers' )
->atMost()
->once()
->with( false )
->andReturns( true );

Functions\expect( 'current_user_can' )
->atMost()
->once()
Expand All @@ -159,7 +119,7 @@ public function test_get_messages_filter_returns_string() {
* The pre-connection JITMs are added using the `jetpack_pre_connection_jitms` filter.
*/
public function test_get_messages_return_message() {
$this->set_prompt_helpers_and_user_cap_conditions();
$this->set_user_cap_conditions();

Filters\expectApplied( 'jetpack_pre_connection_jitms' )
->once()
Expand All @@ -176,7 +136,7 @@ public function test_get_messages_return_message() {
* tested path.
*/
public function test_get_messages_unmatched_message_path() {
$this->set_prompt_helpers_and_user_cap_conditions();
$this->set_user_cap_conditions();

Filters\expectApplied( 'jetpack_pre_connection_jitms' )
->once()
Expand All @@ -191,7 +151,7 @@ public function test_get_messages_unmatched_message_path() {
* missing the message_path key.
*/
public function test_get_messages_missing_key() {
$this->set_prompt_helpers_and_user_cap_conditions();
$this->set_user_cap_conditions();

unset( $this->test_jitms[0]['message_path'] );

Expand All @@ -207,7 +167,7 @@ public function test_get_messages_missing_key() {
* A pre-connection JITM is displayed if it has unexpected keys.
*/
public function test_get_messages_extra_key() {
$this->set_prompt_helpers_and_user_cap_conditions();
$this->set_user_cap_conditions();

$this->test_jitms[0]['extra_key'] = 'extra jitm key';

Expand All @@ -220,12 +180,7 @@ public function test_get_messages_extra_key() {
$this->assertSame( $this->test_jitms[0]['id'], $messages[0]->id );
}

private function set_prompt_helpers_and_user_cap_conditions() {
Filters\expectApplied( 'jetpack_pre_connection_prompt_helpers' )
->once()
->with( false )
->andReturns( true );

private function set_user_cap_conditions() {
Functions\expect( 'current_user_can' )
->once()
->andReturn( true );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Pre-connection JITMs: update connection links to have from parameter.


72 changes: 57 additions & 15 deletions projects/plugins/jetpack/class-jetpack-pre-connection-jitms.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package jetpack
*/

use Automattic\Jetpack\Redirect;

/**
* Jetpack's Pre-Connection JITMs. These can be displayed with the JITM package.
*/
Expand All @@ -16,29 +18,28 @@ class Jetpack_Pre_Connection_JITMs {
* @return array An array containing the pre-connection JITM messages.
*/
private function get_raw_messages() {
$jetpack_setup_url = $this->generate_admin_url(
array(
'page' => 'jetpack',
'#/setup' => '',
)
);
$button_caption = __( 'Set up Jetpack', 'jetpack' );
/* Translators: placeholders are links. */
$media_description = __( 'Click on the <strong>Set up Jetpack</strong> button to agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com, and gain access to Site Accelerator.', 'jetpack' );
/* Translators: placeholders are links. */
$widgets_description = __( 'Click on the <strong>Set up Jetpack</strong> button to agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com, and gain access to great additional widgets.', 'jetpack' );
/* Translators: placeholders are links. */
$posts_description = __( 'Click on the <strong>Set up Jetpack</strong> button to agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com, and gain access to in-depth stats about your site.', 'jetpack' );

$messages = array(
array(
'id' => 'jpsetup-upload',
'message_path' => '/wp:upload:admin_notices/',
'message' => __( 'Do you want lightning-fast images?', 'jetpack' ),
'description' => __( 'Set up Jetpack, enable Site Accelerator, and start serving your images lightning fast, for free.', 'jetpack' ),
'button_link' => $jetpack_setup_url,
'button_caption' => __( 'Set up Jetpack', 'jetpack' ),
'description' => $this->generate_description_with_tos( $media_description ),
'button_caption' => $button_caption,
),
array(
'id' => 'jpsetup-widgets',
'message_path' => '/wp:widgets:admin_notices/',
'message' => __( 'Looking for even more widgets?', 'jetpack' ),
'description' => __( 'Set up Jetpack for great additional widgets that display business contact info and maps, blog stats, and top posts.', 'jetpack' ),
'button_link' => $jetpack_setup_url,
'button_caption' => __( 'Set up Jetpack', 'jetpack' ),
'description' => $this->generate_description_with_tos( $widgets_description ),
'button_caption' => $button_caption,
),
);

Expand All @@ -47,15 +48,56 @@ private function get_raw_messages() {
'id' => 'jpsetup-posts',
'message_path' => '/wp:edit-post:admin_notices/',
'message' => __( 'Do you know which of these posts gets the most traffic?', 'jetpack' ),
'description' => __( 'Set up Jetpack to get in-depth stats about your content and visitors.', 'jetpack' ),
'button_link' => $jetpack_setup_url,
'button_caption' => __( 'Set up Jetpack', 'jetpack' ),
'description' => $this->generate_description_with_tos( $posts_description ),
'button_caption' => $button_caption,
);
}

foreach ( $messages as $key => $message ) {
/*
* Add Connect URL to each message, with from including jitm id.
*/
$jetpack_setup_url = $this->generate_admin_url(
array(
'page' => 'jetpack#/setup',
'from' => sprintf( 'pre-connection-jitm-%s', $message['id'] ),
)
);
$messages[ $key ]['button_link'] = $jetpack_setup_url;
}

return $messages;
}

/**
* Generate a description text with links to ToS documents.
*
* Those messages must mention the ToS agreement message,
* but do not use the standard message defined in jetpack_render_tos_blurb.
* Instead, they use their own custom messages.
*
* @param string $description Description string with placeholders.
*
* @return string
*/
private function generate_description_with_tos( $description ) {
return sprintf(
wp_kses(
$description,
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
'strong' => true,
)
),
esc_url( Redirect::get_url( 'wpcom-tos' ) ),
esc_url( Redirect::get_url( 'jetpack-support-what-data-does-jetpack-sync' ) )
);
}

/**
* Adds the input query arguments to the admin url.
*
Expand Down
2 changes: 2 additions & 0 deletions projects/plugins/jetpack/functions.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ function jetpack_get_migration_data( $option_name ) {
/**
* Prints a TOS blurb used throughout the connection prompts.
*
* Note: custom ToS messages are also defined in Jetpack_Pre_Connection_JITMs->get_raw_messages()
*
* @since 5.3
*
* @echo string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_add_pre_connection_jitms_button_link() {
$jitms = new Jetpack_Pre_Connection_JITMs();
$messages = $jitms->add_pre_connection_jitms( array() );

$query = 'admin.php?page=jetpack&#/setup';
$query = 'admin.php?page=jetpack#/setup&from=pre-connection-jitm-jpsetup-upload';

// Verify that the `jpsetup-upload` JITM is in the list of JITMs.
$index = array_search( 'jpsetup-upload', array_column( $messages, 'id' ), true );
Expand Down

0 comments on commit 7e18142

Please sign in to comment.