Skip to content

Instantly share code, notes, and snippets.

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

Eric Mann ericmann

⚒️
Creating ...
View GitHub Profile
@ericmann
ericmann / gist:2591384
Created May 4, 2012 02:12
Non-parent theme psuedoframework
View gist:2591384

#Parent Themes There actually is nothing wrong with the parent/child theme model. I strongly believe that the only kind of theme that should ever be distributed is a parent theme - so clients/devs can create and modify a child theme on top of it.

But I have a problem with developing on top of a parent theme if the child theme is meant for general distribution. Child themes should never be re-sold or distributed.

If I'm planning to build a theme for release, starting with an existing parent theme and building a child theme is a really bad idea.

#Frameworks

Working with the popular theme frameworks is just an extension of this problem - i.e. using Genesis or Builder as a generic parent theme and building a custom design as a child theme on top of it.

@ericmann
ericmann / gist:2604547
Created May 5, 2012 18:22
Post meta wrapper
View gist:2604547
function get_meta_bool( $post_id, $key ) {
var $string_value = get_post_meta( $post_id, $key, true );
return (bool) $string_value
}
View gist:2765331
Set up images like this:
<div id="raffle">
<img src="..." data-link="http://link.url" />
<img src="..." data-link="http://link.url" />
</div>
Then set up a JS event listener:
jQuery('#raffle').on('click', 'img', function(e) {
View gist:2776232
void this_is_a_subroutine( $args ) {
if ( check )
return;
do_something();
do_something_else();
if ( check )
return;
@ericmann
ericmann / gist:2784237
Created May 24, 2012 21:05
Consolidating my Websites
View gist:2784237

When WordPress first rolled in multisite features, I was thrilled. I immediately activated them and merged the two sites I already had - my personal portfolio and my business blog. At the time, I also had to have a "parent network" site ... so it really became three sites:

  • eamann.com (my primary domain and network parent)
  • work.eamann.com (my portfolio)
  • mindsharestrategy.com (mapped domain for my business blog)

Over time, my business blog evolved to contain a whole slew of other content - articles on faith, the outdoors, creative writing, etc. I added a couple of new mapped domains to my network and branched the content out to keep things separate:

  • prosepainting.com (creative writing)
  • groundedchristianity.com (faith essays)
@ericmann
ericmann / gist:2876388
Created June 5, 2012 17:26
"Phone app" template from WordCamp Phoenix presentation
View gist:2876388
<?php
/*
Template Name: RPC Test
*/
/**
* This template interacts with a new XML-RPC endpoint created specifically to handle `wcphx.change_query`
* Code for the endpoint is available in a ZIP file at: http://eam.me/3-
* Slides from the WordCamp Phoenix presentation are at: http://www.slideshare.net/ericmann/playing-nice-with-others-11758893
* Video from the presentation is at: http://wordpress.tv/2012/06/04/eric-mann-playing-nice-with-others-integrating-wp-with-other-apis/
View gist:2937180
// How can I rewrite this to perform multiple checks in a row without repeating if (_allowed.IPs.Contains(userIPAddress)) { authentic = true; goto result; } every time?
public class Authentication {
private List<string> _allowedIPs;
public bool IsAuthentic(string userIPAddress) {
bool authentic = false;
if (_allowedIPs == null)
_allowedIPs = new List<string>();
@ericmann
ericmann / gist:3005609
Created June 27, 2012 17:38
Authentication System
View gist:3005609

##The Scenario

I have a client-side web application that bounces requests against a server-side API. For the sake of simplicity, every request must pass a username and password. This is similar to old school XML-RPC where the username and password are passed as parameters in every request.

However, as this is a REST service, some of the requests (GET and DELETE) don't have message bodies and must pass the username and password as query variables in the URL:

GET http://application.url/endpoint?username=xxxx&password=xxxx

This is, frankly, a bad idea. Requests are logged on the server, so if I send the password in plaintext, it's now sitting in a log file somewhere on the server. I don't ever want to be sending the password in plaintext over the wire, so I'm stuck with a dilemma.

@ericmann
ericmann / gist:3130115
Created July 17, 2012 15:31
Sunrise if we architect to use a singleton
View gist:3130115
<?php
/**
* Here's the Sunrise class demonstrating how it would be used as a singleton.
* NOTE: Code is for discussion only and has not been tested.
*/
class Sunrise {
static private $instance = null;
static public function get_instance() {
if ( ! isset( self::$instance ) ) {
@ericmann
ericmann / gist:3788867
Created September 26, 2012 16:00
Auto-generate URLs
View gist:3788867

#The Problem

I need to create custom links based on the current page URL within WordPress. The system needs to work with both pretty and default permalinks. I have a custom rewrite endpoint defined that needs to be added.

So if the URL of the page is http://site.url/?p=25 I need to create http://site.url/?p=25&custom=1

If the URL is http://site.url/2012/post-slug I need to create http://site.url/2012/post-slug/custom

I can't find a built-in function to do this, so I'm thinking I'll need to build my own to do this. Some pseudo-code: