Skip to content

Instantly share code, notes, and snippets.

View mattheu's full-sized avatar

Matthew Haines-Young mattheu

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