forked from stormuk/wp-turbolinks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordpress-turbolinks.php
47 lines (32 loc) · 1.27 KB
/
wordpress-turbolinks.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
Plugin Name: WordPress Turbolinks
Description: Implement the Turbolinks feature of Rails 4.0 for WordPress
Author: Adam Pope
Author URI: http://www.stormconsultancy.co.uk
This is an experimental port of @dhh's Turbolinks gem for Rails
*/
function enqueue_turbolinks() {
if(!is_admin()) {
//var_dump(plugin_dir_url(__FILE__));
$dir = get_option('siteurl') .'/wp-content/plugins/' . basename(dirname(__FILE__)) .'/';
wp_register_script('turbolinks', $dir . 'assets/turbolinks.js');
wp_enqueue_script('turbolinks');
wp_register_script('turbolinks-jquery', $dir . 'assets/jquery.turbolinks.js', array('jquery', 'turbolinks'));
wp_enqueue_script('turbolinks-jquery');
}
}
add_action('wp_enqueue_scripts', 'enqueue_turbolinks');
function add_xhr_location(){
header("X-XHR-Current-Location: ". selfURL());
}
add_action('template_redirect', 'add_xhr_location');
//http://stackoverflow.com/questions/2236873/getting-the-full-url-of-the-current-page-php
function selfURL()
{
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = "http".$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
?>