Skip to content

Instantly share code, notes, and snippets.

@khromov
Last active March 2, 2016 14:52
Show Gist options
  • Select an option

  • Save khromov/3cb8a35c7365552ceb9e to your computer and use it in GitHub Desktop.

Select an option

Save khromov/3cb8a35c7365552ceb9e to your computer and use it in GitHub Desktop.
Set correct preview link when using WordPress MU Domain Mapping Plugin
<?php
add_filter('get_sample_permalink_html', function($return, $id, $new_title, $new_slug) {
$post_type_object = get_post_type_object(get_post_type($id));
//Append rewrite slug if it exists
if(isset($post_type_object->rewrite['slug'])) {
$url_append = '/' . $post_type_object->rewrite['slug'];
}
else {
$url_append = '';
}
//Bail if domain URL doesn't exist
if(!function_exists('domain_mapping_siteurl')) {
return $return;
}
//Try to find mapped domain
global $wpdb;
$domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$wpdb->blogid}' AND active='1' LIMIT 1" );
//Mapped domain found
if($domain) {
//Replace the preview link
$return = preg_replace('/(<span id=\"sample-permalink\"[^>]*>)(.*)(<span.*)/', "$1http://{$domain}{$url_append}/$3", $return);
}
return $return;
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment