Skip to content

Instantly share code, notes, and snippets.

View ericmann's full-sized avatar
⚒️
Creating ...

Eric Mann ericmann

⚒️
Creating ...
View GitHub Profile
// the upload image button, saves the id and outputs a preview of the image
$('.meta_box_upload_image_button').click(function() {
formID = $(this).attr('rel');
formfield = $(this).siblings('.meta_box_upload_image');
preview = $(this).siblings('.meta_box_preview_image');
tb_show('Choose Image', 'media-upload.php?post_id='+formID+'&type=image&custom=simple&TB_iframe=1');
window.orig_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {
img = $('img',html);
imgurl = img.attr('src');
<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Zooming Japan &#187; Blog</title> <atom:link href="http://zoomingjapan.com/blog/feed/" rel="self" type="application/rss+xml" /><link>http://zoomingjapan.com</link> <description></description> <lastBuildDate>Wed, 10 Oct 2012 15:03:55 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Akita: Kakunodate</title><link>http://zoomingjapan.com/travel/akita-kakunodate/</link> <comments>http://zoomingjapan.com/travel/akita-kakunodate/#comments</comments> <pubDate>Wed, 10 Oct 2012 15:03:55 +0000</pubDate> <dc:creator>zoomingjapan</dc:creator> <category><![C
@ericmann
ericmann / gist:4028438
Created November 6, 2012 23:25
Endpoint registration
function my_init() {
add_rewrite_endpoint( 'my_entry', EP_ALL );
add_rewrite_endpoint( 'my_booked', EP_ALL );
add_rewrite_endpoint( 'my_custom_css', EP_ALL );
}
/**
* Flush rewrite rules on plugin activation.
*/
@ericmann
ericmann / robot.js
Created December 3, 2012 16:46
Test Bot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
<?php
class regions {
static function initialize()
{
// We need to process the_content as early as possible, to be sure that DOM tree identical to edited one
// Also, function accept 2 arguments, so when needed we can supply exact regions to apply
if ( !is_admin() ) { // We don't want to run this on the backend
if (true) { // until apply_filter use current()/next()
add_filter('the_content', array(self::instance(), 'content_split_join'), -99991, 2);
} else {
@ericmann
ericmann / gist:4332800
Created December 18, 2012 22:47
A hacky example of something I'm actually doing in a client project. We need to include the content of sub posts/pages on a parent post/page using the `the_content` filter. We also need to pass the content of the child posts/pages through the `the_content` filter, so it's important to remove the filter immediately otherwise it's recursively appl…
<?php
add_filter( 'the_content', 'my_content_filter' );
/**
* Auto appends the content of child posts to the main post
*/
function my_content_filter( $content ) {
global $post;
<?php
/**
* Outputs the current weather conditions
*/
function ocj_weather() {
$conditions = get_transient( 'current_weather' );
if ( false === $conditions ) {
$key = '771f294942a9ba11';
$current = 'http://api.wunderground.com/api/' . $key . '/conditions/q/OH/Columbus.json';
@ericmann
ericmann / gist:5010291
Created February 22, 2013 02:32
Do as I saw, not as I do. Despite a comment explicitly stating that `wp_head()` should be the last item in the page's `<head>` section, there are scripts and styles declared in-line below it. Including an outdated version of jQuery shipped with the theme itself. This makes it impossible to use `wp_enqueue_scripts()` to add any jQuery extensions …
<?php
/**
* header.php
*/
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<!-- meta tags and such omitted for brevity -->
@ericmann
ericmann / gist:5206391
Last active December 15, 2015 05:09 — forked from jeremyfelt/gist:5206360
(function (window, $, thirdyo ) ) {
var mycallbackfunction = function() {}
thirdyo.thirdpartyfunction( mycallbackfunction );
})(window, jQuery, thirdyo );
( function( window, undefined ) {
var Logger = function() {
var SELF = this,
log = [];
SELF.append = function( data ) {
log.push( data );
};
SELF.getData = function() {