From 056134466140f73f94a93b0a4103393a11606360 Mon Sep 17 00:00:00 2001 From: dkoo Date: Thu, 23 May 2024 10:54:38 -0600 Subject: [PATCH 1/2] feat(ras): add flag to setup CLI command to skip default campaign setp --- includes/cli/class-initializer.php | 18 +++++++++++++--- includes/cli/class-ras.php | 33 +++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/includes/cli/class-initializer.php b/includes/cli/class-initializer.php index eccb8cddc1..9884f4298a 100644 --- a/includes/cli/class-initializer.php +++ b/includes/cli/class-initializer.php @@ -42,19 +42,31 @@ public static function register_comands() { // Utility commands for managing RAS data via WP CLI. WP_CLI::add_command( 'newspack ras setup', - [ 'Newspack\CLI\RAS', 'cli_setup_ras' ] + [ 'Newspack\CLI\RAS', 'cli_setup_ras' ], + [ + 'shortdesc' => 'Enable Reader Activation features.', + 'synopsis' => [ + [ + 'type' => 'flag', + 'name' => 'skip-campaigns', + 'default' => false, + 'description' => 'Skip the creation of default campaign prompts and segments.', + 'optional' => true, + ], + ], + ] ); WP_CLI::add_command( 'newspack verify-reader', [ 'Newspack\CLI\RAS', 'cli_verify_reader' ], [ - 'shortdesc' => 'Verify a reader account . ', + 'shortdesc' => 'Verify a reader account.', 'synopsis' => [ [ 'type' => 'positional', 'name' => 'user', - 'description' => 'ID or email of the user account . ', + 'description' => 'ID or email of the user account.', 'optional' => false, 'repeating' => false, ], diff --git a/includes/cli/class-ras.php b/includes/cli/class-ras.php index f0c0123817..68bd52e54c 100644 --- a/includes/cli/class-ras.php +++ b/includes/cli/class-ras.php @@ -8,6 +8,8 @@ namespace Newspack\CLI; use WP_CLI; +use Newspack\Engagement_Wizard; +use Newspack\Plugin_Manager; use Newspack\Reader_Activation; defined( 'ABSPATH' ) || exit; @@ -17,34 +19,45 @@ */ class RAS { /** - * Verify the given user, bypassing the need to complete the email-based verification flow. + * Enable Reader Activation features without having to complete the onboarding wizard. + * + * @param array $args Positional args. + * @param array $assoc_args Associative args. */ - public static function cli_setup_ras() { - if ( Reader_Activation::is_ras_campaign_configured() ) { + public static function cli_setup_ras( $args, $assoc_args ) { + $skip_campaigns = ! empty( $assoc_args['skip-campaigns'] ); + if ( ! $skip_campaigns && Reader_Activation::is_ras_campaign_configured() ) { WP_CLI::error( __( 'RAS is already configured for this site.', 'newspack-plugin' ) ); } - if ( ! class_exists( '\Newspack_Popups_Presets' ) ) { - WP_CLI::error( __( 'Newspack Campaigns plugin not found.', 'newspack-plugin' ) ); + if ( ! $skip_campaigns && ! class_exists( '\Newspack_Popups_Presets' ) ) { + WP_CLI::warning( __( 'Newspack Campaigns plugin not found. Activating...', 'newspack-plugin' ) ); + Plugin_Manager::install( 'newspack-popups' ); + Plugin_Manager::activate( 'newspack-popups' ); } - if ( ! class_exists( '\Newspack_Newsletters_Subscription' ) ) { - WP_CLI::error( __( 'Newspack Newsletters plugin not found.', 'newspack-plugin' ) ); + WP_CLI::warning( __( 'Newspack Newsletters plugin not found. Activating...', 'newspack-plugin' ) ); + Plugin_Manager::activate( 'newspack-newsletters' ); } if ( \is_wp_error( \Newspack_Newsletters_Subscription::get_lists() ) ) { WP_CLI::error( __( 'Newspack Newsletters provider not set.', 'newspack-plugin' ) ); } - $result = \Newspack_Popups_Presets::activate_ras_presets(); - + $result = $skip_campaigns ? Reader_Activation::update_setting( 'enabled', true ) : \Newspack_Popups_Presets::activate_ras_presets(); if ( ! $result ) { WP_CLI::error( __( 'Something went wrong. Please check for required plugins and try again.', 'newspack-plugin' ) ); exit; } - WP_CLI::success( __( 'RAS enabled with default prompts.', 'newspack-plugin' ) ); + WP_CLI::success( + sprintf( + // Translators: 'with' or 'without' default prompts. + __( 'RAS enabled %s default prompts.', 'newspack-plugin' ), + $skip_campaigns ? 'without' : 'with' + ) + ); } /** From 25a1d4d9ccf3bf2c67a13efaf8e32959c28a14f4 Mon Sep 17 00:00:00 2001 From: dkoo Date: Thu, 23 May 2024 11:18:48 -0600 Subject: [PATCH 2/2] fix: install plugins even if skipping Campaigns setup --- includes/cli/class-ras.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/cli/class-ras.php b/includes/cli/class-ras.php index 68bd52e54c..a0b46bf29f 100644 --- a/includes/cli/class-ras.php +++ b/includes/cli/class-ras.php @@ -30,9 +30,9 @@ public static function cli_setup_ras( $args, $assoc_args ) { WP_CLI::error( __( 'RAS is already configured for this site.', 'newspack-plugin' ) ); } - if ( ! $skip_campaigns && ! class_exists( '\Newspack_Popups_Presets' ) ) { + if ( ! class_exists( '\Newspack_Popups_Presets' ) ) { WP_CLI::warning( __( 'Newspack Campaigns plugin not found. Activating...', 'newspack-plugin' ) ); - Plugin_Manager::install( 'newspack-popups' ); + Plugin_Manager::install( 'newspack-popups' ); // Must be installed before being activated to avoid a fatal. Plugin_Manager::activate( 'newspack-popups' ); } @@ -41,7 +41,7 @@ public static function cli_setup_ras( $args, $assoc_args ) { Plugin_Manager::activate( 'newspack-newsletters' ); } - if ( \is_wp_error( \Newspack_Newsletters_Subscription::get_lists() ) ) { + if ( ! $skip_campaigns && \is_wp_error( \Newspack_Newsletters_Subscription::get_lists() ) ) { WP_CLI::error( __( 'Newspack Newsletters provider not set.', 'newspack-plugin' ) ); }