forked from 10up/nodeifywp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
API.php
57 lines (46 loc) · 1.48 KB
/
API.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
55
56
57
<?php
namespace NodeifyWP;
class API extends \WP_REST_Controller {
/**
* Register our api routes
*
* @since 0.5
*/
public function register_routes() {
$version = '1';
$namespace = 'nodeifywp/v' . $version;
$base = 'route';
register_rest_route( $namespace, '/' . $base, [
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'get_route' ],
'permission_callback' => '__return_true',
'args' => [
'context' => [
'default' => 'view',
],
],
],
] );
}
/**
* Given a location url, return all relevant info for that url: posts, route, menus, template tags, etc.
*
* @since 0.5
* @return array
*/
public function get_route() {
$resolver = new \GM\UrlToQuery();
$query_args = $resolver->resolve( $_GET['location'] );
$GLOBALS['wp_the_query'] = new \WP_Query( $query_args );
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
$GLOBALS['wp_the_query']->query( $query_args );
if ( ! ( $GLOBALS['wp_the_query']->is_singular || $GLOBALS['wp_the_query']->is_archive || $GLOBALS['wp_the_query']->is_search || $GLOBALS['wp_the_query']->is_feed || $GLOBALS['wp_the_query']->is_trackback || $GLOBALS['wp_the_query']->is_404 || $GLOBALS['wp_the_query']->is_admin || $GLOBALS['wp_the_query']->is_robots ) ) {
$GLOBALS['wp_the_query']->is_home = true;
}
do_action( 'nodeifywp_render' );
App::instance()->register_posts( $query_args );
$output = App::instance()->v8->context;
return $output;
}
}