';
// Check if at least one detection method is enabled
$has_detection = (
!empty(get_option('_wuadblockguard_fast_detection')) ||
!empty(get_option('_wuadblockguard_custom_load_js_enable')) ||
!empty(get_option('_wuadblockguard_network_detection')) ||
!empty(get_option('_wuadblockguard_remote_detection'))
);
if ($adblockguard_enable && $has_detection) {
echo '' . esc_html__('Yes', 'ad-block-guard') . '';
} else {
echo '' . esc_html__('No', 'ad-block-guard') . '';
}
echo '
';
if ($adblockguard_enable && $has_detection) {
echo '
' . esc_html__('Passed', 'ad-block-guard') . '
';
} else {
$error_message = !$adblockguard_enable
? __('AdBlock Guard System is globally disabled in the detection options', 'ad-block-guard')
: __('No detection methods are enabled. At least one detection method must be selected', 'ad-block-guard');
echo '
';
/**
* =============================================================
* "WP Rocket - Cache System" TABLE (only if WP_ROCKET_VERSION)
* =============================================================
*/
if (defined('WP_ROCKET_VERSION')) {
$wp_rocket_settings = get_option('wp_rocket_settings', []);
$conflicting_settings = [
//'minify_concatenate_js' => 'The "Combine JavaScript files" option is not compatible and must be deactivated.',
'manual_preload' => 'The "Activate Preloading" option is enabled in WP Rocket. Your pages are automatically cached. Please ensure you clear caches if you make changes to display or exclusions.',
'defer_all_js' => 'The "Defer All JavaScript files" option creates processing delays for the AdBlock overlay. If these delays are unsatisfactory please disable this option in WP Rocket.',
'delay_js' => 'The "Delay JavaScript" option is enabled in WP Rocket and will cause significant overlay loading delays. If these delays are unsatisfactory please disable this option in WP Rocket.',
];
echo '
';
}
// If you want to ensure directory sizes are computed:
if (!class_exists('\WP_Site_Health')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
}
if (class_exists('\WP_Site_Health')) {
$site_health = \WP_Site_Health::get_instance();
if (method_exists($site_health, 'perform_async_tests')) {
$site_health->perform_async_tests();
}
}
// Then fetch the debug data
if (!class_exists('\WP_Debug_Data')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
}
if (class_exists('\WP_Debug_Data')) {
// true => include sensitive data in the output
$debug_data = \WP_Debug_Data::debug_data(true);
// If any data is returned, convert it into an HTML table
if (!empty($debug_data) && is_array($debug_data)) {
$body .= '
Site Health Debug Info (WP_Debug_Data):
';
$body .= '
';
foreach ($debug_data as $section_key => $section) {
// Each $section has 'label' and 'fields' keys
$section_label = !empty($section['label']) ? $section['label'] : ucfirst($section_key);
$body .= '
' . esc_html($section_label) . '
';
// The 'fields' array typically contains key => value
if (!empty($section['fields']) && is_array($section['fields'])) {
foreach ($section['fields'] as $field_key => $field) {
$field_label = $field['label'] ?? $field_key;
$field_value = is_array($field['value']) || is_object($field['value'])
? wp_json_encode($field['value'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
: $field['value'];
$field_value = is_string($field_value) ? $field_value : '';
// Escape or format as needed
$body .= '
';
$body .= '
' . esc_html($field_label) . '
';
$body .= '
' . nl2br(esc_html($field_value)) . '
';
$body .= '
';
}
}
}
$body .= '
';
} else {
$body .= '
No debug data found or site health is not available.
';
}
} else {
$body .= '
No \WP_Debug_Data data not found or site health is not available.
';
}
// Path to your plugin's log file
$log_path = ADBLOCKGUARD_PLUGIN_DIR . 'ad-block-guard.log';
// Build attachments array
$attachments = array();
// If the log exists, load the last 5k lines & store in a temp file
if (file_exists($log_path)) {
$log_tail = self::get_last_lines($log_path, 5000);
if ($log_tail) {
// Build a custom-named temp file in system temp directory
$timestamp = time();
$named_tmp = sys_get_temp_dir() . "/ad-block-guard-tail-{$timestamp}.log";
// Write the tail
file_put_contents($named_tmp, $log_tail);
// Add to attachments
$attachments[] = $named_tmp;
}
}
// Prepare HTML headers for wp_mail
$headers = ['Content-Type: text/html; charset=UTF-8'];
// Attempt to send
$sent = wp_mail(ADBLOCKGUARD_EMAIL, $subject, $body, $headers, $attachments);
// Clean up the temp file(s)
if ($sent && !empty($attachments)) {
foreach ($attachments as $tmp_file) {
wp_delete_file($tmp_file);
}
}
if ($sent) {
echo '
';
esc_html_e('Your request has been sent successfully!', 'ad-block-guard');
echo '
';
}
/**
* Safely read only the last $maxLines lines from a file
* and return them as a single string.
*/
private static function get_last_lines( $file_path, $max_lines = 5000 ) {
if ( ! file_exists( $file_path ) ) {
return '';
}
// Read entire file into array, ignoring newlines
// (Simple approach — if your log is extremely large, you might need a more efficient method)
$lines = @file( $file_path, FILE_IGNORE_NEW_LINES );
if ( ! is_array( $lines ) ) {
return '';
}
// Slice the last $max_lines lines
$total = count( $lines );
if ( $total > $max_lines ) {
$lines = array_slice( $lines, -$max_lines );
}
// Re-join into one string
return implode( "\n", $lines );
}
}