-
-
Save maciejbis/db89eac1b45fe8f28289025984f121c4 to your computer and use it in GitHub Desktop.
List all Permalink Manager redirects
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
<?php | |
function pm_debug_redirects() { | |
if(isset($_GET['debug_urls'])) { | |
global $permalink_manager, $permalink_manager_uris, $permalink_manager_redirects; | |
if(!empty($permalink_manager_uris)) { | |
$uri_post_class = $permalink_manager->functions['uri-functions-post']; | |
$uri_tax_class = $permalink_manager->functions['uri-functions-tax']; | |
$home_url = Permalink_Manager_Helper_Functions::get_permalink_base(); | |
remove_filter( '_get_page_link', array($uri_post_class, 'custom_post_permalinks'), 99, 2); | |
remove_filter( 'page_link', array($uri_post_class, 'custom_post_permalinks'), 99, 2); | |
remove_filter( 'post_link', array($uri_post_class, 'custom_post_permalinks'), 99, 2); | |
remove_filter( 'post_type_link', array($uri_post_class, 'custom_post_permalinks'), 99, 2); | |
remove_filter( 'attachment_link', array($uri_post_class, 'custom_post_permalinks'), 99, 2); | |
remove_filter( 'term_link', array($uri_tax_class, 'custom_tax_permalinks'), 999, 2 ); | |
remove_filter( 'category_link', array($uri_tax_class, 'custom_tax_permalinks'), 999, 2 ); | |
remove_filter( 'tag_link', array($uri_tax_class, 'custom_tax_permalinks'), 999, 2 ); | |
$html = "<table border=\"1\">"; | |
$html .= sprintf("<thead><tr><th>%s</th><th>%s</th></tr></thead>", 'Original URL', 'Permalink Manager URL'); | |
// Native redirects | |
foreach($permalink_manager_uris as $element_id => $uri) { | |
if(is_numeric($element_id)) { | |
$original_permalink = user_trailingslashit(get_permalink($element_id)); | |
$custom_permalink = user_trailingslashit($home_url . "/" . $uri); | |
} else { | |
$term_id = preg_replace("/[^0-9]/", "", $element_id); | |
$term = get_term($term_id); | |
if(empty($term->taxonomy)) { continue; } | |
$original_permalink = user_trailingslashit(get_term_link($term->term_id, $term->taxonomy)); | |
$custom_permalink = user_trailingslashit($home_url . "/" . $uri); | |
} | |
if($original_permalink == $custom_permalink && $original_permalink !== '/') { continue; } | |
$html .= sprintf("<tr><td>%s</td><td>%s</td></tr>", $original_permalink, $custom_permalink); | |
} | |
} | |
// Custom redirects | |
if($permalink_manager_redirects) { | |
$html .= sprintf("<tr><td colspan=\"2\"><strong>%s</strong></td></tr>", 'Custom redirects URLs'); | |
foreach($permalink_manager_redirects as $element_id => $redirects) { | |
if(empty($permalink_manager_uris[$element_id])) { continue; } | |
$custom_permalink = user_trailingslashit($home_url . "/" . $permalink_manager_uris[$element_id]); | |
if(is_array($redirects)) { | |
$redirects = array_values($redirects); | |
$redirects_count = count($redirects); | |
foreach($redirects as $index => $redirect) { | |
$redirect_url = user_trailingslashit($home_url . "/" . $redirect); | |
if($index == 0) { | |
$html .= sprintf("<tr><td>%s</td><td rowspan=\"%d\">%s</td></tr>", $redirect_url, $redirects_count, $custom_permalink); | |
} else { | |
$html .= sprintf("<tr><td>%s</td></tr>", $redirect_url); | |
} | |
} | |
} | |
} | |
} | |
$html .= "</table>"; | |
echo $html; | |
die(); | |
} | |
} | |
add_action('init', 'pm_debug_redirects'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment