Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
<?php
/**
* Filter the link query arguments.
*
* Allows modification of the link query arguments before querying.
*
* @since 3.7.0
*
* @param array $query {
* An array of query arguments.
<?php
/**
* @type string 'sort_column' What columns to sort pages by, comma-separated.
* Default 'post_title'. Accepts 'post_author', 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'ID', 'rand', 'comment_count').
*
@DrewAPicture
DrewAPicture / update_post_fields.php
Created September 2, 2013 17:49
Update post fields (counter part to get_post_field()
<?php
/**
* Update one or more post fields
*
* @global wpdb $wpdb
*
* @param array $field Array of field/value pairs to update.
* @param WP_Post|int $post Post object or id.
*
* @return int|bool Number of updated rows, false on failure.
@DrewAPicture
DrewAPicture / update_image_date.php
Last active December 22, 2015 02:49
Use attachment date from EXIF data on image upload.
<?php
class Unnamed_Theme {
public function __construct() {
add_filter( 'wp_update_attachment_metadata', array( $this, 'update_image_date' ), 10, 2 );
}
/**
* Update the 'post_date' field with the date in the image meta
*
* @param array $data The attachment meta array.
<?php
class Unnamed_Theme {
public function __construct() {
add_filter( 'login_redirect', array( $this, 'login_redirect' ), 10, 3 );
}
public function login_redirect( $redirect_to, $request, $user ) {
return admin_url( 'media-new.php' );
}
@DrewAPicture
DrewAPicture / class-wp-docs-collection.php
Last active December 21, 2015 23:48
get_pages args docs
<?php
/**
* WP Docs Collection Class
*
* Stores data sets commonly referenced in WordPress inline documentation.
*
* @since 3.7.0
*/
class WP_Docs {
@DrewAPicture
DrewAPicture / functional.php
Last active December 21, 2015 23:19
Functional array docs ideas
<?php
/**
* @param array $date_query {
* @type string 'column' (optional) Column to query against, default is 'post_date'.
* @type string 'compare' (optional) Comparison operator, defaul is '='. @see WP_Date_Query::get_compare()
* @type string 'relation' (optional) How the sub-arrays should be compared, accepts 'AND' (default) or 'OR'.
* }
@DrewAPicture
DrewAPicture / gist:6141436
Last active December 20, 2015 13:48
Post Formats + other removed functions and filters in 3.6
http://codex.wordpress.org/Function_Reference/get_attached_audio
http://codex.wordpress.org/Function_Reference/get_attached_video
http://codex.wordpress.org/Function_Reference/get_attached_images
http://codex.wordpress.org/Function_Reference/get_attached_image_srcs
http://codex.wordpress.org/Function_Reference/get_content_media
http://codex.wordpress.org/Function_Reference/get_content_audio
http://codex.wordpress.org/Function_Reference/get_content_video
http://codex.wordpress.org/Function_Reference/get_content_images
http://codex.wordpress.org/Function_Reference/get_content_image
http://codex.wordpress.org/Function_Reference/get_content_galleries
@DrewAPicture
DrewAPicture / gistmerge.sh
Last active August 15, 2016 18:12
Script to merge a Gist fork into your original. You'll need the id of your Gist and the id of the fork.
#!/bin/bash
# usage: ORIG=###### NEW=###### ./gistmerge.sh
# $ORIG = The Gist ID of your Gist
# $NEW = The Gist ID of the fork
# Note: chmod u+x gistmerge.sh may be necessary
# if you're getting permissions errors
printf "\n\n... Cloning original Gist.\n\n"
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {