-
Notifications
You must be signed in to change notification settings - Fork 0
/
routemaster.php
30 lines (27 loc) · 1.17 KB
/
routemaster.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/*
Plugin Name: Routemaster
Description: An implementation of the MVC pattern where WordPress provides the model.
Version: 2.0.3
*/
//include ooPost compatibility class if oowp plugin is active
add_action('plugins_loaded', function(){
if (class_exists('Outlandish\\Wordpress\\Oowp\\PostTypes\\WordpressPost')) {
//change preview link to have routing that can be picked up by Routemaster
add_filter('preview_post_link', function ($link) {
$qs = parse_url($link, PHP_URL_QUERY);
$args = wp_parse_args($qs);
//only modify link of unpublished posts (published posts use preview_id param)
if (isset($args['p']) || isset($args['page_id'])) {
$id = isset($args['p']) ? $args['p'] : $args['page_id'];
$post = Outlandish\Wordpress\Oowp\PostTypes\WordpressPost::createWordpressPost($id);
if ($post) {
$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
$link = $post->permalink();
$link .= '?' . $qs;
}
}
return $link;
});
}
});