PluginProbe
Hostinger Tools / 2.1.1
Hostinger Tools v2.1.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 / class-hostinger-admin-hooks.php

class-hostinger-admin-hooks.php in Hostinger Tools 2.1.1, at includes/admin/class-hostinger-admin-hooks.php

182 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 add_action( 'requests-curl.before_request', array( $this, 'session_write_close' ), 9999 );
26 }
27
28 public function enable_woo_onboarding(): bool {
29
30 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
31 return false;
32 }
33
34 if ( ! $this->helper->is_hostinger_admin_page() || ! $this->helper->is_woocommerce_site() ) {
35 return false;
36 }
37
38 $woocommerce_onboarding_profile = get_option( 'woocommerce_onboarding_profile', null );
39
40 // WooCommerce onboarding already done (skipped).
41 if ( ! empty( $woocommerce_onboarding_profile['skipped'] ) ) {
42 return false;
43 }
44
45 // WooCommerce onboarding already done (completed).
46 if ( ! empty( $woocommerce_onboarding_profile['completed'] ) ) {
47 return false;
48 }
49
50 $woo_onboarding_enabled = get_option( 'hostinger_woo_onboarding_enabled', null );
51
52 if ( $woo_onboarding_enabled === null && get_option( 'hts_new_installation', false ) === 'new' ) {
53 update_option( 'hostinger_woo_onboarding_enabled', true, false );
54 update_option( 'hts_new_installation', 'old' );
55 }
56
57 return true;
58 }
59
60 public function rate_plugin(): void {
61 $promotional_banner_hidden = get_transient( 'hts_hide_promotional_banner_transient' );
62 $two_hours_in_seconds = 7200;
63
64 if ( $promotional_banner_hidden && time() > $promotional_banner_hidden + $two_hours_in_seconds ) {
65 require_once HOSTINGER_ABSPATH . 'includes/admin/views/partials/hostinger-rate-us.php';
66 }
67 }
68
69 public function omnisend_discount_notice(): void {
70 $omnisend_notice_hidden = filter_var( isset( $_SESSION['hts_omnisend_notice_hidden'] ) ? $_SESSION['hts_omnisend_notice_hidden'] : false, FILTER_VALIDATE_BOOLEAN );
71
72 if ( ! $omnisend_notice_hidden && ( $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' ) ) ) : ?>
73 <div class="notice notice-info hts-admin-notice hts-omnisend">
74 <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>
75 <div>
76 <a class="button button-primary"
77 href="https://your.omnisend.com/LXqyZ0"
78 target="_blank"><?= esc_html__( 'Get Discount', 'hostinger' ); ?></a>
79 <button type="button" class="notice-dismiss"></button>
80 </div>
81 </div>
82 <?php endif;
83 wp_nonce_field( 'hts_close_omnisend', 'hts_close_omnisend_nonce', true );
84 }
85
86 public function hide_astra_builder_selection_screen(): void {
87 add_filter( 'st_enable_block_page_builder', '__return_true' );
88 }
89
90 /**
91 *
92 * @param string $classes
93 *
94 * @return string
95 */
96 public function add_woocommerce_onboarding_class( string $classes ): string {
97
98 $classes .= ' hostinger-woocommerce-onboarding-page';
99
100 return $classes;
101 }
102
103 /**
104 * @return bool
105 */
106 public function store_ready_message_logic(): bool {
107 if ( ! Hostinger_Helper::is_woocommerce_site() || ! Hostinger_Helper::woocommerce_onboarding_choice() ) {
108 return false;
109 }
110
111 if ( isset( $_GET['hide-store-notice'] ) ) {
112 update_option( 'hostinger_woo_ready_message_shown', 1 );
113
114 return false;
115 }
116
117 return false;
118 }
119
120 /**
121 * @return string
122 */
123 public function show_store_ready_message(): string {
124 if ( ! $this->helper->can_show_store_ready_message() ) {
125 return '';
126 }
127
128 ?>
129 <div class="notice notice-hst">
130 <h3>
131 <?php echo esc_html__( 'Your store is ready!', 'hostinger' ); ?>
132 </h3>
133 <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>
134 <p>
135 <a href="<?php echo esc_url( admin_url( 'admin.php?page=hostinger&hide-store-notice' ) ); ?>"
136 class="components-button is-primary"><?php echo esc_html__( 'Visit Hostinger plugin', 'hostinger' ); ?></a>
137 <a href="<?php echo esc_url( home_url() ); ?>"
138 target="_blank"
139 class="components-button is-secondary"><?php echo esc_html__( 'Preview store', 'hostinger' ); ?></a>
140 </p>
141 </div>
142 <?php
143
144 return '';
145 }
146
147 /**
148 * @return string
149 */
150 public function force_woo_notices(): string {
151 if ( ! $this->helper->can_show_store_ready_message() ) {
152 return '';
153 }
154 ?>
155 <style type="text/css">
156 .woocommerce-layout__notice-list-hide {
157 display: block !important;
158 }
159
160 .notice-hst {
161 border-left-color: #673DE6;
162 }
163 </style>
164 <?php
165
166 return '';
167 }
168
169 /**
170 * Session start REST API fix
171 *
172 * @param $curlhandle
173 *
174 * @return void
175 */
176 public function session_write_close( $curlhandle ): void {
177 session_write_close();
178 }
179 }
180
181 $hostinger_admin_hooks = new Hostinger_Admin_Hooks();
182