Skip to content

Instantly share code, notes, and snippets.

View mattheu's full-sized avatar

Matthew Haines-Young mattheu

View GitHub Profile
@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 / nav-menu-headings.php
Last active August 29, 2015 13:56
Replace wp nav menu links that have just a hash url with headings
<?php
/*
Plugin Name: Nav Menu Headings
Plugin URI: https://gist.github.com/mattheu/9093265
Description: Add headings to nav menus
Author: Matth.eu
Version: 0.1-alpha
Author URI: http://matth.eu
Text Domain: nav-menu-headings
Domain Path: /lang
@mattheu
mattheu / gist:9366497
Created March 5, 2014 12:46
Remove Buttons From TinyMCE 4.0
<?php
add_filter( 'tiny_mce_before_init', function( $mceInit, $editor_id ) {
if ( $editor_id != 'vcl-placeholder-tinymce-id' )
return $mceInit;
$toolbars = array(
'toolbar1' => explode( ',', $mceInit['toolbar1'] ),
'toolbar2' => explode( ',', $mceInit['toolbar2'] ),
@mattheu
mattheu / Readme.md
Last active August 29, 2015 13:59
Core ticket idea = Split sideload_media_image function into 2

media_sideload_image could be a super useful function, except for one thing, it returns image HTML which is limited in what it can be used for.

What if it returned the attachment ID? That would be useful and media_sideload_image comes so close!

I've needed this a few times in the past and I've just had to copy/paste this function and edit it to return ID. Some examples of when I could have used this:

  1. writing content importers
  2. a plugin to sideload external images from post content comments on save

My proposal is to split media_sideload_image into 2 functions. The first, media_handle_sideload_image sideloads the image and returns the attachment ID. The second media_sideload_image returns the image HTML.

(function() {
// Code goes here.
}());
(function($) {
// More code here. And we can pass global vars we want.
@mattheu
mattheu / gist:7f2c0b7325e218eabb90
Created August 18, 2014 13:53
Sanitization/Validation Helper Class
<?php
class CFO_Sanitize {
public static function sanitize_array( $fields, $data ) {
$clean_data = array();
foreach ( $fields as $field ) {
@mattheu
mattheu / gist:01e95497345bd5a475f4
Last active August 29, 2015 14:07
Improved HM debug
<?php
function hm( $args ) {
$args = func_get_args();
?>
<style>
.hm_debug { word-wrap: break-word; white-space: pre; text-align: left; position: relative; background-color: rgba(0, 0, 0, 0.8); font-size: 11px; color: #a1a1a1; margin: 10px; padding: 10px; margin: 0 auto; width: 80%; overflow: auto; -moz-border-radius: 5px; -webkit-border-radius: 5px; text-shadow: none; }
@mattheu
mattheu / hmpmr.php
Last active August 29, 2015 14:07
Register Revisions for Meta and Taxonomies
<?php
/*
Plugin Name: HM Post Meta Revisions
Description: Register Revisions for meta keys.
Version: 1.0
Author: Matthew Haines-Young (building on code from John Blackbourn)
*/
class HM_Post_Meta_Revisions {
@mattheu
mattheu / gist:c4ec739e53b107d59f0c
Last active August 29, 2015 14:08
Idea for new register meta functionality in core.
<?php
$_wp_registered_meta = array();
/**
* Register meta key
*
* Supported arguments.
* label, field_type, sanitize_callback, auth_callback
*
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');