-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ras): add flag to setup CLI command to skip default campaign setup #3132
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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' ) ); | ||||||
WP_CLI::warning( __( 'Newspack Campaigns plugin not found. Activating...', 'newspack-plugin' ) ); | ||||||
Plugin_Manager::install( 'newspack-popups' ); // Must be installed before being activated to avoid a fatal. | ||||||
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() ) ) { | ||||||
if ( ! $skip_campaigns && \is_wp_error( \Newspack_Newsletters_Subscription::get_lists() ) ) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should |
||||||
WP_CLI::error( __( 'Newspack Newsletters provider not set.', 'newspack-plugin' ) ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message should rather inform about the inability to get lists, instead of making an assumption about how |
||||||
} | ||||||
|
||||||
$result = \Newspack_Popups_Presets::activate_ras_presets(); | ||||||
|
||||||
$result = $skip_campaigns ? Reader_Activation::update_setting( 'enabled', true ) : \Newspack_Popups_Presets::activate_ras_presets(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
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' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "with" and "without" are should be translatable:
Suggested change
However, this might be making too many assumptions about language structure. I think a safer bet would be to have two separate no-placeholder strings instead of a conditional placeholder value. |
||||||
) | ||||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not error out, but only warn about the campaigns being already configured. See comment below – this CLI command should always allow to enable RAS.