Skip to content

Instantly share code, notes, and snippets.

View mattheu's full-sized avatar

Matthew Haines-Young mattheu

View GitHub Profile
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.

@mattheu
mattheu / Shortcake-meeting-notes-2016-01-05.md
Created January 5, 2016 23:18
Shortcake meeting notes 5/1/2016

Shortcake 2016. Content Blocks of Shortcakes

Its a New year, and a new focus for shortcake. We met today on #feature-shortcode to catch up on feedback from the community summit and WordCampUS, as well as to chat about whats up next.

General feedback is that people are interested in what we’ve done, but there was some concern about how we’re storing data, as well as the general UI and how it is coupled with the media library and TinyMCE.

The technical limitations of the current Shortcode API are something we’ve run into. There have been a number of proposed solutions; from a new syntax, to storing structured data in post meta or as a custom post type. However the purpose of Shortcake has always been to make these decisions less critical. The biggest challenge for us right now is to come up with a really great interface and user experience.

For 2016, we’re decided to focus on creating a great way to manage complex blocks of content, implemented using shortcodes.

<?php
/**
*
* Add file last modified time to version param of of enqueued scripts & styles
*
* This automagically busts cache whenever there is a change in a file.
*/
add_action( 'wp_enqueue_scripts', function() {