Skip to content

Commit

Permalink
Launchpad: Add earn checklist (#33200)
Browse files Browse the repository at this point in the history
  • Loading branch information
edanzer authored Oct 12, 2023
1 parent 173d2ce commit b265159
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Launchpad: Add earn-newsletter checklist.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,34 @@ function wpcom_launchpad_get_task_definitions() {
return '/page/' . $data['site_slug_encoded'];
},
),

// Earn tasks
'stripe_connected' => array(
'get_title' => function () {
return __( 'Connect a Stripe account to collect payments', 'jetpack-mu-wpcom' );
},
'is_visible_callback' => '__return_true',
'is_complete_callback' => 'wpcom_launchpad_is_stripe_connected',
'get_calypso_path' => function ( $task, $default, $data ) {
if ( function_exists( 'get_memberships_connected_account_redirect' ) ) {
return get_memberships_connected_account_redirect(
get_current_user_id(),
get_current_blog_id()
);
}
return '/earn/payments/' . $data['site_slug_encoded'];
},
),
'paid_offer_created' => array(
'get_title' => function () {
return __( 'Set up an offer for your supporters', 'jetpack-mu-wpcom' );
},
'is_complete_callback' => 'wpcom_launchpad_has_paid_membership_plans',
'is_visible_callback' => '__return_true',
'get_calypso_path' => function ( $task, $default, $data ) {
return '/earn/payments-plans/' . $data['site_slug_encoded'];
},
),
);

$extended_task_definitions = apply_filters( 'wpcom_launchpad_extended_task_definitions', array() );
Expand Down Expand Up @@ -855,6 +883,52 @@ function wpcom_launchpad_get_newsletter_subscriber_count() {
return (int) $total_subscribers;
}

/**
* Determines if Stripe has been connected.
*
* @return bool Whether Stripe account is connected.
*/
function wpcom_launchpad_is_stripe_connected() {
$membership_settings = wpcom_launchpad_get_membership_settings();
if ( ! $membership_settings ) {
return false;
}
return isset( $membership_settings['connected_account_id'] ) && $membership_settings['connected_account_id'] !== '';
}

/**
* Determines if any paid membership plan exists.
*
* @return bool Whether paid plan exists.
*/
function wpcom_launchpad_has_paid_membership_plans() {
$membership_settings = wpcom_launchpad_get_membership_settings();
if ( ! $membership_settings ) {
return false;
}
return isset( $membership_settings['products'] ) && is_array( $membership_settings['products'] ) && ( count( $membership_settings['products'] ) > 0 );
}

/**
* Get membership settings.
*
* @return array|null Membership settings or null.
*/
function wpcom_launchpad_get_membership_settings() {
$is_atomic = defined( 'IS_ATOMIC' ) && IS_ATOMIC;

// Memberships lib is only available on Simple sites.
// A follow up will fetch membership settings for Atomic.
if ( $is_atomic ) {
return null;
}

require_lib( 'memberships' );
$blog_id = get_current_blog_id();
$settings = (array) get_memberships_settings_for_site( $blog_id );
return $settings;
}

/**
* Callback for completing first post published task.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ function wpcom_launchpad_get_task_list_definitions() {
),
'is_enabled_callback' => 'wpcom_launchpad_is_paid_newsletter_enabled',
),
'earn' => array(
'title' => 'Earn',
'task_ids' => array(
'stripe_connected',
'paid_offer_created',
),
'is_enabled_callback' => '__return_true',
),
);

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

0 comments on commit b265159

Please sign in to comment.