Skip to content

Instantly share code, notes, and snippets.

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

Eric Mann ericmann

⚒️
Creating ...
View GitHub Profile
<?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() {
@ericmann
ericmann / gist:5245768
Created March 26, 2013 14:28
Three code snippets from my talk at the Portland WordPress User Group meetup on 3/25/2013
<?php
/**
* Custom Hacks for PDXWP Meetup
*/
/**
* Clean up the output of the <head> block
*/
function pdxwp_clean_header() {
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
<?php
class MyTestClass extends PHPUnit_Framework_TestCase {
public function setUp() {
\WP_Mock::setUp();
}
public function tearDown() {
\WP_Mock::tearDown();
}
<?php
$fb_request_url = 'http://api.facebook.com/restserver.php';
$fb_request_url = add_query_arg(
array(
'method' => 'links.getStats',
'urls' => $url
),
$fb_request_url
);
<?php
function update_wppa_list_limit( $current ) {
return 5;
}
add_filter( 'wppa_list_limit', 'update_wppa_list_limit' );