';
/**
* =============================================================
* "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 not compatible and must be deactivated.',
'defer_all_js' => 'The "Defer All JavaScript files" option creates processing delays and must be deactivated.',
'delay_js' => 'The "Delay JavaScript" option creates significant overlay delays and must be deactivated.',
];
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'])
? print_r($field['value'], true)
: $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 ) {
@unlink( $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 );
}
}