Skip to content

Instantly share code, notes, and snippets.

@lgedeon
lgedeon / gist:4441042
Created January 3, 2013 05:23
Simplified get terms - had to do this to get to something else but thought it might come in handy someday
function get_terms($taxonomy, $args = '') {
global $wpdb;
$empty_array = array();
$single_taxonomy = true;
if ( ! taxonomy_exists($taxonomy) ) {
$error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
return $error;
<?php
/**
* Implements taxonomy command.
*
* @package wp-cli
*/
class Taxonomy_Command extends WP_CLI_Command {
/**
* Exports all terms from a taxonomy.
@lgedeon
lgedeon / gist:4760250
Created February 12, 2013 04:29
strips control characters from feed content
// non-prefixed version submited to core as patch
function tc_strip_for_xml( $string ) {
// Store the site charset as a static to avoid multiple calls to get_option()
static $is_utf8;
if ( ! isset( $is_utf8 ) ) {
$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
}
if ( ! $is_utf8 ) {
return $string;
}
@lgedeon
lgedeon / gist:5414093
Last active December 16, 2015 09:38
Generic field sanitization class for WP core.
<?php
/**
* Provide functionality to register new Archive Elements
*/
/**
* Proposed generic field class to be used by the Settings API, Widgets,
@lgedeon
lgedeon / Filter WIth Args
Last active December 19, 2015 10:09
1st pass - needs sanitization, optional parameters (have to reorder), abstract to do actions too.
<?php
class FilterWithArgs {
protected $filter;
protected $function;
protected $priority;
protected $arg_count;
protected $args;
public function __construct( $filter, $function, $priority, $arg_count, $args ) {
$this->filter = $filter;
$this->function = $function;
@lgedeon
lgedeon / time-range
Created July 27, 2013 02:37
partial time range solution
/**
* Returns a compact date range like March 27-29, 1977 from two unix time stamps. If $end is empty
* or less than start returns start only.
*
* @param int $start Unix timestamp
* @param int $end Unix timestamp
* @param string $round Least unit of time to include - supported values: day, hour, minute
* @param string $include Largest unit of time to include - supported values: year, month, hour
*
* Samples:
@lgedeon
lgedeon / clever
Created September 1, 2013 01:14
clever way to find a term when you don't know what you have been given
} elseif ( isset ( $item->taxonomy ) && isset( $item->term ) ) {
if ( ( is_int( $item->term ) && $term = get_term_by( 'id', $item->term, $item->taxonomy ) )
|| ( $term = get_term_by( 'name', $item->term, $item->taxonomy ) )
|| ( $term = get_term_by( 'slug', $item->term, $item->taxonomy ) ) ) {
$item_array['menu-item-type'] = 'taxonomy';
$item_array['menu-item-object'] = $term->taxonomy;
$item_array['menu-item-object-id'] = $term->term_id;
$item_array['menu-item-title'] = ( $item_array['menu-item-title'] ) ?: $term->name;
} else {
continue;
@lgedeon
lgedeon / gist:6643888
Created September 20, 2013 21:04
what am I doing wrong?
function seoslides_pre_user_query( $query ) {
if( 'DateRegistered' == $query->query_vars['orderby'] ) {// echo 'thus far';
$query->query_from .= " LEFT JOIN wp_usermeta m ON (wp_users.ID = m.user_id AND m.meta_key = 'user_registered')";
$query->query_orderby = "ORDER BY m.meta_value " . $query->query_vars['order'];
}
}
add_action( 'pre_user_query', 'seoslides_pre_user_query' );
function seoslides_manage_users_columns( $columns ) {
$columns['user_registered'] = 'Date Registered';
@lgedeon
lgedeon / Lightbox Evolution
Created November 7, 2013 02:37
Wrong just wrong
<?PHP
/*
Plugin Name: Lightbox Evolution
Plugin URI: http://codecanyon.net/item/lightbox-evolution-for-wordpress/119478
Description: <strong>Lightbox Evolution</strong> is a tool for displaying images, html content, maps, and videos in a "lightbox" style that floats overtop of web page. Using Lightbox Evolution, website authors can showcase a wide assortment of media in all major browsers without navigating users away from the linking page.
Version: 1.4.5
Author: Eduardo Daniel Sada
Author URI: http://codecanyon.net/user/aeroalquimia/portfolio
*/
@lgedeon
lgedeon / duck punch toggle
Created December 5, 2013 18:24
Basic toggling
<div id="container">
<h1>Hello
<span class="seoslides-vistoggler">
<a href="#">Trigger</a>
<span>hide me</span>
</span> world
</h1>
The trigger can be a link, button, or anything else as long as it isn't in a span :)
</div>
<style>