Created
June 16, 2021 12:33
-
-
Save maciejbis/442ce7256a9a60978f7bc569864055fe to your computer and use it in GitHub Desktop.
Permalink Manager - Site Kit by Google (compatibility snippet)
This file contains hidden or 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_fix_googlesitekit_urls() { | |
global $permalink_manager_ignore_permalink_filters; | |
if(is_user_logged_in() && isset($_GET['permaLink']) && class_exists('Permalink_Manager_Core_Functions')) { | |
$old_url = trim(esc_url_raw($_GET['permaLink']), '/'); | |
$post = Permalink_Manager_Core_Functions::detect_post(null, $old_url, true); | |
if(!empty($post->ID)) { | |
$permalink_manager_ignore_permalink_filters = true; | |
$new_url = trim(get_permalink($post->ID), '/'); | |
$permalink_manager_ignore_permalink_filters = false; | |
if($new_url !== $old_url) { | |
$new_url = urlencode($new_url); | |
$target_url = admin_url("?page=googlesitekit-dashboard&permaLink={$new_url}"); | |
wp_safe_redirect($target_url); | |
exit(); | |
} | |
} | |
} | |
} | |
add_action('init', 'pm_fix_googlesitekit_urls', 30); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment