This commit is contained in:
2025-11-18 16:39:33 +00:00
parent c70394d367
commit df1f90c6cd
9673 changed files with 3464697 additions and 34 deletions
@@ -0,0 +1,394 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
use Hostinger\EasyOnboarding\Admin\Actions;
use Hostinger\EasyOnboarding\AmplitudeEvents\Amplitude;
use Hostinger\EasyOnboarding\AmplitudeEvents\Actions as AmplitudeActions;
use Hostinger\EasyOnboarding\Helper;
use Hostinger\EasyOnboarding\Admin\Actions as Admin_Actions;
use WP_Post;
defined( 'ABSPATH' ) || exit;
class AutocompleteSteps {
/**
* @var Helper
*/
private Helper $helper;
/**
* @var Onboarding
*/
private Onboarding $onboarding;
/**
* @var Amplitude
*/
private Amplitude $amplitude;
public function __construct() {
$this->onboarding = new Onboarding();
$this->helper = new Helper();
$this->amplitude = new Amplitude();
add_action( 'admin_init', array( $this, 'init_onboarding' ), 0 );
add_action( 'save_post_product', array( $this, 'new_product_creation' ), 10, 3 );
add_action( 'woocommerce_shipping_zone_method_added', array( $this, 'shipping_zone_added' ), 10, 3 );
add_action( 'googlesitekit_authorize_user', array( $this, 'googlesite_connected' ) );
add_action( 'admin_init', array( $this, 'woocommerce_steps_completed' ) );
if ( is_plugin_active( 'hostinger-affiliate-plugin/hostinger-affiliate-plugin.php' ) ) {
add_action( 'admin_init', array( $this, 'affiliate_plugin_connected' ) );
}
if ( is_admin() && isset( $_GET['page'] ) && $_GET['page'] === 'hostinger' ) {
add_action( 'admin_init', array( $this, 'domain_is_connected' ) );
}
if ( $this->helper->is_store_setup_completed() ) {
add_action( 'admin_init', array( $this, 'website_setup_completed' ) );
}
add_action( 'astra_sites_import_complete', array( $this, 'astra_website_import_completed' ) );
add_action( 'admin_init', array( $this, 'ai_website_generated' ) );
add_action( 'admin_init', array( $this, 'check_ai_discovery_is_enabled' ) );
if ( is_plugin_active( 'hostinger-reach/hostinger-reach.php' ) ) {
add_action( 'admin_init', array( $this, 'reach_plugin_connected' ) );
}
add_action( 'admin_init', array( $this, 'check_onboarding_steps_was_completed' ) );
}
public function init_onboarding(): void {
$this->onboarding->init();
}
public function affiliate_plugin_connected(): void {
if ( ! class_exists( '\Hostinger\AffiliatePlugin\Admin\PluginSettings' ) ) {
return;
}
$action = Admin_Actions::AMAZON_AFFILIATE;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
$settings = new \Hostinger\AffiliatePlugin\Admin\PluginSettings();
$plugin_settings = $settings->get_plugin_settings()->to_array();
$amazon_connection_status = $plugin_settings['amazon_connection_status'] ?? '';
$mercado_connection_status = $plugin_settings['mercado_connection_status'] ?? '';
if ( $amazon_connection_status === \Hostinger\AffiliatePlugin\Admin\Options\PluginOptions::STATUS_CONNECTED || $mercado_connection_status === \Hostinger\AffiliatePlugin\Admin\Options\PluginOptions::STATUS_CONNECTED ) {
$this->onboarding->complete_step( $category_id, $action );
$params = array(
'action' => AmplitudeActions::ONBOARDING_ITEM_COMPLETED,
'step_type' => $action,
);
$this->amplitude->send_event( $params );
}
}
public function reach_plugin_connected(): void {
// Do not try to autocomplete step, because it is not added to steps list.
$onboarding_steps_was_completed = get_option( 'hostinger_onboarding_steps_was_completed', 0 );
if ( (int) $onboarding_steps_was_completed === 1 ) {
return;
}
$action = Admin_Actions::REACH;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
$api_key = get_option( 'hostinger_reach_api_key', null );
if ( ! empty( $api_key ) ) {
$this->onboarding->complete_step( $category_id, $action );
$params = array(
'action' => AmplitudeActions::ONBOARDING_ITEM_COMPLETED,
'step_type' => $action,
);
$this->amplitude->send_event( $params );
}
}
public function woocommerce_steps_completed(): void {
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
return;
}
if ( ! $this->helper->is_woocommerce_onboarding_completed() ) {
return;
}
$action = Admin_Actions::STORE_TASKS;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
$this->onboarding->complete_step( $category_id, $action );
$params = array(
'action' => AmplitudeActions::ONBOARDING_ITEM_COMPLETED,
'step_type' => Admin_Actions::STORE_TASKS,
);
$this->amplitude->send_event( $params );
}
/**
* @return void
*/
public function domain_is_connected(): void {
$action = Admin_Actions::DOMAIN_IS_CONNECTED;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
if ( ! $this->helper->is_free_subdomain() && ! $this->helper->is_preview_domain() ) {
if ( ! did_action( 'hostinger_domain_connected' ) ) {
$this->onboarding->complete_step( $category_id, $action );
$params = array(
'action' => AmplitudeActions::ONBOARDING_ITEM_COMPLETED,
'step_type' => Admin_Actions::DOMAIN_IS_CONNECTED,
);
$this->amplitude->send_event( $params );
do_action( 'hostinger_domain_connected' );
}
}
}
public function website_setup_completed(): void {
$action = Admin_Actions::SETUP_STORE;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
$this->onboarding->complete_step( $category_id, $action );
}
/**
* @param int $post_id
* @param bool $update
* @param string $action
*
* @return void
*/
public function new_post_item_creation( int $post_id, bool $update, string $action ): void {
$cookie_value = isset( $_COOKIE[ $action ] ) ? sanitize_text_field( wp_unslash( $_COOKIE[ $action ] ) ) : '';
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) || wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
return;
}
if ( $update && $cookie_value === $action ) {
$this->onboarding->complete_step( $category_id, $action );
}
}
/**
* @param int $post_id
* @param WP_Post $post
* @param bool $update
*
* @return void
*/
public function new_product_creation( int $post_id, WP_Post $post, bool $update ): void {
if ( wp_is_post_revision( $post_id ) ) {
return;
}
if ( $post->post_status !== 'publish' ) {
return;
}
if ( empty( $post->post_author ) ) {
return;
}
if ( $this->onboarding->is_completed( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Admin_Actions::ADD_PRODUCT ) ) {
return;
}
$this->onboarding->complete_step( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Admin_Actions::ADD_PRODUCT );
$add_product_event_sent = get_option( 'hostinger_add_product_event_sent', false );
if ( ! empty( $add_product_event_sent ) ) {
return;
}
$params = array(
'action' => AmplitudeActions::WOO_ITEM_COMPLETED,
'step_type' => Admin_Actions::ADD_PRODUCT,
);
$this->amplitude->send_event( $params );
update_option( 'hostinger_add_product_event_sent', true );
}
/**
* @param $instance_id
* @param $type
* @param $zone_id
*
* @return void
*/
public function shipping_zone_added( int $instance_id, string $type, int $zone_id ): void {
if ( $this->onboarding->is_completed( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Admin_Actions::ADD_SHIPPING ) ) {
return;
}
$this->onboarding->complete_step( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Admin_Actions::ADD_SHIPPING );
$params = array(
'action' => AmplitudeActions::WOO_ITEM_COMPLETED,
'step_type' => Admin_Actions::ADD_SHIPPING,
);
$this->amplitude->send_event( $params );
}
public function googlesite_connected(): void {
$category = Onboarding::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID;
if ( $this->onboarding->is_completed( $category, Admin_Actions::GOOGLE_KIT ) ) {
return;
}
$this->onboarding->complete_step( $category, Admin_Actions::GOOGLE_KIT );
$params = array(
'action' => AmplitudeActions::ONBOARDING_ITEM_COMPLETED,
'step_type' => Admin_Actions::GOOGLE_KIT,
);
$this->amplitude->send_event( $params );
}
public function astra_website_import_completed(): void {
$action = Admin_Actions::AI_STEP;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
$this->onboarding->complete_step( $category_id, $action );
}
public function ai_website_generated(): void {
$action = Admin_Actions::AI_STEP;
$category_id = $this->find_category_from_actions( $action );
if ( empty( $category_id ) ) {
return;
}
if ( $this->onboarding->is_completed( $category_id, $action ) ) {
return;
}
$hostinger_ai_version = get_option( 'hostinger_ai_version', false );
if ( empty( $hostinger_ai_version ) ) {
return;
}
$this->onboarding->complete_step( $category_id, $action );
}
public function check_onboarding_steps_was_completed(): void {
$onboarding_steps_was_completed = get_option( 'hostinger_onboarding_steps_was_completed', null );
if ( ! is_null( $onboarding_steps_was_completed ) ) {
return;
}
update_option( 'hostinger_onboarding_steps_was_completed', ( $this->onboarding->is_onboarding_completed_without_reach() ? 1 : 0 ) );
}
public function check_ai_discovery_is_enabled(): void {
if ( ! Actions::is_enable_ai_discovery_step_eligible() ) {
return;
}
$options_key = defined( 'HOSTINGER_PLUGIN_SETTINGS_OPTION' ) ? HOSTINGER_PLUGIN_SETTINGS_OPTION : 'hostinger_tools';
$settings = get_option( $options_key, array() );
$optin_mcp = $settings['optin_mcp'] ?? false;
$enable_llms_txt = $settings['enable_llms_txt'] ?? false;
if ( $optin_mcp && $enable_llms_txt ) {
$this->onboarding->complete_step( Onboarding::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::ENABLE_AI_DISCOVERY );
}
}
/**
* @param $action
*
* @return string
*/
private function find_category_from_actions( string $action ): string {
foreach ( Admin_Actions::get_category_action_lists() as $category => $actions ) {
if ( in_array( $action, $actions, true ) ) {
return $category;
}
}
return '';
}
}
@@ -0,0 +1,739 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
use Hostinger\EasyOnboarding\Admin\Actions;
use Hostinger\EasyOnboarding\Admin\Onboarding\Steps\Button;
use Hostinger\EasyOnboarding\Admin\Onboarding\Steps\Step;
use Hostinger\EasyOnboarding\Admin\Onboarding\Steps\StepCategory;
use Hostinger\EasyOnboarding\AmplitudeEvents\Actions as AmplitudeActions;
use Hostinger\EasyOnboarding\AmplitudeEvents\Amplitude;
use Hostinger\EasyOnboarding\Helper;
defined( 'ABSPATH' ) || exit;
class Onboarding {
private const HOSTINGER_ADD_DOMAIN_URL = 'https://hpanel.hostinger.com/add-domain/';
private const HOSTINGER_WEBSITES_URL = 'https://hpanel.hostinger.com/websites';
public const HOSTINGER_EASY_ONBOARDING_STEPS_OPTION_NAME = 'hostinger_easy_onboarding_steps';
public const HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID = 'website_setup';
public const HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID = 'online_store_setup';
/**
* @var Helper
*/
private Helper $helper;
/**
* @var array
*/
private array $step_categories = array();
/**
* @return void
*/
public function init(): void {
$this->helper = new Helper();
$this->load_step_categories();
}
/**
* @return array
*/
public function get_step_categories(): array {
return array_map(
function ( $item ) {
return $item->to_array();
},
$this->step_categories
);
}
/**
* @param string $step_category_id
* @param string $step_id
*
* @return bool
*/
public function complete_step( string $step_category_id, string $step_id ): bool {
if ( ! $this->validate_step( $step_category_id, $step_id ) ) {
return false;
}
$onboarding_steps = $this->get_saved_steps();
if ( empty( $onboarding_steps[ $step_category_id ] ) ) {
$onboarding_steps[ $step_category_id ] = array();
}
$onboarding_steps[ $step_category_id ][ $step_id ] = true;
$this->maybe_send_store_events( $onboarding_steps );
return update_option( self::HOSTINGER_EASY_ONBOARDING_STEPS_OPTION_NAME, $onboarding_steps, false );
}
/**
* @param string $step_category_id
* @param string $step_id
*
* @return bool
*/
public function validate_step( string $step_category_id, string $step_id ): bool {
if ( $step_category_id === self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID
&& in_array( $step_id, Actions::STORE_ACTIONS_LIST, true )
) {
return true;
}
$step_categories = $this->get_step_categories();
if ( empty( $step_categories ) ) {
return false;
}
// Try to match step category id.
$found = false;
foreach ( $step_categories as $step_category ) {
if ( $step_category['id'] === $step_category_id ) {
if ( ! empty( $step_category['steps'] ) ) {
foreach ( $step_category['steps'] as $step ) {
if ( $step['id'] === $step_id ) {
$found = true;
break;
}
}
}
break;
}
}
if ( empty( $found ) ) {
return false;
}
return true;
}
/**
* @param string $step_category_id
* @param string $step_id
*
* @return bool
*/
public function is_completed( string $step_category_id, string $step_id ): bool {
$onboarding_steps = $this->get_saved_steps();
if ( empty( $onboarding_steps[ $step_category_id ][ $step_id ] ) ) {
return false;
}
return (bool) $onboarding_steps[ $step_category_id ][ $step_id ];
}
public function maybe_send_store_events( array $steps ): void {
if ( $this->is_store_ready( $steps ) ) {
$this->send_event( AmplitudeActions::WOO_READY_TO_SELL, true );
}
if ( $this->is_store_completed( $steps ) ) {
$this->send_event( AmplitudeActions::WOO_SETUP_COMPLETED, true );
}
}
public function get_first_step_data(): Step {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
$step = new Step( Actions::AI_STEP );
$builder_type = get_option( 'hostinger_builder_type' );
if ( $builder_type === 'ai' ) {
$themes = wp_get_themes();
$is_ai_theme_installed = array_key_exists( 'hostinger-ai-theme', $themes );
$is_ai_theme_active = ( get_stylesheet() === 'hostinger-ai-theme' );
$is_ai_theme_ready = $is_ai_theme_installed && $is_ai_theme_active;
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/ai_step.svg' );
if ( ! $is_ai_theme_ready ) {
$step->set_title( __( 'Create a site with AI', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Build a professional, custom-designed site in moments. Just a few clicks and AI handles the rest.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button();
$primary_button->set_title( __( 'Create site with AI', 'hostinger-easy-onboarding' ) );
$primary_button->set_modal_name( 'CreateWebsiteWithAiBuilderModal' );
$secondary_button = new Button();
$secondary_button->set_title( __( 'Not now', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
} else {
$step->set_title( __( 'Want to create a new AI site?', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Your new site will replace the current one. Use the same description or change it.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button();
$primary_button->set_title( __( 'Keep current site', 'hostinger-easy-onboarding' ) );
$primary_button->set_is_skippable( true );
$secondary_button = new Button();
$secondary_button->set_title( __( 'Create new site', 'hostinger-easy-onboarding' ) );
$secondary_button->set_url( admin_url( 'admin.php?page=hostinger-ai-website-creation&redirect=hostinger-easy-onboarding' ) );
$secondary_button->set_is_completable( false );
}
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
return $step;
}
if ( $builder_type === 'prebuilt' ) {
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/prebuilt.svg' );
$step->set_title( __( 'Want to create a new site on a different template?', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Your new site will replace the current one. Choose from 140+ professional templates.', 'hostinger-easy-onboarding' ) );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::AI_STEP ) ) {
$primary_button = new Button();
$primary_button->set_title( __( 'Keep current site', 'hostinger-easy-onboarding' ) );
$primary_button->set_is_skippable( true );
$step->set_primary_button( $primary_button );
$secondary_button = new Button();
$secondary_button->set_title( __( 'Choose another template', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_astra_needed( true );
$secondary_button->set_url( admin_url( 'themes.php?page=starter-templates&ci=1' ) );
$secondary_button->set_is_completable( false );
$step->set_secondary_button( $secondary_button );
}
}
$whitelist_plans = array(
'cloud_economy',
'cloud_enterprise',
'cloud_professional',
'hostinger_business',
);
$hosting_plan = get_option( 'hostinger_hosting_plan', false );
if ( $builder_type === 'theme' && ! empty( $hosting_plan ) ) {
$primary_button = new Button();
$secondary_button = new Button();
if ( in_array( $hosting_plan, $whitelist_plans, true ) ) {
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/ai_step.svg' );
$step->set_title( __( 'Want to create a new site?', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Your new site will replace the current one. Choose from 140+ professional templates or use AI.', 'hostinger-easy-onboarding' ) );
$primary_button->set_title( __( 'Keep current site', 'hostinger-easy-onboarding' ) );
$primary_button->set_is_skippable( true );
$secondary_button->set_title( __( 'Create new site', 'hostinger-easy-onboarding' ) );
$secondary_button->set_modal_name( 'CreateWebsiteWithAiBuilderModal' );
} else {
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/prebuilt.svg' );
$step->set_title( __( 'Want to create a new site on a pre-built template?', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Your new site will replace the current one. Choose from 140+ professional templates.', 'hostinger-easy-onboarding' ) );
$primary_button->set_title( __( 'Keep current site', 'hostinger-easy-onboarding' ) );
$primary_button->set_is_skippable( true );
$secondary_button->set_title( __( 'Choose a template', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_astra_needed( true );
$secondary_button->set_url( admin_url( 'themes.php?page=starter-templates&ci=1' ) );
$secondary_button->set_is_completable( false );
}
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::AI_STEP ) ) {
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
}
}
if ( $builder_type === 'blank' && ! empty( $hosting_plan ) ) {
$primary_button = new Button();
$secondary_button = new Button();
if ( in_array( $hosting_plan, $whitelist_plans, true ) ) {
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/ai_step.svg' );
$step->set_title( __( 'Start creating your site', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Build a professional, custom-designed site in moments. Choose from 140+ templates or use AI.', 'hostinger-easy-onboarding' ) );
$primary_button->set_title( __( 'Create site', 'hostinger-easy-onboarding' ) );
$primary_button->set_modal_name( 'CreateWebsiteWithAiBuilderModal' );
$secondary_button->set_title( __( 'Not now', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
} else {
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/prebuilt.svg' );
$step->set_title( __( 'Start creating your site', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Build a custom-designed site in minutes with professional templates. You’ll be ready to go live in a few clicks.', 'hostinger-easy-onboarding' ) );
$primary_button->set_title( __( 'Choose template', 'hostinger-easy-onboarding' ) );
$primary_button->set_is_astra_needed( true );
$primary_button->set_url( admin_url( 'themes.php?page=starter-templates&ci=1' ) );
$secondary_button->set_title( __( 'Not now', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
}
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::AI_STEP ) ) {
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
}
}
return $step;
}
public static function is_first_step_active(): bool {
$builder_type = get_option( 'hostinger_builder_type' );
$builder_type_whitelist = array(
'ai',
'theme',
'blank',
'prebuilt',
);
if ( ! in_array( $builder_type, $builder_type_whitelist, true ) ) {
return false;
}
$hosting_plan = get_option( 'hostinger_hosting_plan', false );
if ( empty( $hosting_plan ) ) {
return false;
}
return true;
}
public function is_onboarding_completed_without_reach(): bool {
$actions = Actions::get_action_list_without_reach();
foreach ( $actions as $action_id => $action ) {
if ( ! $this->is_completed( Onboarding::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, $action ) ) {
return false;
}
}
return true;
}
/**
* @return void
*/
private function load_step_categories(): void {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
$website_step_category = new StepCategory(
self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID,
__( 'Website setup', 'hostinger-easy-onboarding' )
);
$first_step = $this->get_first_step_data();
if ( ! empty( $first_step->get_title() ) ) {
$website_step_category->add_step( $first_step );
}
if ( is_plugin_active( 'hostinger-affiliate-plugin/hostinger-affiliate-plugin.php' ) ) {
$website_step_category->add_step( $this->get_amazon_affiliate_step() );
}
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$website_step_category->add_step( $this->get_started_with_store() );
}
// Connect domain.
$website_step_category->add_step( $this->get_add_domain_step() );
$website_step_category->add_step( $this->get_google_kit_step() );
if ( Actions::is_enable_ai_discovery_step_eligible() ) {
$website_step_category->add_step( $this->get_enable_ai_discovery_step() );
}
if ( $this->is_reach_eliglible() ) {
$website_step_category->add_step( $this->get_reach_step() );
}
// Add category.
$this->step_categories[] = $website_step_category;
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$store_step_category = new StepCategory(
self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID,
__( 'Online store setup', 'hostinger-easy-onboarding' )
);
// Setup online store.
$store_step_category->add_step( $this->get_setup_online_store() );
// Add product.
$store_step_category->add_step( $this->get_add_product_step() );
// Add payment method.
$store_step_category->add_step( $this->get_payment_method_step() );
if ( ! $this->helper->is_selling_digital_products() ) {
// Add shipping method.
$store_step_category->add_step( $this->get_shipping_method_step() );
}
$this->step_categories[] = $store_step_category;
}
}
private function send_event( string $action, bool $once = false ): bool {
if ( $once ) {
$option_name = 'hostinger_amplitude_' . $action;
$event_sent = get_option( $option_name, false );
if ( $event_sent ) {
return false;
}
}
$amplitude = new Amplitude();
$params = array( 'action' => $action );
$event = $amplitude->send_event( $params );
if ( $once ) {
update_option( $option_name, true );
}
return ! empty( $event );
}
private function is_store_completed( $steps ): bool {
$all_woo_steps = Actions::get_category_action_lists()[ Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID ];
$completed_woo_steps = ! empty( $steps[ Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID ] ) ? $steps[ Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID ] : array();
foreach ( $all_woo_steps as $step_key ) {
if ( empty( $completed_woo_steps[ $step_key ] ) ) {
return false;
}
}
return true;
}
private function is_store_ready( array $steps ): bool {
$store_steps = $steps[ Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID ] ?? array();
return ! empty( $store_steps[ Actions::ADD_PAYMENT ] ) && ! empty( $store_steps[ Actions::ADD_PRODUCT ] );
}
private function get_reach_step(): Step {
$step = new Step( Actions::REACH );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/hostinger_reach.svg' );
$step->set_title( __( 'Turn site visitors into subscribers', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Collect emails from forms on your site and start sending on-brand email campaigns with Hostinger Reach – all powered by AI.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Try free for 1 year', 'hostinger-easy-onboarding' ) );
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-reach' ) );
$secondary_button = new Button( __( 'Not needed', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::REACH ) ) {
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
}
return $step;
}
/**
* @return array
*/
private function get_saved_steps(): array {
return get_option( self::HOSTINGER_EASY_ONBOARDING_STEPS_OPTION_NAME, array() );
}
private function get_add_domain_step(): Step {
$step = new Step( Actions::DOMAIN_IS_CONNECTED );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/connect_domain.svg' );
$step->set_title( __( 'Add a domain', 'hostinger-easy-onboarding' ) );
$button = new Button( __( 'Add domain', 'hostinger-easy-onboarding' ) );
if ( $this->helper->is_free_subdomain() || $this->helper->is_preview_domain() ) {
if ( $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::DOMAIN_IS_CONNECTED ) ) {
$step->set_title( __( 'Connect on hPanel', 'hostinger-easy-onboarding' ) );
}
$step->set_description(
__(
'Visit hPanel and connect a real domain. If you already did this, please wait up to 24h until the domain fully connects',
'hostinger-easy-onboarding'
)
);
$site_url = preg_replace( '#^https?://#', '', get_site_url() );
$hpanel_url = self::HOSTINGER_WEBSITES_URL . '/' . $site_url;
$button->set_title( __( 'Connect on hPanel', 'hostinger-easy-onboarding' ) );
$button->set_url( $hpanel_url );
} else {
if ( $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::DOMAIN_IS_CONNECTED ) ) {
$step->set_title( __( 'Connected a domain', 'hostinger-easy-onboarding' ) );
}
$step->set_description(
__(
'Every website needs a domain that makes it easy to access and remember. Get yours in just a few clicks.',
'hostinger-easy-onboarding'
)
);
$site_url = preg_replace( '#^https?://#', '', get_site_url() );
$hpanel_url = self::HOSTINGER_ADD_DOMAIN_URL . $site_url . '/select';
$query_parameters = array(
'websiteType' => 'wordpress',
'redirectUrl' => self::HOSTINGER_WEBSITES_URL,
);
$button->set_url( $hpanel_url . '?' . http_build_query( $query_parameters ) );
}
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::DOMAIN_IS_CONNECTED ) ) {
$step->set_primary_button( $button );
}
return $step;
}
private function get_amazon_affiliate_step(): Step {
$step = new Step( Actions::AMAZON_AFFILIATE );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/amazon_affiliate.svg' );
if ( get_locale() === 'pt_BR' ) {
$step->set_title( __( 'Promote products on your site', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Start promoting affiliate products and earn rewards. It’s quick and easy to get started.', 'hostinger-easy-onboarding' ) );
$button = new Button( __( 'Start promoting', 'hostinger-easy-onboarding' ) );
} else {
$step->set_title( __( 'Connect your Amazon account to the site', 'hostinger-easy-onboarding' ) );
if ( $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::AMAZON_AFFILIATE ) ) {
$step->set_title( __( 'Connected your Amazon account', 'hostinger-easy-onboarding' ) );
}
$step->set_description( __( 'Link your Amazon Associates account to your website, start promoting products, and earn rewards. No API key required.', 'hostinger-easy-onboarding' ) );
$button = new Button( __( 'Connect Amazon to site', 'hostinger-easy-onboarding' ) );
}
$button->set_url( admin_url( 'admin.php?page=hostinger-amazon-affiliate' ) );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::AMAZON_AFFILIATE ) ) {
$step->set_primary_button( $button );
}
return $step;
}
private function get_started_with_store(): Step {
$step = new Step( Actions::STORE_TASKS );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/store_tasks.svg' );
$step->set_title( __( 'Set up your online store', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Get ready to sell online. Add your first product, then set up shipping and payments.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Get started', 'hostinger-easy-onboarding' ) );
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-get-onboarding' ) );
if ( $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::STORE_TASKS ) ) {
$primary_button->set_title( __( 'View list', 'hostinger-easy-onboarding' ) );
}
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::STORE_TASKS ) ) {
$step->set_primary_button( $primary_button );
}
return $step;
}
private function get_enable_ai_discovery_step(): Step {
$step = new Step( Actions::ENABLE_AI_DISCOVERY );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/ai_discovery.svg' );
$step->set_title( __( 'Make your site discoverable by AI', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Let AI explore, understand, and interact with your site. All content updates are auto-tracked so AI tools stay in sync with your site’s latest version.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Turn on', 'hostinger-easy-onboarding' ) );
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-get-onboarding' ) );
$secondary_button = new Button( __( 'Not needed', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::ENABLE_AI_DISCOVERY ) ) {
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
}
return $step;
}
private function get_setup_online_store(): Step {
$step = new Step( Actions::SETUP_STORE );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/store_tasks.svg' );
$step->set_title( __( 'Add store details', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'We\'ll use this information to help you set up your store faster.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Get started', 'hostinger-easy-onboarding' ) );
if ( $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::SETUP_STORE ) ) {
$primary_button->set_url( admin_url( 'admin.php?page=wc-settings' ) );
} else {
$primary_button->set_modal_name( 'SetupOnlineStoreModal' );
}
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::SETUP_STORE ) ) {
$step->set_primary_button( $primary_button );
}
return $step;
}
private function get_add_product_step(): Step {
$step = new Step( Actions::ADD_PRODUCT );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/add_product.svg' );
$step->set_title( __( 'Add your first product or service', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Sell products, services and digital downloads. Set up and customize each item to fit your business needs.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Add product', 'hostinger-easy-onboarding' ) );
$primary_button->set_url( admin_url( 'post-new.php?post_type=product' ) );
$secondary_button = new Button( __( 'Not now', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::ADD_PRODUCT ) ) {
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
}
return $step;
}
private function get_payment_method_step(): Step {
$step = new Step( Actions::ADD_PAYMENT );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/add_payment_method.svg' );
$step->set_title( __( 'Set up payments', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Get ready to sell online. Add your first product, then set up payments and shipping.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Set up payment method', 'hostinger-easy-onboarding' ) );
$primary_button->set_modal_name( 'SetupPaymentMethodModal' );
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-get-onboarding&subPage=hostinger-store-add-payment-method' ) );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::ADD_PAYMENT ) ) {
$step->set_primary_button( $primary_button );
}
return $step;
}
private function get_shipping_method_step(): Step {
$step = new Step( Actions::ADD_SHIPPING );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/add_shipping_method.svg' );
$step->set_title( __( 'Manage shipping', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Choose the ways you\'d like to ship orders to customers. You can always add others later.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Set up shipping method', 'hostinger-easy-onboarding' ) );
$primary_button->set_modal_name( 'SetupShippingMethodModal' );
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-get-onboarding&subPage=hostinger-store-add-shipping-method' ) );
$secondary_button = new Button( __( 'Not needed', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::ADD_SHIPPING ) ) {
$step->set_primary_button( $primary_button );
$step->set_secondary_button( $secondary_button );
}
return $step;
}
private function get_google_kit_step(): Step {
$step = new Step( Actions::GOOGLE_KIT );
$step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/google_kit.svg' );
$step->set_title( __( 'Get found on Google', 'hostinger-easy-onboarding' ) );
$step->set_description( __( 'Make sure that your website shows up when visitors are looking for your business on Google.', 'hostinger-easy-onboarding' ) );
$primary_button = new Button( __( 'Set up Google Site Kit', 'hostinger-easy-onboarding' ) );
$primary_button->set_url( admin_url( 'admin.php?page=googlesitekit-splash' ) );
if ( $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::GOOGLE_KIT ) ) {
$primary_button->set_title( __( 'Manage', 'hostinger-easy-onboarding' ) );
} else {
$primary_button->set_modal_name( 'SkipGoogleSiteKitModal' );
}
$secondary_button = new Button( __( 'Not needed', 'hostinger-easy-onboarding' ) );
$secondary_button->set_is_skippable( true );
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::DOMAIN_IS_CONNECTED ) ) {
$step->set_error_message( __( 'Connect your domain first', 'hostinger-easy-onboarding' ) );
$primary_button->set_title( '' );
$secondary_button->set_title( '' );
$step->set_secondary_button( $secondary_button );
}
if ( ! $this->is_completed( self::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, Actions::GOOGLE_KIT ) ) {
$step->set_primary_button( $primary_button );
}
return $step;
}
private function is_reach_eliglible(): bool {
$onboarding_steps_was_completed = get_option( 'hostinger_onboarding_steps_was_completed', null );
if ( $onboarding_steps_was_completed ) {
return false;
}
return true;
}
}
@@ -0,0 +1,277 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
defined( 'ABSPATH' ) || exit;
class Plugin {
/**
* @var string
*/
private string $icon_url = '';
/**
* @var string
*/
private string $name = '';
/**
* @var string
*/
private string $slug = '';
/**
* @var string
*/
private string $description = '';
/**
* @var array|mixed
*/
private array $locale_supported = array();
/**
* @var bool
*/
private bool $global = false;
/**
* @var string
*/
private string $type = '';
/**
* @var bool
*/
private bool $is_active = false;
/**
* @var bool
*/
private bool $is_recommended = false;
/**
* @var bool
*/
private bool $is_installed = false;
/**
* @var bool
*/
private bool $is_config_url = false;
/**
* @var string
*/
private string $config_url = '';
/**
* @param $icon_url
* @param $name
* @param $slug
* @param $description
* @param $type
* @param $locale_supported
* @param $is_global
* @param bool $is_config_url
* @param string $config_url
*/
public function __construct( $icon_url, $name, $slug, $description, $type, $locale_supported, $is_global, $is_config_url = false, $config_url = '' ) {
$this->icon_url = $icon_url;
$this->name = $name;
$this->slug = $slug;
$this->description = $description;
$this->type = $type;
$this->locale_supported = $locale_supported;
$this->is_global = $is_global;
$this->is_config_url = $is_config_url;
$this->config_url = $config_url;
}
/**
* @return string
*/
public function get_icon_url(): string {
return $this->icon_url;
}
/**
* @param string $icon_url
*/
public function set_icon_url( string $icon_url ): void {
$this->icon_url = $icon_url;
}
/**
* @return string
*/
public function get_name(): string {
return $this->name;
}
/**
* @param string $name
*/
public function set_name( string $name ): void {
$this->name = $name;
}
/**
* @return string
*/
public function get_slug(): string {
return $this->slug;
}
/**
* @param string $slug
*/
public function set_slug( string $slug ): void {
$this->slug = $slug;
}
/**
* @return string
*/
public function get_description(): string {
return $this->description;
}
/**
* @param string $description
*/
public function set_description( string $description ): void {
$this->description = $description;
}
/**
* @return array
*/
public function get_locale_supported(): array {
return $this->locale_supported;
}
/**
* @param array $locale_supported
*/
public function set_locale_supported( array $locale_supported ): void {
$this->locale_supported = $locale_supported;
}
/**
* @return bool
*/
public function get_is_global(): bool {
return $this->is_global;
}
/**
* @param bool $is_global
*/
public function set_is_global( bool $is_global ): void {
$this->is_global = $is_global;
}
/**
* @return string
*/
public function get_type(): string {
return $this->type;
}
/**
* @param string $type
*/
public function set_type( string $type ): void {
$this->type = $type;
}
/**
* @return bool
*/
public function get_is_active(): bool {
return $this->is_active;
}
/**
* @param bool $is_active
*/
public function set_is_active( bool $is_active ): void {
$this->is_active = $is_active;
}
/**
* @return bool
*/
public function get_is_recommended(): bool {
return $this->is_recommended;
}
/**
* @param bool $is_recommended
*/
public function set_is_recommended( bool $is_recommended ): void {
$this->is_recommended = $is_recommended;
}
/**
* @return bool
*/
public function get_is_installed(): bool {
return $this->is_installed;
}
/**
* @param bool $is_installed
*/
public function set_is_installed( bool $is_installed ): void {
$this->is_installed = $is_installed;
}
/**
* @return bool
*/
public function get_is_config_url(): bool {
return $this->is_config_url;
}
/**
* @param bool $is_config_url
*/
public function set_is_config_url( bool $is_config_url ): void {
$this->is_config_url = $is_config_url;
}
/**
* @return string
*/
public function get_config_url(): string {
return $this->config_url;
}
/**
* @param string $config_url
*/
public function set_config_url( string $config_url ): void {
$this->config_url = $config_url;
}
/**
* @return array
*/
public function to_array(): array {
return array(
'icon_url' => $this->get_icon_url(),
'name' => $this->get_name(),
'slug' => $this->get_slug(),
'description' => $this->get_description(),
'locale_supported' => $this->get_locale_supported(),
'global' => $this->get_is_global(),
'type' => $this->get_type(),
'is_recommended' => $this->get_is_recommended(),
'is_active' => $this->get_is_active(),
'is_installed' => $this->get_is_installed(),
'is_config_url' => $this->get_is_config_url(),
'config_url' => $this->get_config_url(),
);
}
}
@@ -0,0 +1,157 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
use Hostinger\EasyOnboarding\Helper;
defined( 'ABSPATH' ) || exit;
class PluginManager {
/**
* @var array
*/
private array $plugins;
public function __construct() {
$this->load_plugins();
}
/**
* @return void
*/
private function load_plugins(): void {
$locales = array( 'US', 'UK', 'ES', 'FR', 'MX', 'CO', 'DE', 'IT', 'NL' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-gateway-stripe/assets/icon-128x128.png', 'WooCommerce Stripe Gateway', 'woocommerce-gateway-stripe', __( 'Take credit card payments on your store using Stripe.', 'hostinger-easy-onboarding' ), 'payment', $locales, true, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
$locales = array( 'US', 'UK', 'IN', 'BR', 'ES', 'FR', 'MX', 'CO', 'DE', 'IT', 'NL' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-paypal-payments/assets/icon-128x128.png', 'WooCommerce PayPal Payments', 'woocommerce-paypal-payments', __( 'PayPal\'s latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts.', 'hostinger-easy-onboarding' ), 'payment', $locales, true, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-connection' ) );
$locales = array( 'US', 'BR', 'ES', 'FR', 'DE', 'IT', 'NL' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-payments/assets/icon-128x128.png', 'WooPayments', 'woocommerce-payments', __( 'Accept payments via credit card. Manage transactions within WordPress.', 'hostinger-easy-onboarding' ), 'payment', $locales, true, true, admin_url( 'admin.php?page=wc-admin&path=%2Fpayments%2Fconnect' ) );
$locales = array( 'BR', 'MX', 'CO' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-mercadopago/assets/icon-128x128.png', 'Mercado Pago', 'woocommerce-mercadopago', __( 'Configure the payment options and accept payments with cards, ticket and money of Mercado Pago account.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=mercadopago-settings' ) );
$locales = array( 'US', 'UK', 'ES', 'FR' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-square/assets/icon-128x128.png', 'WooCommerce Square', 'woocommerce-square', __( 'Securely accept payments, synchronize sales, and seamlessly manage inventory and product data between WooCommerce and Square POS.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=woocommerce-square-onboarding' ) );
$locales = array( 'US', 'UK', 'IN', 'ES', 'FR', 'DE', 'IT', 'NL' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-gateway-amazon-payments-advanced/assets/icon-128x128.png', 'WooCommerce Amazon Pay', 'woocommerce-gateway-amazon-payments-advanced', __( 'Amazon Pay is embedded directly into your existing web site, and all the buyer interactions with Amazon Pay and Login with Amazon take place in embedded widgets so that the buyer never leaves your site. ', 'hostinger-easy-onboarding' ), 'payment', $locales, true, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=amazon_payments_advanced' ) );
$locales = array( 'IN' );
$this->plugins[] = new Plugin( 'https://ps.w.org/upi-qr-code-payment-for-woocommerce/assets/icon-128x128.png', 'UPI QR Code Payment Gateway', 'upi-qr-code-payment-for-woocommerce', __( 'It enables a WooCommerce site to accept payments through UPI apps like BHIM, Google Pay, Paytm, PhonePe or any Banking UPI app. Avoid payment gateway charges.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc-upi' ) );
$locales = array( 'ES' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woo-redsys-gateway-light/assets/icon-128x128.png', 'WooCommerce Redsys Gateway Light', 'woo-redsys-gateway-light', __( 'Extends WooCommerce with a RedSys gateway.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=redsys' ) );
$locales = array( 'BR' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woo-pagseguro-rm/assets/icon.svg', 'Módulo PagSeguro', 'woo-pagseguro-rm', __( 'Adiciona PagSeguro como meio de pagamento (com desconto nas taxas oficiais).', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=pagseguro' ) );
$locales = array( 'PK' );
$this->plugins[] = new Plugin( 'https://ps.w.org/simpaisa-wallet-payment-services/assets/icon-128x128.png', 'Simpaisa Wallet (Jazzcash & Easypaisa) Payment Services', 'simpaisa-wallet-payment-services', __( 'Simpaisa is providing Easy To Integrate Jazzcash & Easypaisa Digital Payment Services.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=simpaisa_woo_jz_ep_wallet' ) );
$locales = array( 'IT' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woo-satispay/assets/icon-128x128.png', 'WooCommerce Satispay', 'woo-satispay', __( 'The plugin allows you to accept digital payments from Satispay users.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=satispay' ) );
$locales = array( 'ID' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woo-xendit-virtual-accounts/assets/icon-128x128.png', 'Woocommerce – Xendit', 'woo-xendit-virtual-accounts', __( 'This enables you to accept various payments via Xendit with just a few clicks.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=xendit_gateway' ) );
$this->plugins[] = new Plugin( 'https://ps.w.org/midtrans-woocommerce/assets/icon-128x128.png', 'Midtrans-WooCommerce', 'midtrans-woocommerce', __( 'Midtrans-WooCommerce is official plugin from Midtrans. Midtrans is an online payment gateway.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=midtrans' ) );
$this->plugins[] = new Plugin( 'https://ps.w.org/doku-payment/assets/icon-128x128.png', 'DOKU Payment', 'doku-payment', __( 'DOKU plugin offers a seamless, secure payment solution allowing your customers to choose from various payment methods and complete transactions directly on your WooCommerce store.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=checkout&section=doku_gateway' ) );
$this->plugins[] = new Plugin( 'https://ps.w.org/duitku-social-payment-gateway/assets/icon-128x128.png', 'Duitku Payment Gateway', 'duitku-social-payment-gateway', __( 'Duitku Payment Gateway integrates with your WooCommerce store and lets you accept those payments through our payment gateway.', 'hostinger-easy-onboarding' ), 'payment', $locales, false, false );
// Shipping.
$locales = array( 'US' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-services/assets/icon-128x128.png', 'WooCommerce Shipping & Tax', 'woocommerce-services', __( 'Hosted services for WooCommerce: automated tax calculation, shipping label printing, and smoother payment setup.', 'hostinger-easy-onboarding' ), 'shipping', $locales, false );
$locales = array();
$this->plugins[] = new Plugin( 'https://ps.w.org/flexible-shipping/assets/icon.svg', 'Flexible Shipping', 'flexible-shipping', __( 'Create additional shipment methods in WooCommerce and enable pricing based on cart weight or total.', 'hostinger-easy-onboarding' ), 'shipping', $locales, true, true, admin_url( 'admin.php?page=wc-settings&tab=shipping&section=flexible_shipping_info' ) );
$locales = array( 'BR' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woocommerce-correios/assets/icon-128x128.png', 'Correios for WooCommerce', 'woocommerce-correios', __( 'Adds Correios shipping methods to your WooCommerce store.', 'hostinger-easy-onboarding' ), 'shipping', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=integration&section=correios-integration' ) );
$locales = array( 'FR' );
$this->plugins[] = new Plugin( 'https://ps.w.org/colissimo-shipping-methods-for-woocommerce/assets/icon.svg', 'Colissimo shipping methods', 'colissimo-shipping-methods-for-woocommerce', __( 'This extension gives you the possibility to use the Colissimo shipping methods in WooCommerce', 'hostinger-easy-onboarding' ), 'shipping', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=lpc' ) );
$locales = array( 'US' );
$this->plugins[] = new Plugin( 'https://ps.w.org/woo-usps-simple-shipping/assets/icon-128x128.png', 'USPS Simple Shipping', 'woo-usps-simple-shipping', __( 'The USPS Simple plugin calculates rates for domestic shipping dynamically using USPS API during checkout.', 'hostinger-easy-onboarding' ), 'shipping', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=shipping&section=usps_simple' ) );
$locales = array( 'FR' );
$this->plugins[] = new Plugin( 'https://ps.w.org/wc-multishipping/assets/icon-128x128.png', 'Chronopost & Mondial relay', 'wc-multishipping', __( 'Create Chronopost & Mondial relay shipping labels and send them easily.', 'hostinger-easy-onboarding' ), 'shipping', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=mondial_relay' ) );
$locales = array( 'ID' );
$this->plugins[] = new Plugin( 'https://ps.w.org/epeken-all-kurir/assets/icon-128x128.png', 'Epeken All Kurir Plugin for Woocommerce', 'epeken-all-kurir', __( 'Epeken All Kurir Plugin is a WordPress plugin for woocommerce to enable shipping methods featuring many shipping companies in Indonesia for Indonesia e-commerce.', 'hostinger-easy-onboarding' ), 'shipping', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=shipping&section=epeken_courier' ) );
$this->plugins[] = new Plugin( 'https://ps.w.org/anteraja/assets/icon-128x128.png', 'Anteraja Integrated Shipping Plugin for WooCommerce', 'anteraja', __( 'Anteraja Plugin is a WordPress plugin for WooCommerce for integrate Anteraja', 'hostinger-easy-onboarding' ), 'shipping', $locales, false, true, admin_url( 'admin.php?page=wc-settings&tab=shipping&section=anteraja' ) );
}
/**
* @param \Hostinger\EasyOnboarding\Admin\Onboarding\Plugin $plugin
*
* @return bool
*/
private function check_recommended( Plugin $plugin ): bool {
$locale = get_option( 'woocommerce_default_country', '' );
if ( empty( $locale ) ) {
return false;
}
$country_locale = substr( $locale, 0, 2 );
if ( in_array( $country_locale, $plugin->get_locale_supported(), true ) ) {
return true;
}
return false;
}
/**
* Get plugins by type and/or locale.
*
* @param string|null $type
* @param string|null $locale
* @return array
*/
public function get_plugins_by_criteria( string $type = null, string $locale = null ): array {
// Get by type first.
$filtered_by_type = array_filter(
$this->plugins,
function ( $plugin ) use ( $type ) {
return $plugin->get_type() === $type;
}
);
$all_plugins = get_plugins();
// Filter by supported locale or global available.
$filter_by_locale = array_filter(
$filtered_by_type,
function ( Plugin $plugin ) use ( $locale, $all_plugins ) {
// Set if plugin is active and/or recommended.
$plugin_slug = $plugin->get_slug();
$helper = new Helper();
$plugin_path = $helper->get_plugin_main_file( $plugin_slug );
if ( ! is_wp_error( $plugin_path ) ) {
$plugin->set_is_active( is_plugin_active( $plugin_path ) );
$plugin->set_is_installed( array_key_exists( $plugin_path, $all_plugins ) );
} else {
$plugin->set_is_active( false );
$plugin->set_is_installed( false );
}
$is_recommended = $this->check_recommended( $plugin );
$plugin->set_is_recommended( $is_recommended );
return $is_recommended || $plugin->get_is_global();
}
);
return array_map(
function ( $item ) {
return $item->to_array();
},
$filter_by_locale
);
}
}
@@ -0,0 +1,20 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
use Hostinger\EasyOnboarding\Admin\Actions as Admin_Actions;
defined( 'ABSPATH' ) || exit;
class Settings {
public static function all_steps_completed(): bool {
$actions = Admin_Actions::ACTIONS_LIST;
$completed_steps = get_option( 'hostinger_onboarding_steps', array() );
$completed_step_actions = array_column( $completed_steps, 'action' );
$completed_steps_count = count( array_intersect( $completed_step_actions, $actions ) );
return $completed_steps_count === count( $actions );
}
}
new Settings();
@@ -0,0 +1,121 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding\Steps;
defined( 'ABSPATH' ) || exit;
class Button {
/**
* @var string
*/
private string $title;
/**
* @var bool
*/
private bool $is_skippable;
/**
* @var string
*/
private string $url = '';
private string $modal_name = '';
private bool $is_astra_needed = false;
private bool $is_completable = true;
public function __construct( string $title = '', bool $is_skippable = false, string $url = '', bool $is_completable = true ) {
$this->title = $title;
$this->is_skippable = $is_skippable;
$this->url = $url;
$this->is_completable = $is_completable;
}
/**
* @return string
*/
public function get_title(): string {
return $this->title;
}
/**
* @param string $title
*
* @return void
*/
public function set_title( string $title ): void {
$this->title = $title;
}
/**
* @return bool
*/
public function get_is_skippable(): bool {
return $this->is_skippable;
}
/**
* @param bool $is_skippable
*
* @return void
*/
public function set_is_skippable( bool $is_skippable ): void {
$this->is_skippable = $is_skippable;
}
/**
* @return string
*/
public function get_url(): string {
return $this->url;
}
/**
* @param string $url
*
* @return void
*/
public function set_url( string $url ): void {
$this->url = $url;
}
public function get_modal_name(): string {
return $this->modal_name;
}
public function set_modal_name( string $modal_name ): void {
$this->modal_name = $modal_name;
}
public function get_is_astra_needed(): bool {
return $this->is_astra_needed;
}
public function set_is_astra_needed( bool $is_astra_needed ): void {
$this->is_astra_needed = $is_astra_needed;
}
public function get_is_completable(): bool {
return $this->is_completable;
}
public function set_is_completable( bool $is_completable ): void {
$this->is_completable = $is_completable;
}
/**
* @return array
*/
public function to_array(): array {
return array(
'title' => $this->get_title(),
'is_skippable' => $this->get_is_skippable(),
'is_astra_needed' => $this->get_is_astra_needed(),
'url' => $this->get_url(),
'modal_name' => $this->get_modal_name(),
'is_completable' => $this->get_is_completable(),
);
}
}
@@ -0,0 +1,209 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding\Steps;
defined( 'ABSPATH' ) || exit;
class Step {
/**
* @var string
*/
private string $id = '';
/**
* @var bool
*/
private bool $is_completed = false;
/**
* @var string
*/
private string $title = '';
/**
* @var string
*/
private string $description = '';
/**
* @var string
*/
private string $image_url = '';
/**
* @var Button
*/
private Button $primary_button;
/**
* @var Button
*/
private Button $secondary_button;
/**
* @var string
*/
private string $error_message = '';
/**
* @param string $id
* @param string $title
* @param string $description
* @param string $image_url
*/
public function __construct( string $id, string $title = '', string $description = '', string $image_url = '' ) {
$this->id = $id;
$this->title = $title;
$this->description = $description;
$this->image_url = $image_url;
$this->primary_button = new Button( '' );
$this->secondary_button = new Button( '' );
}
/**
* @return string
*/
public function get_id(): string {
return $this->id;
}
/**
* @param string $id
*
* @return void
*/
public function set_id( string $id ): void {
$this->id = $id;
}
/**
* @return bool
*/
public function get_is_completed(): bool {
return $this->is_completed;
}
/**
* @param bool $is_completed
*
* @return void
*/
public function set_is_completed( bool $is_completed ): void {
$this->is_completed = $is_completed;
}
/**
* @return string
*/
public function get_title(): string {
return $this->title;
}
/**
* @param string $title
*
* @return void
*/
public function set_title( string $title ): void {
$this->title = $title;
}
/**
* @return string
*/
public function get_description(): string {
return $this->description;
}
/**
* @param string $description
*
* @return void
*/
public function set_description( string $description ): void {
$this->description = $description;
}
/**
* @return string
*/
public function get_image_url(): string {
return $this->image_url;
}
/**
* @param string $image_url
*
* @return void
*/
public function set_image_url( string $image_url ): void {
$this->image_url = $image_url;
}
/**
* @return Button
*/
public function get_primary_button(): Button {
return $this->primary_button;
}
/**
* @param Button $primary_button
*
* @return void
*/
public function set_primary_button( Button $primary_button ): void {
$this->primary_button = $primary_button;
}
/**
* @return Button
*/
public function get_secondary_button(): Button {
return $this->secondary_button;
}
/**
* @param Button $secondary_button
*
* @return void
*/
public function set_secondary_button( Button $secondary_button ): void {
$this->secondary_button = $secondary_button;
}
/**
* @return string
*/
public function get_error_message(): string {
return $this->error_message;
}
/**
* @param string $error_message
*
* @return void
*/
public function set_error_message( string $error_message ): void {
$this->error_message = $error_message;
}
/**
* @return array
*/
public function to_array(): array {
$primary_button = ! empty( $this->get_primary_button() ) ? $this->get_primary_button()->to_array() : array();
$secondary_button = ! empty( $this->get_secondary_button() ) ? $this->get_secondary_button()->to_array() : array();
return array(
'id' => $this->get_id(),
'is_completed' => $this->get_is_completed(),
'title' => $this->get_title(),
'description' => $this->get_description(),
'image_url' => $this->get_image_url(),
'primary_button' => $primary_button,
'secondary_button' => $secondary_button,
'error_message' => $this->get_error_message(),
);
}
}
@@ -0,0 +1,122 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding\Steps;
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
defined( 'ABSPATH' ) || exit;
class StepCategory {
/**
* @var string
*/
private string $title = '';
/**
* @var string
*/
private string $id = '';
/**
* @var array
*/
private array $steps = array();
public function __construct( string $id, string $title = '', array $steps = array() ) {
$this->title = $title;
$this->id = $id;
$this->steps = $steps;
}
/**
* @return string
*/
public function get_title(): string {
return $this->title;
}
/**
* @param string $title
*
* @return void
*/
public function set_title( string $title ): void {
$this->title = $title;
}
/**
* @return string
*/
public function get_id(): string {
return $this->id;
}
/**
* @param string $id
*
* @return void
*/
public function set_id( string $id ): void {
$this->id = $id;
}
/**
* @return array
*/
public function get_steps(): array {
return $this->steps;
}
/**
* @param array $steps
*
* @return void
*/
public function set_steps( array $steps ): void {
$this->steps = $steps;
}
/**
* @param Step $step
*
* @return void
*/
public function add_step( Step $step ): void {
$step = $this->update_step_status( $step );
$this->steps[] = $step;
}
/**
* @return array
*/
public function to_array(): array {
return array(
'title' => $this->get_title(),
'id' => $this->get_id(),
'steps' => array_map(
function ( $item ) {
return $item->to_array();
},
$this->get_steps()
),
);
}
/**
* @param Step $step
*
* @return Step
*/
public function update_step_status( Step $step ): Step {
$onboarding_steps = get_option( Onboarding::HOSTINGER_EASY_ONBOARDING_STEPS_OPTION_NAME, array() );
if ( empty( $onboarding_steps[ $this->get_id() ][ $step->get_id() ] ) ) {
return $step;
}
$step->set_is_completed( (bool) $onboarding_steps[ $this->get_id() ][ $step->get_id() ] );
return $step;
}
}
@@ -0,0 +1,45 @@
<?php
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
defined( 'ABSPATH' ) || exit;
class WelcomeCards {
public function get_welcome_cards(): array {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
$welcome_cards = array();
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$welcome_cards[] = array(
'id' => 'woocommerce',
'image' => 'setup-online-store.png',
'title' => __( 'Set up an online store', 'hostinger-easy-onboarding' ),
'link' => 'admin.php?page=hostinger-get-onboarding&subPage=hostinger-store-setup-information',
'description' => wp_kses( __( 'Setup <strong>WooCommerce</strong>, add products or services, and start selling today.', 'hostinger-easy-onboarding' ), array( 'strong' => array() ) ),
);
}
if ( is_plugin_active( 'hostinger-affiliate-plugin/hostinger-affiliate-plugin.php' ) ) {
$welcome_cards[] = array(
'id' => 'affiliate',
'image' => 'run-amazon-affiliate-site.png',
'title' => __( 'Run an Amazon Affiliate site', 'hostinger-easy-onboarding' ),
'link' => admin_url( 'admin.php?page=hostinger-amazon-affiliate' ),
'description' => wp_kses( __( 'Connect your <strong>Amazon Associate</strong> account to fetch API details.', 'hostinger-easy-onboarding' ), array( 'strong' => array() ) ),
);
}
if ( is_plugin_active( 'hostinger-ai-assistant/hostinger-ai-assistant.php' ) ) {
$welcome_cards[] = array(
'id' => 'ai',
'image' => 'generate-content-with-ai.png',
'title' => __( 'Generate content with AI', 'hostinger-easy-onboarding' ),
'link' => admin_url( 'admin.php?page=hostinger-ai-assistant' ),
'description' => wp_kses( __( 'Get images, text, and SEO keywords created for you instantly.', 'hostinger-easy-onboarding' ), array( 'strong' => array() ) ),
);
}
return $welcome_cards;
}
}