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:7117050
Last active December 26, 2015 07:39
WP-CLI command to generate test content. Lorem ipsum post text and random images from the flickr api.
<?php
define( 'MPH_GENERATOR_FLICKR_API_KEY', '' );
if ( ! 'MPH_GENERATOR_FLICKR_API_KEY' )
die( 'You must define the Flickr API key.' );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
/**
@mattheu
mattheu / gist:7127778
Created October 23, 2013 22:18
## Fix login loop. * When WordPress is installed in a subdirectory, wp-admin/ links don't work correctly. We fix this with an nginx rewrite. * But... it appends reauth=1 to the url which forces a reauthentication when submitted... and you have to log in again!
/**
* Fix login loop.
*
* When WordPress is installed in a subdirectory, wp-admin/ links don't work correctly. We fix this with an nginx rewrite.
* But... it appends reauth=1 to the url which forces a reauthentication when submitted... and you have to log in again!
*/
add_filter( 'login_url', function( $url ) {
if ( '/wp-admin/' === add_query_arg( array() ) ) {
@mattheu
mattheu / gist:7135691
Last active December 26, 2015 10:19
Salty-WordPress / Nginx conf - for projects where the acual site is in a public directory add this to the Salty WordPress default config
if ( -d /srv/www/$root/public ) {
set $root '${root}/public';
}
@mattheu
mattheu / CMB-field.linklist.js
Last active May 24, 2016 09:04
A custom CMB field type for some flexible content
@mattheu
mattheu / gist:8056370
Last active December 31, 2015 22:49
Instructions for setting up the WP Remote API Demo app locally.

Salty WordPress expects the public directory to be the project root, however The WP Remote API Demo app has the public facing site in the build directory. You will need to modify the default nginx config file to get it working.

In the Salty WordPress directory, edit config/salt/config/nginx/default

Immediately before this section...

if ( !-d /srv/www/$root ) {
        set $root 'default';
}
@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.

@mattheu
mattheu / gist:508d3246eea566e6fa33
Last active May 15, 2021 19:44
Tidy Up WordPress TinyMCE 4 editor buttons
<?php
// Modify Tiny_MCE init
add_filter('tiny_mce_before_init', 'tmy_modify_tinyMCE4', 10, 2 );
/**
* Filter TinyMCE4 Init args.
*/
function tmy_modify_tinyMCE4( $mceInit, $editor_id ) {
(function() {
// Code goes here.
}());
(function($) {
// More code here. And we can pass global vars we want.