Skip to content

Instantly share code, notes, and snippets.

View adamsilverstein's full-sized avatar
💭
Working remotely, as usual

Adam Silverstein adamsilverstein

💭
Working remotely, as usual
View GitHub Profile
@adamsilverstein
adamsilverstein / gist:a60012a09681520d75aa
Last active August 29, 2015 14:03 — forked from markjaquith/gist:4219135
Apply WordPress patches from the command line
#!/usr/bin/ruby
#
# The MIT License (MIT)
# Copyright (c) 2013 Mark Jaquith
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@adamsilverstein
adamsilverstein / gist:7741b38133fe3a593382
Last active August 29, 2015 14:04
Allow on* JS handlers for IMG elements in WordPress / TinyMCE 4
add_filter( 'tiny_mce_before_init', 'my_mce_init', 20 );
function my_mce_init( $init ) {
if ( current_user_can('unfiltered_html') ) {
if ( ! empty( $init['extended_valid_elements'] ) ) {
$init['extended_valid_elements'] .= ',';
} else {
$init['extended_valid_elements'] = '';
}
$init['extended_valid_elements'] .= 'img[id|accesskey|class|dir|lang|style|tabindex|title|contenteditable|contextmenu|draggable|dropzone|hidden|spellcheck|translate|src|alt=|usemap|ismap|width|height|name|longdesc|align|border|hspace|vspace|crossorigin|onclick|ondblclick|onmousedown|onmouseenter|onmouseleave|onmousemove|onmouseover|onmouseout|onmouseup|onkeydown|onkeypress|onkeyup]';
function set_attribute( element, setFrom, setTo ) {
var val = element.val();
from = 'type=\"' + setFrom + '\"',
to = 'type=\"' + setTo + '\"';
// Workaround for element.attr('type', 'password'); doesn't work in ie8
element
.replaceWith(
element = $( element.wrap( '<label></label>' )
.parent('label')
@adamsilverstein
adamsilverstein / 0_reuse_code.js
Created October 2, 2015 21:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
var uuid = require('node-uuid'), // npm install node-uuid
crypto = require('crypto');
var UUID_NUM = 1000000;
var uuid_table = {};
@adamsilverstein
adamsilverstein / add_to_functions.php
Last active November 11, 2015 05:07 — forked from ocean90/gist:5586293
Make Many Big Revisions
<?php
// How many revisions should be created?
$num_of_revisions = 900;
// Demo content
$content = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, minim
@adamsilverstein
adamsilverstein / deprecated_warning_disabler.php
Last active December 10, 2015 15:31
Disabled deprecated warnings in WordPress.
<?php
add_filter( 'deprecated_constructor_trigger_error', '__return_false' );
add_filter( 'deprecated_function_trigger_error', '__return_false' );
add_filter( 'deprecated_file_trigger_error', '__return_false' );
@adamsilverstein
adamsilverstein / PrintTrace
Created October 10, 2013 06:32
This function will print a stack telling you where it was called from. See http://stackoverflow.com/questions/708140/php-fatal-error-cannot-redeclare-class.
function PrintTrace() {
$trace = debug_backtrace();
echo '<pre>';
$sb = array();
foreach($trace as $item) {
if(isset($item['file'])) {
$sb[] = htmlspecialchars("$item[file]:$item[line]");
} else {
$sb[] = htmlspecialchars("$item[class]:$item[function]");
}
@adamsilverstein
adamsilverstein / gocat.js
Last active January 6, 2016 05:33
Create a post with categories
// Create a new post
var post = new wp.api.models.Posts({ title:'new test' } );
post.save();
// Get a collection of the post's categories
var postCategories = post.getCategories();
// The new post has an single Category: Uncategorized
postCategories.at( 0 ).get('name');
// response -> "Uncategorized"
jQuery( document ).on( 'click', 'div.attachment-preview', function( e ) {
console.log( 'Image clicked', e );
// Do ajax stuff here...
} );