| @@ -2,59 +2,169 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Hostinger\Admin; |
| 4 | 4 | |
| 5 | 5 | use Hostinger\Helper; |
| 6 | -use Hostinger\WpHelper\Utils; | |
| 7 | 6 | |
| 8 | 7 | defined( 'ABSPATH' ) || exit; |
| 9 | 8 | |
| 10 | 9 | class Hooks { |
| 11 | - /** | |
| 12 | - * @var Helper | |
| 13 | - */ | |
| 14 | - private Helper $helper; | |
| 15 | 10 | |
| 16 | - /** | |
| 17 | - * @var Utils | |
| 18 | - */ | |
| 19 | - private Utils $utils; | |
| 11 | + private Helper $helper; | |
| 20 | 12 | |
| 21 | - public function __construct( $utils ) { | |
| 22 | - $this->helper = new Helper(); | |
| 23 | - $this->utils = $utils ?? new Utils(); | |
| 24 | - add_action( 'admin_footer', array( $this, 'rate_plugin' ) ); | |
| 25 | - add_filter( 'wp_kses_allowed_html', array( $this, 'custom_kses_allowed_html' ), 10, 1 ); | |
| 26 | - } | |
| 13 | + public function __construct() { | |
| 14 | + $this->helper = new Helper(); | |
| 15 | + add_action( 'admin_footer', array( $this, 'rate_plugin' ) ); | |
| 16 | + add_action( 'admin_init', array( $this, 'hide_astra_builder_selection_screen' ) ); | |
| 17 | + add_action( 'admin_init', array( $this, 'enable_woo_onboarding' ) ); | |
| 18 | + add_action( 'admin_notices', array( $this, 'omnisend_discount_notice' ) ); | |
| 19 | + add_filter( 'woocommerce_prevent_automatic_wizard_redirect', '__return_true' ); | |
| 27 | 20 | |
| 28 | - /** | |
| 29 | - * @return void | |
| 30 | - */ | |
| 31 | - public function rate_plugin(): void { | |
| 32 | - $admin_path = parse_url( admin_url(), PHP_URL_PATH ); | |
| 21 | + if ( ! Helper::show_woocommerce_onboarding() ) { | |
| 22 | + add_filter( 'admin_body_class', array( $this, 'add_woocommerce_onboarding_class' ) ); | |
| 23 | + } | |
| 33 | 24 | |
| 34 | - if ( ! $this->utils->isThisPage( $admin_path . 'admin.php?page=' . Menu::MENU_SLUG ) ) { | |
| 35 | - return; | |
| 36 | - } | |
| 25 | + add_action( 'admin_init', array( $this, 'store_ready_message_logic' ), 0 ); | |
| 26 | + add_action( 'admin_notices', array( $this, 'show_store_ready_message' ), 0 ); | |
| 27 | + add_action( 'admin_head', array( $this, 'force_woo_notices' ) ); | |
| 28 | + } | |
| 37 | 29 | |
| 38 | - require_once HOSTINGER_ABSPATH . 'includes/Admin/Views/Partials/RateUs.php'; | |
| 39 | - } | |
| 30 | + public function enable_woo_onboarding(): bool { | |
| 40 | 31 | |
| 32 | + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
| 33 | + return false; | |
| 34 | + } | |
| 41 | 35 | |
| 36 | + if ( ! $this->helper->is_hostinger_admin_page() || ! $this->helper->is_woocommerce_site() ) { | |
| 37 | + return false; | |
| 38 | + } | |
| 42 | 39 | |
| 43 | - public function custom_kses_allowed_html( $allowed ) { | |
| 44 | - $allowed['svg'] = array( | |
| 45 | - 'xmlns' => true, | |
| 46 | - 'width' => true, | |
| 47 | - 'height' => true, | |
| 48 | - 'viewBox' => true, | |
| 49 | - 'fill' => true, | |
| 50 | - 'style' => true, | |
| 51 | - 'class' => true, | |
| 52 | - ); | |
| 53 | - $allowed['path'] = array( | |
| 54 | - 'd' => true, | |
| 55 | - 'fill' => true, | |
| 56 | - ); | |
| 40 | + $woocommerce_onboarding_profile = get_option( 'woocommerce_onboarding_profile', null ); | |
| 57 | 41 | |
| 58 | - return $allowed; | |
| 59 | - } | |
| 42 | + // WooCommerce onboarding already done (skipped). | |
| 43 | + if ( ! empty( $woocommerce_onboarding_profile['skipped'] ) ) { | |
| 44 | + return false; | |
| 45 | + } | |
| 46 | + | |
| 47 | + // WooCommerce onboarding already done (completed). | |
| 48 | + if ( ! empty( $woocommerce_onboarding_profile['completed'] ) ) { | |
| 49 | + return false; | |
| 50 | + } | |
| 51 | + | |
| 52 | + $woo_onboarding_enabled = get_option( 'hostinger_woo_onboarding_enabled', null ); | |
| 53 | + | |
| 54 | + if ( $woo_onboarding_enabled === null && get_option( 'hts_new_installation', false ) === 'new' ) { | |
| 55 | + update_option( 'hostinger_woo_onboarding_enabled', true, false ); | |
| 56 | + update_option( 'hts_new_installation', 'old' ); | |
| 57 | + } | |
| 58 | + | |
| 59 | + return true; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public function rate_plugin(): void { | |
| 63 | + $promotional_banner_hidden = get_transient( 'hts_hide_promotional_banner_transient' ); | |
| 64 | + $two_hours_in_seconds = 7200; | |
| 65 | + | |
| 66 | + if ( $promotional_banner_hidden && time() > $promotional_banner_hidden + $two_hours_in_seconds ) { | |
| 67 | + require_once HOSTINGER_ABSPATH . 'includes/Admin/Views/Partials/RateUs.php'; | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + public function omnisend_discount_notice(): void { | |
| 72 | + $omnisend_notice_hidden = get_transient( 'hts_omnisend_notice_hidden' ); | |
| 73 | + | |
| 74 | + 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' ) ) ) : ?> | |
| 75 | + <div class="notice notice-info hts-admin-notice hts-omnisend"> | |
| 76 | + <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' ), array( 'b' => array() ) ); ?></p> | |
| 77 | + <div> | |
| 78 | + <a class="button button-primary" | |
| 79 | + href="https://your.omnisend.com/LXqyZ0" | |
| 80 | + target="_blank"><?= esc_html__( 'Get Discount', 'hostinger' ); ?></a> | |
| 81 | + <button type="button" class="notice-dismiss"></button> | |
| 82 | + </div> | |
| 83 | + </div> | |
| 84 | + <?php endif; | |
| 85 | + wp_nonce_field( 'hts_close_omnisend', 'hts_close_omnisend_nonce', true ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + public function hide_astra_builder_selection_screen(): void { | |
| 89 | + add_filter( 'st_enable_block_page_builder', '__return_true' ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * | |
| 94 | + * @param string $classes | |
| 95 | + * | |
| 96 | + * @return string | |
| 97 | + */ | |
| 98 | + public function add_woocommerce_onboarding_class( string $classes ): string { | |
| 99 | + | |
| 100 | + $classes .= ' hostinger-woocommerce-onboarding-page'; | |
| 101 | + | |
| 102 | + return $classes; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * @return bool | |
| 107 | + */ | |
| 108 | + public function store_ready_message_logic(): bool { | |
| 109 | + if ( ! Helper::is_woocommerce_site() || ! Helper::woocommerce_onboarding_choice() ) { | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | + | |
| 113 | + if ( isset( $_GET['hide-store-notice'] ) ) { | |
| 114 | + update_option( 'hostinger_woo_ready_message_shown', 1 ); | |
| 115 | + | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + | |
| 119 | + return false; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * @return string | |
| 124 | + */ | |
| 125 | + public function show_store_ready_message(): string { | |
| 126 | + if ( ! $this->helper->can_show_store_ready_message() ) { | |
| 127 | + return ''; | |
| 128 | + } | |
| 129 | + | |
| 130 | + ?> | |
| 131 | + <div class="notice notice-hst"> | |
| 132 | + <h3> | |
| 133 | + <?php echo esc_html__( 'Your store is ready!', 'hostinger' ); ?> | |
| 134 | + </h3> | |
| 135 | + <p><?php echo esc_html__( 'One more step to reach your online success. Finalize the visual and technical aspects of your website using our recommendations checklist.', 'hostinger' ); ?></p> | |
| 136 | + <p> | |
| 137 | + <a href="<?php echo esc_url( admin_url( 'admin.php?page=hostinger&hide-store-notice' ) ); ?>" | |
| 138 | + class="components-button is-primary"><?php echo esc_html__( 'Visit Hostinger plugin', 'hostinger' ); ?></a> | |
| 139 | + <a href="<?php echo esc_url( home_url() ); ?>" | |
| 140 | + target="_blank" | |
| 141 | + class="components-button is-secondary"><?php echo esc_html__( 'Preview store', 'hostinger' ); ?></a> | |
| 142 | + </p> | |
| 143 | + </div> | |
| 144 | + <?php | |
| 145 | + | |
| 146 | + return ''; | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * @return string | |
| 151 | + */ | |
| 152 | + public function force_woo_notices(): string { | |
| 153 | + if ( ! $this->helper->can_show_store_ready_message() ) { | |
| 154 | + return ''; | |
| 155 | + } | |
| 156 | + ?> | |
| 157 | + <style type="text/css"> | |
| 158 | + .woocommerce-layout__notice-list-hide { | |
| 159 | + display: block !important; | |
| 160 | + } | |
| 161 | + | |
| 162 | + .notice-hst { | |
| 163 | + border-left-color: #673DE6; | |
| 164 | + } | |
| 165 | + </style> | |
| 166 | + <?php | |
| 167 | + | |
| 168 | + return ''; | |
| 169 | + } | |
| 60 | 170 | } |