PluginProbe
Hostinger Tools / 2.2.1
Hostinger Tools v2.2.1
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / includes / Admin / Hooks.php

Hooks.php in Hostinger Tools 2.2.1, at includes/Admin/Hooks.php

171 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hostinger\Admin;
4
5 use Hostinger\Helper;
6
7 defined( 'ABSPATH' ) || exit;
8
9 class Hooks {
10
11 private Helper $helper;
12
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' );
20
21 if ( ! Helper::show_woocommerce_onboarding() ) {
22 add_filter( 'admin_body_class', array( $this, 'add_woocommerce_onboarding_class' ) );
23 }
24
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 }
29
30 public function enable_woo_onboarding(): bool {
31
32 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
33 return false;
34 }
35
36 if ( ! $this->helper->is_hostinger_admin_page() || ! $this->helper->is_woocommerce_site() ) {
37 return false;
38 }
39
40 $woocommerce_onboarding_profile = get_option( 'woocommerce_onboarding_profile', null );
41
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 }
170 }
171