Skip to content

Instantly share code, notes, and snippets.

@blobaugh
blobaugh / gist:8875679
Created February 8, 2014 02:19
Bad php
<?php
echo $bob['thisisbad'];
@blobaugh
blobaugh / gist:9900488
Created March 31, 2014 19:39
March 2014 .vimrc
syntax on
set number
set linebreak
set showbreak=+++
set textwidth=0
set showmatch
set visualbell
set hlsearch
set smartcase
set ignorecase
@blobaugh
blobaugh / gist:9995104
Created April 5, 2014 17:31
WordPress Plugin Handbook Revision update
Missing from the Plugin Handbook
These are notes of things from the new plugin handbook that are either currently missing or that need some serious updating.
Section 1 - Intro to Plugin Dev
How do plugins work
What is a plugin - Just sounds cheesy, and it is inaccurate on what a plugin needs. See 2. Plugin Basics
Section 2 - Plugin Basics
Activation/Deactivation hooks
@blobaugh
blobaugh / gist:f60fb50838edabd49159
Created February 14, 2015 19:58
WCMaui Code Demo
add_filter( 'the_content', function( $content ) {
$response = wp_remote_get( 'http://ben.lobaugh.net/wp-json/posts' );
if( '200' == wp_remote_retrieve_response_code( $response ) ) {
$posts = json_decode( wp_remote_retrieve_body( $response ) );
foreach( $posts AS $p ) {
echo $p->title->rendered . "<br/>";
<?php
add_action( 'do_meta_boxes', function() {
global $pagenow;
if( 'edit.php' != $pagenow ) {
// Only show on edit.php page
return;
}
<!DOCTYPE html>
<html lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8">
<title>JS Driven Weather View</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="https://raw.github.com/andris9/jStorage/master/jstorage.js"></script>
@blobaugh
blobaugh / unregisterposttype.php
Created October 2, 2015 20:48
Unregister post type
if ( ! function_exists( 'unregister_post_type' ) ) :
function unregister_post_type( $post_type ) {
global $wp_post_types;
if ( isset( $wp_post_types[ $post_type ] ) ) {
unset( $wp_post_types[ $post_type ] );
return true;
}
return false;
}
endif;
@blobaugh
blobaugh / gist:3132215
Created July 17, 2012 21:26
simple php recursion
function showit( $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $s )
showit( $s );
} else {
echo $stuff;
}
}
@blobaugh
blobaugh / facebook_share_count.php
Created October 9, 2015 14:17
Facebook share count
<?php
function wds_post_facebook_count( $post_id ) {
$api = "https://graph.facebook.com/";
$url = $api . urlencode( get_permalink( $post_id ) );
$response = wp_remote_get( $url );
if( is_wp_error( $response ) ) {
return 0;
}
@blobaugh
blobaugh / linkedin_share_count.php
Created October 9, 2015 14:21
LinkedIn Share Count
<?php
function linkedin_share_count( $post_id ) {
$api = 'http://www.linkedin.com/countserv/count/share?format=json&url=';
$api .= urlencode( get_permalink( $post_id ) );
if ( ! ( $count = get_transient( 'linkedin_count' . $post_id ) ) ) {
$response = wp_remote_get( $api );
if( is_wp_error( $response ) ) {
// eat it
return 0;