/
Theme.php
54 lines (44 loc) · 1.15 KB
/
Theme.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
48
49
50
51
52
53
54
<?php
namespace elasticsearch;
/**
* This theme class provides utilities for introducing advanced functionality (such as ajax faceting) to your theme.
*
* @license http://opensource.org/licenses/MIT
* @author Paris Holley <mail@parisholley.com>
* @version 4.0.1
**/
class Theme{
private static $selector;
private static $instance;
/**
* Tells wordpress to detect when ?esajax=1 is in the URL and remove header/footer so content can be replaced on page with AJX
**/
public static function enableAjaxHooks(){
if(isset($_GET['esasync'])){
add_action('get_header', function(){
ob_start();
});
add_action('get_footer', array(__NAMESPACE__ .'\Theme', '_ajax_footer'));
}
}
public static function setSelector($selector){
self::$selector = $selector;
}
public static function _ajax_footer(){
$html = ob_get_contents();
ob_clean();
\phpQuery::newDocumentHTML($html);
global $wp_query;
$result = array(
'content' => pq(self::$selector)->html(),
'faceting' => Faceting::all(),
'found' => $wp_query->found_posts
);
echo json_encode($result);
if(!empty($_REQUEST)){
// only fail on webserver, not tests
die();
}
}
}
?>