__( 'Settings', 'wp-domain-mapping' ), 'dns-setup' => __( 'DNS Setup', 'wp-domain-mapping' ), 'health' => __( 'Domain Health', 'wp-domain-mapping' ), 'import-export' => __( 'Import/Export', 'wp-domain-mapping' ) ); // Display success messages for tabs if ( isset( $_GET['checked'] ) && $_GET['checked'] && $current_tab === 'health' ) { echo '

' . __( 'Domain health check completed.', 'wp-domain-mapping' ) . '

'; } if ( isset( $_GET['checking'] ) && $_GET['checking'] && $current_tab === 'health' ) { echo '

' . __( 'Domain health check started. The check is running in the background.', 'wp-domain-mapping' ) . '

'; } if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && $current_tab === 'health' ) { echo '

' . __( 'Settings saved.', 'wp-domain-mapping' ) . '

'; } if ( isset( $_GET['imported'] ) && $_GET['imported'] && $current_tab === 'import-export' ) { $count = intval( $_GET['imported'] ); echo '

' . sprintf( _n( '%d domain mapping imported successfully.', '%d domain mappings imported successfully.', $count, 'wp-domain-mapping' ), $count ) . '

'; } if ( isset( $_GET['export'] ) && $_GET['export'] == 'success' && $current_tab === 'import-export' ) { echo '

' . __( 'Domain mappings exported successfully.', 'wp-domain-mapping' ) . '

'; } ?>
$tab_label ) : ?>
>
>
>
>

' . esc_html( $dm_cname ) . '' ); ?>

CNAME @ 3600
CNAME www 3600

' . esc_html( $dm_ipaddress ) . '' ); ?>

$ip ) : ?>
A @ 3600
A www 3600

' . esc_html( $dm_cname ) . '' ); ?>

CNAME @ 3600
CNAME www 3600

' . esc_html( $dm_ipaddress ) . '' ); ?>

$ip ) : ?>
A @ 3600
A www 3600

' . esc_html( WP_CONTENT_DIR ) . '' ); ?>
' . esc_html( SUNRISE ) . '' ); ?> define( 'SUNRISE', 'on' );



get_var( "SHOW TABLES LIKE '$table'" ) != $table ) { $tables_exist = false; break; } } ?>
get_results(" SELECT d.*, b.domain as original_domain, b.path FROM {$tables['domains']} d JOIN {$wpdb->blogs} b ON d.blog_id = b.blog_id ORDER BY d.blog_id ASC, d.active DESC "); // Get health check results $health_results = get_site_option( 'dm_domain_health_results', array() ); // Check if batch processing is in progress $health_check_progress = get_site_option( 'dm_health_check_progress', false ); ?>


domain ); $health_data = isset( $health_results[$domain_key] ) ? $health_results[$domain_key] : null; $site_name = get_blog_option( $domain->blog_id, 'blogname', __( 'Unknown', 'wp-domain-mapping' ) ); ?>
domain ); ?> active ) : ?>
original_domain . $domain->path ); ?>

%s', esc_url($wpcy_link), __('文派叶子 🍃(WPCY.COM)', 'wp-domain-mapping') ) ); ?>

>

>

>

>


>


>

blog_id domain active
1 example.com 1
2 example.org 0
create_tables(); if ( isset($current_site->path) && $current_site->path != "/" ) { wp_die( sprintf( esc_html__( "Warning! This plugin will only work if WordPress is installed in the root directory of your webserver. It is currently installed in '%s'.", "wp-domain-mapping" ), esc_html( $current_site->path ) )); } $tables = dm_get_table_names(); $total_domains = $wpdb->get_var( "SELECT COUNT(*) FROM {$tables['domains']}" ); $primary_domains = $wpdb->get_var( "SELECT COUNT(*) FROM {$tables['domains']} WHERE active = 1" ); $edit_row = false; if ( isset( $_GET['edit_domain'] ) ) { $edit_domain = sanitize_text_field( $_GET['edit_domain'] ); $edit_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$tables['domains']} WHERE domain = %s", $edit_domain )); } // Include the admin page template require_once WP_DOMAIN_MAPPING_DIR_PATH . 'admin/domains-page.php'; } /** * Render user domain mapping page */ function dm_render_user_page( $protocol = null, $domains = null ) { global $wpdb; if ( null === $protocol ) { $protocol = is_ssl() ? 'https://' : 'http://'; } if ( null === $domains ) { $domains = dm_get_domains_by_blog_id( $wpdb->blogid ); } // Include original user page content require_once WP_DOMAIN_MAPPING_DIR_PATH . 'admin/user-page.php'; } /** * Check COOKIE_DOMAIN configuration status in a performance-friendly way * Uses caching to avoid reading wp-config.php on every page load * * @return array Status information about COOKIE_DOMAIN configuration */ function dm_check_cookie_domain_status() { // Cache key for storing the check result $cache_key = 'dm_cookie_domain_check_' . md5(ABSPATH); $cached_result = get_transient($cache_key); // Return cached result if still valid (cached for 1 hour) if ($cached_result !== false) { // Always check runtime values as they can change $cached_result['runtime_defined'] = defined('COOKIE_DOMAIN'); $cached_result['is_mapped_request'] = defined('MAPPED_DOMAIN') && MAPPED_DOMAIN; // Update debug info if (defined('WP_DEBUG') && WP_DEBUG) { $debug_parts = array(); $debug_parts[] = 'Runtime defined: ' . ($cached_result['runtime_defined'] ? 'Yes' : 'No'); if ($cached_result['runtime_defined']) { $debug_parts[] = 'Value: ' . COOKIE_DOMAIN; } $debug_parts[] = 'Mapped request: ' . ($cached_result['is_mapped_request'] ? 'Yes' : 'No'); $cached_result['debug_info'] = 'Debug: ' . implode(', ', $debug_parts); } return $cached_result; } // Initialize result array $result = array( 'is_optimal' => false, 'has_warning' => false, 'message' => '', 'debug_info' => '', 'wp_config_has_definition' => false, 'runtime_defined' => defined('COOKIE_DOMAIN'), 'is_mapped_request' => defined('MAPPED_DOMAIN') && MAPPED_DOMAIN ); // Check if COOKIE_DOMAIN is defined in wp-config.php $wp_config_path = ABSPATH . 'wp-config.php'; if (file_exists($wp_config_path)) { // Use a more efficient approach - only read first part of file $file_handle = fopen($wp_config_path, 'r'); if ($file_handle) { $line_count = 0; $max_lines = 200; // Only check first 200 lines for performance while (($line = fgets($file_handle)) !== false && $line_count < $max_lines) { $line = trim($line); $line_count++; // Skip empty lines and comments if (empty($line) || substr($line, 0, 2) === '//' || substr($line, 0, 1) === '#' || substr($line, 0, 2) === '/*') { continue; } // Stop at the end of configuration section if (strpos($line, "require_once") !== false && strpos($line, "wp-settings.php") !== false) { break; } // Check for COOKIE_DOMAIN definition if (preg_match('/define\s*\(\s*[\'"]COOKIE_DOMAIN[\'"]/', $line)) { $result['wp_config_has_definition'] = true; break; } } fclose($file_handle); } } // Determine status and message - Always allow access, just show warnings if (!$result['wp_config_has_definition']) { $result['is_optimal'] = true; if ($result['runtime_defined'] && $result['is_mapped_request']) { $result['message'] = __('Not defined in wp-config.php (optimal). Currently managed by domain mapping.', 'wp-domain-mapping'); } else { $result['message'] = __('Not defined in wp-config.php (optimal for domain mapping)', 'wp-domain-mapping'); } } else { // Even if defined in wp-config.php, don't block access - just show warning if ($result['runtime_defined']) { $result['has_warning'] = true; $result['message'] = __('Defined in wp-config.php but currently working', 'wp-domain-mapping'); } else { $result['has_warning'] = true; $result['message'] = __('Defined in wp-config.php (may affect some domain mapping features)', 'wp-domain-mapping'); } } // Add debug information if WP_DEBUG is enabled if (defined('WP_DEBUG') && WP_DEBUG) { $debug_parts = array(); $debug_parts[] = 'Runtime defined: ' . ($result['runtime_defined'] ? 'Yes' : 'No'); if ($result['runtime_defined']) { $debug_parts[] = 'Value: ' . COOKIE_DOMAIN; } $debug_parts[] = 'Mapped request: ' . ($result['is_mapped_request'] ? 'Yes' : 'No'); $debug_parts[] = 'Config file check: ' . ($result['wp_config_has_definition'] ? 'Found' : 'Not found'); $result['debug_info'] = 'Debug: ' . implode(', ', $debug_parts); } // Cache the result for 1 hour (exclude runtime values from cache) $cache_data = $result; unset($cache_data['runtime_defined'], $cache_data['is_mapped_request'], $cache_data['debug_info']); set_transient($cache_key, $cache_data, HOUR_IN_SECONDS); return $result; } /** * Legacy function to prevent blocking access - always returns false * This ensures backward compatibility with any existing checks */ function dm_cookie_domain_is_blocking() { return false; } /** * Safe check for COOKIE_DOMAIN without blocking access * This can be used throughout the plugin without causing access issues */ function dm_is_cookie_domain_safe() { $status = dm_check_cookie_domain_status(); return $status['is_optimal'] || $status['has_warning']; }