PluginProbe
Hostinger Tools / 3.0.39
Hostinger Tools v3.0.39
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.39, at includes/Hooks.php

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