Skip to content

Instantly share code, notes, and snippets.

View cassler's full-sized avatar

Darin Cassler cassler

View GitHub Profile
@cassler
cassler / purge-transients.php
Created June 6, 2014 20:03
Removes non-essential transients from DB
<?php
if ( ! function_exists('purge_transients') ) {
function purge_transients($older_than = '7 days', $safemode = true) {
global $wpdb;
$older_than_time = strtotime('-' . $older_than);
if ($older_than_time > time() || $older_than_time < 1) {
return false;
@cassler
cassler / curl-timer.sh
Last active August 29, 2015 14:02
Timed CURL
#!/bin/bash
CURL="/usr/bin/curl"
GAWK="/usr/bin/gawk"
echo -n "Please pass the url you want to measure: "
read url
URL="$url"
result=`$CURL -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} $URL`
echo " Time_Connect Time_startTransfer Time_total "
echo $result | $GAWK -F: '{ print $1" "$2" "$3}'
@cassler
cassler / wp-format-loop.md
Last active August 29, 2015 13:58
Post Format Detecting Loop

Use Details

You'll want to start by creating a file ```/content/loop.php`` - will be your default or "standard" format loop. For additional post format support, you'll need to add a loop file to match. For example, if your theme supports the post formats 'aside', 'video', and 'audio' then you should have:

  • /content/loop.php : Standard/Default View
  • /content/loop-aside.php : View for Aside Post Format
  • /content/loop-video.php : View for Video Post Format
  • /content/loop-audio.php : View for Audio Post Format

As you cycle through your loop, the correct template part will be rendered for each post format.

@cassler
cassler / event-sorter.php
Created February 7, 2014 04:17
Automatically sort custom post type 'event' by meta-key 'event-date' and only display posts in the future.
<?php function order_events_by_date($request){
$dummy_query = new WP_Query();
$dummy_query->parse_query( $request );
if($dummy_query->is_singular()):
return $request;
elseif(isset($request['post_type']) && $request['post_type'] == 'event'):
if(!is_admin()):
$request['orderby'] = 'meta_value menu_order title';
$request['meta_key'] = 'event-date';
$request['order'] = 'ASC';
@cassler
cassler / bootstrap-walker.php
Created February 7, 2014 04:15
Bootstrap Wordpress Nav Walker, changes markup on your menus to use bootstrap formatting
<?php class responsive_menu_walker extends Walker_Nav_Menu
{
function start_lvl(&$output, $depth) {
// update the <li> element
$bookmark = 'den-menu-top';
$li_pos = strrpos ( $output, $bookmark );
$output = substr($output, 0, $li_pos+strlen($bookmark)) . " dropdown" . substr($output, $li_pos+strlen($bookmark), strlen($output) - $li_pos);
// update the <a> element
$bookmark = "<a ";
@cassler
cassler / den_event_date.php
Created February 7, 2014 04:14
Assumes your post has a stored date meta-key called 'event-date'. This template tag will render the human readable date. If the meta-key matches the current date, it will instead return 'Today'
<?php
/**
* Return human version of zulu time
*
* Assumes your post has a stored date meta-key called 'event-date'. This template tag will render the human
* readable date. If the meta-key matches the current date, it will instead return 'Today'
*
* @package den_framework
* @subpackage den_calendar
@cassler
cassler / hook-page-title.php
Created February 7, 2014 04:07
Show the proper H1 based on context
<?php function den_page_title() {
$post = $posts[0]; // Hack. Set $post so that the_date() works.
/* If this is a category archive */
if (is_category()) {
echo '<h1>Archive for the &#8216;' . single_cat_title() . '&#8217; Category</h1>';
} elseif( is_tag() ) { // If is tag archive
echo '<h1>Posts Tagged &#8216;' . single_tag_title(); . '&#8217;</h1>';
/* If this is a daily archive */
} elseif (is_day()) {
@cassler
cassler / widget-enhanced-recent-posts.php
Created February 7, 2014 03:59
More powerful recent posts widget
<?php
class Widget_Recent_Posts_Xtra extends WP_Widget {
// name this widget.
// naming this widget allows us to use filters for unique widget areas.
var $namespace = "xtra-recent-posts-widget";
function __construct() {
$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
parent::__construct('recent-posts', __('Custom Recent Posts'), $widget_ops);
@cassler
cassler / function-breadcrumbs.php
Created February 7, 2014 03:57
Super Easy Wordpress Breadcrumbs
/**
* Super Easy Breadcrumbs
*
* Creates an unordered list for ancestor links.
*
* @example <?php easy_breadcrumbs(); ?>
* @author Scott Nelle
* @package den_framework
* @subpackage den_custom_hooks
**/
@cassler
cassler / gist:8857177
Created February 7, 2014 03:56
wp-get-meta-keys
/**
* Get all meta keys for given object.
*
* Finds all custom meta keys for a given post and extracts them to an array for easy access.
* @example $meta = den_get_meta;
* @example echo ($meta['my-key'] ? $meta['my-key'] : null );
* @return array of meta keys for post
* @author Darin Cassler
* @package den_framework
* @subpackage den_custom_hooks