| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?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/build/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' );
-
- /**
- * disable endpoints in rest api
- **/
- add_filter( 'rest_endpoints', function ( $endpoints ) {
- if ( isset( $endpoints['/wp/v2/users'] ) ) {
- unset( $endpoints['/wp/v2/users'] );
- }
- if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
- unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
- }
-
- if ( isset( $endpoints['/wp/v2/comments'] ) ) {
- unset( $endpoints['/wp/v2/comments'] );
- }
- if ( isset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] ) ) {
- unset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] );
- }
-
- if ( isset( $endpoints['/wp/v2/settings'] ) ) {
- unset( $endpoints['/wp/v2/settings'] );
- }
- return $endpoints;
- } );
-
- /**
- * remove wordpress version number from files
- **/
- remove_action( 'wp_head', 'wp_generator' );
|