Skip to content

Instantly share code, notes, and snippets.

View fadingdust's full-sized avatar

M. Wallace fadingdust

View GitHub Profile
@fadingdust
fadingdust / VueServiceStore.csv
Created March 26, 2018 01:00
Using the Local Store as an API
Used By Defined By Function
Component Store.getters.getPageBySlug() state.posts.find();
Store Service.getPageBySlug() Vue.http.get( path );
@fadingdust
fadingdust / functions.php
Created March 16, 2018 22:34
Page and Post Router for Vue.js from @gilbitron
<?php
function rest_theme_scripts() {
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(
'routes' => rest_theme_routes(), //Drop in to JS from PHP
) );
}
add_action( 'wp_enqueue_scripts', 'rest_theme_scripts' );
@fadingdust
fadingdust / wp-vue-starter.js
Created March 16, 2018 22:29
Basic Vue Router Config from @michaelsoriano
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [ { path: '/', component: Home },
{ path: '/post/:slug', name: 'post', component: Single },
{ path: '/preview/:id', name: 'preview', component: Single },
{ path: '/page/:slug', name: 'page', component: Page },
{ path: '/category/:cat_id', name:'category', component: Archive },
{ path: '/tag/:tag_id', name : 'tag', component: Archive },
{ path: '/blog/', name : 'blog', component: Archive },
{ path: '/search/', name : 'search', component: Search },
@fadingdust
fadingdust / wordpress-rest-header-query-count.php
Created March 7, 2018 21:56
Add an HTTP header on Wordpress REST API responses showing the number of MySQL Queries performed
<?php
// Add the Number of queries to the header, because I'm a nerd.
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'X-Query-Count: '.intval( get_num_queries() ) );
return $value;
});