' . esc_html__( 'Tip: Fewer warnings and no fails generally mean smoother long-running tasks.', 'ai-content-wizard') . '
';
// Современное модальное окно для подсказок
echo '
';
echo '
';
echo '
';
echo '
' . esc_html__('Help message for your host', 'ai-content-wizard') . '
';
echo '
';
echo '
';
echo ' ';
echo '
';
echo '
';
echo ' ';
echo ' ';
echo '
';
echo '
';
echo '
';
// JS: обработка кликов по ссылкам и копирование
echo '';
echo '
'; // .acw-sys-wrap
}
function ai_content_wizard_get_help_message($helpId) {
switch ($helpId) {
case 'php-version':
return __('Dear Hosting Provider,
I am writing to request an upgrade to the PHP version on my server. My website requires PHP version 7.1 or higher for optimal performance and security. Could you please assist with upgrading the PHP version on my server?
Thank you for your support.', 'ai-content-wizard');
case 'memory-limit':
return __('Dear Hosting Provider,
My website requires at least 256M of PHP memory limit to operate efficiently. I kindly ask for your assistance in increasing the PHP memory limit on my server to meet this requirement.
Thank you for your help.', 'ai-content-wizard');
case 'max-execution-time':
return __('Dear Hosting Provider,
I am encountering issues with timeouts on my website. To resolve this, I need the PHP maximum execution time to be at least 300 seconds. Could you please increase this limit on my server?
Your assistance is greatly appreciated.', 'ai-content-wizard');
case 'seo-plugin':
return __('Dear Plugin Developer,
I am using the AI Content Wizard plugin on my WordPress website and noticed it recommends having an SEO plugin like Yoast, Rank Math, or All in One SEO for optimal features. Can you please provide guidance or assistance in selecting and installing the right SEO plugin for my site?
Thank you for your support.', 'ai-content-wizard');
case 'uploads-directory':
return __('Dear Hosting Provider,
My website requires the ability to upload files and generate media, but currently, the uploads directory is not writable. Can you please assist in ensuring that the uploads directory on my server is writable?
Thank you for your help.', 'ai-content-wizard');
case 'http-timeout':
return __('Dear Hosting Provider,
I am experiencing issues with HTTP request timeouts on my website. To resolve this, I need the server to handle HTTP requests with a timeout of at least 15 seconds. Could you please assist in adjusting this setting?
Your help is much appreciated.', 'ai-content-wizard');
case 'max-input-time':
return __('Dear Hosting Provider,
I am encountering issues with long-running input operations that require a higher PHP max_input_time. Please increase max_input_time to at least 300 seconds on my server.
Thank you.', 'ai-content-wizard');
case 'default-socket-timeout':
return __('Dear Hosting Provider,
My website is experiencing socket timeouts during HTTP requests. To resolve this, please increase default_socket_timeout to at least 15 seconds.
Thank you for your assistance.', 'ai-content-wizard');
case 'litespeed-request-timeout':
return __('Dear Hosting Provider,
I have noticed that LiteSpeed is terminating requests after 240 seconds by default. Please increase the LSAPI Request Timeout to at least 500 seconds to ensure long-running operations complete successfully.
Thank you for your assistance.', 'ai-content-wizard');
case 'apache-timeout':
return __('Dear Hosting Provider,
Please set Apache Timeout to at least 500 seconds to support long-running requests. This can be configured in the Apache httpd.conf or appropriate includes.
Thank you.', 'ai-content-wizard');
case 'apache-reqtimeout':
return __('Dear Hosting Provider,
Please adjust Apache mod_reqtimeout (RequestReadTimeout) to avoid premature terminations. Recommended: header=0 body=0 (disabled) or values equivalent to ≥ 500 seconds.
Thank you.', 'ai-content-wizard');
case 'nginx-fastcgi-read-timeout':
return __('Dear Hosting Provider,
Please set Nginx fastcgi_read_timeout to 500–600 seconds to allow long-running PHP responses.
Thank you.', 'ai-content-wizard');
case 'nginx-proxy-read-timeout':
return __('Dear Hosting Provider,
If a reverse proxy is used, please set Nginx proxy_read_timeout to 500–600 seconds to prevent upstream timeouts.
Thank you.', 'ai-content-wizard');
case 'php-fpm-request-terminate-timeout':
return __('Dear Hosting Provider,
Please set PHP-FPM request_terminate_timeout to 0 (no limit) or at least 500 seconds in the pool configuration file to avoid killing long-running PHP scripts.
Thank you.', 'ai-content-wizard');
default:
error_log('Returning default message for unknown ID: ' . $helpId); // Для отладки
return __('No specific help message available for this issue.', 'ai-content-wizard');
}
}
function ai_content_wizard_system_check() {
$results = [];
// Проверка версии PHP
$results[] = [
'PHP Version >= 7.1',
phpversion(),
'7.1',
version_compare(phpversion(), '7.1', '>=') ? 'OK' : 'Fail',
'Ensure your server is running PHP version 7.1 or higher for optimal performance and security.',
'php-version'
];
// Проверка памяти
$memory_limit = ini_get('memory_limit');
$required_memory = '256M';
$results[] = [
'Memory Limit >= 256M',
$memory_limit,
$required_memory,
ai_content_wizard_compare_memory($memory_limit, $required_memory) ? 'OK' : 'Fail',
'Increase the PHP memory limit to at least 256M to handle intensive operations.',
'memory-limit'
];
// Проверка таймаута
$max_execution_time = ini_get('max_execution_time');
$execution_status = $max_execution_time < 100 ? 'Fail' : ($max_execution_time < 300 ? 'warning' : 'OK');
$execution_color = $execution_status === 'OK' ? 'green' : ($execution_status === 'warning' ? 'orange' : 'red');
$results[] = [
'Max Execution Time',
$max_execution_time . ' seconds',
'>= 300 seconds',
$execution_status,
'Set the PHP maximum execution time to at least 300 seconds to prevent timeouts during resource-intensive tasks.',
'max-execution-time'
];
// Проверка времени ожидания ввода (max_input_time)
$max_input_time = ini_get('max_input_time');
$input_status = ($max_input_time >= 300) ? 'OK' : 'warning';
$results[] = [
'Max Input Time',
$max_input_time . ' seconds',
'>= 300 seconds',
$input_status,
'Set the PHP max_input_time to at least 300 seconds to allow long-running input operations.',
'max-input-time'
];
// Проверка таймаута сокета (default_socket_timeout)
$socket_timeout = ini_get('default_socket_timeout');
$socket_status = ($socket_timeout >= 15) ? 'OK' : 'warning';
$results[] = [
'Default Socket Timeout',
$socket_timeout . ' seconds',
'>= 15 seconds',
$socket_status,
'Increase default_socket_timeout to at least 15 seconds to avoid premature socket closures.',
'default-socket-timeout'
];
// Web server & SAPI (informational row)
$server_software = $_SERVER['SERVER_SOFTWARE'] ?? 'unknown';
$sapi = php_sapi_name();
$results[] = [
'Web Server / PHP SAPI',
$server_software . ' / ' . $sapi,
'—',
'OK',
'Detected runtime environment (informational).',
'web-server-info'
];
// Effective Request Timeout from last probe (if any)
$probe_summary = get_option('acw_timeout_probe_last');
if (is_array($probe_summary) && !empty($probe_summary['effective'])) {
$eff = intval($probe_summary['effective']);
$req = '>= 500 seconds';
$status = ($eff >= 500) ? 'OK' : (($eff >= 300) ? 'warning' : 'Fail');
$results[] = [
'Effective Request Timeout (probe)',
$eff . ' seconds',
$req,
$status,
'Detected limiter: ' . ($probe_summary['suspected'] ?? 'Unknown') . '. Consider raising limits to meet recommended value.',
'effective-probe-timeout'
];
}
// LiteSpeed timeout check
if (stripos($server_software, 'litespeed') !== false) {
// LiteSpeed по умолчанию обрывает запросы через 240 секунд
$lts_ini = ini_get('litespeed.req_timeout');
$lts_current = ($lts_ini && $lts_ini > 0) ? $lts_ini . ' seconds' : 'Unknown';
$lts_required = '500–600 seconds';
$lts_status = ($lts_ini && $lts_ini >= 500) ? 'OK' : 'Fail';
$lts_recommendation = 'Set LiteSpeed LSAPI Request Timeout to 500–600 seconds in the server configuration (external app settings).';
$results[] = [
'LiteSpeed Request Timeout',
$lts_current,
$lts_required,
$lts_status,
$lts_recommendation,
'litespeed-request-timeout'
];
}
// Apache checks
if (stripos($server_software, 'apache') !== false) {
$results[] = [
'Apache Timeout',
'Unknown',
'>= 500 seconds',
'warning',
'Set Apache Timeout to ≥ 500 seconds for long-running requests (httpd.conf). Default may be 300s.',
'apache-timeout'
];
$results[] = [
'Apache mod_reqtimeout (RequestReadTimeout)',
'Unknown',
'header=0 body=0 (disabled) or ≥ 500 seconds',
'warning',
'Adjust RequestReadTimeout to avoid premature termination during large uploads/long responses.',
'apache-reqtimeout'
];
}
// Nginx checks
if (stripos($server_software, 'nginx') !== false || stripos($sapi, 'fpm') !== false) {
$results[] = [
'Nginx fastcgi_read_timeout',
'Unknown',
'>= 500 seconds',
'warning',
'Set fastcgi_read_timeout to 500–600s in nginx.conf / site config to allow long PHP responses.',
'nginx-fastcgi-read-timeout'
];
$results[] = [
'Nginx proxy_read_timeout',
'Unknown',
'>= 500 seconds',
'warning',
'If using a reverse proxy, set proxy_read_timeout to 500–600s to prevent upstream timeouts.',
'nginx-proxy-read-timeout'
];
}
// PHP-FPM check
if (stripos($sapi, 'fpm') !== false) {
$results[] = [
'PHP-FPM request_terminate_timeout',
'Unknown',
'0 (disabled) or ≥ 500 seconds',
'warning',
'Set request_terminate_timeout = 0 (no limit) or ≥ 500s in pool.d/*.conf.',
'php-fpm-request-terminate-timeout'
];
}
// Проверка наличия SEO плагинов
$seo_plugin_status = ai_content_wizard_is_seo_plugin_active() ? 'OK' : 'warning';
$results[] = [
'SEO Plugin Installed',
ai_content_wizard_get_seo_plugins_list(),
'Yoast, Rank Math, or All in One SEO',
$seo_plugin_status,
'Having an SEO plugin like Yoast, Rank Math, or All in One SEO is recommended for optimal SEO features.',
'seo-plugin'
];
// Проверка возможности записи в директорию
$upload_dir = wp_upload_dir();
$upload_dir_writable = is_writable($upload_dir['basedir']);
$results[] = [
'Writable Uploads Directory',
$upload_dir_writable ? 'Writable' : 'Not Writable',
'Writable',
$upload_dir_writable ? 'OK' : 'Fail',
'Ensure the uploads directory is writable to allow file uploads and media generation.',
'uploads-directory'
];
// Проверка таймаута HTTP-запросов
$http_timeout_ok = ai_content_wizard_check_http_timeout();
$results[] = [
'HTTP Request Timeout',
$http_timeout_ok ? 'OK' : 'Fail',
'OK',
$http_timeout_ok ? 'OK' : 'Fail',
'Ensure the server can handle HTTP requests with a timeout of at least 15 seconds.',
'http-timeout'
];
return $results;
}
function ai_content_wizard_is_seo_plugin_active() {
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
return is_plugin_active('wordpress-seo/wp-seo.php') || is_plugin_active('seo-by-rank-math/rank-math.php') || is_plugin_active('all-in-one-seo-pack/all_in_one_seo_pack.php');
}
function ai_content_wizard_get_seo_plugins_list() {
$plugins = [];
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
$plugins[] = 'Yoast SEO';
}
if (is_plugin_active('seo-by-rank-math/rank-math.php')) {
$plugins[] = 'Rank Math SEO';
}
if (is_plugin_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) {
$plugins[] = 'All in One SEO Pack';
}
return implode(', ', $plugins) ?: 'None';
}
function ai_content_wizard_compare_memory($current_limit, $required_limit) {
$current_bytes = ai_content_wizard_convert_to_bytes($current_limit);
$required_bytes = ai_content_wizard_convert_to_bytes($required_limit);
return $current_bytes >= $required_bytes;
}
function ai_content_wizard_convert_to_bytes($value) {
$value = trim($value);
$last = strtolower($value[strlen($value) - 1]);
$value = (int) $value;
switch($last) {
case 'g':
$value *= 1024;
case 'm':
$value *= 1024;
case 'k':
$value *= 1024;
}
return $value;
}
function ai_content_wizard_check_http_timeout() {
// Устанавливаем рекомендуемый таймаут
$recommended_timeout = 15; // секунды
// Делаем тестовый запрос для проверки таймаута
$response = wp_remote_post('https://example.com', ['timeout' => $recommended_timeout]);
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
// Проверяем, не связана ли ошибка с таймаутом
return strpos($error_message, 'timed out') === false;
}
return true;
}
add_action('admin_post_acw_export_diagnostics', 'ai_content_wizard_export_diagnostics');
function ai_content_wizard_export_diagnostics() {
if (!current_user_can('manage_options') || !check_admin_referer('acw_export_diag')) {
wp_die(__('Not allowed', 'ai-content-wizard'));
}
$diag = ai_content_wizard_collect_diagnostics();
nocache_headers();
header('Content-Type: application/json; charset=utf-8');
header('Content-Disposition: attachment; filename="acw-diagnostics-' . date('Ymd-His') . '.json"');
echo wp_json_encode($diag, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
add_action('admin_post_acw_phpinfo', 'ai_content_wizard_phpinfo');
function ai_content_wizard_phpinfo() {
if (!current_user_can('manage_options') || !check_admin_referer('acw_phpinfo')) {
wp_die(__('Not allowed', 'ai-content-wizard'));
}
echo 'PHP Info';
ob_start();
phpinfo();
$phpinfo = ob_get_clean();
echo $phpinfo;
echo '';
exit;
}