| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * Theme Functions - functions.php
- *
- * 1. Scripts needed to run the vue theme
- */
-
- $path = $_SERVER['DOCUMENT_ROOT'];
-
- require_once $path . '/wp-load.php';
- require_once $path . '/wp-config.php';
- require_once $path . '/wp-includes/wp-db.php';
- require_once $path . '/wp-includes/pluggable.php';
-
- // https://github.com/EvanAgee/vuejs-wordpress-theme-starter/blob/master/functions.php
- remove_action( 'template_redirect', 'redirect_canonical' );
- function remove_redirects() {
- add_rewrite_rule( '^/(.+)/?', 'index.php', 'top' );
- }
- add_action( 'init', 'remove_redirects' );
-
-
- function vue_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;
- }
-
- /* 1 */
- function vue_theme_scripts() {
-
- wp_enqueue_style( 'style', get_stylesheet_uri() );
-
- if ( defined( 'IS_DEV' ) && IS_DEV ) {
- wp_register_script(
- 'vue-theme',
- 'http://localhost:8081/main.js',
- array( 'jquery' ),
- false,
- true
- );
- } else {
- wp_register_script(
- 'vue-theme',
- get_template_directory_uri() . '/public/main.js',
- array( 'jquery' ),
- false,
- true
- );
- }
-
- wp_localize_script( 'vue-theme', 'wp', array(
- 'template' => get_stylesheet_directory_uri(),
- 'rest' => esc_url_raw( rest_url() ),
- 'site_name' => get_bloginfo( 'name' ),
- // 'nonce' => wp_create_nonce( 'wp_rest' ),
- 'routes' => vue_theme_routes(),
- ) );
-
- wp_enqueue_script( 'vue-theme' );
- }
- add_action( 'wp_enqueue_scripts', 'vue_theme_scripts' );
|