Skip to content

Instantly share code, notes, and snippets.

@maciejbis
Created June 16, 2021 12:33
Show Gist options
  • Save maciejbis/442ce7256a9a60978f7bc569864055fe to your computer and use it in GitHub Desktop.
Save maciejbis/442ce7256a9a60978f7bc569864055fe to your computer and use it in GitHub Desktop.
Permalink Manager - Site Kit by Google (compatibility snippet)
<?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