Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions inc/admin/class-configuration-checker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Configuration Checker for WordPress Multisite setup issues.
*
* @package WP_Ultimo
* @subpackage Admin
* @since 2.4.7
*/

namespace WP_Ultimo\Admin;

// Exit if accessed directly
defined('ABSPATH') || exit;

/**
* Checks for common configuration issues that can affect multisite installations.
*
* @since 2.4.7
*/
class Configuration_Checker {

use \WP_Ultimo\Traits\Singleton;

/**
* Initialize the class and register hooks.
*
* @since 2.4.7
* @return void
*/
public function init(): void {

add_action('admin_init', [$this, 'check_cookie_domain_configuration']);
}

/**
* Checks for COOKIE_DOMAIN configuration issues on subdomain multisite installs.
*
* When COOKIE_DOMAIN is defined as false on a subdomain multisite installation,
* it can cause authentication and session issues across subdomains.
*
* @since 2.4.7
* @return void
*/
public function check_cookie_domain_configuration(): void {
if (! is_network_admin()) {
return;
}
// Only check on subdomain installs
if ( ! is_subdomain_install()) {
return;
}

// Check if COOKIE_DOMAIN is defined and set to false
if (defined('COOKIE_DOMAIN') && COOKIE_DOMAIN === false) {
$message = sprintf(
// translators: %1$s is 'wp-config.php', %2$s is 'COOKIE_DOMAIN', %3$s is 'false'
esc_html__('Your %1$s has %2$s set to %3$s, which can cause authentication and session issues on subdomain multisite installations. Please remove this line from your wp-config.php file or set it to an appropriate value.', 'ultimate-multisite'),
'<strong>wp-config.php</strong>',
'<strong>COOKIE_DOMAIN</strong>',
'<strong>false</strong>',
);
$message .= '<br><a href="https://developer.wordpress.org/apis/wp-config-php/#set-cookie-domain" target="_blank" rel="noopener noreferrer">' . esc_html__('Learn more about cookie settings', 'ultimate-multisite') . ' &rarr;</a>';

\WP_Ultimo()->notices->add(
$message,
'warning',
'network-admin',
'cookie_domain_false_warning'
);
}
}
}
5 changes: 5 additions & 0 deletions inc/class-wp-ultimo.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ public function load_public_apis(): void {
*/
if (is_admin()) {
require_once wu_path('inc/functions/admin.php');

/*
* Configuration Checker for multisite setup issues
*/
\WP_Ultimo\Admin\Configuration_Checker::get_instance();
}
}

Expand Down
Loading