PluginProbe
Hostinger Tools / 2.0.9
Hostinger Tools v2.0.9
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.0.9, at includes/admin/class-hostinger-admin-hooks.php

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