Created
April 19, 2017 14:15
-
-
Save maxyudin/278e461895292706116716e6f0b9c496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
From http://jakeparis.com/2015/05/debugging-wordpress-rewrite-rules/ | |
*/ | |
function jp_debug_rewrite_rules($where = 'head') { | |
// only do this on public side | |
if( is_admin() ) return false; | |
switch($where) { | |
case 'foot' : | |
$filter = 'wp_before_admin_bar_render'; | |
break; | |
case 'footer' : | |
$filter = 'wp_before_admin_bar_render'; | |
break; | |
default : | |
$filter = 'get_header'; | |
break; | |
} | |
add_filter($filter,function(){ | |
global $wp_rewrite, $wp, $template; | |
if (!empty($wp_rewrite->rules)) { ?> | |
<style>h5{background:#000!important;color:#fff!important;padding:1em!important;margin:1em!important}table{margin:1em!important}table td{border:1px solid silver;padding:5px}tr.matchedrule td{border-color:transparent}tr.matchedrule>td{background:HSLA(52,96%,67%,1)}tr.matchedrule+tr.matchedrule>td{background:HSLA(52,96%,67%,.5)}tr.matchedrule table td+td{font-weight:700}</style> | |
<h5>Rewrite Rules</h5> | |
<table> | |
<thead> | |
<tr> | |
<td> | |
<td>Rule | |
<td>Rewrite | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
$i = 1; | |
foreach ($wp_rewrite->rules as $name => $value) { | |
if( $name == $wp->matched_rule ) { | |
echo '<tr class="matchedrule"> | |
<td>' . $i . ' | |
<td>'.$name.' | |
<td>' . $value . ' | |
</tr> | |
<tr class="matchedrule"> | |
<td colspan="3"> | |
<table> | |
<tr><td>Request | |
<td>' . $wp->request . ' | |
<tr><td>Matched Rewrite Query | |
<td title="'.urldecode($wp->matched_query).'">' . $wp->matched_query . ' | |
<tr><td>Loaded template | |
<td>'. basename($template) . ' | |
</table> | |
</td> | |
</tr>'; | |
} else { | |
echo '<tr> | |
<td>'.$i.' | |
<td>'.$name.' | |
<td>'.$value.' | |
</tr>'; | |
} | |
$i++; | |
} | |
?> | |
</tbody> | |
</table> | |
<?php | |
} | |
}); | |
} | |
jp_debug_rewrite_rules(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment