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