Skip to content

Instantly share code, notes, and snippets.

View mattheu's full-sized avatar

Matthew Haines-Young mattheu

View GitHub Profile
@mattheu
mattheu / block.js
Created April 18, 2018 09:41
Gutenberg - Test case custom block for passing content to render callback
const el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
InnerBlocks = wp.blocks.InnerBlocks;
registerBlockType( 'gutenberg-boilerplate-es5/hello-world-step-01', {
title: 'Hello World (Step 1)',
icon: 'universal-access-alt',
category: 'layout',
!function(a,b,c,d,e,f,g,h,i){function j(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=s&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=s&f+1],c=c*d+h[s&(h[f]=h[g=s&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function k(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(k(a[c],b-1))}catch(f){}return d.length?d:"string"==e?a:a+"\0"}function l(a,b){for(var c,d=a+"",e=0;e<d.length;)b[s&e]=s&(c^=19*b[s&e])+d.charCodeAt(e++);return n(b)}function m(c){try{return o?n(o.randomBytes(d)):(a.crypto.getRandomValues(c=new Uint8Array(d)),n(c))}catch(e){return[+new Date,a,(c=a.navigator)&&c.plugins,a.screen,n(b)]}}function n(a){return String.fromCharCode.apply(0,a)}var o,p=c.pow(d,e),q=c.pow(2,f),r=2*q,s=d-1,t=c["seed"+i]=function(a,f,g){var h=[];f=1==f?{entropy:!0}:f||{};var o=l(k(f.entropy?[a,n(b)]:null==a?m():a,3),h),s=new j(h);return l(n(s.S),b),(f.pass||g||function(a,b,d){return d?(c[i]=a,b):a})(function(){
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import _ from 'lodash';
// Simple row block.
const Row = ({ children = [] }) => {
return <div className="block block-row sun-row-v3">
{ children.map( ( block, i ) => <Block key={ i } {...block} /> ) }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>body, html { background: rgba(0,0,0,0.05); padding: 0; margin: 0; }</style>
</head>
<body>
@mattheu
mattheu / grid-overlay-bookmarklet.js
Last active August 2, 2017 05:05
Grid Overlay Bookmarklet
( function( window, document ) {
var el = document.querySelector( '.grid-overlay' );
if ( el ) {
el.parentNode.removeChild( el );
return;
}
var colCount = 16;
<?php
/**
* We do not want to load any plugins.
*/
function wpcom_vip_load_plugin( $plugin ) {
// Array of files to check for loading the plugin. This is to support
// non-standard plugin structures, such as $folder/plugin.php
<?php
add_action( 'rest_api_init', 'wpleeds_rest_api' );
function wpleeds_rest_api() {
register_rest_route(
'wpleeds/v1',
'/movies/(?P<name>.+)/?$',
[
<?php
add_action( 'rest_api_init', 'wpleeds_rest_api' );
function wpleeds_rest_api() {
register_rest_route(
'wpleeds/v1',
'^/movies/?$',
[
<?php
add_action( 'rest_api_init', 'my_rest_api' );
function my_rest_api() {
// My custom endpoint code here.
}
@mattheu
mattheu / templating.md
Created March 14, 2016 14:42
Templating

Using handlebars in WordPress.

One approach we have taken is to mix handlebars templates into the standard WordPress theme templates.

We have a template function available in WordPress render_hbs_template which will render a handlebars template using the data provided. Under the hood render_hbs_template uses this PHP class https://github.com/zordius/lightncandy

The render function handles some logic around caching the compiled templates to improve performance using these.

Here is an example single.php template of how this might be used to render an article.