MOON
Server: Apache
System: Linux server1.primemusicproductions.com 4.18.0-477.27.2.el8_8.x86_64 #1 SMP Fri Sep 29 08:21:01 EDT 2023 x86_64
User: primrwxj (1001)
PHP: 8.3.3
Disabled: NONE
Upload Files
File: //home/primrwxj/hampersbypj.com/wp-content/plugins/https-fixer/https-fixer.php
<?php
/**
 * Plugin Name: HTTPS Fixer
 * Plugin URI: https://yourwebsite.com
 * Description: Fixes HTTPS inconsistencies by ensuring WordPress uses HTTPS when available
 * Version: 1.0.0
 * Author: Onaolapo Adeyemi of Crewlane Technologies
 * License: GPL v2 or later
 * Text Domain: https-fixer
 */

// Avoid direct access
if (!defined('ABSPATH')) {
    exit;
}

class HTTPSFixer {
    
    public function __construct() {
        add_action('init', array($this, 'maybe_start_buffer'));
        add_action('shutdown', array($this, 'maybe_end_buffer'));
        add_action('admin_init', array($this, 'check_https_settings'));
        add_filter('script_loader_src', array($this, 'fix_resource_url'));
        add_filter('style_loader_src', array($this, 'fix_resource_url'));
    }
    
    /**
     * Check if we should start output buffering for content replacement
     */
    public function maybe_start_buffer() {
        if (is_ssl() && !$this->is_admin_request()) {
            ob_start(array($this, 'replace_http_with_https'));
        }
    }
    
    /**
     * Check if we should end output buffering
     */
    public function maybe_end_buffer() {
        if (ob_get_length() && is_ssl() && !$this->is_admin_request()) {
            ob_end_flush();
        }
    }
    
    /**
     * Replace HTTP URLs with HTTPS in content
     */
    public function replace_http_with_https($buffer) {
        if (is_ssl()) {
            $home_url = home_url();
            $http_home_url = str_replace('https:', 'http:', $home_url);
            $buffer = str_replace($http_home_url, $home_url, $buffer);
            $buffer = str_replace('http://' . $_SERVER['HTTP_HOST'], 'https://' . $_SERVER['HTTP_HOST'], $buffer);
        }
        return $buffer;
    }
    
    /**
     * Fix resource URLs (scripts, styles)
     */
    public function fix_resource_url($url) {
        if (is_ssl()) {
            $url = str_replace('http://', 'https://', $url);
        }
        return $url;
    }
    
    /**
     * Check if WordPress and Site addresses are properly set to HTTPS
     */
    public function check_https_settings() {
        // Only run for admin users
        if (!current_user_can('manage_options')) {
            return;
        }
        
        // Check if we're using HTTPS
        if (is_ssl()) {
            $siteurl = get_option('siteurl');
            $home = get_option('home');
            
            // If options don't use HTTPS, notify admin
            if (strpos($siteurl, 'https') !== 0 || strpos($home, 'https') !== 0) {
                add_action('admin_notices', array($this, 'admin_notice'));
            }
        }
    }
    
    /**
     * Display admin notice about HTTPS settings
     */
    public function admin_notice() {
        ?>
        <div class="notice notice-warning">
            <p><?php _e('Your site is being accessed via HTTPS, but your WordPress Address or Site Address is not configured to use HTTPS. This may cause mixed content issues.', 'https-fixer'); ?></p>
            <p><?php printf(__('Please update your <a href="%s">General Settings</a> to use HTTPS URLs.', 'https-fixer'), admin_url('options-general.php')); ?></p>
        </div>
        <?php
    }
    
    /**
     * Check if current request is for admin area
     */
    private function is_admin_request() {
        return is_admin() || defined('DOING_AJAX') || defined('DOING_CRON');
    }
}

// Initialize the plugin
new HTTPSFixer();