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
← All changes | includes/Hooks.php +101 -123 3.0.723.0.39 View file →
@@ -2,156 +2,134 @@
2 2
3 3 namespace Hostinger;
4 4
5 5 use Hostinger\Admin\PluginSettings;
6 -use Hostinger\Admin\Jobs\NotifyMcpJob;
7 -use Hostinger\Mcp\EventHandlerFactory;
8 6 use Hostinger\WpHelper\Utils;
9 7
10 8 defined( 'ABSPATH' ) || exit;
11 9
12 10 class Hooks {
13 - public function __construct() {
14 - add_filter( 'xmlrpc_enabled', array( $this, 'check_xmlrpc_enabled' ) );
15 - add_filter( 'wp_is_application_passwords_available', array( $this, 'check_authentication_password_enabled' ) );
16 - add_filter( 'wp_headers', array( $this, 'check_pingback' ) );
17 - add_action( 'init', array( $this, 'plugins_loaded' ) );
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( 'transition_post_status', array( $this, 'handle_transition_post_status' ), 10, 3 );
21 - add_action( 'updated_option', array( $this, 'handle_updated_option' ), 10, 3 );
22 - }
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' ) );
23 17
24 - public function handle_transition_post_status( string $new_status, string $old_status, \WP_Post $post ): void {
25 - if ( $new_status === 'publish' || $old_status === 'publish' ) {
26 - do_action(
27 - NotifyMcpJob::JOB_NAME,
28 - array(
29 - 'event' => EventHandlerFactory::MCP_EVENT_PAGE_UPDATED,
30 - 'post_id' => $post->ID,
31 - )
32 - );
33 - }
34 - }
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 + }
35 22
36 - public function handle_updated_option( string $option, mixed $old_value, mixed $value ): void {
37 - if ( $option === 'cron' || $this->is_transient( $option ) ) {
38 - return;
39 - }
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 + }
40 27
41 - if ( $old_value !== $value ) {
42 - do_action( NotifyMcpJob::JOB_NAME, array( 'event' => EventHandlerFactory::MCP_EVENT_UPDATED ) );
43 - }
28 + if ( ! in_array( 'hostinger/hostinger.php', $options['plugins'], true ) ) {
29 + return;
30 + }
44 31
45 - if ( $option === HOSTINGER_PLUGIN_SETTINGS_OPTION && isset( $value['optin_mcp'] ) && isset( $old_value['optin_mcp'] ) ) {
46 - if ( $old_value['optin_mcp'] !== $value['optin_mcp'] ) {
47 - do_action(
48 - NotifyMcpJob::JOB_NAME,
49 - array(
50 - 'event' => EventHandlerFactory::MCP_EVENT_OPTIN_TOGGLED,
51 - 'value' => $value['optin_mcp'],
52 - )
53 - );
54 - }
55 - }
56 - }
32 + $settings = get_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, array() );
57 33
58 - /**
59 - * @return void
60 - */
61 - public function plugins_loaded() {
62 - $utils = new Utils();
63 - $plugin_settings = new PluginSettings();
64 - $settings = $plugin_settings->get_plugin_settings();
34 + if ( ! empty( $settings['disable_authentication_password'] ) ) {
35 + return;
36 + }
65 37
66 - if ( defined( 'WP_CLI' ) && \WP_CLI ) {
67 - return;
68 - }
38 + $options = new DefaultOptions();
39 + $options->configure_authentication_password();
40 + }
69 41
70 - // Xmlrpc.
71 - if ( $settings->get_disable_xml_rpc() && $utils->isThisPage( 'xmlrpc.php' ) ) {
72 - exit( 'Disabled' );
73 - }
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();
74 49
75 - // SSL redirect.
76 - if ( $settings->get_force_https() && ! is_ssl() ) {
77 - if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
78 - $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
50 + if ( defined( 'WP_CLI' ) && \WP_CLI ) {
51 + return;
52 + }
79 53
80 - if ( $settings->get_force_www() && strpos( $host, 'www.' ) === false ) {
81 - $host = 'www.' . $host;
82 - }
54 + // Xmlrpc.
55 + if ( $settings->get_disable_xml_rpc() && $utils->isThisPage( 'xmlrpc.php' ) ) {
56 + exit( 'Disabled' );
57 + }
83 58
84 - wp_safe_redirect( 'https://' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
85 - exit;
86 - }
87 - }
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'] ) );
88 63
89 - // Force www.
90 - if ( $settings->get_force_www() ) {
91 - if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
92 - $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
64 + if ( $settings->get_force_www() && strpos( $host, 'www.' ) === false ) {
65 + $host = 'www.' . $host;
66 + }
93 67
94 - if ( strpos( $host, 'www.' ) === false ) {
95 - wp_safe_redirect( 'https://www.' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
96 - exit;
97 - }
98 - }
99 - }
100 - }
68 + wp_safe_redirect( 'https://' . $host . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 301 );
69 + exit;
70 + }
71 + }
101 72
102 - /**
103 - * @param mixed $headers
104 - *
105 - * @return mixed
106 - */
107 - public function check_pingback( $headers ) {
108 - $plugin_settings = new PluginSettings();
109 - $settings = $plugin_settings->get_plugin_settings();
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'] ) );
110 77
111 - if ( $settings->get_disable_xml_rpc() ) {
112 - unset( $headers['X-Pingback'] );
113 - }
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 + }
114 85
115 - return $headers;
116 - }
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();
117 94
118 - /**
119 - * @param bool $enabled
120 - *
121 - * @return bool
122 - */
123 - public function check_xmlrpc_enabled( bool $enabled ): bool {
124 - $plugin_settings = new PluginSettings();
125 - $settings = $plugin_settings->get_plugin_settings();
95 + if ( $settings->get_disable_xml_rpc() ) {
96 + unset( $headers['X-Pingback'] );
97 + }
126 98
127 - if ( $settings->get_disable_xml_rpc() ) {
128 - return false;
129 - }
99 + return $headers;
100 + }
130 101
131 - return $enabled;
132 - }
102 + /**
103 + * @return bool
104 + */
105 + public function check_xmlrpc_enabled(): bool {
106 + $plugin_settings = new PluginSettings();
107 + $settings = $plugin_settings->get_plugin_settings();
133 108
134 - /**
135 - * @return bool
136 - */
137 - public function check_authentication_password_enabled(): bool {
138 - $plugin_settings = new PluginSettings();
139 - $settings = $plugin_settings->get_plugin_settings();
109 + if ( $settings->get_disable_xml_rpc() ) {
110 + return false;
111 + }
140 112
141 - if ( $settings->get_disable_authentication_password() ) {
142 - return false;
143 - }
113 + return true;
114 + }
144 115
145 - return true;
146 - }
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();
147 122
148 - public function litespeed_flush_cache(): void {
149 - if ( has_action( 'litespeed_purge_all' ) ) {
150 - do_action( 'litespeed_purge_all' );
151 - }
152 - }
123 + if ( $settings->get_disable_authentication_password() ) {
124 + return false;
125 + }
153 126
154 - private function is_transient( $option ): bool {
155 - return str_contains( $option, '_transient' );
156 - }
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 + }
157 135 }