forked from gilbitron/wp-rest-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
46 lines (38 loc) · 1.27 KB
/
functions.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
<?php
add_theme_support( 'title-tag' );
function rest_theme_scripts() {
wp_enqueue_style( 'normalize', get_template_directory_uri() . '/assets/normalize.css', false, '3.0.3' );
wp_enqueue_style( 'style', get_stylesheet_uri(), array( 'normalize' ) );
$base_url = esc_url_raw( home_url() );
$base_path = rtrim( parse_url( $base_url, PHP_URL_PATH ), '/' );
wp_enqueue_script( 'rest-theme-vue', get_template_directory_uri() . '/rest-theme/dist/build.js', array(), '1.0.0', true );
wp_localize_script( 'rest-theme-vue', 'wp', array(
'root' => esc_url_raw( rest_url() ),
'base_url' => $base_url,
'base_path' => $base_path ? $base_path . '/' : '/',
'nonce' => wp_create_nonce( 'wp_rest' ),
'site_name' => get_bloginfo( 'name' ),
'routes' => rest_theme_routes(),
) );
}
add_action( 'wp_enqueue_scripts', 'rest_theme_scripts' );
function rest_theme_routes() {
$routes = array();
$query = new WP_Query( array(
'post_type' => 'any',
'post_status' => 'publish',
'posts_per_page' => -1,
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$routes[] = array(
'id' => get_the_ID(),
'type' => get_post_type(),
'slug' => basename( get_permalink() ),
);
}
}
wp_reset_postdata();
return $routes;
}