Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
<?php
add_filter( 'attachment_fields_to_edit', 'attachment_fields_to_edit', 10, 2 );
add_filter( 'attachment_fields_to_save', 'attachment_fields_to_save', 10, 2 );
function attachment_fields_to_edit( $form_fields, $post ) {
$form_fields["client_test_input"] = array(
"label" => __( 'Test Input URL' , 'client' ),
"value" => get_post_meta( $post->ID, "_client_test_input", true ),
"helps" => __( 'Test Input Field', 'client' )
);
<?php
remove_filter( 'the_content', 'wpautop' );
$content = wpautop( $content, false );
echo apply_filters( 'the_content', $content );
add_filter( 'the_content', 'wpautop' );
<?php
/**
* Integrate Imager.js with WordPress
*
* Imager.js is BBC's solution for serving responsive and retina images, without
* the double payload issues that affect other solutions. For more information:
*
* https://github.com/BBC-News/Imager.js/
*
* This collection of functions modifies the output of WordPress's
// iframes
var $iframes = $( document.querySelectorAll( '.videos iframe' ) );
function iframeSizing() {
var $this = $( this ),
width = $this.width(),
height = $this.height(),
containerWidth = $this.parent().width(),
heightRatio = height / width,
newHeight = heightRatio * containerWidth;
@DrewAPicture
DrewAPicture / concat-hack.php
Created April 10, 2014 19:46
Attempting to concatenate something in-line onto the end of the post content, wpautop insists on adding a line break between them. This gets around that.
<?php
remove_filter( 'the_content', 'wpautop' );
$content = wpautop( $content, false );
echo apply_filters( 'the_content', $content );
add_filter( 'the_content', 'wpautop' );
@DrewAPicture
DrewAPicture / count-stuff.php
Created May 6, 2014 00:46
Count words and junk.
<?php
function count_wtd_words() {
$posts = get_posts( array(
'tag' => 'write-the-docs',
'posts_per_page' => -1,
'suppress_filters' => false,
'post_status' => 'publish',
) );
<?php
$id = (int) $id;
if ( empty( $id ) ) {
return new WP_Error( 'json_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) );
}
$post = get_post( $id, ARRAY_A );
<?php
/**
* Retrieve a variable cache key via RegEx.
*
* A good use for this would be where an incrementer is part of the key and you can't
* necessarily predict what it is, though you can predict the format it will take.
*/
function get_variable_cache_key() {
/**
* @global WP_Object_Cache $wp_object_cache
<?php
array(2) {
[0]=>
object(stdClass)#4117 (7) {
["type"]=>
string(4) "core"
["slug"]=>
string(7) "default"
["language"]=>
string(5) "de_DE"
<?php
[13-Oct-2014 05:29:15 UTC] Array
(
[content] => One or more associative arrays of date query parameters.
[0] => Array
(
[content] =>
[types] => Array
(
[0] => array