Skip to content
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

Add an "Are you sure" interstitial #9

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 69 additions & 14 deletions includes/DeactivationSurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace NewfoldLabs\WP\Module\Deactivation;

use NewfoldLabs\WP\ModuleLoader\Container;
use function NewfoldLabs\WP\ModuleLoader\container;

/**
Expand All @@ -18,6 +19,71 @@ class DeactivationSurvey {
* DeactivationSurvey constructor.
*/
public function __construct() {
// $this->container = $container;

$defaults = array(
'surveyAriaTitle' => __( 'Plugin Deactivation Survey', 'wp-module-deactivation' ),
'surveyTitle' => sprintf(
__( 'Thank you for using the %s plugin!', 'wp-module-deactivation' ),
ucwords( container()->plugin()->id )
),
'surveyDesc' => __( 'Please take a moment to let us know why you\'re deactivating this plugin.', 'wp-module-deactivation' ),
'formAriaLabel' => __( 'Plugin Deactivation Form', 'wp-module-deactivation' ),
'label' => __( 'Why are you deactivating this plugin?', 'wp-module-deactivation' ),
'placeholder' => __( 'Please share the reason here...', 'wp-module-deactivation' ),
'submit' => __( 'Submit & Deactivate', 'wp-module-deactivation' ),
'submitAriaLabel' => __( 'Submit and Deactivate Plugin', 'wp-module-deactivation' ),
'cancel' => __( 'Cancel', 'wp-module-deactivation' ),
'cancelAriaLabel' => __( 'Cancel Deactivation', 'wp-module-deactivation' ),
'skip' => __( 'Skip & Deactivate', 'wp-module-deactivation' ),
'skipAriaLabel' => __( 'Skip and Deactivate Plugin', 'wp-module-deactivation' ),
'continue' => __( 'Continue', 'wp-module-deactivation' ),
'continueAriaLabel' => __( 'Continue Deactivation', 'wp-module-deactivation' ),
'sureTitle' => __( 'Are you sure you want to deactivate?', 'wp-module-deactivation' ),
'sureDesc' => __( 'If the Bluehost plugin is deactivated, these features will no longer work:', 'wp-module-deactivation' ),
'sureCards' => array(
array(
'title' => sprintf(
__( '%s Caching', 'wp-module-deactivation' ),
ucwords( container()->plugin()->id )
),
'desc' => __( 'Automatically clears the server page cache when your site updates', 'wp-module-deactivation' ),
'condition' => true,
),
array(
'title' => sprintf(
__( '%s Staging', 'wp-module-deactivation' ),
ucwords( container()->plugin()->id )
),
'desc' => __( 'Create a staging copy of your site to safely test changes', 'wp-module-deactivation' ),
'condition' => true,
),
array(
'title' => __( 'WooCommerce Tools', 'wp-module-deactivation' ),
'desc' => __( 'Run campaigns and promotions on your store', 'wp-module-deactivation' ),
'condition' => 'window.NewfoldRuntime.isWoocommerceActive',
),
array(
'title' => __( 'Wonder Blocks & Patterns Library', 'wp-module-deactivation' ),
'desc' => __( 'Dozens of beautiful block templates and patterns', 'wp-module-deactivation' ),
'condition' => true,
),
),
'sureHelp' => sprintf(
__( 'Need Help? Check the <a href="%s">help center</a> for support.', 'wp-module-deactivation' ),
'/wp-admin/admin.php?page=' . container()->plugin()->id . '#/help'
),
);

// Merge defaults with container values from plugin
// $this->strings = wp_parse_args(
// $container->has( 'deactivation' ) ?
// $container['deactivation'] :
// array(),
// $defaults
// );
$this->strings = $defaults;

$this->deactivation_survey_assets();
$this->deactivation_survey_runtime();
}
Expand Down Expand Up @@ -60,6 +126,8 @@ public function deactivation_survey_assets() {
public function deactivation_survey_runtime() {
$plugin_slug = explode( '/', container()->plugin()->basename )[0];

// Validate strings->cards via condition

wp_localize_script(
'nfd-deactivation-survey',
'newfoldDeactivationSurvey',
Expand All @@ -68,20 +136,7 @@ public function deactivation_survey_runtime() {
'restApiNonce' => wp_create_nonce( 'wp_rest' ),
'brand' => container()->plugin()->id,
'pluginSlug' => $plugin_slug,
'strings' => array(
'surveyTitle' => __( 'Plugin Deactivation Survey', 'wp-module-deactivation' ),
'dialogTitle' => sprintf( __( 'Thank you for using the %s plugin!', 'wp-module-deactivation' ), ucwords( container()->plugin()->id ) ),
'dialogDesc' => __( 'Please take a moment to let us know why you\'re deactivating this plugin.', 'wp-module-deactivation' ),
'formAriaLabel' => __( 'Plugin Deactivation Form', 'wp-module-deactivation' ),
'label' => __( 'Why are you deactivating this plugin?', 'wp-module-deactivation' ),
'placeholder' => __( 'Please share the reason here...', 'wp-module-deactivation' ),
'submit' => __( 'Submit & Deactivate', 'wp-module-deactivation' ),
'submitAriaLabel' => __( 'Submit and Deactivate Plugin', 'wp-module-deactivation' ),
'cancel' => __( 'Cancel', 'wp-module-deactivation' ),
'cancelAriaLabel' => __( 'Cancel Deactivation', 'wp-module-deactivation' ),
'skip' => __( 'Skip & Deactivate', 'wp-module-deactivation' ),
'skipAriaLabel' => __( 'Skip and Deactivate Plugin', 'wp-module-deactivation' ),
),
'strings' => $this->strings,
)
);
}
Expand Down
Loading
Loading