# hostinger/3.0.0/includes/Hooks.php

Hostinger Tools, version 3.0.0. 84 lines.

- Page: https://pluginprobe.com/plugins/hostinger/3.0.0/code/includes/Hooks.php
- Raw: https://pluginprobe.com/plugins/hostinger/3.0.0/raw/includes/Hooks.php
- Modified: 2024-06-04T12:01:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/hostinger/3.0.0/code/includes/Hooks.php#L10-L20`.

```php
<?php

namespace Hostinger;

use Hostinger\Admin\PluginSettings;
use Hostinger\WpHelper\Utils;

defined( 'ABSPATH' ) || exit;

class Hooks {
	public function __construct() {
        // XMLRpc / Force SSL
        add_filter( 'xmlrpc_enabled', array( $this, 'check_xmlrpc_enabled' ) );
        add_filter( 'wp_headers', array( $this, 'check_pingback' ));
        add_filter( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
	}

    /**
     * @return void
     */
    public function plugins_loaded() {
        $utils = new Utils();
        $plugin_settings = new PluginSettings();
        $settings = $plugin_settings->get_plugin_settings();

        if ( defined( 'WP_CLI' ) && WP_CLI ) {
            return;
        }

        // Xmlrpc.
        if($settings->get_disable_xml_rpc() && $utils->isThisPage('xmlrpc.php')) {
            exit('Disabled');
        }

        // SSL redirect.
        if($settings->get_force_https() && !is_ssl()) {
            $host = $_SERVER['HTTP_HOST'];

            if ($settings->get_force_www() && strpos($_SERVER['HTTP_HOST'], 'www.') === false) {
                $host = 'www.'.$host;
            }

            wp_redirect('https://' . $host . $_SERVER['REQUEST_URI'], 301);
            exit();
        }

        // Force www.
        if ($settings->get_force_www() && strpos($_SERVER['HTTP_HOST'], 'www.') === false) {
            wp_redirect('https://www.' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301);
            exit;
        }
    }

    /**
     * @param $headers
     *
     * @return mixed
     */
    public function check_pingback( $headers ) {
        $plugin_settings = new PluginSettings();
        $settings = $plugin_settings->get_plugin_settings();

        if($settings->get_disable_xml_rpc()) {
            unset($headers['X-Pingback']);
        }

        return $headers;
    }

    /**
     * @return bool
     */
    public function check_xmlrpc_enabled(): bool {
        $plugin_settings = new PluginSettings();
        $settings = $plugin_settings->get_plugin_settings();

        if($settings->get_disable_xml_rpc()) {
            return false;
        }

        return true;
    }
}

```
