Skip to content

Instantly share code, notes, and snippets.

View clifgriffin's full-sized avatar

Clifton Griffin clifgriffin

View GitHub Profile
<?php
$properties = array('name','slug','id');
foreach ($properties as $prop) {
if (!isset($atts[$prop])) continue;
$Product = new Product($atts[ $prop ],$prop);
}
if ( ! empty($Product->id) ) {
ShoppProduct($Product);
} elseif ( ! isset( ShoppProduct->id() ) ) {
add_action('wp_ajax_cart_modal_update', 'update_cart_modal');
add_action('wp_ajax_nopriv_cart_modal_update', 'update_cart_modal');
function update_cart_modal() {
parse_str($_REQUEST['form_fields'], $_REQUEST);
if (!empty($_REQUEST['items'])) {
foreach ($_REQUEST['items'] as $id => $item) {
if (array_key_exists('quantity', $item) && is_numeric($item['quantity'])) {
$item['quantity'] = absint($item['quantity']);
@clifgriffin
clifgriffin / gist:6384966
Created August 30, 2013 00:19
Sort get_terms, naturally
<?php
function sort_terms ( $terms ) {
$sort_terms = array();
foreach($terms as $term) {
$sort_terms[$term->name] = $term;
}
uksort( $sort_terms, 'strnatcmp');
@clifgriffin
clifgriffin / sort_terms_naturally.php
Created August 30, 2013 13:23
Add new orderby parameter to get_terms in WordPress to allow for natural or alphanumeric sort
<?php
add_filter('get_terms', 'sort_terms_naturally', 20, 3);
function sort_terms_naturally ( $terms, $taxonomies, $args ) {
if ( isset($args['orderby']) && $args['orderby'] == 'natural' ) {
$sort_terms = array();
foreach($terms as $term) {
$sort_terms[$term->name] = $term;
}
@clifgriffin
clifgriffin / sort_naturally_post_edit.php
Created August 30, 2013 13:35
Leverage https://gist.github.com/clifgriffin/6389814 to sort terms naturally on post edit screens.
<?php
add_filter('get_terms_orderby', 'reorder_categories_admin', 20, 2);
function reorder_categories_admin($orderby, $args)
{
global $pagenow;
// If not category, bail
if ( ! isset($args['taxonomy']) || $args['taxonomy'] != 'category' ) return $orderby;
@clifgriffin
clifgriffin / gist:6412715
Last active December 22, 2015 03:49
Settings API
<?php
require_once './SettingsAPI.php';
class MyPlugin extends SettingsAPI {
var $prefix = 'myplugin_';
/* CRAZY AWESOME STUFF */
}
<?php
/**
* WordPress Simple Settings
*
* A simple framework for managing WordPress plugin settings.
*
* @author Clifton H. Griffin II
* @version 0.1
* @copyright Clif Griffin Development, Inc. 2013
* @license GNU GPL version 3 (or later) {@see license.txt}
@clifgriffin
clifgriffin / wooslider-shopp.php
Last active December 24, 2015 10:19
Making WooSlider and Shopp play nicely together.
<?php
add_filter('wooslider_get_slides', 'shopp_wooslider', 10, 4);
public function shopp_wooslider($slides, $type, $args, $settings) {
if( is_shopp_product() ) {
$slides = array();
if ( shopp('product', 'has-images') ) {
while( shopp('product','images') ) {
$data = array( 'content' => shopp('product','get-image',"setting={$args['size']}") );
@clifgriffin
clifgriffin / gist:6924528
Created October 10, 2013 19:56
An infinitely looping pulse animation that you can stop.
function start_pulse(element) {
jQuery(element).removeClass("stopped");
jQuery(element).fadeIn(500, function() {
jQuery(this).fadeOut(500, function() {
if ( !jQuery(this).hasClass("stopped") ) {
start_pulse();
} else {
jQuery(this).fadeIn(500);
}
@clifgriffin
clifgriffin / gist:7472268
Last active December 28, 2015 08:29
An AJAX handler for impersonating customers. (Broken)
<?php
add_action('wp_ajax_impersonate_customer', 'mg_impersonate_customer');
function mg_impersonate_customer() {
get_currentuserinfo();
$Order = ShoppOrder();
$Order->data['Agent'] = $current_user->user_login;
$Order->data['CustomerUserID'] = $customer->wpuser;