PluginProbe
Hostinger Tools / 3.0.20
Hostinger Tools v3.0.20
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.20, at includes/Hooks.php

101 lines 2.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_headers', array( $this, 'check_pingback' ) );
15 add_filter( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
16
17 add_action( 'update_option_woocommerce_coming_soon', array( $this, 'litespeed_flush_cache' ) );
18 add_action( 'update_option_woocommerce_store_pages_only', array( $this, 'litespeed_flush_cache' ) );
19 }
20
21 /**
22 * @return void
23 */
24 public function plugins_loaded() {
25 $utils = new Utils();
26 $plugin_settings = new PluginSettings();
27 $settings = $plugin_settings->get_plugin_settings();
28
29 if ( defined( 'WP_CLI' ) && \WP_CLI ) {
30 return;
31 }
32
33 // Xmlrpc.
34 if ( $settings->get_disable_xml_rpc() && $utils->isThisPage( 'xmlrpc.php' ) ) {
35 exit( 'Disabled' );
36 }
37
38 // SSL redirect.
39 if ( $settings->get_force_https() && ! is_ssl() ) {
40 if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
41 $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
42
43 if ( $settings->get_force_www() && strpos( $host, 'www.' ) === false ) {
44 $host = 'www.' . $host;
45 }
46
47 wp_safe_redirect( 'https://' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
48 exit;
49 }
50 }
51
52 // Force www.
53 if ( $settings->get_force_www() ) {
54 if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
55 $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
56
57 if ( strpos( $host, 'www.' ) === false ) {
58 wp_safe_redirect( 'https://www.' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
59 exit;
60 }
61 }
62 }
63 }
64
65 /**
66 * @param mixed $headers
67 *
68 * @return mixed
69 */
70 public function check_pingback( $headers ) {
71 $plugin_settings = new PluginSettings();
72 $settings = $plugin_settings->get_plugin_settings();
73
74 if ( $settings->get_disable_xml_rpc() ) {
75 unset( $headers['X-Pingback'] );
76 }
77
78 return $headers;
79 }
80
81 /**
82 * @return bool
83 */
84 public function check_xmlrpc_enabled(): bool {
85 $plugin_settings = new PluginSettings();
86 $settings = $plugin_settings->get_plugin_settings();
87
88 if ( $settings->get_disable_xml_rpc() ) {
89 return false;
90 }
91
92 return true;
93 }
94
95 public function litespeed_flush_cache(): void {
96 if ( has_action( 'litespeed_purge_all' ) ) {
97 do_action( 'litespeed_purge_all' );
98 }
99 }
100 }
101