Last active
March 2, 2016 14:52
-
-
Save khromov/3cb8a35c7365552ceb9e to your computer and use it in GitHub Desktop.
Set correct preview link when using WordPress MU Domain Mapping Plugin
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 | |
| 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