Skip to content

Instantly share code, notes, and snippets.

@Pebblo

Pebblo/tw_log_rewrite_rules_array.php Secret

Last active Jun 11, 2020
Embed
What would you like to do?
Example plugin to log the rewrite_rules to debug.log. WP_DEBUG_LOG needs to be enabled on the site.
<?php
/*
* Plugin Name: rewrite_rules log plugin
* Description: This plugin adds a log entry to debug.log each time permalinks are flushed.
* Author: Tony Warwick
* Version: 1.0.0
*/
// ==== Debug ====
if ( ! function_exists('ee_write_log')) {
function ee_write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
// ==== Function to log rewrite_rule ====
function tw_log_rewrite_rules_array($rewrite_array)
{
$e = new \Exception;
ee_write_log(
array(
'time' => date("Y-m-d H:i:s"),
'rewrite_array' => $rewrite_array,
'stacktrace' => $e->getTraceAsString(),
'EE-Check' => isset($rewrite_array['events/?$']) ? 'true' : 'false'
)
);
return $rewrite_array;
}
add_filter('rewrite_rules_array', 'tw_log_rewrite_rules_array', 10, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.