Skip to content

Instantly share code, notes, and snippets.

View coderaaron's full-sized avatar

Aaron Graham coderaaron

  • Washington University in St. Louis
  • St. Louis, MO
View GitHub Profile
// add style selector drop down
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
// customize the MCE editor
function aah_customize_mce( $init ) {
@coderaaron
coderaaron / pre-commit
Created May 12, 2014 14:10
Pre-commit hook to bump version number
#!/bin/sh
# Standard WUSM version numbering:
# year.month.day.commit
#
# This script searches all files in the git repo
# and bumps the version number
new=$(date +"%y.%m.%d.0")
a=( ${new//./ } )
file=$(grep -lir "Version:" *.php)
@coderaaron
coderaaron / dropdown.php
Created May 12, 2014 20:17
How to safely add custom style to TinyMCE 4.0 "Formats" dropdown
<?php
// Add new styles to the TinyMCE "formats" menu dropdown
if ( ! function_exists( 'wusm_styles_dropdown' ) ) {
function wusm_styles_dropdown( $settings ) {
// Create array of new styles
// array of arrays, see example here: http://codex.wordpress.org/TinyMCE_Custom_Styles
$new_styles = array(
array(
'title' => 'Custom Styles',
@coderaaron
coderaaron / group_585839e690eb1.json
Created February 1, 2017 21:32
Default Google Map center (on options page)
...
{
"height": "",
"center_lat": "38.641265",
"center_lng": "-90.2881593",
"zoom": "",
"key": "field_5858518f3db94",
"label": "Map Center",
"name": "washu_ppi_places_map_center",
"type": "google_map",
@coderaaron
coderaaron / group_58545ba3a2777.json
Created February 1, 2017 21:34
Map Field on CPT
...
{
"height": "",
"center_lat": "38.641265",
"center_lng": "-90.2881593",
"zoom": "",
"key": "field_58545be03c13a",
"label": "Location\/Map",
"name": "washu_ppi_map",
"type": "google_map",
@coderaaron
coderaaron / washu-people-places-items.php
Created February 1, 2017 21:36
Set the default map center
add_filter( 'acf/load_field/name=washu_ppi_map', array( self::$instance, 'set_default_google_maps_center' ) );
...
public static function set_default_google_maps_center( $field ) {
$google_map_center = get_field( 'washu_ppi_places_map_center', 'option' );
$field[ 'center_lat' ] = $google_map_center[ 'lat' ];
$field[ 'center_lng' ] = $google_map_center[ 'lng' ];
return $field;
@coderaaron
coderaaron / washu-people-places-items.php
Created February 3, 2017 21:58
Load template from theme first, fall back to plugin template
add_filter( 'template_include', array( self::$instance, 'ppi_load_single_template' ), 99 );
...
function ppi_load_single_template( $template ) {
...
if ( is_singular( 'things' ) ) {
// look in child or parent themes for template files first
if ( $theme_template = locate_template( 'single-items.php' ) ) {
$template = $theme_template;
} else {
$template = self::$directories['templates'] . 'single-items.php';
@coderaaron
coderaaron / <multiple>.php
Created February 3, 2017 22:00
Super-simple partials
require_once( WASHU_PPI_PLUGIN_DIR . 'templates/partials/ppi-loop.php' );
...
require( WASHU_PPI_PLUGIN_DIR . 'templates/partials/' . get_post_type() . '.php' );
@coderaaron
coderaaron / <multiple>.php
Created February 3, 2017 22:03
How to get a custom WP_Query in the global $post
global $ppi_query;
...
$ppi_query = new WP_Query( $args );
...
global $ppi_query;
global $post;
if ( $ppi_query ==null ) { $ppi_query = $wp_query; }
@coderaaron
coderaaron / WP-page_order.sql
Created February 20, 2018 20:49
Get WordPres pages from database in menu order
SELECT
a.post_title title,
a.post_content content
FROM
(SELECT
m.post_title,
m.post_content,
m.ID,
m.post_parent,
m.menu_order as self_order,