';
$output .= '
';
$output .= '' . esc_html__( 'CartFlows: Custom Script Migration', 'cartflows' ) . '
';
$output .= esc_html__( 'CartFlows now has dedicated JavaScript and CSS editors for custom scripts in your funnels and steps. Click "Migrate Data" to move your existing scripts to the new editors, or choose "Remind Me Later" to be notified again in 7 days.', 'cartflows' );
$output .= '
';
$output .= '
';
$output .= '';
$output .= ' ';
$output .= '';
$output .= '
';
$output .= '
';
echo wp_kses_post( $output );
}
/**
* Handle snooze (remind me later) AJAX request for the script migration notice.
*
* Increments the skip counter and updates the skip timestamp.
* After 2 skips, sets the status to 'accepted' to stop showing the notice.
*
* @since 2.2.2
* @return void
*/
public function snooze_script_migration_notice() {
if ( ! check_ajax_referer( 'cartflows-snooze-script-migration', 'security', false ) ) {
wp_send_json_error( array( 'message' => __( 'Invalid nonce.', 'cartflows' ) ) );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'cartflows' ) ) );
}
$update = Cartflows_Update::get_instance();
if ( $update instanceof Cartflows_Update ) {
$update->set_script_migration_status( 'skipped' );
$update->increment_migration_skip_count();
// After 2 skips, stop showing the notice permanently.
if ( $update->get_migration_skip_count() >= 2 ) {
$update->set_script_migration_status( 'accepted' );
}
wp_send_json_success( array( 'message' => __( 'You will be reminded in 7 days.', 'cartflows' ) ) );
}
wp_send_json_error( array( 'message' => __( 'Unable to update migration status.', 'cartflows' ) ) );
}
/**
* After save of permalinks.
*/
public function notices_scripts() {
if ( ! $this->allowed_screen_for_notices() || ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
return;
}
wp_enqueue_style( 'cartflows-custom-notices', CARTFLOWS_URL . 'admin/assets/css/notices.css', array(), CARTFLOWS_VER );
wp_enqueue_script( 'cartflows-notices', CARTFLOWS_URL . 'admin/assets/js/ui-notice.js', array( 'jquery' ), CARTFLOWS_VER, true );
$localize_vars = array(
'ignore_gb_notice' => wp_create_nonce( 'cartflows-ignore-gutenberg-notice' ),
'dismiss_weekly_report_email_notice' => wp_create_nonce( 'cartflows-disable-weekly-report-email-notice' ),
'snooze_script_migration' => wp_create_nonce( 'cartflows-snooze-script-migration' ),
'migrate_custom_scripts' => wp_create_nonce( 'cartflows_migrate_custom_scripts' ),
'dismiss_migration_complete_notice' => wp_create_nonce( 'cartflows-dismiss-script-migration-complete-notice' ),
);
wp_localize_script( 'cartflows-notices', 'cartflows_notices', $localize_vars );
}
/**
* After save of permalinks.
*/
public function show_admin_notices() {
if ( ! $this->allowed_screen_for_notices() || ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
return;
}
global $wp_version;
if ( version_compare( $wp_version, '5.0', '>=' ) && is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
add_action( 'admin_notices', array( $this, 'gutenberg_plugin_deactivate_notice' ) );
}
add_action( 'admin_notices', array( $this, 'show_weekly_report_email_settings_notice' ) );
add_action( 'admin_notices', array( $this, 'show_script_migration_notice' ) );
add_action( 'admin_notices', array( $this, 'show_script_migration_complete_notice' ) );
$image_path = esc_url( CARTFLOWS_URL . 'assets/images/cartflows-logo-small.jpg' );
Astra_Notices::add_notice(
array(
'id' => 'cartflows-5-start-notice',
'type' => 'info',
'class' => 'cartflows-5-star',
'show_if' => true,
/* translators: %1$s white label plugin name and %2$s deactivation link */
'message' => sprintf(
'';
$output .= '
';
$output .= '' . esc_html__( 'CartFlows: Custom Script Migration Complete', 'cartflows' ) . '
';
$output .= esc_html__( 'Your scripts have been successfully migrated to the dedicated JavaScript and CSS editors.', 'cartflows' );
$output .= '
';
$output .= '
';
echo wp_kses_post( $output );
}
/**
* Handle dismiss AJAX request for the script migration complete notice.
*
* Permanently hides the migration complete notice once the user dismisses it.
*
* @since 2.2.2
* @return void
*/
public function dismiss_script_migration_complete_notice() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'cartflows' ) ) );
}
check_ajax_referer( 'cartflows-dismiss-script-migration-complete-notice', 'security' );
update_option( 'cartflows_script_migration_complete_notice_dismissed', 'yes' );
wp_send_json_success();
}
/**
* Check allowed screen for notices.
*
* @since 1.0.0
*
* @param array $exclude_page_ids Optional. Array of screen IDs to exclude from displaying notices.
* @return bool True if the notice should be displayed, false otherwise.
*/
public function allowed_screen_for_notices( $exclude_page_ids = array() ) {
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$allowed_screens = array(
'dashboard',
'plugins',
);
// Exclude any page ids passed in $exclude_page_ids from $allowed_screens.
if ( ! empty( $exclude_page_ids ) && is_array( $exclude_page_ids ) ) {
$allowed_screens = array_diff( $allowed_screens, $exclude_page_ids );
}
if ( in_array( $screen_id, $allowed_screens, true ) ) {
return true;
}
return false;
}
/**
* Check if the user has completed the onboarding, skipped the onboarding on ready step, and the store checkout is imported.
*
* @since 2.1.6
* @return bool
*/
public function should_display_nps_survey_notice() {
$is_store_checkout_imported = (bool) get_option( '_cartflows_wizard_store_checkout_set', false ); // Must be true.
$onboarding_completed = (bool) get_option( 'wcf_setup_complete', false ); // Must be true.
$is_first_funnel_imported = (bool) get_option( 'wcf_first_flow_imported', false ); // Must be true.
$total_funnels = intval( wp_count_posts( CARTFLOWS_FLOW_POST_TYPE )->publish ); // Must be greater than or equal to 1.
/**
* Show the notice in two conditions.
* 1. If completed the onboarding steps/process of plugin and sets their first store checkout funnel successfully.
* 2. If sets up the first funnel manually and makes it live.
*/
return ( true === $is_store_checkout_imported && true === $onboarding_completed ) || ( true === $is_first_funnel_imported && ! empty( $total_funnels ) && 1 >= $total_funnels ) || ( ! empty( $total_funnels ) && 1 >= $total_funnels );
}
}
Cartflows_Admin_Notices::get_instance();