| Server IP : 38.190.208.107 / Your IP : 216.73.216.51 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.10/wp-content/plugins/clarity-seo/includes/ |
Upload File : |
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
// Advanced Redirect Manager (expands basic redirects with regex, 404 logging, export)
function clarity_seo_handle_redirects() {
if (is_404() && isset($_SERVER['REQUEST_URI'])) {
$redirects = get_option('clarity_seo_redirects', []);
$current_url = sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI']));
// Log 404
$logs = get_option('clarity_seo_404_logs', []);
$logs[] = ['url' => $current_url, 'time' => current_time('mysql'), 'referer' => wp_get_referer()];
update_option('clarity_seo_404_logs', array_slice($logs, -100)); // Keep last 100
// Check for match, support regex
foreach ($redirects as $from => $to) {
if (preg_match('#^' . str_replace('#', '\\#', $from) . '$#', $current_url)) {
wp_safe_redirect($to, 301);
exit;
}
}
}
}
// 404 Monitor callback
function clarity_seo_404_callback() {
$logs = get_option('clarity_seo_404_logs', []);
?>
<div class="wrap">
<h1><?php esc_html_e('404 Monitor', 'clarity-seo'); ?></h1>
<?php if (!empty($logs)): ?>
<table class="wp-list-table widefat fixed striped">
<thead><tr><th>URL</th><th>Time</th><th>Referer</th></tr></thead>
<tbody>
<?php foreach (array_reverse($logs) as $log): ?>
<tr>
<td><?php echo esc_html($log['url']); ?></td>
<td><?php echo esc_html($log['time']); ?></td>
<td><?php echo esc_html($log['referer']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
<input type="hidden" name="action" value="clarity_seo_export_404">
<?php wp_nonce_field('clarity_seo_export_404'); ?>
<?php submit_button(__('Export CSV', 'clarity-seo'), 'secondary'); ?>
</form>
<?php else: ?>
<p><?php esc_html_e('No 404 logs yet.', 'clarity-seo'); ?></p>
<?php endif; ?>
</div>
<?php
}
// Export 404 logs to CSV
add_action('admin_post_clarity_seo_export_404', function() {
check_admin_referer('clarity_seo_export_404');
$logs = get_option('clarity_seo_404_logs', []);
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="404_logs.csv"');
$output = fopen('php://output', 'w');
fputcsv($output, ['URL', 'Time', 'Referer']);
foreach ($logs as $log) {
fputcsv($output, $log);
}
exit;
});
?>