Skip to content

Commit

Permalink
Subscriber page: add Launchpad tasks & task list (#33948)
Browse files Browse the repository at this point in the history
* Add subscriber-related tasks to launchpad

New tasks related to subscribers have been added to the launchpad. The tasks added are 'import_subscribers', 'share_site' and 'add_subscribe_block' which allow users to import existing subscribers, share site and add subscribe block to the theme respectively. Logic for checking if the subscribe block has been added to the template part content has also been included, marking the task as complete when the block is found.

* Add subscriber-related tasks to launchpad

New tasks related to subscribers have been added to the launchpad. The tasks added are 'import_subscribers', 'share_site' and 'add_subscribe_block' which allow users to import existing subscribers, share site and add subscribe block to the theme respectively. Logic for checking if the subscribe block has been added to the template part content has also been included, marking the task as complete when the block is found.

* Extend subscribe block check to all saved templates

* Add check for FSE

* Update projects/packages/jetpack-mu-wpcom/src/features/launchpad/launchpad-task-definitions.php

Co-authored-by: daledupreez <[email protected]>

* Change wording

* Update projects/packages/jetpack-mu-wpcom/src/features/launchpad/launchpad.php

Co-authored-by: daledupreez <[email protected]>

* Rebase

* Bump version of jetpack-mu-wpcom and mu-wpcom-plugin

* Update versions

* Update projects/packages/jetpack-mu-wpcom/changelog/add-subscriber-launchpad-tasks

Co-authored-by: Ivan Ottinger <[email protected]>

---------

Co-authored-by: daledupreez <[email protected]>
Co-authored-by: Ivan Ottinger <[email protected]>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6787147353
  • Loading branch information
TimBroddin authored and matticbot committed Nov 7, 2023
1 parent db7cffc commit e8fc494
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.17.0-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- Added Subscribers page Launchpad tasks

## [4.16.2] - 2023-11-03
### Fixed
- Launchpad hooks: Made more resilient against non-array values. [#33923]
Expand Down Expand Up @@ -418,6 +425,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Testing initial package release.

[4.17.0-alpha]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v4.16.2...v4.17.0-alpha
[4.16.2]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v4.16.1...v4.16.2
[4.16.1]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v4.16.0...v4.16.1
[4.16.0]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v4.15.1...v4.16.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "4.16.x-dev"
"dev-trunk": "4.17.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "4.16.2",
"version": "4.17.0-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion src/class-jetpack-mu-wpcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class Jetpack_Mu_Wpcom {

const PACKAGE_VERSION = '4.16.2';
const PACKAGE_VERSION = '4.17.0-alpha';
const PKG_DIR = __DIR__ . '/../';

/**
Expand Down
59 changes: 59 additions & 0 deletions src/features/launchpad/launchpad-task-definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,27 @@ function wpcom_launchpad_get_task_definitions() {
return '/site-monitoring/' . $data['site_slug_encoded'];
},
),
'import_subscribers' => array(
'get_title' => function () {
return __( 'Import existing subscribers', 'jetpack-mu-wpcom' );
},
'id_map' => 'subscribers_added',
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => '__return_true',
'get_calypso_path' => function ( $task, $default, $data ) {
return '/subscribers/' . $data['site_slug_encoded'] . '#add-subscribers';
},
),
'add_subscribe_block' => array(
'get_title' => function () {
return __( 'Add the Subscribe Block to your site', 'jetpack-mu-wpcom' );
},
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => 'wpcom_launchpad_is_add_subscribe_block_visible',
'get_calypso_path' => function ( $task, $default, $data ) {
return '/site-editor/' . $data['site_slug_encoded'];
},
),
);

$extended_task_definitions = apply_filters( 'wpcom_launchpad_extended_task_definitions', array() );
Expand Down Expand Up @@ -1768,6 +1789,44 @@ function wpcom_launchpad_edit_page_check( $post_id, $post ) {
}
add_action( 'post_updated', 'wpcom_launchpad_edit_page_check', 10, 3 );

/**
* Determine `add_subscribe_block` task visibility. The task is visible if using a FSE theme.
*
* @return bool True if we should show the task, false otherwise.
*/
function wpcom_launchpad_is_add_subscribe_block_visible() {
return is_callable( array( '\Automattic\Jetpack\Blocks', 'is_fse_theme' ) ) && \Automattic\Jetpack\Blocks::is_fse_theme();
}

/**
* When a template or template part is saved, check if the subscribe block is in the content.
*
* @param int $post_id The ID of the post being updated.
* @param WP_Post $post The post object.
*
* @return bool True if the task is completed, false otherwise.
*/
function wpcom_launchpad_add_subscribe_block_check( $post_id, $post ) {
// If this is just a revision, don't proceed.
if ( wp_is_post_revision( $post_id ) ) {
return;
}

// Check if it's a published template or template part.
if ( $post->post_status !== 'publish' || ( $post->post_type !== 'wp_template' && $post->post_type !== 'wp_template_part' ) ) {
return;
}

// Check if our subscribe block is in the template or template part content.
if ( has_block( 'jetpack/subscriptions', $post->post_content ) ) {
// Run your specific function if the subscribe block is found.
wpcom_mark_launchpad_task_complete( 'add_subscribe_block' );
}
}

// Hook the function to the save_post action for all post types.
add_action( 'save_post', 'wpcom_launchpad_add_subscribe_block_check', 10, 2 );

/**
* Returns if the site has domain or bundle purchases.
*
Expand Down
8 changes: 8 additions & 0 deletions src/features/launchpad/launchpad.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ function wpcom_launchpad_get_task_list_definitions() {
),
'is_enabled_callback' => 'wpcom_launchpad_is_hosting_flow_enabled',
),
'subscribers' => array(
'title' => 'Subscribers',
'task_ids' => array(
'import_subscribers',
'add_subscribe_block',
'share_site',
),
),
);

$extended_task_list_definitions = apply_filters( 'wpcom_launchpad_extended_task_list_definitions', array() );
Expand Down

0 comments on commit e8fc494

Please sign in to comment.