Skip to content

Instantly share code, notes, and snippets.

View mattheu's full-sized avatar

Matthew Haines-Young mattheu

View GitHub Profile
@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');
@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
*
@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 {