PluginProbe
Hostinger Tools / 3.0.34
Hostinger Tools v3.0.34
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 / Hooks.php

Hooks.php in Hostinger Tools 3.0.34, at includes/Hooks.php

141 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 namespace Hostinger;
4
5 use Hostinger\DefaultOptions;
6 use Hostinger\Admin\Options\PluginOptions;
7 use Hostinger\Admin\PluginSettings;
8 use Hostinger\WpHelper\Utils;
9
10 defined( 'ABSPATH' ) || exit;
11
12 class Hooks {
13 public function __construct() {
14 // XMLRpc / Force SSL
15 add_filter( 'xmlrpc_enabled', array( $this, 'check_xmlrpc_enabled' ) );
16 add_filter( 'wp_is_application_passwords_available', array( $this, 'check_authentication_password_enabled' ) );
17 add_filter( 'wp_headers', array( $this, 'check_pingback' ) );
18 add_filter( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
19
20 add_action( 'update_option_woocommerce_coming_soon', array( $this, 'litespeed_flush_cache' ) );
21 add_action( 'update_option_woocommerce_store_pages_only', array( $this, 'litespeed_flush_cache' ) );
22 add_action( 'upgrader_process_complete', array( $this, 'disable_auth_passwords_on_update' ), 10, 2 );
23 }
24
25 public function disable_auth_passwords_on_update( \WP_Upgrader $upgrader_object, array $options ): void {
26 if ( $options['action'] !== 'update' || $options['type'] !== 'plugin' || empty( $options['plugins'] ) ) {
27 return;
28 }
29
30 if ( ! in_array( 'hostinger/hostinger.php', $options['plugins'], true ) ) {
31 return;
32 }
33
34 $settings = get_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, [] );
35
36 if ( ! empty( $settings['disable_authentication_password'] ) ) {
37 return;
38 }
39
40 $default_options = new DefaultOptions();
41 $updated_settings = $default_options->check_authentication_password( $settings );
42
43 $plugin_options = new PluginOptions( $updated_settings );
44 update_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, $plugin_options->to_array(), false );
45 }
46
47 /**
48 * @return void
49 */
50 public function plugins_loaded() {
51 $utils = new Utils();
52 $plugin_settings = new PluginSettings();
53 $settings = $plugin_settings->get_plugin_settings();
54
55 if ( defined( 'WP_CLI' ) && \WP_CLI ) {
56 return;
57 }
58
59 // Xmlrpc.
60 if ( $settings->get_disable_xml_rpc() && $utils->isThisPage( 'xmlrpc.php' ) ) {
61 exit( 'Disabled' );
62 }
63
64 // SSL redirect.
65 if ( $settings->get_force_https() && ! is_ssl() ) {
66 if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
67 $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
68
69 if ( $settings->get_force_www() && strpos( $host, 'www.' ) === false ) {
70 $host = 'www.' . $host;
71 }
72
73 wp_safe_redirect( 'https://' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
74 exit;
75 }
76 }
77
78 // Force www.
79 if ( $settings->get_force_www() ) {
80 if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
81 $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
82
83 if ( strpos( $host, 'www.' ) === false ) {
84 wp_safe_redirect( 'https://www.' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
85 exit;
86 }
87 }
88 }
89 }
90
91 /**
92 * @param mixed $headers
93 *
94 * @return mixed
95 */
96 public function check_pingback( $headers ) {
97 $plugin_settings = new PluginSettings();
98 $settings = $plugin_settings->get_plugin_settings();
99
100 if ( $settings->get_disable_xml_rpc() ) {
101 unset( $headers['X-Pingback'] );
102 }
103
104 return $headers;
105 }
106
107 /**
108 * @return bool
109 */
110 public function check_xmlrpc_enabled(): bool {
111 $plugin_settings = new PluginSettings();
112 $settings = $plugin_settings->get_plugin_settings();
113
114 if ( $settings->get_disable_xml_rpc() ) {
115 return false;
116 }
117
118 return true;
119 }
120
121 /**
122 * @return bool
123 */
124 public function check_authentication_password_enabled(): bool {
125 $plugin_settings = new PluginSettings();
126 $settings = $plugin_settings->get_plugin_settings();
127
128 if ( $settings->get_disable_authentication_password() ) {
129 return false;
130 }
131
132 return true;
133 }
134
135 public function litespeed_flush_cache(): void {
136 if ( has_action( 'litespeed_purge_all' ) ) {
137 do_action( 'litespeed_purge_all' );
138 }
139 }
140 }
141