PluginProbe
Hostinger Tools / 3.0.3
Hostinger Tools v3.0.3
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.3, at includes/Hooks.php

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