Skip to content

Instantly share code, notes, and snippets.

@boonebgorges
Created March 4, 2024 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boonebgorges/83ad69a81052c5ce43001d7c7523a586 to your computer and use it in GitHub Desktop.
Save boonebgorges/83ad69a81052c5ce43001d7c7523a586 to your computer and use it in GitHub Desktop.
redirect logger
<?php
add_filter(
'wp_redirect',
function( $location ) {
$log_entry = sprintf(
"[%s] - Redirect URI: %s\nStack Trace: %s\n\n",
date( 'Y-m-d H:i:s' ),
$location,
wp_debug_backtrace_summary()
);
$upload_dir = wp_upload_dir();
$log_path = $upload_dir['basedir'] . '/redirect-log.txt';
error_log( $log_entry, 3, $log_path );
return $location;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment