Skip to content

Instantly share code, notes, and snippets.

View mattheu's full-sized avatar

Matthew Haines-Young mattheu

View GitHub Profile
@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() {
@mattheu
mattheu / class-dom-kses.php
Last active November 17, 2015 13:02
Dom Kses
<?php
trait Dom_Kses {
/**
* wp_kses, but using DOMDocument.
*
* Clean HTML to allowed_html.
* Also restrict attributes by those in whitelist.
*
@mattheu
mattheu / 1.php
Created August 27, 2015 13:57
Post Objects Example
<?php
namespace Post_Objects;
class Post {
private $_post;
public function get_id() {
return $this->data->id;
@mattheu
mattheu / gist:380c841e611a64ab329b
Last active August 29, 2015 14:23
Close comments for new autodrafts
<?php
/**
* Set default comment status to closed for woocommerce products.
*/
add_filter( 'wp_insert_post_data', function( $data, $postarr ) {
// Auto draft is the status given to the initial post created
// when visiting the 'add new product' page in the WP-Admin.
// This still allows posts to be created programatically with comments open.
@mattheu
mattheu / gist:2c8624788aef1dfc0eb8
Created May 12, 2015 13:40
VIPs Download Remote Image and create attachment in WordPress.
<?php
/**
* Downloads an external image and optionally attaches it to a post.
*
* Contains most of core's media_sideload_image() but returns an attachment ID instead of HTML.
*
* Note: this function does not validate the domain that the image is coming from. Please make sure
* to validate this before downloading the image. Should only pull down images from trusted sources.
*
@mattheu
mattheu / gist:33238c774df4d32813c6
Created May 11, 2015 19:17
Disable WordPress Comments
<?php
namespace DisableComments;
add_action( 'init', 'DisableComments\disable_comments_post_types_support' );
add_filter( 'comments_array', 'DisableComments\disable_comments_hide_existing_comments', 10, 2 );
add_action( 'admin_menu', 'DisableComments\disable_comments_admin_menu' );
add_action( 'admin_init', 'DisableComments\disable_comments_admin_menu_redirect' );
add_action( 'admin_init', 'DisableComments\disable_comments_dashboard' );
add_action( 'init', 'DisableComments\disable_comments_admin_bar' );
@mattheu
mattheu / gist:d821b76c4824fcfce6f5
Last active August 29, 2015 14:20
WordPress Split Term Checker
<?php
/**
* Plugin Name: Split Shared Term Checker.
* Plugin URI: https://gist.github.com/mattheu/d821b76c4824fcfce6f5
* Description: Check for shared terms and track when they are split. Find in the tools sub menu.
* Version: 0.0.1
* Author: Matthew Haines-Young
* Author URI: http://matth.eu
* License: GPL2
*/
@mattheu
mattheu / gist:88f86762486f863a5763
Created April 6, 2015 19:06
Shortcode Classes
<?php
/**
* Example Shortcode Classes.
* Shamelessly stolen fron Daniel Bachhuber
*
* Short-term - a wrapper around add_shortcode.
* Long-term - WP should use shortcode classes and povide compatability with old-style shortcodes.
*/
var CMBAdmin = function() {
var self = this;
self.init = function() {
self.$contentFormatSelect = jQuery('.field#content-format select' ).first();
self.$metaboxes = self.$contentFormatSelecself.closest('.cmb_metabox');
self.$videoField = jQuery('.field#content-video' ).closest('.cmb-row');