Initial commit: Atomaste website
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\WelcomeCards;
|
||||
use Hostinger\EasyOnboarding\DefaultOptions;
|
||||
use Hostinger\WpHelper\Utils;
|
||||
use Hostinger\EasyOnboarding\WooCommerce\Options as WooCommerceOptions;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Activator {
|
||||
|
||||
public static function activate(): void {
|
||||
$options = new DefaultOptions();
|
||||
$options->add_options();
|
||||
|
||||
self::update_installation_state_on_activation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves installation state.
|
||||
*/
|
||||
public static function update_installation_state_on_activation(): void {
|
||||
$installation_state = get_option( 'hts_new_installation', false );
|
||||
|
||||
if ( $installation_state !== 'old' ) {
|
||||
add_option( 'hts_new_installation', 'new' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Actions {
|
||||
public const AI_STEP = 'ai_step';
|
||||
public const STORE_TASKS = 'store_tasks';
|
||||
public const SETUP_STORE = 'setup_store';
|
||||
public const ADD_PRODUCT = 'add_product';
|
||||
public const ADD_PAYMENT = 'add_payment_method';
|
||||
public const ADD_SHIPPING = 'add_shipping_method';
|
||||
public const DOMAIN_IS_CONNECTED = 'connect_domain';
|
||||
|
||||
public const AMAZON_AFFILIATE = 'amazon_affiliate';
|
||||
|
||||
public const GOOGLE_KIT = 'google_kit';
|
||||
public const ACTIONS_LIST = array(
|
||||
self::DOMAIN_IS_CONNECTED,
|
||||
);
|
||||
|
||||
public const STORE_ACTIONS_LIST = array(
|
||||
self::SETUP_STORE,
|
||||
self::ADD_PRODUCT,
|
||||
self::ADD_PAYMENT,
|
||||
self::ADD_SHIPPING
|
||||
);
|
||||
|
||||
public static function get_category_action_lists(): array {
|
||||
return array(
|
||||
Onboarding::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID => self::get_action_list(),
|
||||
Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID => self::get_store_action_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_action_list(): array {
|
||||
$list = self::ACTIONS_LIST;
|
||||
|
||||
if ( ! empty( Onboarding::get_first_step_data() ) ) {
|
||||
$list[] = self::AI_STEP;
|
||||
}
|
||||
|
||||
if ( is_plugin_active( 'hostinger-affiliate-plugin/hostinger-affiliate-plugin.php' ) ) {
|
||||
$list[] = self::AMAZON_AFFILIATE;
|
||||
}
|
||||
|
||||
if( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
|
||||
$list[] = self::STORE_TASKS;
|
||||
}
|
||||
|
||||
$list[] = self::GOOGLE_KIT;
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function get_store_action_list(): array {
|
||||
return self::STORE_ACTIONS_LIST;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
use Hostinger\EasyOnboarding\Admin\Actions as Admin_Actions;
|
||||
use Hostinger\EasyOnboarding\Admin\Hooks as Admin_Hooks;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Ajax {
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'define_ajax_events' ), 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function define_ajax_events(): void {
|
||||
$events = array(
|
||||
'identify_action',
|
||||
);
|
||||
|
||||
foreach ( $events as $event ) {
|
||||
add_action( 'wp_ajax_hostinger_' . $event, array( $this, $event ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function identify_action(): void {
|
||||
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
|
||||
$security_check = $this->request_security_check( $nonce );
|
||||
|
||||
if ( ! empty( $security_check ) ) {
|
||||
wp_send_json_error( $security_check );
|
||||
}
|
||||
|
||||
$action = sanitize_text_field( $_POST['action_name'] ) ?? '';
|
||||
|
||||
if ( in_array( $action, Admin_Actions::ACTIONS_LIST, true ) ) {
|
||||
setcookie( $action, $action, time() + ( 86400 ), '/' );
|
||||
wp_send_json_success( $action );
|
||||
} else {
|
||||
wp_send_json_error( 'Invalid action' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $nonce
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function request_security_check( $nonce ) {
|
||||
if ( ! wp_verify_nonce( $nonce, 'hts-ajax-nonce' ) ) {
|
||||
return 'Invalid nonce';
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return 'Lack of permissions';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\Admin\Menu;
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
use Hostinger\EasyOnboarding\Rest\StepRoutes;
|
||||
use Hostinger\WpHelper\Utils;
|
||||
use Hostinger\WpMenuManager\Menus;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Hostinger_Admin_Assets
|
||||
*
|
||||
* Handles the enqueueing of styles and scripts for the Hostinger admin pages.
|
||||
*/
|
||||
class Assets {
|
||||
/**
|
||||
* @var Helper Instance of the Hostinger_Helper class.
|
||||
*/
|
||||
private Helper $helper;
|
||||
|
||||
/**
|
||||
* @var Utils
|
||||
*/
|
||||
private Utils $utils;
|
||||
|
||||
public function __construct() {
|
||||
$this->helper = new Helper();
|
||||
$this->utils = new Utils();
|
||||
|
||||
add_action('admin_enqueue_scripts', array($this, 'admin_styles'));
|
||||
add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
|
||||
add_action('enqueue_block_editor_assets', array($this, 'gutenberg_edit_pages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues styles for the Hostinger admin pages.
|
||||
*/
|
||||
public function admin_styles(): void {
|
||||
if ( $this->utils->isThisPage( 'wp-admin/admin.php?page=hostinger-get-onboarding' ) || $this->utils->isThisPage( 'wp-admin/admin.php?page=' . Menus::MENU_SLUG ) ) {
|
||||
wp_enqueue_style( 'hostinger_easy_onboarding_main_styles', HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/css/main.min.css', array(), HOSTINGER_EASY_ONBOARDING_VERSION );
|
||||
|
||||
$hide_notices = '.notice { display: none !important; }';
|
||||
wp_add_inline_style('hostinger_easy_onboarding_main_styles', $hide_notices);
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'hostinger_easy_onboarding_global_styles', HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/css/global.min.css', array(), HOSTINGER_EASY_ONBOARDING_VERSION );
|
||||
|
||||
if ( $this->helper->is_preview_domain() && is_user_logged_in() ) {
|
||||
wp_enqueue_style( 'hostinger_easy_onboarding_preview_styles', HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/css/hts-preview.min.css', array(), HOSTINGER_EASY_ONBOARDING_VERSION );
|
||||
}
|
||||
|
||||
if( is_plugin_active( 'wpforms/wpforms.php' ) ) {
|
||||
$hide_wp_forms_counter = '.wp-admin #wpadminbar .wpforms-menu-notification-counter { display: none !important; }';
|
||||
wp_add_inline_style( 'hostinger_easy_onboarding_global_styles', $hide_wp_forms_counter );
|
||||
}
|
||||
if( is_plugin_active( 'googleanalytics/googleanalytics.php' ) ) {
|
||||
$hide_wp_forms_notification = '.wp-admin .monsterinsights-menu-notification-indicator { display: none !important; }';
|
||||
wp_add_inline_style( 'hostinger_easy_onboarding_global_styles', $hide_wp_forms_notification );
|
||||
}
|
||||
|
||||
if( is_plugin_active( 'woocommerce/woocommerce.php' ) && !is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' ) ) {
|
||||
$hide_woo_payments_menu = '.wp-admin #toplevel_page_wc-admin-path--payments-connect, .wp-admin #toplevel_page_wc-admin-path--wc-pay-welcome-page { display: none !important; }';
|
||||
wp_add_inline_style( 'hostinger_easy_onboarding_global_styles', $hide_woo_payments_menu );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues scripts for the Hostinger admin pages.
|
||||
*/
|
||||
public function admin_scripts(): void {
|
||||
if ( $this->utils->isThisPage( 'wp-admin/admin.php?page=hostinger-get-onboarding' ) || $this->utils->isThisPage( 'wp-admin/admin.php?page=' . Menus::MENU_SLUG ) ) {
|
||||
wp_enqueue_script(
|
||||
'hostinger_easy_onboarding_main_scripts',
|
||||
HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/js/main.min.js',
|
||||
array(
|
||||
'jquery',
|
||||
'wp-i18n',
|
||||
),
|
||||
HOSTINGER_EASY_ONBOARDING_VERSION,
|
||||
false
|
||||
);
|
||||
|
||||
$all_plugins = get_plugins();
|
||||
|
||||
$edit_site_url = admin_url( 'edit.php?post_type=page' );
|
||||
|
||||
$front_page_id = get_option('page_on_front');
|
||||
|
||||
if ( wp_is_block_theme() ) {
|
||||
|
||||
$edit_site_url = admin_url( 'site-editor.php' );
|
||||
|
||||
} else {
|
||||
|
||||
if ( ! empty($front_page_id)) {
|
||||
$query_args = [
|
||||
'post' => $front_page_id,
|
||||
'action' => 'edit',
|
||||
];
|
||||
|
||||
$edit_site_url = add_query_arg($query_args, admin_url('post.php'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$localize_data = array(
|
||||
'promotional_link' => $this->helper->get_promotional_link_url( get_locale() ),
|
||||
'completed_steps' => get_option( 'hostinger_onboarding_steps', array() ),
|
||||
'list_visibility' => get_option( StepRoutes::LIST_VISIBILITY_OPTION, 1 ),
|
||||
'site_url' => get_site_url(),
|
||||
'edit_site_url' => $edit_site_url,
|
||||
'plugin_url' => HOSTINGER_EASY_ONBOARDING_PLUGIN_URL,
|
||||
'admin_url' => admin_url('admin-ajax.php'),
|
||||
'user_locale' => get_user_locale(),
|
||||
'plugin_assets_url' => HOSTINGER_EASY_ONBOARDING_ASSETS_URL,
|
||||
'plugin_url' => $this->helper->getHostingerPluginUrl(),
|
||||
'translations' => array(
|
||||
'hostinger_easy_onboarding_black_friday_not_interested' => __( 'Not interested', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_black_friday_get_deal' => __( 'Get deal', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_black_friday_you_will_love_these_deals' => __( 'You’ll love these great deals that were handpicked just for you.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_biggest_cyber_monday_sale' => __( 'The biggest ever <span style="color: #8C85FF">Cyber Monday</span> sale!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_biggest_black_friday_sale' => __( 'The biggest ever <span style="color: #8C85FF">Black Friday</span> sale!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_the_biggest_every_white_friday_sale' => __( 'The biggest ever <span style="color: #8C85FF">White Friday</span> sale!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_the_biggest_ever_amazing_friday_sale' => __( 'The biggest ever <span style="color: #8C85FF">Amazing Friday</span> sale!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_the_biggest_ever_blessed_friday_sale' => __( 'The biggest ever <span style="color: #8C85FF">Blessed Friday</span> sale!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_the_biggest_ever_end_of_the_year_sale' => __( 'The biggest ever <span style="color: #8C85FF">End of the year</span> sale!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_online_store_setup' => __( 'Online store setup', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_preview_website' => __( 'Preview website', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_continue' => __( 'Continue', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_market_your_business' => __( 'Market your business', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_manage_shipping' => __( 'Manage shipping', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_run_email_marketing_campaigns' => __( 'Run email marketing campaigns', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_run_email_marketing_campaigns_description' => __( 'Expand your audience with the help of Omnisend. Create email campaigns that drive sales.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_ship_products_with_ease' => __( 'Ship products with ease', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_shipping_methods' => __( 'Shipping methods', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_try_omnisend' => __( 'Try Omnisend', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_your_store_name' => __( 'Your store name', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_your_business_email' => __( 'Your business email', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_where_is_your_store' => __( 'Where is your store located?', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_what_products_what_do_you_sell' => __( 'What type of products or services will you sell?', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_ship_products_with_ease_description' => __( 'Choose the ways you\'d like to ship orders to customers. You can always add others later.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_getting_features_ready' => __( 'Getting your features ready', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_your_progress' => __( 'Your progress', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_store_info' => __( 'Setup my online store', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_set_up_a_payment_method' => __( 'Set up a payment method', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_set_up_payment_method' => __( 'Set up payment method', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_set_up_a_payment_method_description' => __( 'Get ready to accept customer payments. Let them pay for your products and services with ease.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_first_product' => __( 'Add your first product', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_first_product_or_service' => __( 'Add your first product or service', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_first_product_or_service_description' => __( 'Sell products, services, and digital downloads. Set up and customize each item to fit your business needs.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_setup_google_site_kit' => __( 'Setup Google Site Kit', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_setup_google_site_kit_description' => __( 'Increase your sites visibility by enabling its discoverability in the Google search engine.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_start_earning' => __( 'Start earning', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_your_domain_to_hostinger' => __( 'Connect your domain to Hostinger', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_wait_for_domain_propagation' => __( 'Wait for domain propagation', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_nameserver' => __( 'Nameserver', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_your_domain_to_hostinger' => __( 'Connect your domain to Hostinger', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_your_domain_description_step_one' => __( 'You can connect a domain to Hostinger by changing the nameservers. Different domain providers are have unique procedures for changing nameservers. Here are Hostinger\'s nameservers:', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_your_domain_description_step_two' => __( ' Learn how to connect your domain to Hostinger by watching this tutorial on YouTube for a step-by-step guide:', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_point_domain_nameservers' => __( 'How to Point Domain Name to Web Hosting', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_play_on_youtube' => __( 'Play on YouTube', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_share_your_referral_link' => __( 'Share your referral link with friends and family and <strong>receive 20% commission</strong> for every successful referral.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_invite_friend' => __( 'Invite a Friend, Earn Up to $100', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_website_setup' => __( 'Website setup', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_create_a_logo_description' => __( 'Adding a logo is a great way to personalize a website or add branding information. You can use your existing logo or create a new one using the <a href="https://logo.hostinger.com/?ref=wordpress-onboarding" style="text-decoration:none; font-weight:bold; color:#673de6">AI Logo Maker.</a>', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_upload_your_logo' => __( 'Upload your logo', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_welcome_to_wordpress_title' => __( '👋 Welcome to WordPress', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_website_url' => __( 'Website URL', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_get_domain_description_step_one' => __( 'Your website is already published and can be accessed using Hostinger free temporary subdomain right now. Here is the current URL of your website:', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_get_domain_description_step_two' => __( 'You need to purchase a domain for your website before the preview domain becomes inaccessible. Find a desired website name using a <a style="text-decoration:none; font-weight:bold; color:#673de6" target="_blank" href="https://hpanel.hostinger.com/domains/domain-checker" >domain name searcher.</a >', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_go_to_customize_page_description' => __( 'In the left sidebar, click Appearance to expand the menu. In the Appearance section, click Customize. The Customize page will open.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_post_description' => __( 'Edit post description', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_upload_an_image' => __( 'Upload an image', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_site_title' => __( 'Edit site title', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_cancel' => __( 'Cancel', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_a_new_page' => __( 'Add a new page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_your_domain' => __( 'Connect your domain', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_create_a_logo_title' => __( 'Create a logo', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_go_to_customize_page_title' => __( 'Go to the Customize page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_upload_your_logo_title' => __( 'Upload your logo', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_upload_your_logo_description' => __( 'In the left sidebar, click Site Identity, then click on the Select Site Icon button. Here, you can upload your brand logo.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_take_me_there' => __( 'Take me there', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_get_started' => __( 'Get started!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_skip' => __( 'Skip', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_setup_my_online_store' => __( 'Setup my online store', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_setup_my_online_store_description' => __( 'Enter your store details so we can help you set up your online store faster.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_your progress' => __( 'Your progress', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_complete' => __( 'Complete', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_website_setup' => __( 'Website setup', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_congrats_all_completed' => __( 'Congrats, you’re ready to show off your site!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_customize_your_sites' => __( 'Customize the way your site looks and start welcoming visitors.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_setup_website' => __( 'Setup website', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_online_store_almost_there' => __( '<strong>Almost there!</strong> Just a few more steps to get your site ready for online success.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_completed_steps' => __( 'Completed steps', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_onboarding' => __( 'Onboarding', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_show_list' => __( 'Show list', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_tutorials' => __( 'Tutorials', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_knowledge_base' => __( 'Knowledge Base', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_hide_list' => __( 'Hide list', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_site' => __( 'Edit site', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_dismiss' => __( 'Dismiss', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_finish_setting_up_plugins' => __( 'Now <strong>finish setting up</strong> the plugins you’ve installed.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_view_plugins' => __( 'View plugins', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_done_setting_up_online_store' => __( 'You’re done setting up your online store!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_view_completed' => __( 'View completed', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_hide_completed' => __( 'Hide completed', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_domain_now' => __( 'Connect domain now', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_got_it' => __( 'Got it!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_go_to_posts_title' => __( 'Go to Posts', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_go_to_posts_description' => __( 'In the left sidebar, find the Posts button. Click on the All Posts button and find the post for which you want to change the description.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_post_title' => __( 'Edit post', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_post_description' => __( 'Hover over the chosen post to see the options menu. Click on the Edit button to open the post editor.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_description_title' => __( 'Edit description', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_description_description' => __( 'You can see the whole post in the editor. Find the description part and change it to your preferences.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_find_the_media_page_title' => __( 'Find the Media page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_find_the_media_page_description' => __( 'In the left sidebar, find the Media button. Click on the Library button to see all the images you have uploaded to your website.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_upload_an_image_title' => __( 'Upload an image', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_upload_an_image_description' => __( 'To upload a new image, click on Add New button on the Media Library page and select files.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_an_image_title' => __( 'Edit an image', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_edit_an_image_description' => __( 'If you wish to edit the image, click on the chosen image and click the Edit Image button. You can now crop, rotate, flip or scale the selected image.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_go_to_the_customize_page_title' => __( 'Go to the Customize page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_go_to_the_customize_page_description' => __( 'In the left sidebar, click Appearance to expand the menu. In the Appearance section, click Customize. The Customize page will open.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_access_site_identity_and_edit_title_title' => __( 'Access site identity and edit title', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_access_site_identity_and_edit_title_description' => __( 'In the left sidebar, click Site Identity and edit your site title.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_a_new_page_title' => __( 'Add a new page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_plugin' => __( 'Add plugin', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_plugin_added' => __( 'Added', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_plugin_configure' => __( 'Configure', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect' => __( 'Connect', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_dismiss' => __( 'Dismiss', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_generate_content' => __( 'Generate content', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_plugin_installed' => __( 'Installed', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_generate_content_with_ai' => __( 'Generate content with AI', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_generate_content_with_ai_description' => __( 'Get images, text, and SEO keywords created for you instantly – try <strong>AI Content Creator</strong>.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_run_amazon_affiliate_site' => __( 'Run an Amazon Affiliate site', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_run_amazon_affiliate_site_description' => __( 'Connect your <strong>Amazon Associate</strong> account to fetch API details.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_plugin_activate' => __( 'Activate', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_a_new_page_description' => __( 'In the left sidebar, find the Pages menu and click on Add New button. You will see the WordPress page editor. Each paragraph, image, or video in the WordPress editor is presented as a “block” of content.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_title_title' => __( 'Add a title', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_back' => __( 'Back', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboaring_payment_plugins' => __( 'Payment plugins', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboaring_shipping_plugins' => __( 'Shipping plugins', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_payment_settings' => __( 'Payment settings', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_set_up_payments' => __( 'Set up payments', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_recommended_for_you' => __( 'Recommended for you', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_other' => __( 'Other', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_shipping_settings' => __( 'Shipping settings', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_shipping_method' => __( 'Add shipping method', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_shipping_without_additional_plugins' => __( 'You can also set up a shipping method without installing additional plugins.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_or_use_payment_plugins' => __( 'Or use payment plugins', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_or_use_shipping_plugins' => __( 'Or use shipping plugins', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_use_built_in_shipping_methods' => __( '<strong>Use built-in shipping methods</strong> - no extra plugins needed.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_use_built_in_payment_methods' => __( '<strong>Use built-in payment methods</strong> - no extra plugins needed.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_title_description' => __( 'Add the title of the page, for example, About. Click the Add Title text to open the text box where you will add your title. The title of your page should be descriptive of the information the page will have.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_content_title' => __( 'Add content', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_add_content_description' => __( 'Content can be anything you wish, for example, text, images, videos, tables, and lots more. Click on a plus sign and choose any block you want to add to the page.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_publish_the_page_title' => __( 'Publish the page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_set_up_site_kit' => __( 'Set up Site Kit', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_set_up_shipping' => __( 'Set up shipping', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_continue_setup' => __( 'Continue setup', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_yes_skip_step' => __( 'Yes, skip step', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_google_site_kit_not_needed' => __( 'Google Site Kit is an essential plugin that makes sure that potential visitors can find your site on Google.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_are_you_sure' => __( 'Are you sure?', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_domain_first' => __( 'Connect your domain first', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_publish_the_page_description' => __( 'Before publishing, you can preview your created page by clicking on the Preview button. If you are happy with the result, click the Publish button.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_get_a_domain_title' => __( 'Get a domain', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_build_effective_landing_page' => __( 'How to Build an EFFECTIVE Landing Page with WordPress (2024)', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_connect_your_domain_to_hostinger_title' => __( 'Connect your domain to Hostinger', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_make_website' => __( 'How to Make a Website (2024): Simple, Quick, & Easy Tutorial', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_wait_for_domain_propagation_description' => __( 'Domain propagation can take up to 24 hours. Your domain will propagate automatically, and you don\'t need to take any action during this time.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_create_wordpress_contact_us_page' => __( 'How to Create a WordPress Contact Us Page', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_i_bought_domain_now_what' => __( 'I Bought a Domain, Now What?', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_create_coming_soon_page' => __( 'How to Create Your Coming Soon Page in WordPress (2024)', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_get_maximum_wordpress_optimization' => __( 'LiteSpeed Cache: How to Get 100% WordPress Optimization', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_backup_wordpress_site' => __( 'How to Back Up a WordPress Site', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_import_images_to_wordpress_website' => __( 'How to Import Images Into WordPress Website', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_how_to_setup_wordpress_smtp' => __( 'How to Set Up WordPress SMTP', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_knowledge_base' => __( 'Knowledge Base', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_find_answers_in_knowledge_base' => __( 'Find the answers you need in our Knowledge Base', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_help_center' => __( 'Help Center', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_wordpress_tutorials' => __( 'WordPress tutorials', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_learn_wordpress' => __( 'Learn WordPress', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_hostinger_academy' => __( 'Hostinger Academy', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_setup_page_confirmation_text' => __( 'Opt-in to receive tips, discounts, and recommendations from the WooCommerce team directly in your inbox.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_tell_us_about_your_business' => __( 'Tell us a bit about your business', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_tell_us_about_your_business_description' => __( 'We\'ll use this information to help you set up your store faster.', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_get_in_touch_with_live_specialists' => __( 'Get in touch with our live specialists', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_welcome_to_wordpress' => __( 'Welcome to WordPress!', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_follow_steps_complete_setup' => __( 'Follow these steps to complete your setup', 'hostinger-easy-onboarding' ),
|
||||
'hostinger_easy_onboarding_this_field_is_required' => __( 'This field is required', 'hostinger-easy-onboarding' ),
|
||||
|
||||
),
|
||||
'rest_base_url' => esc_url_raw( rest_url() ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'ajax_nonce' => wp_create_nonce( 'updates' ),
|
||||
'google_site_kit_state' => array(
|
||||
'is_installed' => array_key_exists( 'google-site-kit/google-site-kit.php', $all_plugins),
|
||||
'is_active' => is_plugin_active( 'google-site-kit/google-site-kit.php' ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
|
||||
|
||||
$localize_data['woo'] = array(
|
||||
'store_email' => get_bloginfo( 'admin_email' ),
|
||||
'type_of_products' => array(
|
||||
array(
|
||||
'name' => 'clothing_and_accessories',
|
||||
'label' => __('Clothing and accessories', 'woocommerce')
|
||||
),
|
||||
array(
|
||||
'name' => 'health_and_beauty',
|
||||
'label' => __('Health and beauty', 'woocommerce')
|
||||
),
|
||||
array(
|
||||
'name' => 'food_and_drink',
|
||||
'label' => __('Food and drink', 'woocommerce')
|
||||
),
|
||||
array(
|
||||
'name' => 'home_furniture_and_garden',
|
||||
'label' => __('Home, furniture and garden', 'woocommerce')
|
||||
),
|
||||
array(
|
||||
'name' => 'education_and_learning',
|
||||
'label' => __('Education and learning', 'woocommerce')
|
||||
),
|
||||
array(
|
||||
'name' => 'electronics_and_computers',
|
||||
'label' => __('Electronics and computers', 'woocommerce')
|
||||
),
|
||||
array(
|
||||
'name' => 'other',
|
||||
'label' => __('Other', 'woocommerce')
|
||||
),
|
||||
),
|
||||
'store_countries' => $this->get_countries_and_states()
|
||||
);
|
||||
}
|
||||
|
||||
wp_localize_script(
|
||||
'hostinger_easy_onboarding_main_scripts',
|
||||
'hostinger_easy_onboarding',
|
||||
$localize_data
|
||||
);
|
||||
}
|
||||
|
||||
wp_enqueue_script(
|
||||
'hostinger_easy_onboarding_global_scripts',
|
||||
HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/js/global-scripts.min.js',
|
||||
array(
|
||||
'jquery',
|
||||
'wp-i18n',
|
||||
),
|
||||
HOSTINGER_EASY_ONBOARDING_VERSION,
|
||||
false
|
||||
);
|
||||
|
||||
$global_data = array(
|
||||
'rest_base_url' => esc_url_raw( rest_url() ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'hostinger_nonce' => wp_create_nonce( 'hts-ajax-nonce' ),
|
||||
'is_onboarding_completed' => $this->helper->is_website_onboarding_completed() ? 'true' : 'false',
|
||||
'onboarding_page_url' => admin_url( 'admin.php?page=hostinger-get-onboarding' )
|
||||
);
|
||||
|
||||
if ( is_plugin_active( 'hostinger-ai-assistant/hostinger-ai-assistant.php' ) ) {
|
||||
$global_data['ai_block_inject'] = [
|
||||
'user_id' => get_current_user_id()
|
||||
];
|
||||
}
|
||||
|
||||
wp_localize_script(
|
||||
'hostinger_easy_onboarding_global_scripts',
|
||||
'hostinger_easy_onboarding_global',
|
||||
$global_data
|
||||
);
|
||||
}
|
||||
|
||||
public function gutenberg_edit_pages(): void
|
||||
{
|
||||
// Automatically load imported dependencies and assets version.
|
||||
$asset_file = include HOSTINGER_EASY_ONBOARDING_ABSPATH . 'gutenberg/edit-pages-panel/build/index.asset.php';
|
||||
|
||||
// Enqueue CSS dependencies.
|
||||
foreach ($asset_file['dependencies'] as $style) {
|
||||
wp_enqueue_style($style);
|
||||
}
|
||||
|
||||
wp_enqueue_script(
|
||||
'gutenberg_edit_pages_panel',
|
||||
HOSTINGER_EASY_ONBOARDING_GUTENBERG_URL . '/edit-pages-panel/build/index.js',
|
||||
$asset_file['dependencies'],
|
||||
$asset_file['version'],
|
||||
false
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'gutenberg_edit_pages_panel',
|
||||
HOSTINGER_EASY_ONBOARDING_GUTENBERG_URL . '/edit-pages-panel/build/style-index.css',
|
||||
array(),
|
||||
$asset_file['version']
|
||||
);
|
||||
}
|
||||
|
||||
private function get_countries_and_states()
|
||||
{
|
||||
$countries = WC()->countries->get_countries();
|
||||
if ( ! $countries ) {
|
||||
return array();
|
||||
}
|
||||
$output = array();
|
||||
foreach ( $countries as $key => $value ) {
|
||||
$states = WC()->countries->get_states( $key );
|
||||
|
||||
if ( $states ) {
|
||||
foreach ( $states as $state_key => $state_value ) {
|
||||
$output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
|
||||
}
|
||||
} else {
|
||||
$output[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,681 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Actions as Admin_Actions;
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
use Hostinger\EasyOnboarding\AmplitudeEvents\Actions as AmplitudeActions;
|
||||
use Hostinger\EasyOnboarding\AmplitudeEvents\Amplitude;
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
use Hostinger\EasyOnboarding\WooCommerce\GatewayManager;
|
||||
use Hostinger\EasyOnboarding\WooCommerce\Options as WooCommerceOptions;
|
||||
use Hostinger\WpHelper\Utils;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
class Hooks
|
||||
{
|
||||
public const WOOCOMMERCE_PAGES = [
|
||||
'admin.php?page=wc-admin',
|
||||
'edit.php?post_type=shop_order',
|
||||
'admin.php?page=wc-admin&path=/customers',
|
||||
'edit.php?post_type=shop_coupon&legacy_coupon_menu=1',
|
||||
'admin.php?page=wc-admin&path=/marketing',
|
||||
'admin.php?page=wc-reports',
|
||||
'admin.php?page=wc-settings',
|
||||
'admin.php?page=wc-status',
|
||||
'admin.php?page=wc-admin&path=/extensions',
|
||||
'edit.php?post_type=product',
|
||||
'post-new.php?post_type=product',
|
||||
'edit.php?post_type=product&page=product-reviews',
|
||||
'edit.php?post_type=product&page=product_attributes',
|
||||
'edit-tags.php?taxonomy=product_cat&post_type=product',
|
||||
'edit-tags.php?taxonomy=product_tag&post_type=product',
|
||||
'admin.php?page=wc-admin&path=/analytics/overview',
|
||||
'admin.php?page=wc-admin',
|
||||
'admin.php?page=wc-orders',
|
||||
];
|
||||
|
||||
public const COMPLETED_REMINDER_VISIBLE_PAGES = [
|
||||
'admin.php?page=googlesitekit-splash',
|
||||
'admin.php?page=googlesitekit-dashboard'
|
||||
];
|
||||
|
||||
public const COMPLETED_REMINDER_OPTION_NAME = 'hostinger_setup_completed';
|
||||
|
||||
public const WOOPAYMENTS_REMINDER_OPTION_NAME = 'hostinger_woopayments_completed';
|
||||
|
||||
public const WOO_ONBOARDING_NOTICE_TRANS = 'hostinger_return_to_onboarding';
|
||||
/**
|
||||
* @var Onboarding
|
||||
*/
|
||||
private Onboarding $onboarding;
|
||||
|
||||
private Helper $helper;
|
||||
|
||||
public const DAY_IN_SECONDS = 86400;
|
||||
|
||||
public function __construct() {
|
||||
$this->helper = new Helper();
|
||||
$this->onboarding = new Onboarding();
|
||||
|
||||
add_action( 'admin_init', array( $this, 'init_onboarding' ), 0 );
|
||||
|
||||
// Admin footer actions
|
||||
add_action( 'admin_footer', array( $this, 'rate_plugin' ) );
|
||||
|
||||
// Admin init actions
|
||||
add_action( 'admin_init', array( $this, 'admin_init_actions' ) );
|
||||
add_action( 'admin_init', array( $this, 'set_woocommerce_options' ), 0 );
|
||||
|
||||
// Admin notices
|
||||
add_action( 'admin_notices', array( $this, 'omnisend_discount_notice' ) );
|
||||
|
||||
// Return back to onboarding.
|
||||
add_action( 'admin_footer', array( $this, 'back_to_onboarding_notice' ) );
|
||||
add_filter( 'admin_body_class', array( $this, 'add_onboarding_notice_class' ) );
|
||||
|
||||
// Admin Styles
|
||||
add_action( 'admin_head', array( $this, 'hide_notices' ) );
|
||||
|
||||
// WooCommerce filters
|
||||
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', function () {
|
||||
return true;
|
||||
}, 999 );
|
||||
add_filter( 'woocommerce_enable_setup_wizard', function () {
|
||||
return false;
|
||||
}, 999 );
|
||||
|
||||
// Spectra
|
||||
add_filter( 'uagb_enable_redirect_activation', function () {
|
||||
return false;
|
||||
}, 999 );
|
||||
|
||||
// Hooking up one action before and removing astra redirect to onboarding
|
||||
if ( function_exists( 'astra_sites_redirect_to_onboarding' ) ) {
|
||||
add_action('admin_menu', function () {
|
||||
remove_action('admin_init', 'astra_sites_redirect_to_onboarding');
|
||||
});
|
||||
}
|
||||
|
||||
add_filter('get_edit_post_link', [$this, 'change_shop_page_edit_url'], 99, 3);
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'disable_beaver_builder_redirect' ) );
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'disable_monsterinsights_redirect' ) );
|
||||
|
||||
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
|
||||
add_action('updated_option', [$this, 'check_if_payment_gateway_enabled'], 20, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public function init_onboarding() {
|
||||
$this->onboarding->init();
|
||||
}
|
||||
|
||||
public function hide_notices() {
|
||||
$helper = new Helper();
|
||||
?>
|
||||
<style>
|
||||
|
||||
<?php
|
||||
|
||||
if ( is_plugin_active( 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php' ) || is_plugin_active( 'astra-sites/astra-sites.php' ) ) {
|
||||
?>
|
||||
.interface-interface-skeleton .editor-header__settings button[aria-controls="zip-ai-page-level-settings:zip-ai-page-settings-panel"] {
|
||||
display: none !important;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
<?php if ( ! $helper->is_woocommerce_onboarding_completed() ) : ?>
|
||||
.post-php.post-type-product #wpadminbar .wpforms-menu-notification-counter,
|
||||
.post-php.post-type-product #wpadminbar .aioseo-menu-notification-counter,
|
||||
.post-php.post-type-product .woocommerce-layout__header-tasks-reminder-bar,
|
||||
.post-php.post-type-product .litespeed_icon.notice.is-dismissible,
|
||||
.post-php.post-type-product .monsterinsights-menu-notification-indicator,
|
||||
.post-php.post-type-product .aioseo-review-plugin-cta,
|
||||
.post-php.post-type-product .omnisend-connection-notice-hidden,
|
||||
.post-php.post-type-product #astra-upgrade-pro-wc {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.notice.hts-notice {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $this->is_woocommerce_admin_page() && ! $helper->is_woocommerce_onboarding_completed() ) : ?>
|
||||
#wpadminbar .wpforms-menu-notification-counter,
|
||||
#wpadminbar .aioseo-menu-notification-counter,
|
||||
.woocommerce-layout__header-tasks-reminder-bar,
|
||||
.litespeed_icon.notice.is-dismissible,
|
||||
.monsterinsights-menu-notification-indicator,
|
||||
.aioseo-review-plugin-cta,
|
||||
.omnisend-connection-notice-hidden,
|
||||
#astra-upgrade-pro-wc,
|
||||
.notice {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.notice.hts-notice {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
<?php endif; ?>
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function admin_init_actions(): void {
|
||||
$this->hide_astra_builder_selection_screen();
|
||||
$this->hide_metaboxes();
|
||||
$this->hide_monsterinsight_notice();
|
||||
$this->check_plugins_and_remove_duplicates();
|
||||
}
|
||||
public function check_plugins_and_remove_duplicates() {
|
||||
// Check if the script has already run
|
||||
if (get_option('hostinger_woocommerce_pages_cleanup_done')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if Astra Sites and WooCommerce are activated
|
||||
if (is_plugin_active('astra-sites/astra-sites.php') && is_plugin_active('woocommerce/woocommerce.php')) {
|
||||
// List of pages to check
|
||||
$page_slugs = array("shop", "cart", "checkout", "my-account");
|
||||
$astra_page_slugs = array("shop-2", "cart-2", "checkout-2", "my-account-2");
|
||||
$pages_to_remove = array();
|
||||
$pages_to_rename = array();
|
||||
|
||||
$query = new \WP_Query(array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name__in' => array_merge($page_slugs, $astra_page_slugs),
|
||||
'posts_per_page' => -1
|
||||
));
|
||||
|
||||
if ($query->have_posts()) {
|
||||
$pages = $query->posts;
|
||||
$page_ids = array();
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$page_ids[$page->post_name] = $page->ID;
|
||||
}
|
||||
|
||||
foreach ($page_slugs as $index => $slug) {
|
||||
$astra_slug = $astra_page_slugs[$index];
|
||||
if (isset($page_ids[$slug]) && isset($page_ids[$astra_slug])) {
|
||||
$pages_to_remove[] = $page_ids[$slug];
|
||||
$pages_to_rename[$astra_slug] = $page_ids[$astra_slug];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset post data after query
|
||||
wp_reset_postdata();
|
||||
|
||||
// Assign the 'shop-2', 'cart-2', 'checkout-2' pages as WooCommerce pages
|
||||
foreach ($pages_to_rename as $astra_slug => $page_id) {
|
||||
switch ($astra_slug) {
|
||||
case 'shop-2':
|
||||
update_option('woocommerce_shop_page_id', $page_id);
|
||||
break;
|
||||
case 'cart-2':
|
||||
update_option('woocommerce_cart_page_id', $page_id);
|
||||
break;
|
||||
case 'checkout-2':
|
||||
update_option('woocommerce_checkout_page_id', $page_id);
|
||||
break;
|
||||
case 'my-account-2':
|
||||
update_option('woocommerce_my_account_page_id', $page_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the original 'shop', 'cart', 'checkout' pages
|
||||
foreach ($pages_to_remove as $page_id) {
|
||||
wp_delete_post($page_id, true);
|
||||
}
|
||||
|
||||
// Rename 'shop-2', 'cart-2', 'checkout-2' to 'shop', 'cart', 'checkout'
|
||||
foreach ($pages_to_rename as $astra_slug => $page_id) {
|
||||
$new_slug = str_replace('-2', '', $astra_slug);
|
||||
$new_title = $new_slug == 'my-account' ? 'My Account' : ucfirst($new_slug);
|
||||
wp_update_post(array(
|
||||
'ID' => $page_id,
|
||||
'post_name' => $new_slug,
|
||||
'post_title' => $new_title
|
||||
));
|
||||
}
|
||||
|
||||
// Set the option to indicate the script has run
|
||||
update_option('hostinger_woocommerce_pages_cleanup_done', 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function hide_metaboxes(): void {
|
||||
$this->hide_plugin_metabox( 'google-analytics-for-wordpress/googleanalytics.php', 'monsterinsights-metabox', 'metaboxhidden_product' );
|
||||
$this->hide_plugin_metabox( 'all-in-one-seo-pack/all_in_one_seo_pack.php', 'aioseo-settings', 'aioseo-settings' );
|
||||
$this->hide_plugin_metabox( 'litespeed-cache/litespeed-cache.php', 'litespeed_meta_boxes', 'litespeed_meta_boxes' );
|
||||
$this->hide_astra_theme_metabox();
|
||||
$this->hide_custom_fields_metabox();
|
||||
|
||||
// Hide panels in Gutenberg editor
|
||||
$this->hide_plugin_panel('all-in-one-seo-pack/all_in_one_seo_pack.php', 'meta-box-aioseo-settings');
|
||||
}
|
||||
|
||||
public function hide_astra_theme_metabox(): void {
|
||||
if ( ! $this->is_astra_theme_active() ) {
|
||||
return;
|
||||
}
|
||||
$this->hide_metabox( 'astra_settings_meta_box', 'astra_metabox' );
|
||||
}
|
||||
|
||||
public function hide_custom_fields_metabox(): void {
|
||||
$this->hide_metabox( 'postcustom', 'custom_fields_metabox' );
|
||||
}
|
||||
|
||||
public function hide_metabox( string $metabox_id, string $transient_suffix ): void {
|
||||
$helper = new Utils();
|
||||
$user_id = get_current_user_id();
|
||||
$transient_key = $transient_suffix . '_' . $user_id;
|
||||
$hide_metabox = get_transient( $transient_key );
|
||||
|
||||
if ( $hide_metabox ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hide_metabox = get_user_meta( $user_id, 'metaboxhidden_product', true );
|
||||
|
||||
if ( ! is_array( $hide_metabox ) ) {
|
||||
$hide_metabox = array();
|
||||
}
|
||||
|
||||
if ( $helper->isThisPage( 'post-new.php?post_type=product' ) ) {
|
||||
if ( ! in_array( $metabox_id, $hide_metabox ) ) {
|
||||
array_push( $hide_metabox, $metabox_id );
|
||||
}
|
||||
|
||||
update_user_meta( $user_id, 'metaboxhidden_product', $hide_metabox );
|
||||
set_transient( $transient_key, 'hidden', self::DAY_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
public function is_astra_theme_active(): bool {
|
||||
$theme = wp_get_theme();
|
||||
|
||||
return $theme->get( 'Name' ) === 'Astra';
|
||||
}
|
||||
|
||||
public function hide_monsterinsight_notice(): void {
|
||||
if ( is_plugin_active( 'google-analytics-for-wordpress/googleanalytics.php' ) ) {
|
||||
define( 'MONSTERINSIGHTS_DISABLE_TRACKING', true );
|
||||
}
|
||||
}
|
||||
|
||||
public function rate_plugin(): void {
|
||||
$promotional_banner_hidden = get_transient( 'hts_hide_promotional_banner_transient' );
|
||||
$two_hours_in_seconds = 7200;
|
||||
|
||||
if ( $promotional_banner_hidden && time() > $promotional_banner_hidden + $two_hours_in_seconds ) {
|
||||
require_once HOSTINGER_EASY_ONBOARDING_ABSPATH . 'includes/Admin/Views/Partials/RateUs.php';
|
||||
}
|
||||
}
|
||||
|
||||
public function omnisend_discount_notice(): void {
|
||||
$omnisend_notice_hidden = get_transient( 'hts_omnisend_notice_hidden' );
|
||||
|
||||
if ( $omnisend_notice_hidden === false && $this->helper->is_this_page( '/wp-admin/admin.php?page=omnisend' ) && ( Helper::is_plugin_active( 'class-omnisend-core-bootstrap' ) || Helper::is_plugin_active( 'omnisend-woocommerce' ) ) ) : ?>
|
||||
<div class="notice notice-info hts-admin-notice hts-omnisend">
|
||||
<p><?php echo wp_kses( __( 'Use the special discount code <b>ONLYHOSTINGER30</b> to get 30% off on Omnisend for 6 months when you upgrade.', 'hostinger-easy-onboarding' ), array( 'b' => array() ) ); ?></p>
|
||||
<div>
|
||||
<a class="button button-primary"
|
||||
href="https://your.omnisend.com/LXqyZ0"
|
||||
target="_blank"><?= esc_html__( 'Get Discount', 'hostinger-easy-onboarding' ); ?></a>
|
||||
<button type="button" class="notice-dismiss"></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif;
|
||||
wp_nonce_field( 'hts_close_omnisend', 'hts_close_omnisend_nonce', true );
|
||||
}
|
||||
|
||||
public function hide_astra_builder_selection_screen(): void {
|
||||
add_filter( 'st_enable_block_page_builder', '__return_true' );
|
||||
}
|
||||
|
||||
public function hide_plugin_metabox( string $plugin_slug, string $metabox_id, string $transient_suffix ): void {
|
||||
$helper = new Utils();
|
||||
$user_id = get_current_user_id();
|
||||
$transient_key = $transient_suffix . '_' . $user_id;
|
||||
$hide_metabox = get_transient( $transient_key );
|
||||
|
||||
if ( $hide_metabox ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hide_metabox = get_user_meta( $user_id, 'metaboxhidden_product', true );
|
||||
|
||||
if ( ! is_plugin_active( $plugin_slug ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_array( $hide_metabox ) ) {
|
||||
$hide_metabox = array();
|
||||
}
|
||||
|
||||
if ( $helper->isThisPage( 'post-new.php?post_type=product' ) ) {
|
||||
if ( ! in_array( $metabox_id, $hide_metabox ) ) {
|
||||
array_push( $hide_metabox, $metabox_id );
|
||||
}
|
||||
|
||||
update_user_meta( $user_id, 'metaboxhidden_product', $hide_metabox );
|
||||
set_transient( $transient_key, 'hidden', self::DAY_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
public function hide_plugin_panel( string $plugin_slug, $panel_id ) {
|
||||
if ( ! is_plugin_active( $plugin_slug ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$flag_name = 'hostinger_' . $panel_id . '_changed';
|
||||
|
||||
$hidden_once = get_user_meta( $user_id, $flag_name, true );
|
||||
|
||||
if( $hidden_once ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$persisted_preferences = get_user_meta( $user_id, 'wp_persisted_preferences', true );
|
||||
|
||||
if ( empty( $persisted_preferences ) ) {
|
||||
$persisted_preferences = array(
|
||||
'core/edit-post' => array(
|
||||
'welcomeGuide' => '',
|
||||
'isComplementaryAreaVisible' => 1,
|
||||
'inactivePanels' => array(
|
||||
$panel_id
|
||||
)
|
||||
),
|
||||
'core/edit-site' => array(
|
||||
'welcomeGuide' => '',
|
||||
'isComplementaryAreaVisible' => 1
|
||||
),
|
||||
'_modified' => wp_date( 'c' ),
|
||||
);
|
||||
} else {
|
||||
if( !empty( $persisted_preferences['core/edit-post']['inactivePanels'] ) && !in_array( $panel_id, $persisted_preferences['core/edit-post']['inactivePanels'] ) ) {
|
||||
$persisted_preferences['core/edit-post']['inactivePanels'][] = $panel_id;
|
||||
}
|
||||
}
|
||||
|
||||
update_user_meta( $user_id, 'wp_persisted_preferences', $persisted_preferences );
|
||||
update_user_meta( $user_id, $flag_name, 1 );
|
||||
}
|
||||
|
||||
private function is_completed_reminder_page(): bool
|
||||
{
|
||||
if ( ! isset($_SERVER['REQUEST_URI'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_uri = sanitize_text_field($_SERVER['REQUEST_URI']);
|
||||
|
||||
if (defined('DOING_AJAX') && \DOING_AJAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($current_uri) && strpos($current_uri, '/wp-json/') !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::COMPLETED_REMINDER_VISIBLE_PAGES as $page) {
|
||||
if (strpos($current_uri, $page) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function is_woocommerce_admin_page(): bool
|
||||
{
|
||||
// Product edit etc.
|
||||
if (get_post_type() === 'product') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! isset($_SERVER['REQUEST_URI'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_uri = sanitize_text_field($_SERVER['REQUEST_URI']);
|
||||
|
||||
if (defined('DOING_AJAX') && \DOING_AJAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($current_uri) && strpos($current_uri, '/wp-json/') !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($current_uri) && (strpos($current_uri, 'paymentsonboarding') !== false || strpos($current_uri, '/payments/onboarding') !== false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::WOOCOMMERCE_PAGES as $page) {
|
||||
if (strpos($current_uri, $page) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function back_to_onboarding_notice(): void
|
||||
{
|
||||
$text = __('Just a few more steps to launch your online store', 'hostinger-easy-onboarding');
|
||||
$button_url = admin_url('admin.php?page=hostinger-get-onboarding&subPage=woo-commerce-online-store-setup');
|
||||
$button_class = '';
|
||||
$button_text = __('Continue setup', 'hostinger-easy-onboarding');
|
||||
|
||||
if ( $this->is_onboarding_complete_reminder_visible() ) {
|
||||
$text = __('Congrats, you’re ready to show off your site!', 'hostinger-easy-onboarding');
|
||||
$button_url = admin_url('admin.php?page=hostinger-get-onboarding');
|
||||
$button_class = '';
|
||||
$button_text = __('View checklist', 'hostinger-easy-onboarding');
|
||||
}
|
||||
|
||||
if( $this->is_woopayments_reminder_visible() ) {
|
||||
$text = __('Congrats, you have connected WooPayments!', 'hostinger-easy-onboarding');
|
||||
$button_url = admin_url('admin.php?page=hostinger-get-onboarding&subPage=woo-commerce-online-store-setup');
|
||||
$button_class = '';
|
||||
$button_text = __('Continue setup', 'hostinger-easy-onboarding');
|
||||
}
|
||||
|
||||
if ( $this->is_onboarding_reminder_visible() || $this->is_onboarding_complete_reminder_visible() || $this->is_woopayments_reminder_visible() ) {
|
||||
?>
|
||||
<div class="hostinger-onboarding-reminder">
|
||||
<div class="hostinger-onboarding-reminder__wrap">
|
||||
<div class="hostinger-onboarding-reminder__logo">
|
||||
<svg width="93" height="108" viewBox="0 0 93 108" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||
d="M66.5145 0V32.2221L92.8421 47.4468V13.2693L66.5145 0ZM0.000915527 0.00183105V50.5657H85.6265L59.5744 36.4074L25.6372 36.3911V13.6097L0.000915527 0.00183105ZM66.5145 94.0237V71.4387L32.3155 71.4152C32.3474 71.5655 5.83099 57.0306 5.83099 57.0306L92.8421 57.4371V108L66.5145 94.0237ZM0.000912095 60.9814L0 94.0237L25.6372 107.292V75.8458L0.000912095 60.9814Z"
|
||||
fill="#673DE6"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="hostinger-onboarding-reminder__text">
|
||||
<?php echo $text; ?>
|
||||
</div>
|
||||
<div class="hostinger-onboarding-reminder__cta <?php echo $button_class; ?>">
|
||||
<a href="<?php
|
||||
echo $button_url; ?>">
|
||||
<?php
|
||||
echo $button_text; ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( $this->is_onboarding_complete_reminder_visible() ) {
|
||||
update_option( self::COMPLETED_REMINDER_OPTION_NAME, 1 );
|
||||
}
|
||||
|
||||
if ( $this->is_woopayments_reminder_visible() ) {
|
||||
update_option( self::WOOPAYMENTS_REMINDER_OPTION_NAME, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
public function add_onboarding_notice_class($classes)
|
||||
{
|
||||
if ($this->is_onboarding_reminder_visible() || $this->is_onboarding_complete_reminder_visible()) {
|
||||
$classes .= ' hostinger-onboarding-reminder-visible';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
private function is_onboarding_complete_reminder_visible()
|
||||
{
|
||||
$setup_completed = get_option( self::COMPLETED_REMINDER_OPTION_NAME, false );
|
||||
|
||||
$onboarding_completed = $this->helper->is_website_onboarding_completed();
|
||||
|
||||
if ( is_plugin_active('woocommerce/woocommerce.php') ) {
|
||||
$onboarding_completed = $this->helper->is_woocommerce_onboarding_completed() && $this->helper->is_website_onboarding_completed();
|
||||
}
|
||||
|
||||
return $onboarding_completed
|
||||
&& empty( $setup_completed )
|
||||
&& $this->is_completed_reminder_page();
|
||||
}
|
||||
|
||||
private function is_woopayments_reminder_visible()
|
||||
{
|
||||
$woopayments_completed = get_option( self::WOOPAYMENTS_REMINDER_OPTION_NAME, false );
|
||||
|
||||
return is_plugin_active('woocommerce/woocommerce.php')
|
||||
&& is_plugin_active('woocommerce-payments/woocommerce-payments.php')
|
||||
&& $this->helper->is_woocommerce_payments_ready()
|
||||
&& empty( $woopayments_completed )
|
||||
&& $this->helper->is_this_page( 'paymentsoverview' );
|
||||
}
|
||||
|
||||
private function is_onboarding_reminder_visible()
|
||||
{
|
||||
return is_plugin_active('woocommerce/woocommerce.php')
|
||||
&& ! $this->helper->is_woocommerce_onboarding_completed()
|
||||
&& $this->is_woocommerce_admin_page();
|
||||
}
|
||||
|
||||
public function change_shop_page_edit_url($link, $post_id, $context): string
|
||||
{
|
||||
if ( ! is_plugin_active('woocommerce/woocommerce.php')) {
|
||||
return $link;
|
||||
}
|
||||
|
||||
$shop_page_id = wc_get_page_id( 'shop' );
|
||||
|
||||
if( $shop_page_id != $post_id ) {
|
||||
return $link;
|
||||
}
|
||||
|
||||
if( current_theme_supports( 'block-templates' ) ) {
|
||||
return admin_url( 'site-editor.php?postType=wp_template&postId=woocommerce/woocommerce//archive-product' );
|
||||
}
|
||||
|
||||
return admin_url( 'customize.php?autofocus[section]=woocommerce_product_catalog' );
|
||||
}
|
||||
|
||||
public function disable_beaver_builder_redirect() {
|
||||
if ( !is_plugin_active( 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$redirect = get_option( 'uabb_lite_redirect', false );
|
||||
|
||||
if ( empty( $redirect ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
update_option( 'uabb_lite_redirect', false );
|
||||
|
||||
$this->flush_object_cache();
|
||||
}
|
||||
|
||||
public function disable_monsterinsights_redirect() {
|
||||
if ( !is_plugin_active( 'google-analytics-for-wordpress/googleanalytics.php' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! get_transient( '_monsterinsights_activation_redirect' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete the redirect transient.
|
||||
delete_transient( '_monsterinsights_activation_redirect' );
|
||||
|
||||
$this->flush_object_cache();
|
||||
}
|
||||
|
||||
private function flush_object_cache(): void {
|
||||
if ( has_action( 'litespeed_purge_all_object' ) ) {
|
||||
do_action('litespeed_purge_all_object');
|
||||
}
|
||||
}
|
||||
|
||||
public function check_if_payment_gateway_enabled( $option, $old_value, $value ) {
|
||||
if ( ! str_contains( $option, 'woocommerce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->onboarding->is_completed( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Admin_Actions::ADD_PAYMENT ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payment_gateway_manager = new GatewayManager( \WC_Payment_Gateways::instance() );
|
||||
|
||||
if( $payment_gateway_manager->isAnyGatewayActive() ) {
|
||||
$this->onboarding->complete_step( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Admin_Actions::ADD_PAYMENT );
|
||||
|
||||
$amplitude = new Amplitude();
|
||||
|
||||
$params = array(
|
||||
'action' => AmplitudeActions::WOO_ITEM_COMPLETED,
|
||||
'step_type' => Admin_Actions::ADD_PAYMENT,
|
||||
);
|
||||
|
||||
$amplitude->send_event( $params );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function set_woocommerce_options(): void {
|
||||
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$woocommerce_options_set = get_option( 'hostinger_onboarding_woo_options_set', null );
|
||||
$onboarding_choice_done = get_option( 'hostinger_onboarding_choice_done', null );
|
||||
|
||||
if ( $onboarding_choice_done === null && $woocommerce_options_set === null ) {
|
||||
$woocommerceOptions = new WooCommerceOptions();
|
||||
|
||||
$woocommerceOptions->hideSetupTaskList();
|
||||
$woocommerceOptions->disableWooCommerceShipingZoneCreation();
|
||||
$woocommerceOptions->skipOnboarding();
|
||||
|
||||
update_option( 'hostinger_onboarding_woo_options_set', true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\WpHelper\Utils;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Menu {
|
||||
public const WEBSITE_LIST_URL = 'https://hpanel.hostinger.com/websites';
|
||||
public const HPANEL_HOME = 'https://hpanel.hostinger.com';
|
||||
public const WEBSITE_BILLINGS_URL = 'https://hpanel.hostinger.com/billing/subscriptions';
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'hostinger_menu_subpages', array( $this, 'add_menu_sub_pages' ) );
|
||||
add_filter( 'hostinger_admin_menu_bar_items', array( $this, 'add_admin_bar_items' ) );
|
||||
add_filter( 'hostinger_admin_menu_bar_items', array( $this, 'add_hpanel_bar_items' ), 999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $menu_items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_admin_bar_items(array $menu_items): array {
|
||||
$menu_items[] = array(
|
||||
'id' => 'hostinger-easy-onboarding-admin-bar-onboarding',
|
||||
'title' => esc_html__( 'Onboarding', 'hostinger-easy-onboarding' ),
|
||||
'href' => admin_url( 'admin.php?page=hostinger-get-onboarding' )
|
||||
);
|
||||
|
||||
$menu_items[] = array(
|
||||
'id' => 'hostinger-easy-onboarding-admin-bar-learn',
|
||||
'title' => esc_html__( 'Learn', 'hostinger-easy-onboarding' ),
|
||||
'href' => admin_url( 'admin.php?page=hostinger-get-learn' )
|
||||
);
|
||||
|
||||
return $menu_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $menu_items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_hpanel_bar_items(array $menu_items): array {
|
||||
if (empty(Utils::getApiToken())) {
|
||||
return $menu_items;
|
||||
}
|
||||
|
||||
$external_icon = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M5 21C4.45 21 3.97917 20.8042 3.5875 20.4125C3.19583 20.0208 3 19.55 3 19V5C3 4.45 3.19583 3.97917 3.5875 3.5875C3.97917 3.19583 4.45 3 5 3H11C11.2833 3 11.5208 3.09583 11.7125 3.2875C11.9042 3.47917 12 3.71667 12 4C12 4.28333 11.9042 4.52083 11.7125 4.7125C11.5208 4.90417 11.2833 5 11 5H5V19H19V13C19 12.7167 19.0958 12.4792 19.2875 12.2875C19.4792 12.0958 19.7167 12 20 12C20.2833 12 20.5208 12.0958 20.7125 12.2875C20.9042 12.4792 21 12.7167 21 13V19C21 19.55 20.8042 20.0208 20.4125 20.4125C20.0208 20.8042 19.55 21 19 21H5ZM19 6.4L10.4 15C10.2167 15.1833 9.98333 15.275 9.7 15.275C9.41667 15.275 9.18333 15.1833 9 15C8.81667 14.8167 8.725 14.5833 8.725 14.3C8.725 14.0167 8.81667 13.7833 9 13.6L17.6 5H15C14.7167 5 14.4792 4.90417 14.2875 4.7125C14.0958 4.52083 14 4.28333 14 4C14 3.71667 14.0958 3.47917 14.2875 3.2875C14.4792 3.09583 14.7167 3 15 3H21V9C21 9.28333 20.9042 9.52083 20.7125 9.7125C20.5208 9.90417 20.2833 10 20 10C19.7167 10 19.4792 9.90417 19.2875 9.7125C19.0958 9.52083 19 9.28333 19 9V6.4Z" fill=""/>
|
||||
</svg>';
|
||||
|
||||
$menu_items[] = array(
|
||||
'id' => 'hostinger_hpanel_home_admin_bar',
|
||||
'title' => esc_html__( 'hPanel - Home', 'hostinger-easy-onboarding' ) . $external_icon,
|
||||
'href' => self::HPANEL_HOME,
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
)
|
||||
);
|
||||
|
||||
$menu_items[] = array(
|
||||
'id' => 'hostinger_website_list_admin_bar',
|
||||
'title' => esc_html__( 'hPanel - Websites', 'hostinger-easy-onboarding' ) . $external_icon,
|
||||
'href' => self::WEBSITE_LIST_URL,
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
)
|
||||
);
|
||||
|
||||
$menu_items[] = array(
|
||||
'id' => 'hostinger_billings_admin_bar',
|
||||
'title' => esc_html__( 'hPanel - Billing', 'hostinger-easy-onboarding' ) . $external_icon,
|
||||
'href' => self::WEBSITE_BILLINGS_URL,
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
)
|
||||
);
|
||||
|
||||
return $menu_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submenus
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_menu_sub_pages( array $submenus ): array {
|
||||
$submenus[] = array(
|
||||
'page_title' => __( 'Onboarding', 'hostinger-easy-onboarding' ),
|
||||
'menu_title' => __( 'Onboarding', 'hostinger-easy-onboarding' ),
|
||||
'capability' => 'manage_options',
|
||||
'menu_slug' => 'hostinger-get-onboarding',
|
||||
'callback' => array( $this, 'renderOnboarding' ),
|
||||
'menu_identifier' => 'home',
|
||||
'menu_order' => 10
|
||||
);
|
||||
|
||||
return $submenus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function renderOnboarding(): void {
|
||||
include_once __DIR__ . '/Views/Onboarding.php';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
|
||||
|
||||
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 ( $this->helper->is_hostinger_admin_page() ) {
|
||||
add_action( 'admin_init', array( $this, 'domain_is_connected' ) );
|
||||
}
|
||||
|
||||
if ( $this->helper->isStoreSetupCompleted() ) {
|
||||
add_action( 'admin_init', array( $this, 'website_setup_completed' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function init_onboarding() {
|
||||
$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();
|
||||
|
||||
if ( ! empty( $plugin_settings['connection_status'] ) && $plugin_settings['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 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($instance_id, $type, $zone_id) {
|
||||
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() {
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function find_category_from_actions($action): string {
|
||||
foreach (Admin_Actions::get_category_action_lists() as $category => $actions) {
|
||||
if (in_array($action, $actions)) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Actions;
|
||||
use Hostinger\EasyOnboarding\Admin\Actions as 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 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_data = self::get_first_step_data();
|
||||
|
||||
if ( ! empty( $first_step_data ) ) {
|
||||
$first_step = new Step( Actions::AI_STEP );
|
||||
|
||||
$first_step->set_image_url( HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/images/steps/ai_step.svg' );
|
||||
|
||||
$first_step->set_title_completed( __( 'Started creating your site', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
if ( ! empty( $first_step_data['title'] ) ) {
|
||||
$first_step->set_title( $first_step_data['title'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $first_step_data['description'] ) ) {
|
||||
$first_step->set_description( $first_step_data['description'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $first_step_data['primary_button_title'] ) ) {
|
||||
$button = new Button( $first_step_data['primary_button_title'] );
|
||||
|
||||
if ( ! empty( $first_step_data['primary_button_url'] ) ) {
|
||||
$button->set_url( $first_step_data['primary_button_url'] );
|
||||
}
|
||||
|
||||
$first_step->set_primary_button( $button );
|
||||
}
|
||||
|
||||
if ( ! empty( $first_step_data['secondary_button_title'] ) ) {
|
||||
$button = new Button( $first_step_data['secondary_button_title'] );
|
||||
|
||||
if ( ! empty( $first_step_data['secondary_button_url'] ) ) {
|
||||
$button->set_url( $first_step_data['secondary_button_url'] );
|
||||
} else {
|
||||
$button->set_is_skippable( true );
|
||||
}
|
||||
|
||||
$first_step->set_secondary_button( $button );
|
||||
}
|
||||
|
||||
$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() );
|
||||
|
||||
// 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() );
|
||||
|
||||
// Add shipping method.
|
||||
$store_step_category->add_step( $this->get_shipping_method_step() );
|
||||
|
||||
$this->step_categories[] = $store_step_category;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
$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];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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( __( 'Connect a domain', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$button = new Button( __( 'Connect domain', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
if ( $this->helper->is_free_subdomain() || $this->helper->is_preview_domain() ) {
|
||||
$step->set_title_completed(__('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 {
|
||||
$step->set_title_completed(__('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 ) );
|
||||
}
|
||||
|
||||
$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' );
|
||||
|
||||
$step->set_title( __( 'Connect your Amazon account to the site', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$step->set_title_completed( __( 'Connected your Amazon account', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$step->set_description( __( 'Join the Amazon Affiliate Program to start earning commissions. Link your Amazon affiliate account to your website, start promoting products and earn rewards.', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$button = new Button( __( 'Connect Amazon to site', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$button->set_url( admin_url( 'admin.php?page=hostinger-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&subPage=woo-commerce-online-store-setup' ) );
|
||||
|
||||
$primary_button->set_title_completed( __( 'View list', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$step->set_primary_button( $primary_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( __( 'Store info', '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( __( 'View Details', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$primary_button->set_url( admin_url( 'admin.php?page=wc-settings' ) );
|
||||
|
||||
$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' ) );
|
||||
|
||||
$step->set_primary_button( $primary_button );
|
||||
|
||||
$secondary_button = new Button( __( 'Not interested', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$secondary_button->set_is_skippable( true );
|
||||
|
||||
$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 a payment method', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$step->set_description( __( 'Get ready to accept customer payments. Let them pay for your products and services with ease.', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$primary_button = new Button( __( 'Set up payment method', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-get-onboarding&subPage=hostinger-store-add-payment-method' ) );
|
||||
|
||||
$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( __( 'Shipping methods', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$primary_button->set_url( admin_url( 'admin.php?page=hostinger-get-onboarding&subPage=hostinger-store-add-shipping-method' ) );
|
||||
|
||||
$step->set_primary_button( $primary_button );
|
||||
|
||||
$secondary_button = new Button( __( 'Not needed', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$secondary_button->set_is_skippable( true );
|
||||
|
||||
$step->set_secondary_button( $secondary_button );
|
||||
|
||||
return $step;
|
||||
}
|
||||
|
||||
private function get_google_kit_step(): Step
|
||||
{
|
||||
$step = new Step( Admin_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' ) );
|
||||
|
||||
$primary_button->set_title_completed( __( 'Manage', 'hostinger-easy-onboarding' ));
|
||||
|
||||
$step->set_primary_button( $primary_button );
|
||||
|
||||
$secondary_button = new Button( __( 'Not needed', 'hostinger-easy-onboarding' ) );
|
||||
|
||||
$secondary_button->set_is_skippable( true );
|
||||
|
||||
$step->set_secondary_button( $secondary_button );
|
||||
|
||||
return $step;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
private function is_store_ready( array $steps ): bool {
|
||||
$store_steps = $steps[Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID] ?? array();
|
||||
return !empty( $store_steps[Admin_Actions::ADD_PAYMENT] ) && !empty( $store_steps[Admin_Actions::ADD_PRODUCT] );
|
||||
}
|
||||
|
||||
private function is_store_completed( $steps ): bool {
|
||||
$all_woo_steps = Admin_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 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 );
|
||||
}
|
||||
|
||||
public static function get_first_step_data(): array
|
||||
{
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
$result = array();
|
||||
|
||||
if ( \is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( get_option( 'template' ) == 'hostinger-ai-theme' ) {
|
||||
$hostinger_ai_version = get_option( 'hostinger_ai_version', false );
|
||||
|
||||
if ( empty( $hostinger_ai_version ) ) {
|
||||
$result['title'] = __( 'Create a site with AI', 'hostinger-easy-onboarding' );
|
||||
$result['description'] = __( 'Build a professional, custom-designed site in moments. Just a few clicks and AI handles the rest.', 'hostinger-easy-onboarding' );
|
||||
$result['primary_button_title'] = __( 'Create site with AI', 'hostinger-easy-onboarding' );
|
||||
$result['primary_button_url'] = admin_url( 'admin.php?page=hostinger-ai-website-creation&redirect=hostinger-easy-onboarding' );
|
||||
$result['secondary_button_title'] = __( 'Not now', 'hostinger-easy-onboarding' );
|
||||
} else {
|
||||
$result['title'] = __( 'Want to create a new AI site?', 'hostinger-easy-onboarding' );
|
||||
$result['description'] = __( 'Your new site will replace the current one. Use the same description or change it.', 'hostinger-easy-onboarding' );
|
||||
$result['primary_button_title'] = __( 'Keep current site', 'hostinger-easy-onboarding' );
|
||||
$result['secondary_button_title'] = __( 'Create new site', 'hostinger-easy-onboarding' );
|
||||
$result['secondary_button_url'] = admin_url( 'admin.php?page=hostinger-ai-website-creation&redirect=hostinger-easy-onboarding' );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$whitelist_plans = array(
|
||||
'business_economy',
|
||||
'business_enterprise',
|
||||
'business_professional',
|
||||
'cloud_economy',
|
||||
'cloud_enterprise',
|
||||
'cloud_professional',
|
||||
'gcp_business_8',
|
||||
'hostinger_business',
|
||||
);
|
||||
|
||||
$hosting_plan = get_option( 'hostinger_hosting_plan', false );
|
||||
|
||||
if ( \is_plugin_active( 'hostinger-ai-assistant/hostinger-ai-assistant.php' ) && !empty( $hosting_plan ) && in_array( $hosting_plan, $whitelist_plans ) ) {
|
||||
$result['title'] = __( 'Create content with AI', 'hostinger-easy-onboarding' );
|
||||
$result['description'] = __( 'Build a professional, custom-designed site in moments. Just a few clicks and AI handles the rest.', 'hostinger-easy-onboarding' );
|
||||
$result['primary_button_title'] = __( 'Generate post', 'hostinger-easy-onboarding' );
|
||||
$result['primary_button_url'] = admin_url( 'admin.php?page=hostinger-ai-assistant' );
|
||||
$result['secondary_button_title'] = __( 'Not now', 'hostinger-easy-onboarding' );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
<?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 $global
|
||||
* @param bool $is_config_url
|
||||
* @param string $config_url
|
||||
*/
|
||||
public function __construct($icon_url, $name, $slug, $description, $type, $locale_supported, $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->global = $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_global(): bool
|
||||
{
|
||||
return $this->global;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $global
|
||||
*/
|
||||
public function set_global(bool $global): void
|
||||
{
|
||||
$this->global = $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_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,134 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin\Onboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Plugin;
|
||||
use Hostinger\WpHelper\Utils;
|
||||
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§ion=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§ion=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§ion=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§ion=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§ion=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§ion=pagseguro' ) );
|
||||
|
||||
// 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§ion=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§ion=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§ion=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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
if( in_array($locale, $plugin->get_locale_supported())) {
|
||||
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 );
|
||||
}
|
||||
|
||||
$plugin->set_is_recommended( $this->check_recommended( $plugin ) );
|
||||
|
||||
return in_array( $locale, $plugin->get_locale_supported() ) || $plugin->get_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,125 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin\Onboarding\Steps;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Button {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $title_completed;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private bool $is_skippable;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $url = '';
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $title_completed
|
||||
* @param bool $is_skippable
|
||||
* @param string $url
|
||||
*/
|
||||
public function __construct( string $title, string $title_completed = '', bool $is_skippable = false, string $url = '' ) {
|
||||
$this->title = $title;
|
||||
$this->title_completed = $title_completed;
|
||||
$this->is_skippable = $is_skippable;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_title_completed(): string
|
||||
{
|
||||
return $this->title_completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title_completed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_title_completed( string $title_completed ): void
|
||||
{
|
||||
$this->title_completed = $title_completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function to_array(): array
|
||||
{
|
||||
return array(
|
||||
'title' => $this->get_title(),
|
||||
'title_completed' => $this->get_title_completed(),
|
||||
'is_skippable' => $this->get_is_skippable(),
|
||||
'url' => $this->get_url()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
<?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 $title_completed = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $description = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $image_url = '';
|
||||
|
||||
/**
|
||||
* @var Button
|
||||
*/
|
||||
private Button $primary_button;
|
||||
|
||||
/**
|
||||
* @var Button
|
||||
*/
|
||||
private Button $secondary_button;
|
||||
|
||||
/**
|
||||
* @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_title_completed(): string
|
||||
{
|
||||
return $this->title_completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title_completed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_title_completed(string $title_completed): void
|
||||
{
|
||||
$this->title_completed = $title_completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function to_array(): array
|
||||
{
|
||||
$primary_button = !empty($this->get_primary_button()) ? $this->get_primary_button()->to_array() : [];
|
||||
$secondary_button = !empty($this->get_secondary_button()) ? $this->get_secondary_button()->to_array() : [];
|
||||
|
||||
return array(
|
||||
'id' => $this->get_id(),
|
||||
'is_completed' => $this->get_is_completed(),
|
||||
'title' => $this->get_title(),
|
||||
'title_completed' => $this->get_title_completed(),
|
||||
'description' => $this->get_description(),
|
||||
'image_url' => $this->get_image_url(),
|
||||
'primary_button' => $primary_button,
|
||||
'secondary_button' => $secondary_button
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
class Partnership {
|
||||
const MONSTERINSIGHTS_PARTNER_ID = '3107422';
|
||||
const ASTRA_PARTNER_ID = '12425';
|
||||
const WPFORMS_PARTNER_LINK = 'https://shareasale.com/r.cfm?b=834775&u=3107422&m=64312&urllink=';
|
||||
const AIOSEO_PARTNER_LINK = 'https://shareasale.com/r.cfm?b=1491200&u=3107422&m=94778&urllink=';
|
||||
const HESTIA_AND_NEVE_PARTNER_LINK = 'https://www.shareasale.com/r.cfm?b=642802&u=3107422&m=55096';
|
||||
|
||||
public function __construct() {
|
||||
if ( is_admin() ) {
|
||||
$this->define_admin_hooks();
|
||||
}
|
||||
|
||||
add_action( 'init', array( $this, 'schedule_weekly_cron_job' ) );
|
||||
}
|
||||
|
||||
public function partner_astra() {
|
||||
add_option( 'astra_partner_url_param', self::ASTRA_PARTNER_ID, '', 'no' );
|
||||
}
|
||||
|
||||
public function partner_monsterinsights( $id ) {
|
||||
return self::MONSTERINSIGHTS_PARTNER_ID;
|
||||
}
|
||||
|
||||
public function wpforms_upgrade_link( $link ) {
|
||||
return self::WPFORMS_PARTNER_LINK . rawurlencode( $link );
|
||||
}
|
||||
|
||||
public function aioseo_upgrade_link( $link ) {
|
||||
return self::AIOSEO_PARTNER_LINK . rawurlencode( $link );
|
||||
}
|
||||
|
||||
public function neve_or_hestia_upgrade_link( $utmify_url, $url ) {
|
||||
if ( strpos( $url, 'themes/neve/upgrade' ) !== false || strpos( $url, 'themes/hestia-pro/upgrade' ) !== false ) {
|
||||
return self::HESTIA_AND_NEVE_PARTNER_LINK;
|
||||
}
|
||||
|
||||
return $utmify_url;
|
||||
}
|
||||
|
||||
private function define_admin_hooks() {
|
||||
add_filter( 'optinmonster_sas_id', array( $this, 'partner_monsterinsights' ) );
|
||||
add_filter( 'monsterinsights_shareasale_id', array( $this, 'partner_monsterinsights' ) );
|
||||
add_filter( 'wpforms_upgrade_link', array( $this, 'wpforms_upgrade_link' ) );
|
||||
add_filter( 'aioseo_upgrade_link', array( $this, 'aioseo_upgrade_link' ) );
|
||||
add_filter( 'tsdk_utmify_url_neve', array( $this, 'neve_or_hestia_upgrade_link' ), 11, 2 );
|
||||
add_filter( 'tsdk_utmify_url_hestia-pro', array( $this, 'neve_or_hestia_upgrade_link' ), 11, 2 );
|
||||
}
|
||||
|
||||
public function schedule_weekly_cron_job() {
|
||||
if ( ! wp_next_scheduled( 'run_weekly_partner_astra' ) ) {
|
||||
wp_schedule_event( time(), 'weekly', 'run_weekly_partner_astra' );
|
||||
}
|
||||
add_action( 'run_weekly_partner_astra', array( $this, 'run_weekly_partner_astra' ) );
|
||||
}
|
||||
|
||||
public function run_weekly_partner_astra() {
|
||||
if ( ! get_option( 'astra_partner_url_param' ) ) {
|
||||
$this->partner_astra();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\EasyOnboarding\Settings;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Redirects
|
||||
{
|
||||
private string $platform;
|
||||
public const PLATFORM_HPANEL = 'hpanel';
|
||||
public const BUILDER_TYPE = 'prebuilt';
|
||||
public const HOMEPAGE_DISPLAY = 'page';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if ( ! Settings::get_setting('first_login_at')) {
|
||||
Settings::update_setting('first_login_at', gmdate('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
if (isset($_GET['platform'])) {
|
||||
$this->platform = sanitize_text_field($_GET['platform']);
|
||||
|
||||
if ($this->platform === self::PLATFORM_HPANEL) {
|
||||
$this->loginRedirect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function loginRedirect(): void
|
||||
{
|
||||
$isPrebuildWebsite = get_option('hostinger_builder_type', '') === self::BUILDER_TYPE;
|
||||
$isWoocommercePage = in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')));
|
||||
$homepageId = get_option('show_on_front') === self::HOMEPAGE_DISPLAY ? get_option('page_on_front') : null;
|
||||
$isGutenbergPage = $homepageId ? has_blocks(get_post($homepageId)->post_content) : false;
|
||||
|
||||
add_action('init', function () use ($isPrebuildWebsite, $isWoocommercePage, $homepageId, $isGutenbergPage) {
|
||||
if ($isPrebuildWebsite && ! $isWoocommercePage && $homepageId && $isGutenbergPage) {
|
||||
// Redirect to the Gutenberg editor for the homepage
|
||||
$redirectUrl = get_edit_post_link($homepageId, '');
|
||||
} else {
|
||||
$redirectUrl = admin_url('admin.php?page=hostinger');
|
||||
}
|
||||
|
||||
wp_safe_redirect($redirectUrl);
|
||||
exit;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Admin;
|
||||
|
||||
use Hostinger\Surveys\SurveyManager;
|
||||
use Hostinger\WpHelper\Utils as Helper;
|
||||
|
||||
class Surveys {
|
||||
public const TIME_15_MINUTES = 900;
|
||||
public const DAY_IN_SECONDS = 86400;
|
||||
public const WOO_SURVEY_ID = 'woo_survey';
|
||||
public const PREBUILD_WEBSITE_SURVEY_ID = 'prebuild_website';
|
||||
public const AI_ONBOARDING_SURVEY_ID = 'ai_onboarding';
|
||||
public const PREBUILD_WEBSITE_SURVEY_LOCATION = 'wordpress_prebuild_website';
|
||||
public const WOO_SURVEY_LOCATION = 'wordpress_woocommerce_onboarding';
|
||||
public const AI_ONBOARDING_SURVEY_LOCATION = 'wordpress_ai_onboarding';
|
||||
public const WOO_SURVEY_PRIORITY = 100;
|
||||
public const PREBUILD_WEBSITE_SURVEY_PRIORITY = 90;
|
||||
public const AI_ONBOARDING_SURVEY_PRIORITY = 80;
|
||||
public const SUBMITTED_SURVEY_TRANSIENT = 'submitted_survey_transient';
|
||||
private SurveyManager $surveyManager;
|
||||
|
||||
public function __construct( SurveyManager $surveyManager ) {
|
||||
$this->surveyManager = $surveyManager;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_filter( 'hostinger_add_surveys', [ $this, 'createSurveys' ] );
|
||||
}
|
||||
|
||||
public function createSurveys( $surveys ) {
|
||||
if ( $this->isWoocommerceSurveyEnabled() ) {
|
||||
$scoreQuestion = esc_html__( 'How would you rate your experience setting up a WooCommerce site on our hosting?', 'hostinger-easy-onboarding' );
|
||||
$commentQuestion = esc_html__( 'Do you have any comments/suggestions to improve our WooCommerce onboarding?', 'hostinger-easy-onboarding' );
|
||||
$wooSurvey = SurveyManager::addSurvey( self::WOO_SURVEY_ID, $scoreQuestion, $commentQuestion, self::WOO_SURVEY_LOCATION, self::WOO_SURVEY_PRIORITY );
|
||||
$surveys[] = $wooSurvey;
|
||||
}
|
||||
|
||||
if ( $this->isPrebuildWebsiteSurveyEnabled() ) {
|
||||
$scoreQuestion = esc_html__( 'How would you rate your experience building a website based on a pre-built template? (Score 1-10)', 'hostinger-easy-onboarding' );
|
||||
$commentQuestion = esc_html__( 'How could we make it easier to create a new WordPress website?', 'hostinger-easy-onboarding' );
|
||||
$prebuildWebsiteSurvey = SurveyManager::addSurvey( self::PREBUILD_WEBSITE_SURVEY_ID, $scoreQuestion, $commentQuestion, self::PREBUILD_WEBSITE_SURVEY_LOCATION, self::PREBUILD_WEBSITE_SURVEY_PRIORITY );
|
||||
$surveys[] = $prebuildWebsiteSurvey;
|
||||
}
|
||||
|
||||
if ( $this->isAiOnboardingSurveyEnabled() ) {
|
||||
$scoreQuestion = esc_html__( 'How would you rate your experience using our AI content generation tools in onboarding? (Scale 1-10)', 'hostinger-easy-onboarding' );
|
||||
$commentQuestion = esc_html__( 'Do you have any comments/suggestions to improve our AI tools?', 'hostinger-easy-onboarding' );
|
||||
$prebuildWebsiteSurvey = SurveyManager::addSurvey( self::AI_ONBOARDING_SURVEY_ID, $scoreQuestion, $commentQuestion, self::AI_ONBOARDING_SURVEY_LOCATION, self::AI_ONBOARDING_SURVEY_PRIORITY );
|
||||
$surveys[] = $prebuildWebsiteSurvey;
|
||||
}
|
||||
|
||||
return $surveys;
|
||||
}
|
||||
|
||||
public function isWoocommerceSurveyEnabled(): bool {
|
||||
|
||||
if ( defined( 'DOING_AJAX' ) && \DOING_AJAX ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$notSubmitted = ! get_transient( self::SUBMITTED_SURVEY_TRANSIENT );
|
||||
$notCompleted = $this->surveyManager->isSurveyNotCompleted( self::WOO_SURVEY_ID );
|
||||
$isWoocommercePage = $this->surveyManager->isWoocommerceAdminPage();
|
||||
$defaultWoocommerceCompleted = $this->surveyManager->defaultWoocommerceSurveyCompleted();
|
||||
$oldestProductDate = $this->surveyManager->getOldestProductDate();
|
||||
$sevenDaysAgo = strtotime( '-7 days' );
|
||||
$isClientEligible = $this->surveyManager->isClientEligible();
|
||||
|
||||
if ( $oldestProductDate < $sevenDaysAgo || ! $this->isWithinCreationDateLimit() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $notSubmitted && $notCompleted && $isWoocommercePage && $defaultWoocommerceCompleted && $isClientEligible;
|
||||
}
|
||||
|
||||
public function isPrebuildWebsiteSurveyEnabled(): bool {
|
||||
|
||||
if ( defined( 'DOING_AJAX' ) && \DOING_AJAX ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$helper = new Helper();
|
||||
$notSubmitted = ! get_transient( self::SUBMITTED_SURVEY_TRANSIENT );
|
||||
$notCompleted = $this->surveyManager->isSurveyNotCompleted( self::PREBUILD_WEBSITE_SURVEY_ID );
|
||||
$isHostingerAdminPage = $helper->isThisPage( 'hostinger-get-onboarding' );
|
||||
$isClientEligible = $this->surveyManager->isClientEligible();
|
||||
$astra_templates_active = $helper->isPluginActive( 'astra-sites' );
|
||||
|
||||
if ( ! $isHostingerAdminPage || ! $this->isWithinCreationDateLimit() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $notSubmitted && $notCompleted && $isClientEligible && $astra_templates_active;
|
||||
}
|
||||
|
||||
public function isAiOnboardingSurveyEnabled(): bool {
|
||||
if ( defined( 'DOING_AJAX' ) && \DOING_AJAX ) {
|
||||
return false;
|
||||
}
|
||||
$helper = new Helper();
|
||||
$firstLoginAt = strtotime( get_option( 'hostinger_first_login_at', time() ) );
|
||||
$notSubmitted = ! get_transient( self::SUBMITTED_SURVEY_TRANSIENT );
|
||||
$notCompleted = $this->surveyManager->isSurveyNotCompleted( self::AI_ONBOARDING_SURVEY_ID );
|
||||
$isClientEligible = $this->surveyManager->isClientEligible();
|
||||
$isAiOnboardingPassed = get_option( 'hostinger_ai_onboarding', '' );
|
||||
$isHostingerAdminPage = $helper->isThisPage( 'hostinger-get-onboarding' );
|
||||
|
||||
if ( ! $isAiOnboardingPassed || ! $this->isWithinCreationDateLimit() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $_SERVER['H_STAGING'] ) && $_SERVER['H_STAGING'] ) {
|
||||
return $notSubmitted && $notCompleted && $isClientEligible && $isHostingerAdminPage;
|
||||
}
|
||||
|
||||
if ($firstLoginAt && !$this->isTimeElapsed($firstLoginAt, self::TIME_15_MINUTES)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $notSubmitted && $notCompleted && $isClientEligible && $isHostingerAdminPage;
|
||||
}
|
||||
|
||||
|
||||
public function isTimeElapsed( string $firstLoginAt, int $timeInSeconds ): bool {
|
||||
$currentTime = time();
|
||||
$timeElapsed = $currentTime - $timeInSeconds;
|
||||
|
||||
return $timeElapsed >= $firstLoginAt;
|
||||
}
|
||||
|
||||
private function isWithinCreationDateLimit() : bool {
|
||||
$oldestUser = get_users( array(
|
||||
'number' => 1,
|
||||
'orderby' => 'registered',
|
||||
'order' => 'ASC',
|
||||
'fields' => array( 'user_registered' ),
|
||||
) );
|
||||
|
||||
$oldestUserDate = isset( $oldestUser[0]->user_registered ) ? strtotime( $oldestUser[0]->user_registered ): false;
|
||||
|
||||
return $oldestUserDate && ( time() - $oldestUserDate ) <= ( 7 * self::DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Hostinger\WpMenuManager\Menus;
|
||||
|
||||
echo Menus::renderMenuNavigation();
|
||||
?>
|
||||
<div id="hostinger-easy-onboarding-vue-app"/>
|
||||
<?php
|
||||
@@ -0,0 +1,39 @@
|
||||
<div class="hostinger hsr-banner-container">
|
||||
<div class="hsr-promotional-banner">
|
||||
<div class="hsr-promotional-banner-content">
|
||||
<div>
|
||||
<div class="hsr-onboarding__title"><?php echo esc_html__( 'Invite a Friend, Earn Up to $100', 'hostinger-easy-onboarding' ); ?></div>
|
||||
<p class="hsr-promotional-banner-description">
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__(
|
||||
'Share your referral link with friends and family and <b>receive 20% commission</b> for every successful referral.',
|
||||
'hostinger-easy-onboarding'
|
||||
),
|
||||
array(
|
||||
'b' => array(), // Allowing only <b> tags
|
||||
)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="hsr-buttons">
|
||||
<a class="hsr-btn hsr-purple-btn"
|
||||
href="<?php echo esc_url( $helper->get_promotional_link_url( get_locale() ) ); ?>"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"><?php echo esc_html__( 'Start earning', 'hostinger-easy-onboarding' ); ?></a>
|
||||
<svg class="close-btn"
|
||||
width="25"
|
||||
height="24"
|
||||
viewBox="0 0 25 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M19.5 6.41L18.09 5L12.5 10.59L6.91 5L5.5 6.41L11.09 12L5.5 17.59L6.91 19L12.5 13.41L18.09 19L19.5 17.59L13.91 12L19.5 6.41Z"
|
||||
fill="#2F1C6A"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,52 @@
|
||||
<div class="hostinger hsr-plugin-rating">
|
||||
<p><?php echo esc_html__( 'Rate this plugin', 'hostinger-easy-onboarding' ); ?></p>
|
||||
<div class="hsr-rate-stars">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M12 17.27L18.18 21L16.54 13.97L22 9.24L14.81 8.63L12 2L9.19 8.63L2 9.24L7.46 13.97L5.82 21L12 17.27Z"
|
||||
fill="#673DE6"/>
|
||||
</svg>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M12 17.27L18.18 21L16.54 13.97L22 9.24L14.81 8.63L12 2L9.19 8.63L2 9.24L7.46 13.97L5.82 21L12 17.27Z"
|
||||
fill="#673DE6"/>
|
||||
</svg>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M12 17.27L18.18 21L16.54 13.97L22 9.24L14.81 8.63L12 2L9.19 8.63L2 9.24L7.46 13.97L5.82 21L12 17.27Z"
|
||||
fill="#673DE6"/>
|
||||
</svg>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M12 17.27L18.18 21L16.54 13.97L22 9.24L14.81 8.63L12 2L9.19 8.63L2 9.24L7.46 13.97L5.82 21L12 17.27Z"
|
||||
fill="#673DE6"/>
|
||||
</svg>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M12 17.27L18.18 21L16.54 13.97L22 9.24L14.81 8.63L12 2L9.19 8.63L2 9.24L7.46 13.97L5.82 21L12 17.27Z"
|
||||
fill="#673DE6"/>
|
||||
</svg>
|
||||
</div>
|
||||
<p class="hsr-promotional-banner-description">
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__(
|
||||
'on <a href="https://wordpress.org/support/plugin/hostinger/reviews/#new-post" target="_blank" rel="noopener noreferrer">WordPress.org</a>',
|
||||
'hostinger-easy-onboarding'
|
||||
),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
),
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\AmplitudeEvents;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Actions {
|
||||
public const ONBOARDING_ITEM_COMPLETED = 'wordpress.easy_onboarding.item_completed';
|
||||
|
||||
public const WOO_ITEM_COMPLETED = 'wordpress.woocommerce.item_completed';
|
||||
|
||||
public const WOO_READY_TO_SELL = 'wordpress.woocommerce.store.ready_to_sell';
|
||||
|
||||
public const WOO_SETUP_COMPLETED = 'wordpress.woocommerce.store_setup.completed';
|
||||
public const WP_EDIT = 'wordpress.edit_saved';
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\AmplitudeEvents;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use Hostinger\Amplitude\AmplitudeManager;
|
||||
use Hostinger\EasyOnboarding\AmplitudeEvents\Actions as AmplitudeActions;
|
||||
use Hostinger\WpHelper\Utils as Helper;
|
||||
use Hostinger\WpHelper\Requests\Client;
|
||||
use Hostinger\WpHelper\Config;
|
||||
use Hostinger\WpHelper\Constants;
|
||||
|
||||
class Amplitude
|
||||
{
|
||||
public const WEBSITE_BUILDER_TYPE = 'ai';
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
private Helper $helper;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private Client $client;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private Config $configHandler;
|
||||
|
||||
private array $options = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->helper = new Helper();
|
||||
$this->configHandler = new Config();
|
||||
$this->client = new Client(
|
||||
$this->configHandler->getConfigValue('base_rest_uri', Constants::HOSTINGER_REST_URI), [
|
||||
Config::TOKEN_HEADER => Helper::getApiToken(),
|
||||
Config::DOMAIN_HEADER => $this->helper->getHostInfo(),
|
||||
]
|
||||
);
|
||||
$this->options['builder_type'] = get_option('hostinger_builder_type', '');
|
||||
$this->options['website_id'] = get_option('hostinger_website_id', '');
|
||||
$this->options['subscription_id'] = get_option('hostinger_subscription_id', '');
|
||||
$this->options['event_data'] = get_option('hostinger_amplitude_event_data', []);
|
||||
$this->options['edit_count'] = get_option('hostinger_amplitude_edit_count', 0);
|
||||
$this->options['ai_version'] = get_option('hostinger_ai_version', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function send_event(array $params): array
|
||||
{
|
||||
$amplitudeManager = new AmplitudeManager($this->helper, $this->configHandler, $this->client);
|
||||
|
||||
return $amplitudeManager->sendRequest($amplitudeManager::AMPLITUDE_ENDPOINT, $params);
|
||||
}
|
||||
|
||||
public function sendEditAmplitudeEvent(): void
|
||||
{
|
||||
$edit_count = $this->incrementAmplitudeEditEventCount();
|
||||
|
||||
$params = [
|
||||
'action' => AmplitudeActions::WP_EDIT,
|
||||
'wp_builder_type' => $this->options['builder_type'],
|
||||
'website_id' => $this->options['website_id'],
|
||||
'subscription_id' => $this->options['subscription_id'],
|
||||
'edit_count' => $edit_count,
|
||||
];
|
||||
|
||||
$this->send_event($params);
|
||||
}
|
||||
|
||||
public function canSendEditAmplitudeEvent(): bool
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$event_data = $this->options['event_data'];
|
||||
$isAiWebsiteNotGenerated = !$this->options['ai_version'];
|
||||
|
||||
if (!$this->options['builder_type'] || !$this->options['website_id'] || !$this->options['subscription_id']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->options['builder_type'] == self::WEBSITE_BUILDER_TYPE && $isAiWebsiteNotGenerated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($event_data)) {
|
||||
$event_data = [];
|
||||
}
|
||||
|
||||
// Check if we already have data for today
|
||||
$today_event = $event_data[$today] ?? ['count' => 0, 'last_reset' => 0];
|
||||
|
||||
// Only update if the event count is less than 3
|
||||
if ($today_event['count'] < 3) {
|
||||
$today_event['count'] += 1;
|
||||
$event_data[$today] = $today_event;
|
||||
|
||||
update_option('hostinger_amplitude_event_data', $event_data);
|
||||
wp_cache_delete('hostinger_amplitude_event_data', 'options');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function incrementAmplitudeEditEventCount(): int
|
||||
{
|
||||
$edit_count = (int) $this->options['edit_count'] + 1;
|
||||
|
||||
update_option('hostinger_amplitude_edit_count', $edit_count);
|
||||
wp_cache_delete('hostinger_amplitude_event_data', 'options');
|
||||
|
||||
return $edit_count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Surveys;
|
||||
use Hostinger\EasyOnboarding\Rest\Routes;
|
||||
use Hostinger\EasyOnboarding\Rest\StepRoutes;
|
||||
use Hostinger\EasyOnboarding\Rest\TutorialRoutes;
|
||||
use Hostinger\EasyOnboarding\Rest\WelcomeRoutes;
|
||||
use Hostinger\EasyOnboarding\Rest\WooRoutes;
|
||||
use Hostinger\EasyOnboarding\Admin\Assets as AdminAssets;
|
||||
use Hostinger\EasyOnboarding\Admin\Hooks as AdminHooks;
|
||||
use Hostinger\EasyOnboarding\Admin\Menu as AdminMenu;
|
||||
use Hostinger\EasyOnboarding\Admin\Ajax as AdminAjax;
|
||||
use Hostinger\EasyOnboarding\Admin\Partnership;
|
||||
use Hostinger\EasyOnboarding\Admin\Redirects as AdminRedirects;
|
||||
use Hostinger\EasyOnboarding\Preview\Assets as PreviewAssets;
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\AutocompleteSteps;
|
||||
use Hostinger\Surveys\SurveyManager;
|
||||
use Hostinger\Surveys\Rest as SurveysRest;
|
||||
use Hostinger\WpHelper\Config;
|
||||
use Hostinger\WpHelper\Constants;
|
||||
use Hostinger\WpHelper\Utils as Helper;
|
||||
use Hostinger\WpHelper\Requests\Client;
|
||||
use Hostinger\EasyOnboarding\Cli;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Bootstrap {
|
||||
protected Loader $loader;
|
||||
|
||||
public function __construct() {
|
||||
$this->loader = new Loader();
|
||||
}
|
||||
|
||||
public function run(): void {
|
||||
$this->load_dependencies();
|
||||
$this->set_locale();
|
||||
$this->loader->run();
|
||||
}
|
||||
|
||||
private function load_dependencies(): void {
|
||||
$this->load_onboarding_dependencies();
|
||||
$this->load_public_dependencies();
|
||||
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->load_admin_dependencies();
|
||||
}
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
new Cli();
|
||||
}
|
||||
}
|
||||
|
||||
private function set_locale() {
|
||||
$plugin_i18n = new I18n();
|
||||
$this->loader->add_action( 'init', $plugin_i18n, 'load_plugin_textdomain' );
|
||||
}
|
||||
|
||||
private function surveys(): void
|
||||
{
|
||||
$helper = new Helper();
|
||||
$config = new Config();
|
||||
$client = new Client(
|
||||
$config->getConfigValue( 'base_rest_uri', Constants::HOSTINGER_REST_URI ),
|
||||
[
|
||||
Config::TOKEN_HEADER => $helper->getApiToken(),
|
||||
Config::DOMAIN_HEADER => $helper->getHostInfo(),
|
||||
]
|
||||
);
|
||||
|
||||
if ( class_exists( SurveyManager::class ) ) {
|
||||
$surveysRest = new SurveysRest( $client );
|
||||
$surveyManager = new SurveyManager( $helper, $config, $surveysRest );
|
||||
$surveys = new Surveys( $surveyManager );
|
||||
$surveys->init();
|
||||
}
|
||||
}
|
||||
|
||||
private function load_admin_dependencies(): void
|
||||
{
|
||||
$this->surveys();
|
||||
new AdminAssets();
|
||||
new AdminHooks();
|
||||
new AdminMenu();
|
||||
new AdminRedirects();
|
||||
new AdminAjax();
|
||||
new Partnership();
|
||||
}
|
||||
|
||||
private function load_public_dependencies(): void {
|
||||
new PreviewAssets();
|
||||
new Hooks();
|
||||
new Updates();
|
||||
|
||||
$welcome_routes = new WelcomeRoutes();
|
||||
$step_routes = new StepRoutes();
|
||||
$woo_routes = new WooRoutes();
|
||||
$tutorial_routes = new TutorialRoutes();
|
||||
|
||||
$routes = new Routes( $welcome_routes, $step_routes, $woo_routes, $tutorial_routes );
|
||||
$routes->init();
|
||||
}
|
||||
|
||||
private function load_onboarding_dependencies(): void {
|
||||
new AutocompleteSteps();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use WP_CLI;
|
||||
use Hostinger\EasyOnboarding\Cli\Commands\OnboardingStatus;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cli {
|
||||
/**
|
||||
* Load required files and hooks to make the CLI work.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up and hooks WP CLI to our CLI code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function hooks(): void {
|
||||
if ( class_exists( '\WP_CLI' ) && class_exists( OnboardingStatus::class ) ) {
|
||||
WP_CLI::add_hook( 'after_wp_load', array(
|
||||
OnboardingStatus::class,
|
||||
'define_command'
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Cli\Commands;
|
||||
|
||||
/**
|
||||
* Interface OnboardingStatusInterface
|
||||
*
|
||||
* This interface defines the methods for checking the status of Hostinger Easy Onboarding.
|
||||
*/
|
||||
interface CLICommand {
|
||||
/**
|
||||
* Defines the WP-CLI command for Hostinger onboarding status.
|
||||
*
|
||||
* Adds the 'hostinger onboarding' command to WP-CLI with a short and long description.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function define_command(): void;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php /** @noinspection PhpIllegalPsrClassPathInspection */
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Cli\Commands;
|
||||
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
use WP_CLI;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class OnboardingStatus
|
||||
*
|
||||
* This class defines the WP-CLI command for checking the status of Hostinger Easy Onboarding.
|
||||
*/
|
||||
class OnboardingStatus implements CLICommand {
|
||||
/**
|
||||
* Defines the WP-CLI command for Hostinger onboarding status.
|
||||
*
|
||||
* Adds the 'hostinger onboarding' command to WP-CLI with a short and long description.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function define_command(): void {
|
||||
if ( class_exists( '\WP_CLI' ) ) {
|
||||
WP_CLI::add_command(
|
||||
'hostinger onboarding',
|
||||
self::class,
|
||||
[
|
||||
'shortdesc' => 'Check the status of Hostinger Easy Onboarding',
|
||||
'longdesc' => 'This command allows you to check the status of Hostinger Easy Onboarding Progress for the WooCommerce store.' . "\n\n" .
|
||||
'## EXAMPLES' . "\n\n" .
|
||||
' wp hostinger onboarding woocommerce_status' . "\n" .
|
||||
' Returns whether Hostinger Easy Onboarding for WooCommerce Store setup is completed or is ready to sell in JSON.',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function woocommerce_status(): void
|
||||
{
|
||||
$helper = new Helper();
|
||||
|
||||
$onboarding = [
|
||||
'woocommerce_onboarding_ready_to_sell' => $helper->is_woocommerce_store_ready(),
|
||||
'woocommerce_onboarding_status' => $helper->is_woocommerce_onboarding_completed(),
|
||||
];
|
||||
|
||||
WP_CLI::line(wp_json_encode($onboarding));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Config {
|
||||
private array $config = array();
|
||||
public const TOKEN_HEADER = 'X-Hpanel-Order-Token';
|
||||
public const DOMAIN_HEADER = 'X-Hpanel-Domain';
|
||||
public function __construct() {
|
||||
$this->decode_config( HOSTINGER_EASY_ONBOARDING_WP_CONFIG_PATH );
|
||||
}
|
||||
|
||||
private function decode_config( string $path ): void {
|
||||
if ( file_exists( $path ) ) {
|
||||
$config_content = file_get_contents( $path );
|
||||
$this->config = json_decode( $config_content, true );
|
||||
}
|
||||
}
|
||||
|
||||
public function get_config_value( string $key, $default ): string {
|
||||
if ( $this->config && isset( $this->config[ $key ] ) && ! empty( $this->config[ $key ] ) ) {
|
||||
return $this->config[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Deactivator {
|
||||
public static function deactivate(): void {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class DefaultOptions {
|
||||
public function add_options(): void {
|
||||
foreach ( $this->options() as $key => $option ) {
|
||||
update_option( $key, $option );
|
||||
}
|
||||
}
|
||||
|
||||
private function options(): array {
|
||||
$options = array(
|
||||
'optin_monster_api_activation_redirect_disabled' => 'true',
|
||||
'wpforms_activation_redirect' => 'true',
|
||||
'aioseo_activation_redirect' => 'false',
|
||||
);
|
||||
|
||||
if ( Helper::is_plugin_active( 'astra-sites' ) ) {
|
||||
$options = array_merge( $options, $this->get_astra_options() );
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
private function get_astra_options(): array {
|
||||
return array(
|
||||
'astra_sites_settings' => 'gutenberg'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Bootstrap;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class EasyOnboarding {
|
||||
protected string $plugin_name = 'Hostinger Easy Onboarding';
|
||||
protected string $version;
|
||||
|
||||
public function bootstrap(): void {
|
||||
$this->version = $this->get_plugin_version();
|
||||
$bootstrap = new Bootstrap();
|
||||
$bootstrap->run();
|
||||
}
|
||||
|
||||
public function run(): void {
|
||||
$this->bootstrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define constant
|
||||
*
|
||||
* @param string $name Constant name.
|
||||
* @param string|bool $value Constant value.
|
||||
*/
|
||||
private function define( string $name, $value ): void {
|
||||
if ( ! defined( $name ) ) {
|
||||
define( $name, $value );
|
||||
}
|
||||
}
|
||||
|
||||
private function get_plugin_version(): string {
|
||||
if ( defined( 'HOSTINGER_EASY_ONBOARDING_VERSION' ) ) {
|
||||
return HOSTINGER_EASY_ONBOARDING_VERSION;
|
||||
}
|
||||
|
||||
return '1.0.0';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Errors {
|
||||
|
||||
private $error_messages;
|
||||
|
||||
public function __construct() {
|
||||
$this->error_messages = array(
|
||||
'action_failed' => array(
|
||||
'default' => __( 'Action Failed. Try again or contact support. Apologies.', 'hostinger-easy-onboarding' ),
|
||||
),
|
||||
'unexpected_error' => array(
|
||||
'default' => __( 'An unexpected error occurred. Please try again or contact support.', 'hostinger-easy-onboarding' ),
|
||||
),
|
||||
'server_error' => array(
|
||||
'default' => __( 'We apologize for the inconvenience. The AI content generation process encountered a server error. Please try again later, and if the issue persists, kindly contact our support team for assistance.', 'hostinger-easy-onboarding' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_error_message( string $error_code ) {
|
||||
if ( array_key_exists( $error_code, $this->error_messages ) ) {
|
||||
$message_data = $this->error_messages[ $error_code ];
|
||||
|
||||
return $message_data['default'];
|
||||
} else {
|
||||
return __( 'Unknown error code.', 'hostinger-easy-onboarding' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new Errors();
|
||||
@@ -0,0 +1,453 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\WpHelper\Utils;
|
||||
use Hostinger\WpMenuManager\Menus;
|
||||
use Hostinger\EasyOnboarding\Admin\Actions;
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Helper
|
||||
{
|
||||
public const HOSTINGER_FREE_SUBDOMAIN_URL = 'hostingersite.com';
|
||||
public const HOSTINGER_DEV_FREE_SUBDOMAIN_URL = 'hostingersite.dev';
|
||||
public const HOSTINGER_PAGE = '/wp-admin/admin.php?page=hostinger';
|
||||
public const CLIENT_WOO_COMPLETED_ACTIONS = 'woocommerce_task_list_tracked_completed_tasks';
|
||||
private const PROMOTIONAL_LINKS = array(
|
||||
'fr_FR' => 'https://www.hostinger.fr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'es_ES' => 'https://www.hostinger.es/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'ar' => 'https://www.hostinger.ae/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'zh_CN' => 'https://www.hostinger.com.hk/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'id_ID' => 'https://www.hostinger.co.id/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'lt_LT' => 'https://www.hostinger.lt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'pt_PT' => 'https://www.hostinger.pt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'uk' => 'https://www.hostinger.com.ua/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'tr_TR' => 'https://www.hostinger.com.tr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
'en_US' => 'https://www.hostinger.com/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
|
||||
);
|
||||
const HOSTINGER_LOCALES = [
|
||||
'lt_LT' => 'hostinger.lt',
|
||||
'uk_UA' => 'hostinger.com.ua',
|
||||
'id_ID' => 'hostinger.co.id',
|
||||
'en_US' => 'hostinger.com',
|
||||
'es_ES' => 'hostinger.es',
|
||||
'es_AR' => 'hostinger.com.ar',
|
||||
'es_MX' => 'hostinger.mx',
|
||||
'es_CO' => 'hostinger.co',
|
||||
'pt_BR' => 'hostinger.com.br',
|
||||
'ro_RO' => 'hostinger.ro',
|
||||
'fr_FR' => 'hostinger.fr',
|
||||
'it_IT' => 'hostinger.it',
|
||||
'pl_PL' => 'hostinger.pl',
|
||||
'en_PH' => 'hostinger.ph',
|
||||
'ar_AE' => 'hostinger.ae',
|
||||
'ms_MY' => 'hostinger.my',
|
||||
'ko_KR' => 'hostinger.kr',
|
||||
'vi_VN' => 'hostinger.vn',
|
||||
'th_TH' => 'hostinger.in.th',
|
||||
'tr_TR' => 'hostinger.web.tr',
|
||||
'pt_PT' => 'hostinger.pt',
|
||||
'de_DE' => 'hostinger.de',
|
||||
'en_IN' => 'hostinger.in',
|
||||
'ja_JP' => 'hostinger.jp',
|
||||
'nl_NL' => 'hostinger.nl',
|
||||
'en_GB' => 'hostinger.co.uk',
|
||||
'el_GR' => 'hostinger.gr',
|
||||
'cs_CZ' => 'hostinger.cz',
|
||||
'hu_HU' => 'hostinger.hu',
|
||||
'sv_SE' => 'hostinger.se',
|
||||
'da_DK' => 'hostinger.dk',
|
||||
'fi_FI' => 'hostinger.fi',
|
||||
'sk_SK' => 'hostinger.sk',
|
||||
'no_NO' => 'hostinger.no',
|
||||
'hr_HR' => 'hostinger.hr',
|
||||
'zh_HK' => 'hostinger.com.hk',
|
||||
'he_IL' => 'hostinger.co.il',
|
||||
'lv_LV' => 'hostinger.lv',
|
||||
'et_EE' => 'hostinger.ee',
|
||||
'ur_PK' => 'hostinger.pk',
|
||||
];
|
||||
|
||||
private const HPANEL_DOMAIN_URL = 'https://hpanel.hostinger.com/websites/';
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if plugin is active
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public static function is_plugin_active($plugin_slug): bool
|
||||
{
|
||||
$active_plugins = (array) get_option('active_plugins', array());
|
||||
foreach ($active_plugins as $active_plugin) {
|
||||
if (strpos($active_plugin, $plugin_slug . '.php') !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_api_token(): string
|
||||
{
|
||||
$api_token = '';
|
||||
$token_file = HOSTINGER_EASY_ONBOARDING_WP_TOKEN;
|
||||
|
||||
if (file_exists($token_file) && ! empty(file_get_contents($token_file))) {
|
||||
$api_token = file_get_contents($token_file);
|
||||
}
|
||||
|
||||
return $api_token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the host info (domain, subdomain, subdirectory)
|
||||
*
|
||||
* @since 1.7.0
|
||||
* @access public
|
||||
*/
|
||||
public function get_host_info(): string
|
||||
{
|
||||
$host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field($_SERVER['HTTP_HOST']) : '';
|
||||
$site_url = get_site_url();
|
||||
$site_url = preg_replace('#^https?://#', '', $site_url);
|
||||
|
||||
if (! empty($site_url) && ! empty($host) && strpos($site_url, $host) === 0) {
|
||||
if ($site_url === $host) {
|
||||
return $host;
|
||||
} else {
|
||||
return substr($site_url, strlen($host) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $host;
|
||||
}
|
||||
|
||||
public function is_preview_domain(): bool
|
||||
{
|
||||
if (function_exists('getallheaders')) {
|
||||
$headers = getallheaders();
|
||||
}
|
||||
|
||||
if (isset($headers['X-Preview-Indicator']) && $headers['X-Preview-Indicator']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_free_subdomain(): bool
|
||||
{
|
||||
$site_url = preg_replace('#^https?://#', '', get_site_url());
|
||||
|
||||
return ! empty($site_url) && (strpos($site_url, self::HOSTINGER_FREE_SUBDOMAIN_URL) !== false || strpos($site_url, self::HOSTINGER_DEV_FREE_SUBDOMAIN_URL));
|
||||
}
|
||||
|
||||
public function is_hostinger_admin_page(): bool
|
||||
{
|
||||
|
||||
if (! isset($_SERVER['REQUEST_URI'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_uri = sanitize_text_field($_SERVER['REQUEST_URI']);
|
||||
|
||||
if (defined('DOING_AJAX') && \DOING_AJAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($current_uri) && strpos($current_uri, '/wp-json/') !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strpos($current_uri, self::HOSTINGER_PAGE) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Error log
|
||||
*
|
||||
* @since 1.9.6
|
||||
* @access public
|
||||
*/
|
||||
public function error_log(string $message): void
|
||||
{
|
||||
if (defined('WP_DEBUG') && \WP_DEBUG === true) {
|
||||
error_log(print_r($message, true));
|
||||
}
|
||||
}
|
||||
|
||||
public function default_woocommerce_survey_steps_completed(array $steps): bool
|
||||
{
|
||||
$completed_actions = get_option(self::CLIENT_WOO_COMPLETED_ACTIONS, array());
|
||||
|
||||
return empty(array_diff($steps, $completed_actions));
|
||||
}
|
||||
|
||||
public function is_this_page(string $page): bool
|
||||
{
|
||||
|
||||
if (! isset($_SERVER['REQUEST_URI'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_uri = sanitize_text_field($_SERVER['REQUEST_URI']);
|
||||
|
||||
if (defined('DOING_AJAX') && \DOING_AJAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($current_uri) && strpos($current_uri, '/wp-json/') !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strpos($current_uri, $page) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_promotional_link_url(string $locale): string
|
||||
{
|
||||
if (isset(self::PROMOTIONAL_LINKS[$locale])) {
|
||||
return self::PROMOTIONAL_LINKS[$locale];
|
||||
}
|
||||
|
||||
return self::PROMOTIONAL_LINKS['en_US'];
|
||||
}
|
||||
|
||||
public function get_hpanel_domain_url(): string
|
||||
{
|
||||
$parsed_url = parse_url(get_site_url());
|
||||
$host = $parsed_url['host'];
|
||||
$host_parts = explode('.', $host);
|
||||
$subdomain = (count($host_parts) > 2) ? array_shift($host_parts) . '.' : '';
|
||||
$domain = implode('.', $host_parts);
|
||||
|
||||
return self::HPANEL_DOMAIN_URL . $domain . ($subdomain ? "/wordpress/dashboard/$subdomain$domain" : '');
|
||||
}
|
||||
|
||||
public function check_transient_eligibility($transient_request_key, $cache_time = 3600): bool
|
||||
{
|
||||
try {
|
||||
// Set transient
|
||||
set_transient($transient_request_key, true, $cache_time);
|
||||
|
||||
// Check if transient was set successfully
|
||||
if (false === get_transient($transient_request_key)) {
|
||||
throw new \Exception('Unable to create transient in WordPress.');
|
||||
}
|
||||
|
||||
// If everything is fine, return true
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
// If there's an exception, log the error and return false
|
||||
$this->error_log('Error checking eligibility: ' . $exception->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function woocommerce_onboarding_choice(): bool
|
||||
{
|
||||
return (bool) get_option('hostinger_woo_onboarding_choice', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_woocommerce_site(): bool
|
||||
{
|
||||
return class_exists('WooCommerce');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function show_woocommerce_onboarding(): bool
|
||||
{
|
||||
$woo_onboarding_enabled = get_option('hostinger_woo_onboarding_enabled', false);
|
||||
$woo_setup_wizard_completed = get_option('woocommerce_onboarding_profile', false);
|
||||
|
||||
return (self::is_woocommerce_site() && ! self::woocommerce_onboarding_choice() && $woo_onboarding_enabled && ! $woo_setup_wizard_completed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function can_show_store_ready_message(): bool
|
||||
{
|
||||
if (! self::is_woocommerce_site() || ! self::woocommerce_onboarding_choice()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$store_ready_message_shown = get_option('hostinger_woo_ready_message_shown', null);
|
||||
|
||||
if ($store_ready_message_shown === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((int) $store_ready_message_shown !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->default_woocommerce_survey_completed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function default_woocommerce_survey_completed(): bool
|
||||
{
|
||||
$completed_actions = get_option(self::CLIENT_WOO_COMPLETED_ACTIONS, array());
|
||||
$required_completed_actions = array('products', 'payments');
|
||||
|
||||
return empty(array_diff($required_completed_actions, $completed_actions));
|
||||
}
|
||||
|
||||
public function is_hostinger_menu_page(): bool
|
||||
{
|
||||
$pages = [
|
||||
'wp-admin/admin.php?page=' . Menus::MENU_SLUG
|
||||
];
|
||||
|
||||
$subpages = Menus::getMenuSubpages();
|
||||
|
||||
foreach ($subpages as $page) {
|
||||
if (isset($page['menu_slug'])) {
|
||||
$pages[] = 'wp-admin/admin.php?page=' . $page['menu_slug'];
|
||||
}
|
||||
}
|
||||
|
||||
$utils = new Utils();
|
||||
|
||||
foreach ($pages as $page) {
|
||||
if ($utils->isThisPage($page)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $plugin_slug
|
||||
*
|
||||
* @return string | \WP_Error
|
||||
*/
|
||||
public function get_plugin_main_file(string $plugin_slug): string|\WP_Error
|
||||
{
|
||||
$plugin_dir = WP_PLUGIN_DIR . '/' . $plugin_slug;
|
||||
if (! is_dir($plugin_dir)) {
|
||||
return new \WP_Error('plugin_not_found', __('Plugin directory not found', 'hostinger-easy-onboarding'));
|
||||
}
|
||||
|
||||
$plugin_files = glob($plugin_dir . '/*.php');
|
||||
if (empty($plugin_files)) {
|
||||
return new \WP_Error('plugin_file_not_found', __('No PHP files found in plugin directory', 'hostinger-easy-onboarding'));
|
||||
}
|
||||
|
||||
foreach ($plugin_files as $plugin_file) {
|
||||
$plugin_data = get_plugin_data($plugin_file, false, false);
|
||||
if (! empty($plugin_data['Name'])) {
|
||||
return $plugin_slug . '/' . basename($plugin_file);
|
||||
}
|
||||
}
|
||||
|
||||
return new \WP_Error('plugin_main_file_not_found', __('Plugin main file not found', 'hostinger-easy-onboarding'));
|
||||
}
|
||||
|
||||
public function is_woocommerce_store_ready(): bool
|
||||
{
|
||||
$store_steps = Actions::get_category_action_lists()[Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID] ?? array();
|
||||
|
||||
$onboarding = new Onboarding();
|
||||
|
||||
if (
|
||||
! $onboarding->is_completed(Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::ADD_PAYMENT) ||
|
||||
! $onboarding->is_completed(Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::ADD_PRODUCT)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function is_woocommerce_onboarding_completed(): bool
|
||||
{
|
||||
$all_woo_steps = Actions::get_category_action_lists()[Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID];
|
||||
$onboarding = new Onboarding();
|
||||
|
||||
foreach ($all_woo_steps as $step) {
|
||||
if (! $onboarding->is_completed(Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, $step)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function should_skip_event(): bool
|
||||
{
|
||||
return (defined('DOING_AUTOSAVE') && \DOING_AUTOSAVE) ||
|
||||
(defined('WP_CLI') && \WP_CLI) ||
|
||||
(defined('DOING_AJAX') && \DOING_AJAX) ||
|
||||
(defined('DOING_CRON') && \DOING_CRON);
|
||||
}
|
||||
|
||||
public function is_woocommerce_payments_ready(): bool
|
||||
{
|
||||
$onboarding = new Onboarding();
|
||||
|
||||
if ( $onboarding->is_completed(Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, Actions::ADD_PAYMENT) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_website_onboarding_completed(): bool {
|
||||
$all_steps = Actions::get_category_action_lists()[ Onboarding::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID ];
|
||||
$onboarding = new Onboarding();
|
||||
|
||||
foreach ($all_steps as $step) {
|
||||
if ( ! $onboarding->is_completed(Onboarding::HOSTINGER_EASY_ONBOARDING_WEBSITE_STEP_CATEGORY_ID, $step)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHostingerPluginUrl() : string {
|
||||
$websiteLocale = get_locale() ?? 'en_US';
|
||||
$resellerLocale = get_option( 'hostinger_reseller', '' );
|
||||
$baseDomain = $resellerLocale ? : ( self::HOSTINGER_LOCALES[$websiteLocale] ?? 'hostinger.com' );
|
||||
|
||||
$pluginUrl = rtrim( $baseDomain, '/' ) . '/';
|
||||
$pluginUrl .= str_replace( ABSPATH, '', HOSTINGER_EASY_ONBOARDING_ABSPATH );
|
||||
|
||||
return $pluginUrl;
|
||||
}
|
||||
|
||||
public function isStoreSetupCompleted(): bool {
|
||||
$onboarding_profile = get_option( 'woocommerce_onboarding_profile', [] );
|
||||
$has_onboarding_country = ! empty( $onboarding_profile['is_store_country_set'] );
|
||||
$has_industry = ! empty( $onboarding_profile['industry'] ) && is_array( $onboarding_profile['industry'] );
|
||||
|
||||
return $has_onboarding_country && $has_industry;
|
||||
}
|
||||
}
|
||||
|
||||
$hostinger_helper = new Helper();
|
||||
$hostinger_helper->is_woocommerce_onboarding_completed();
|
||||
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Actions as Admin_Actions;
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
use Hostinger\EasyOnboarding\AmplitudeEvents\Amplitude;
|
||||
use WP_Admin_Bar;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Hooks
|
||||
{
|
||||
public const HOMEPAGE_DISPLAY = 'page';
|
||||
|
||||
private Onboarding $onboarding;
|
||||
private bool $event_incremented = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->onboarding = new Onboarding();
|
||||
|
||||
add_action('init', [$this, 'check_url_and_flush_rules']);
|
||||
add_action('template_redirect', [$this, 'admin_preview_website']);
|
||||
|
||||
add_filter('hostinger_once_per_day_events', [$this, 'limit_triggered_amplitude_events']);
|
||||
|
||||
add_action('activate_plugin', [$this, 'prevent_flexible_shipping_redirect']);
|
||||
add_action('activated_plugin', [$this, 'maybe_mark_payments_step_completed']);
|
||||
|
||||
//Edit site events
|
||||
add_action('save_post', [$this, 'save_post_content'], 10, 3);
|
||||
add_action('updated_option', [$this, 'save_settings'], 10, 1);
|
||||
add_action('customize_save_after', [$this, 'save_customizer_settings']);
|
||||
add_action('admin_bar_menu', [$this, 'customize_admin_bar_logo'], 100);
|
||||
add_action('admin_bar_menu', [$this, 'custom_admin_bar_edit_home_page_link'], 9999);
|
||||
}
|
||||
|
||||
public function save_post_content(int $post_ID, \WP_Post $post, bool $update): void
|
||||
{
|
||||
$amplitudeEvents = new Amplitude();
|
||||
|
||||
if (Helper::should_skip_event() || $this->event_incremented) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($post->post_status === 'auto-draft') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($amplitudeEvents->canSendEditAmplitudeEvent()) {
|
||||
$amplitudeEvents->sendEditAmplitudeEvent();
|
||||
$this->event_incremented = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function save_settings(string $option_name): void
|
||||
{
|
||||
$amplitudeEvents = new Amplitude();
|
||||
$skip_options = in_array($option_name, [
|
||||
'hostinger_amplitude_event_data',
|
||||
'hostinger_amplitude_edit_count',
|
||||
]);
|
||||
$option_page_not_set = ! isset($_POST['option_page']);
|
||||
|
||||
if (Helper::should_skip_event() || $skip_options || $this->event_incremented || $option_page_not_set) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($amplitudeEvents->canSendEditAmplitudeEvent()) {
|
||||
$amplitudeEvents->sendEditAmplitudeEvent();
|
||||
$this->event_incremented = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function save_customizer_settings(): void
|
||||
{
|
||||
$amplitudeEvents = new Amplitude();
|
||||
|
||||
if (Helper::should_skip_event() || $this->event_incremented) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($amplitudeEvents->canSendEditAmplitudeEvent()) {
|
||||
$amplitudeEvents->sendEditAmplitudeEvent();
|
||||
$this->event_incremented = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function check_url_and_flush_rules()
|
||||
{
|
||||
if (defined('DOING_AJAX') && \DOING_AJAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_url = home_url(add_query_arg(null, null));
|
||||
$url_components = wp_parse_url($current_url);
|
||||
|
||||
if (isset($url_components['query'])) {
|
||||
parse_str($url_components['query'], $params);
|
||||
|
||||
if (isset($params['app_name'])) {
|
||||
$app_name = sanitize_text_field($params['app_name']);
|
||||
|
||||
if ($app_name === 'Omnisend App') {
|
||||
if (function_exists('flush_rewrite_rules')) {
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
if (has_action('litespeed_purge_all')) {
|
||||
do_action('litespeed_purge_all');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_preview_website()
|
||||
{
|
||||
if ( ! current_user_can('manage_options')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$amplitude = new Amplitude();
|
||||
|
||||
$appearance = get_option('hostinger_appearance', 'none');
|
||||
$subscription_id = get_option('hostinger_subscription_id', 0);
|
||||
|
||||
$params = [
|
||||
'action' => 'wordpress.preview_site',
|
||||
'appearance' => $appearance,
|
||||
'subscription_id' => $subscription_id,
|
||||
];
|
||||
|
||||
$amplitude->send_event($params);
|
||||
}
|
||||
|
||||
public function limit_triggered_amplitude_events($events): array
|
||||
{
|
||||
$new_events = [
|
||||
'wordpress.preview_site',
|
||||
'wordpress.easy_onboarding.enter',
|
||||
'wordpress.connect_domain.shown',
|
||||
'wordpress.connect_domain.enter',
|
||||
'wordpress.easy_onboarding.completed',
|
||||
'black_friday.banner.offer_shown',
|
||||
];
|
||||
|
||||
return array_merge($events, $new_events);
|
||||
}
|
||||
|
||||
// Mark payments step completed if Amazon Pay payment gateway plugin is activated because this payment gateway is enabled after activation right away.
|
||||
public function maybe_mark_payments_step_completed(string $plugin): void
|
||||
{
|
||||
if ( ! is_plugin_active('woocommerce/woocommerce.php')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($plugin
|
||||
!== 'woocommerce-gateway-amazon-payments-advanced/woocommerce-gateway-amazon-payments-advanced.php') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->onboarding->init();
|
||||
|
||||
if ($this->onboarding->is_completed(
|
||||
Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID,
|
||||
Admin_Actions::ADD_PAYMENT
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->onboarding->complete_step(
|
||||
Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID,
|
||||
Admin_Actions::ADD_PAYMENT
|
||||
);
|
||||
}
|
||||
|
||||
public function prevent_flexible_shipping_redirect(string $plugin): void
|
||||
{
|
||||
// Disable Flexible shipping activation redirect by setting value to true.
|
||||
if ($plugin == 'flexible-shipping/flexible-shipping.php') {
|
||||
$flexible_shipping_redirect = get_option('flexible-shipping-activation-redirected', false);
|
||||
|
||||
if (empty($flexible_shipping_redirect)) {
|
||||
update_option('flexible-shipping-activation-redirected', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function customize_admin_bar_logo(WP_Admin_Bar $wp_admin_bar): void
|
||||
{
|
||||
$wp_admin_bar->add_node([
|
||||
'id' => 'wp-logo',
|
||||
'href' => admin_url(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function custom_admin_bar_edit_home_page_link(WP_Admin_Bar $wp_admin_bar): void
|
||||
{
|
||||
if (wp_is_block_theme()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$front_page_id = get_option('page_on_front');
|
||||
$show_on_front = get_option('show_on_front');
|
||||
|
||||
if ($show_on_front !== self::HOMEPAGE_DISPLAY || !$front_page_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query_args = [
|
||||
'post' => $front_page_id,
|
||||
'action' => 'edit',
|
||||
];
|
||||
|
||||
$edit_url = add_query_arg($query_args, admin_url('post.php'));
|
||||
|
||||
$wp_admin_bar->add_node([
|
||||
'id' => 'edit_home_page',
|
||||
'title' => __('Edit Home Page', 'hostinger-easy-onboarding'),
|
||||
'href' => $edit_url,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class I18n {
|
||||
/**
|
||||
* Load the plugin text domain for translation.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public function load_plugin_textdomain(): void {
|
||||
load_plugin_textdomain(
|
||||
'hostinger-easy-onboarding',
|
||||
false,
|
||||
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Loader {
|
||||
protected array $actions;
|
||||
protected array $filters;
|
||||
|
||||
public function __construct() {
|
||||
$this->actions = array();
|
||||
$this->filters = array();
|
||||
}
|
||||
|
||||
public function add_action( string $hook, $component, string $callback, int $priority = 10, int $accepted_args = 1 ) {
|
||||
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
public function add_filter( string $hook, $component, string $callback, int $priority = 10, int $accepted_args = 1 ) {
|
||||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
|
||||
private function add(
|
||||
array $hooks,
|
||||
string $hook,
|
||||
$component,
|
||||
string $callback,
|
||||
int $priority,
|
||||
int $accepted_args
|
||||
): array {
|
||||
$hooks[] = array(
|
||||
'hook' => $hook,
|
||||
'component' => $component,
|
||||
'callback' => $callback,
|
||||
'priority' => $priority,
|
||||
'accepted_args' => $accepted_args,
|
||||
);
|
||||
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void {
|
||||
foreach ( $this->filters as $hook ) {
|
||||
add_filter(
|
||||
$hook['hook'],
|
||||
array( $hook['component'], $hook['callback'] ),
|
||||
$hook['priority'],
|
||||
$hook['accepted_args']
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $this->actions as $hook ) {
|
||||
add_action(
|
||||
$hook['hook'],
|
||||
array( $hook['component'], $hook['callback'] ),
|
||||
$hook['priority'],
|
||||
$hook['accepted_args']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Preview;
|
||||
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Assets {
|
||||
public function __construct() {
|
||||
$helper = new Helper();
|
||||
if ( $helper->is_preview_domain() ) {
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_css' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_preview_css(): void {
|
||||
if ( is_user_logged_in() ) {
|
||||
wp_enqueue_style( 'hostinger-onboarding-preview-styles', HOSTINGER_EASY_ONBOARDING_ASSETS_URL . '/css/hts-preview.css', array(), HOSTINGER_EASY_ONBOARDING_VERSION );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\Requests;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Client {
|
||||
private string $api_url;
|
||||
private array $default_headers;
|
||||
|
||||
public function __construct( $api_url, $default_headers = array() ) {
|
||||
$this->api_url = $api_url;
|
||||
$this->default_headers = $default_headers;
|
||||
}
|
||||
|
||||
public function get( $endpoint, $params = array(), $headers = array(), $timeout = 120 ) {
|
||||
$url = $this->api_url . $endpoint;
|
||||
$request_args = array(
|
||||
'method' => 'GET',
|
||||
'headers' => array_merge( $this->default_headers, $headers ),
|
||||
'timeout' => $timeout,
|
||||
);
|
||||
|
||||
if ( ! empty( $params ) ) {
|
||||
$url = add_query_arg( $params, $url );
|
||||
}
|
||||
|
||||
$response = wp_remote_get( $url, $request_args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function post( $endpoint, $params = array(), $headers = array(), $timeout = 120 ) {
|
||||
$url = $this->api_url . $endpoint;
|
||||
$request_args = array(
|
||||
'method' => 'POST',
|
||||
'timeout' => $timeout,
|
||||
'headers' => array_merge( $this->default_headers, $headers ),
|
||||
'body' => $params,
|
||||
);
|
||||
|
||||
$response = wp_remote_post( $url, $request_args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding\Rest;
|
||||
|
||||
/**
|
||||
* Avoid possibility to get file accessed directly
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for handling Rest Api Routes
|
||||
*/
|
||||
class Routes {
|
||||
/**
|
||||
* @var WelcomeRoutes
|
||||
*/
|
||||
private WelcomeRoutes $welcome_routes;
|
||||
|
||||
/**
|
||||
* @var StepRoutes
|
||||
*/
|
||||
private StepRoutes $step_routes;
|
||||
|
||||
/**
|
||||
* @var WooRoutes
|
||||
*/
|
||||
private WooRoutes $woo_routes;
|
||||
|
||||
/**
|
||||
* @var TutorialRoutes
|
||||
*/
|
||||
private TutorialRoutes $tutorial_routes;
|
||||
|
||||
/**
|
||||
* @param WelcomeRoutes $welcome_routes
|
||||
* @param StepRoutes $step_routes
|
||||
* @param WooRoutes $woo_routes
|
||||
* @param TutorialRoutes $tutorial_routes
|
||||
*/
|
||||
public function __construct( WelcomeRoutes $welcome_routes, StepRoutes $step_routes, WooRoutes $woo_routes, TutorialRoutes $tutorial_routes ) {
|
||||
$this->welcome_routes = $welcome_routes;
|
||||
$this->step_routes = $step_routes;
|
||||
$this->woo_routes = $woo_routes;
|
||||
$this->tutorial_routes = $tutorial_routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init rest routes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void {
|
||||
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function register_routes(): void {
|
||||
$this->register_welcome_routes();
|
||||
$this->register_step_routes();
|
||||
$this->register_tutorial_routes();
|
||||
|
||||
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
|
||||
$this->register_woo_routes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request WordPress rest request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function permission_check( $request ): bool {
|
||||
// Workaround if Rest Api endpoint cache is enabled.
|
||||
// We don't want to cache these requests.
|
||||
if( has_action('litespeed_control_set_nocache') ) {
|
||||
do_action(
|
||||
'litespeed_control_set_nocache',
|
||||
'Custom Rest API endpoint, not cacheable.'
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( is_user_logged_in() ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Implement custom capabilities when needed.
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function register_welcome_routes(): void {
|
||||
// Return welcome status.
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE,
|
||||
'get-welcome-status',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this->welcome_routes, 'get_welcome_status' ),
|
||||
'permission_callback' => array( $this, 'permission_check' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Update welcome status.
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE,
|
||||
'update-welcome-status',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array( $this->welcome_routes, 'update_welcome_status' ),
|
||||
'permission_callback' => array( $this, 'permission_check' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function register_step_routes(): void {
|
||||
// Return steps.
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE,
|
||||
'get-steps',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this->step_routes, 'get_steps' ),
|
||||
'permission_callback' => array( $this, 'permission_check' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Complete step.
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE,
|
||||
'complete-step',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array( $this->step_routes, 'complete_step' ),
|
||||
'permission_callback' => array( $this, 'permission_check' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Toggle list step.
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE,
|
||||
'toggle-list-visibility',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array( $this->step_routes, 'toggle_list_visibility' ),
|
||||
'permission_callback' => array( $this, 'permission_check' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Activate plugin
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE, 'activate-plugin', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this->step_routes, 'activate_plugin'],
|
||||
'permission_callback' => [$this, 'permission_check'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function register_woo_routes(): void {
|
||||
// Woo Setup
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE, 'woo-setup', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this->woo_routes, 'woo_setup'],
|
||||
'permission_callback' => [$this, 'permission_check'],
|
||||
]
|
||||
);
|
||||
|
||||
// Plugins
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE, 'get-plugins', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this->woo_routes, 'get_plugins'],
|
||||
'permission_callback' => [$this, 'permission_check'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function register_tutorial_routes(): void {
|
||||
// Return steps.
|
||||
register_rest_route(
|
||||
HOSTINGER_EASY_ONBOARDING_REST_API_BASE,
|
||||
'get-tutorials',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this->tutorial_routes, 'get_tutorials' ),
|
||||
'permission_callback' => array( $this, 'permission_check' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding\Rest;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
|
||||
/**
|
||||
* Avoid possibility to get file accessed directly
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for handling Settings Rest API
|
||||
*/
|
||||
class StepRoutes {
|
||||
public const LIST_VISIBILITY_OPTION = 'hostinger_onboarding_list_visibility';
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public function get_steps( \WP_REST_Request $request ): \WP_REST_Response {
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$locale = !empty($parameters['locale']) ? sanitize_text_field($parameters['locale']) : '';
|
||||
$available_languages = get_available_languages();
|
||||
|
||||
if (!empty($locale) && in_array($locale, $available_languages)) {
|
||||
switch_to_locale($locale);
|
||||
}
|
||||
|
||||
$onboarding = new Onboarding();
|
||||
$onboarding->init();
|
||||
|
||||
$data = array(
|
||||
'data' => array(
|
||||
'steps' => $onboarding->get_step_categories(),
|
||||
)
|
||||
);
|
||||
|
||||
$response = new \WP_REST_Response( $data );
|
||||
|
||||
$response->set_headers( array( 'Cache-Control' => 'no-cache' ) );
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function complete_step( \WP_REST_Request $request ): \WP_Error|\WP_REST_Response
|
||||
{
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$errors = array();
|
||||
|
||||
if ( empty( $parameters['step_category_id'] ) ) {
|
||||
/* translators: %s field name that is missing */
|
||||
$errors['step_category_id'] = sprintf( __( '%s missing or empty', 'hostinger-easy-onboarding' ), 'step category id');
|
||||
}
|
||||
|
||||
if ( empty( $parameters['step_id'] ) ) {
|
||||
$errors['step_id'] = sprintf( __( '%s missing or empty', 'hostinger-easy-onboarding' ), 'step category id') ;
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Sorry, there are validation errors.', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST,
|
||||
'errors' => $errors,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$step_category_id = sanitize_text_field( $parameters['step_category_id'] );
|
||||
$step_id = sanitize_text_field( $parameters['step_id'] );
|
||||
|
||||
$onboarding = new Onboarding();
|
||||
$onboarding->init();
|
||||
|
||||
$validate_step = $onboarding->validate_step( $step_category_id, $step_id );
|
||||
|
||||
if(empty($validate_step)) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Step category and/or step does not exist.', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'data' => array(
|
||||
'saved' => $onboarding->complete_step( $step_category_id, $step_id )
|
||||
)
|
||||
);
|
||||
|
||||
if ( has_action( 'litespeed_purge_all' ) ) {
|
||||
do_action( 'litespeed_purge_all' );
|
||||
}
|
||||
|
||||
$response = new \WP_REST_Response( $data );
|
||||
|
||||
$response->set_headers( array( 'Cache-Control' => 'no-cache' ) );
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function toggle_list_visibility( \WP_REST_Request $request ) {
|
||||
$current_state = get_option( self::LIST_VISIBILITY_OPTION, 1 );
|
||||
|
||||
$new_state = !(bool)$current_state;
|
||||
|
||||
$update = update_option( self::LIST_VISIBILITY_OPTION, (int)$new_state );
|
||||
|
||||
return new \WP_REST_Response( array(
|
||||
'status' => $update,
|
||||
'new_state' => $new_state
|
||||
), 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function activate_plugin( \WP_REST_Request $request ): \WP_REST_Response|\WP_Error {
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$plugin = !empty($parameters['plugin']) ? sanitize_text_field($parameters['plugin']) : '';
|
||||
|
||||
$errors = array();
|
||||
|
||||
if(empty($plugin)) {
|
||||
$errors['plugin'] = sprintf( __( '%s missing or empty', 'hostinger-easy-onboarding' ), 'plugin' );
|
||||
}
|
||||
|
||||
$helper = new Helper();
|
||||
$plugin_path = $helper->get_plugin_main_file( $plugin );
|
||||
|
||||
if ( is_plugin_active( $plugin_path ) ) {
|
||||
/* translators: %s plugin slug */
|
||||
$errors['plugin'] = sprintf( __( '%s is already active', 'hostinger-easy-onboarding' ), 'plugin' );
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Sorry, there are validation errors.', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST,
|
||||
'errors' => $errors,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$activated = activate_plugin( $plugin_path );
|
||||
|
||||
if ( is_wp_error( $activated ) ) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Sorry, there are activation errors.', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST,
|
||||
'errors' => $activated->get_error_message(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$response = new \WP_REST_Response( array( 'data' => '' ) );
|
||||
|
||||
$response->set_headers( array( 'Cache-Control' => 'no-cache' ) );
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding\Rest;
|
||||
|
||||
/**
|
||||
* Avoid possibility to get file accessed directly
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
class TutorialRoutes {
|
||||
public function get_tutorials( \WP_REST_Request $request ): \WP_REST_Response {
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$locale = sanitize_text_field( $parameters['locale'] );
|
||||
|
||||
$user_locale = !empty( $locale ) ? substr( $locale, 0, 2) : 'en';
|
||||
|
||||
$tutorials = array(
|
||||
'en' => array(
|
||||
array(
|
||||
'id' => 'F_53_baJe6Q',
|
||||
'title' => 'How to Make a Website (2024): Simple, Quick, & Easy Tutorial',
|
||||
'duration' => '17:47',
|
||||
),
|
||||
array(
|
||||
'id' => 'SU_DOsu9Llk',
|
||||
'title' => 'How to EASILY Manage Google Tools with Google Site Kit - Beginners Guide 2024',
|
||||
'duration' => '12:28',
|
||||
),
|
||||
array(
|
||||
'id' => 'YK-XO7iLyGQ',
|
||||
'title' => 'How to Import Images Into WordPress Website',
|
||||
'duration' => '1:44',
|
||||
),
|
||||
array(
|
||||
'id' => 'WHXtmEppbn8',
|
||||
'title' => 'How to Edit the Footer in WordPress',
|
||||
'duration' => '6:17',
|
||||
),
|
||||
),
|
||||
'pt' => array(
|
||||
array(
|
||||
'id' => 'Ck15HW4koWE',
|
||||
'title' => 'Como Alterar a sua Logo no WordPress (Rápido e Prático)',
|
||||
'duration' => '4:28',
|
||||
),
|
||||
array(
|
||||
'id' => 'OJH713cx-u4',
|
||||
'title' => 'Como Personalizar um Tema do WordPress',
|
||||
'duration' => '13:42',
|
||||
),
|
||||
array(
|
||||
'id' => 'X_04utuq750',
|
||||
'title' => 'Como Editar o Menu dos Temas do WordPress',
|
||||
'duration' => '4:53',
|
||||
),
|
||||
array(
|
||||
'id' => 'cMKPatPvSKk',
|
||||
'title' => 'Como Criar Categorias no WordPress',
|
||||
'duration' => '6:04',
|
||||
),
|
||||
),
|
||||
'es' => array(
|
||||
array(
|
||||
'id' => 'FKp0dvhEN8o',
|
||||
'title' => 'Cómo Personalizar WordPress (2023)',
|
||||
'duration' => '9:02',
|
||||
),
|
||||
array(
|
||||
'id' => '1tvYSsRSgNc',
|
||||
'title' => 'Cómo Crear una Galería de Fotos en WordPress | Fácil y Gratis',
|
||||
'duration' => '5:48',
|
||||
),
|
||||
array(
|
||||
'id' => 'A-yuq3g1KVs',
|
||||
'title' => 'Como Instalar Plugins y Temas en WordPress',
|
||||
'duration' => '4:54',
|
||||
),
|
||||
array(
|
||||
'id' => '_8Z0C6Os1CQ',
|
||||
'title' => 'Cómo Crear un Menú en WordPress (en Menos de 5 minutos)',
|
||||
'duration' => '4:52',
|
||||
),
|
||||
),
|
||||
'fr' => array(
|
||||
array(
|
||||
'id' => 'zpW8jliv45E',
|
||||
'title' => 'Hostinger WordPress : Le Guide Complet pour utiliser WordPress sur Hostinger',
|
||||
'duration' => '8:11',
|
||||
),
|
||||
array(
|
||||
'id' => 'X7ZA9pteqqQ',
|
||||
'title' => 'TUTO WORDPRESS (Débutant) : Créer un site WordPress pour les Nuls',
|
||||
'duration' => '12:56',
|
||||
),
|
||||
array(
|
||||
'id' => 'JIHy3Y6ek_s',
|
||||
'title' => 'Tuto WordPress Débutant (Hostinger hPanel) - Créer un Site par IA',
|
||||
'duration' => '7:21',
|
||||
),
|
||||
array(
|
||||
'id' => 'Te3fM7VuQKg',
|
||||
'title' => 'Installer un Thème WordPress (2023) | Rapide et Facile',
|
||||
'duration' => '2:58',
|
||||
),
|
||||
array(
|
||||
'id' => '2rPq1CiogDk',
|
||||
'title' => 'Google Analytics sur WordPress FACILEMENT avec Google Site Kit : Guide Complet (2023)',
|
||||
'duration' => '7:19',
|
||||
),
|
||||
),
|
||||
'hi' => array(
|
||||
array(
|
||||
'id' => '4wGytQfbmm4',
|
||||
'title' => 'How to Build a Website FAST Using AI in Just 10 Minutes',
|
||||
'duration' => '8:32',
|
||||
),
|
||||
array(
|
||||
'id' => 'AT73ExGMuVc',
|
||||
'title' => 'How to Edit Footer in WordPress in Hindi | Hostinger India',
|
||||
'duration' => '3:48',
|
||||
),
|
||||
array(
|
||||
'id' => 'OIGsBGIaZqM',
|
||||
'title' => 'How to Create a Menu in WordPress in Hindi | Hostinger India',
|
||||
'duration' => '2:38',
|
||||
),
|
||||
array(
|
||||
'id' => 'WFBoHv0xJ60',
|
||||
'title' => 'How to Install WordPress Themes | Hostinger India',
|
||||
'duration' => '2:52',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if ( empty( $tutorials[$user_locale] ) ) {
|
||||
$user_locale = 'en';
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'data' => array(
|
||||
'tutorials' => $tutorials[$user_locale],
|
||||
)
|
||||
);
|
||||
|
||||
$response = new \WP_REST_Response( $data );
|
||||
|
||||
$response->set_headers( array( 'Cache-Control' => 'no-cache' ) );
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding\Rest;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\WelcomeCards;
|
||||
|
||||
/**
|
||||
* Avoid possibility to get file accessed directly
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for handling Settings Rest API
|
||||
*/
|
||||
class WelcomeRoutes {
|
||||
/**
|
||||
* Return welcome status
|
||||
*
|
||||
* @param WP_REST_Request $request WordPress rest request.
|
||||
*
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public function get_welcome_status( \WP_REST_Request $request ): \WP_REST_Response {
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$locale = !empty($parameters['locale']) ? sanitize_text_field($parameters['locale']) : '';
|
||||
$available_languages = get_available_languages();
|
||||
|
||||
if (!empty($locale) && in_array($locale, $available_languages)) {
|
||||
switch_to_locale($locale);
|
||||
}
|
||||
|
||||
$welcome_card = new WelcomeCards();
|
||||
$welcome_cards = $welcome_card->get_welcome_cards();
|
||||
|
||||
$data = array(
|
||||
'data' => array(
|
||||
'welcome_cards' => $welcome_cards,
|
||||
'welcome_choice_done' => get_option( 'hostinger_onboarding_choice_done', false )
|
||||
)
|
||||
);
|
||||
|
||||
$response = new \WP_REST_Response( $data );
|
||||
|
||||
$response->set_headers( array( 'Cache-Control' => 'no-cache' ) );
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_welcome_status( \WP_REST_Request $request )
|
||||
{
|
||||
$parameters = $request->get_params();
|
||||
|
||||
if( empty( $parameters['choice'] ) ) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Choice parameter missing or empty', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$choice = sanitize_text_field( $parameters['choice'] );
|
||||
|
||||
update_option( 'hostinger_onboarding_choice_done', $choice );
|
||||
|
||||
if ( has_action( 'litespeed_purge_all' ) ) {
|
||||
do_action( 'litespeed_purge_all' );
|
||||
}
|
||||
|
||||
$response = new \WP_REST_Response( array( 'data' => array() ) );
|
||||
|
||||
$response->set_headers(array('Cache-Control' => 'no-cache'));
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding\Rest;
|
||||
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\Onboarding;
|
||||
use Hostinger\EasyOnboarding\Admin\Onboarding\PluginManager;
|
||||
use Hostinger\EasyOnboarding\Helper;
|
||||
|
||||
/**
|
||||
* Avoid possibility to get file accessed directly
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for handling WooCommerce related routes
|
||||
*/
|
||||
class WooRoutes {
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public function get_plugins( \WP_REST_Request $request ): \WP_REST_Response|\WP_Error {
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$locale = !empty($parameters['locale']) ? sanitize_text_field($parameters['locale']) : '';
|
||||
$available_languages = get_available_languages();
|
||||
|
||||
if (!empty($locale) && in_array($locale, $available_languages)) {
|
||||
switch_to_locale($locale);
|
||||
}
|
||||
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$type = !empty($parameters['type']) ? $this->filter_allowed_types($parameters['type']) : '';
|
||||
|
||||
$errors = array();
|
||||
|
||||
if(empty($type)) {
|
||||
$errors['type'] = sprintf( __( '%s missing or empty', 'hostinger-easy-onboarding' ), 'type' );
|
||||
}
|
||||
|
||||
$locale = get_option( 'woocommerce_default_country', false );
|
||||
|
||||
if(empty($locale)) {
|
||||
$errors['locale'] = __( 'Shop locale is empty, please setup store first', 'hostinger-easy-onboarding' );
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Sorry, there are validation errors.', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST,
|
||||
'errors' => $errors,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$plugin_manager = new PluginManager();
|
||||
|
||||
$data = array(
|
||||
'plugins' => $plugin_manager->get_plugins_by_criteria( $type, $locale ),
|
||||
'locale' => get_option('woocommerce_default_country', '')
|
||||
);
|
||||
|
||||
$response = new \WP_REST_Response( array( 'data' => $data ) );
|
||||
|
||||
$response->set_headers( array( 'Cache-Control' => 'no-cache' ) );
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function woo_setup( \WP_REST_Request $request )
|
||||
{
|
||||
$parameters = $request->get_params();
|
||||
|
||||
$fields = array(
|
||||
'store_name',
|
||||
'industry',
|
||||
'store_location',
|
||||
'business_email',
|
||||
'is_agree_marketing',
|
||||
);
|
||||
|
||||
$boolean_fields = array(
|
||||
'is_agree_marketing'
|
||||
);
|
||||
|
||||
$errors = array();
|
||||
|
||||
foreach( $fields as $field ) {
|
||||
|
||||
$formatted_field = str_replace( '_', ' ', $field );
|
||||
|
||||
// Boolean field have bit different validation
|
||||
if ( in_array( $field, $boolean_fields ) ) {
|
||||
$field_is_valid = isset( $parameters[$field] );
|
||||
} else {
|
||||
$field_is_valid = !empty( $parameters[$field] );
|
||||
}
|
||||
|
||||
if ( !$field_is_valid ) {
|
||||
$errors[$field] = sprintf( __( '%s missing or empty', 'hostinger-easy-onboarding' ), $formatted_field );
|
||||
} else {
|
||||
$parameters[$field] = sanitize_text_field( $parameters[$field] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$locale_info = include WC()->plugin_path() . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'locale-info.php';
|
||||
|
||||
if(str_contains($parameters['store_location'], ':')) {
|
||||
$store_location = explode( ':', $parameters['store_location'] );
|
||||
$store_location = $store_location[0];
|
||||
} else {
|
||||
$store_location = $parameters['store_location'];
|
||||
}
|
||||
|
||||
if ( empty( $locale_info[$store_location] ) ) {
|
||||
$errors['store_location'] = __( 'Store location locale not found', 'hostinger-easy-onboarding' );
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
return new \WP_Error(
|
||||
'data_invalid',
|
||||
__( 'Sorry, there are validation errors.', 'hostinger-easy-onboarding' ),
|
||||
array(
|
||||
'status' => \WP_Http::BAD_REQUEST,
|
||||
'errors' => $errors,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$store_locale = $locale_info[$store_location];
|
||||
|
||||
// Default WooCommerce values.
|
||||
update_option('woocommerce_default_country', $parameters['store_location'], true);
|
||||
update_option('woocommerce_allowed_countries', 'all', true);
|
||||
update_option('woocommerce_all_except_countries', [], true);
|
||||
update_option('woocommerce_specific_allowed_countries', [], true);
|
||||
update_option('woocommerce_specific_ship_to_countries', [], true);
|
||||
update_option('woocommerce_default_customer_address', 'base', true);
|
||||
update_option('woocommerce_calc_taxes', 'no', true);
|
||||
update_option('woocommerce_enable_coupons', 'yes', true);
|
||||
update_option('woocommerce_calc_discounts_sequentially', 'no', true);
|
||||
update_option('woocommerce_currency', $store_locale['currency_code'], true);
|
||||
update_option('woocommerce_currency_pos', $store_locale['currency_pos'], true);
|
||||
update_option('woocommerce_price_thousand_sep', $store_locale['thousand_sep'], true);
|
||||
update_option('woocommerce_price_decimal_sep', $store_locale['decimal_sep'], true);
|
||||
update_option('woocommerce_price_num_decimals', $store_locale['num_decimals'], true);
|
||||
update_option('woocommerce_weight_unit', $store_locale['weight_unit'], true);
|
||||
update_option('woocommerce_dimension_unit', $store_locale['dimension_unit'], true);
|
||||
|
||||
$onboarding_profile = array();
|
||||
$onboarding_profile['is_store_country_set'] = true;
|
||||
$onboarding_profile['industry'] = array( $parameters['industry'] );
|
||||
$onboarding_profile['is_agree_marketing'] = $parameters['is_agree_marketing'];
|
||||
$onboarding_profile['store_email'] = $parameters['business_email'];
|
||||
$onboarding_profile['completed'] = true;
|
||||
$onboarding_profile['is_plugins_page_skipped'] = true;
|
||||
|
||||
update_option('woocommerce_onboarding_profile', $onboarding_profile, true);
|
||||
|
||||
$onboarding = new Onboarding();
|
||||
$onboarding->init();
|
||||
|
||||
$onboarding->complete_step( Onboarding::HOSTINGER_EASY_ONBOARDING_STORE_STEP_CATEGORY_ID, 'setup_store' );
|
||||
|
||||
if ( has_action( 'litespeed_purge_all' ) ) {
|
||||
do_action( 'litespeed_purge_all' );
|
||||
}
|
||||
|
||||
$response = new \WP_REST_Response( array( ) );
|
||||
|
||||
$response->set_headers(array('Cache-Control' => 'no-cache'));
|
||||
|
||||
$response->set_status( \WP_Http::OK );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function filter_allowed_types( string $type ) {
|
||||
$allowed_types = array( 'shipping', 'payment' );
|
||||
|
||||
return in_array( $type, $allowed_types ) ? $type : '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Settings {
|
||||
public const MYSELF = 'myself';
|
||||
public const FREELANCER = 'freelancer';
|
||||
public const DEVELOPER = 'developer';
|
||||
public const OTHER = 'other';
|
||||
public const BUSINESS_BEGINNER_SEGMENT = 'business_beginner';
|
||||
public const LEARNER_SEGMENT = 'learner';
|
||||
public const BUSINESS_OWNER_SEGMENT = 'business_owner';
|
||||
public const WEBSITE_TYPE_BUSINESS = 'business';
|
||||
public const WEBSITE_TYPE_PORTFOLIO = 'portfolio';
|
||||
public const WEBSITE_TYPE_BLOG = 'blog';
|
||||
public const SITE_TITLE_OPTION = 'blogname';
|
||||
|
||||
public function __construct() {
|
||||
if ( ! $this->get_setting( 'user_segment' ) ) {
|
||||
$this->set_user_segment();
|
||||
}
|
||||
}
|
||||
|
||||
public function set_user_segment(): void {
|
||||
$created_by = self::get_setting( 'survey.website.created_by' );
|
||||
$created_for = self::get_setting( 'survey.website.for' );
|
||||
$need_help = self::get_setting( 'survey.website.need_help' );
|
||||
$work_at = self::get_setting( 'survey.work_at' );
|
||||
|
||||
if ( $this->is_business_beginner( $created_by, $created_for, $need_help ) ) {
|
||||
self::update_setting( 'user_segment', self::BUSINESS_BEGINNER_SEGMENT );
|
||||
}
|
||||
|
||||
if ( $this->is_learner( $work_at, $need_help ) ) {
|
||||
self::update_setting( 'user_segment', self::LEARNER_SEGMENT );
|
||||
}
|
||||
|
||||
if ( $this->is_bussiness_owner( $created_for, $created_by ) ) {
|
||||
self::update_setting( 'user_segment', self::BUSINESS_OWNER_SEGMENT );
|
||||
}
|
||||
}
|
||||
|
||||
private function is_business_beginner( string $created_by, string $created_for, bool $need_help ): bool {
|
||||
return $created_by === self::MYSELF && $created_for === self::MYSELF && $need_help;
|
||||
}
|
||||
|
||||
private function is_learner( string $work_at, bool $need_help ): bool {
|
||||
return $work_at === self::FREELANCER && $need_help;
|
||||
}
|
||||
|
||||
private function is_bussiness_owner( string $created_for, string $created_by ): bool {
|
||||
return $created_for === self::MYSELF && ( $created_by === self::DEVELOPER || $created_by === self::OTHER );
|
||||
}
|
||||
|
||||
public static function get_setting( string $setting ): string {
|
||||
|
||||
if ( $setting ) {
|
||||
return get_option( 'hostinger_' . $setting, '' );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function update_setting( string $setting, $value, $autoload = null ): void {
|
||||
|
||||
if ( $setting ) {
|
||||
update_option( 'hostinger_' . $setting, $value, $autoload );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new Settings();
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Hostinger\EasyOnboarding;
|
||||
|
||||
use Hostinger\EasyOnboarding\Config;
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Updates {
|
||||
private Config $config_handler;
|
||||
private const DEFAULT_PLUGIN_UPDATE_URI = 'https://hostinger-wp-updates.com?action=get_metadata&slug=hostinger-easy-onboarding';
|
||||
private const CANARY_PLUGIN_UPDATE_URI = 'https://hostinger-canary-wp-updates.com?action=get_metadata&slug=hostinger-easy-onboarding';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->config_handler = new Config();
|
||||
$this->updates();
|
||||
}
|
||||
|
||||
private function should_use_canary_uri(): bool {
|
||||
return isset( $_SERVER['H_PLATFORM'] ) && $_SERVER['H_PLATFORM'] === 'Hostinger' && isset( $_SERVER['H_CANARY'] ) && $_SERVER['H_CANARY'] === true;
|
||||
}
|
||||
|
||||
private function get_plugin_update_uri( string $default = self::DEFAULT_PLUGIN_UPDATE_URI ): string {
|
||||
if ( $this->should_use_canary_uri() ) {
|
||||
return self::CANARY_PLUGIN_UPDATE_URI;
|
||||
}
|
||||
|
||||
return $this->config_handler->get_config_value( 'easy_onboarding_plugin_update_uri', $default );
|
||||
}
|
||||
|
||||
public function updates(): void {
|
||||
$plugin_updater_uri = $this->get_plugin_update_uri();
|
||||
|
||||
if ( class_exists( PucFactory::class ) ) {
|
||||
$hts_update_checker = PucFactory::buildUpdateChecker(
|
||||
$plugin_updater_uri,
|
||||
HOSTINGER_EASY_ONBOARDING_ABSPATH . 'hostinger-easy-onboarding.php',
|
||||
'hostinger-easy-onboarding'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\WooCommerce;
|
||||
|
||||
use WC_Payment_Gateways;
|
||||
use WC_Payment_Gateway;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class GatewayManager {
|
||||
public const STRIPE_DYNAMIC_GATEWAY_ID = 'cpsw_stripe_element';
|
||||
/**
|
||||
* @var WC_Payment_Gateways
|
||||
*/
|
||||
private WC_Payment_Gateways $payment_gateways;
|
||||
|
||||
/**
|
||||
* @param WC_Payment_Gateways $payment_gateways
|
||||
*/
|
||||
public function __construct( WC_Payment_Gateways $payment_gateways ) {
|
||||
$this->payment_gateways = $payment_gateways;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAnyGatewayActive(): bool {
|
||||
$payment_gateways = $this->payment_gateways->payment_gateways();
|
||||
|
||||
if ( empty( $payment_gateways ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $payment_gateways as $gateway ) {
|
||||
// Does not have enabled property.
|
||||
if( $gateway->id === self::STRIPE_DYNAMIC_GATEWAY_ID ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $gateway->settings['enabled'] ) && ( $gateway->settings['enabled'] === 'yes' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $gateway->enabled === 'yes' ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\EasyOnboarding\WooCommerce;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Options {
|
||||
/**
|
||||
* Hides Setup task list in WooCommerce
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function hideSetupTaskList(): void {
|
||||
$hidden_tasks = get_option( 'woocommerce_task_list_hidden_lists', false );
|
||||
|
||||
if($hidden_tasks === false) {
|
||||
update_option( 'woocommerce_task_list_hidden_lists', array( 'setup' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables automatic creation of shipping zones
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disableWooCommerceShipingZoneCreation(): void {
|
||||
update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' );
|
||||
update_option( 'woocommerce_admin_reviewed_default_shipping_zones', 'yes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips WooCommerce native onboarding
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function skipOnboarding(): void {
|
||||
$onboarding_profile = get_option( 'woocommerce_onboarding_profile', false );
|
||||
|
||||
if($onboarding_profile === false) {
|
||||
update_option( 'woocommerce_onboarding_profile', array( 'skipped' => true ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user