Skip to content

Instantly share code, notes, and snippets.

View daltonrooney's full-sized avatar

Dalton Rooney daltonrooney

View GitHub Profile
@daltonrooney
daltonrooney / file-upload-handler.php
Created February 4, 2012 13:29
Multi-file WordPress uploads from the front-end
<?php /* This function attaches the image to the post in the database, add it to functions.php */
function insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
@daltonrooney
daltonrooney / gist:1784053
Created February 9, 2012 22:55
Resize vertical images max-height based on width of parent container for responsive layouts
function adaptiveResize() {
var $w, $target;
$target = $('img');
$target.each(function() {
$w = $(this).parent().width();
$target.css('max-height', $w );
});
}
@daltonrooney
daltonrooney / typekit-plugin.php
Created April 4, 2012 16:52
Add custom scripts to header
<?php
/*
* Plugin Name: Add TypeKit scripts to header
*/
function my_theme_custom_head() { ?>
<script type="text/javascript">
/* Your custom scripts go here */
</script>
@daltonrooney
daltonrooney / gist:2570640
Created May 1, 2012 19:16
PSP 1.6.1 custom js
/*!
* jQuery imagesLoaded plugin v2.0.1
* http://github.com/desandro/imagesloaded
*
* MIT License. by Paul Irish et al.
*/
(function(a,b){var c="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";a.fn.imagesLoaded=function(k){var h=this,m=a.isFunction(a.Deferred)?a.Deferred():0,l=a.isFunction(m.notify),e=h.find("img").add(h.filter("img")),f=[],j=[],g=[];function i(){var n=a(j),o=a(g);if(m){if(g.length){m.reject(e,n,o)}else{m.resolve(e)}}if(a.isFunction(k)){k.call(h,e,n,o)
}}function d(n,o){if(n.src===c||a.inArray(n,f)!==-1){return}f.push(n);if(o){g.push(n)}else{j.push(n)}a.data(n,"imagesLoaded",{isBroken:o,src:n.src});if(l){m.notifyWith(a(n),[o,e,a(j),a(g)])}if(e.length===f.length){setTimeout(i);e.unbind(".imagesLoaded")}}if(!e.length){i()}else{e.bind("load.imagesLoaded error.imagesLoaded",function(n){d(n.target,n.type==="error")}).each(function(n,p){var q=p.src;var o=a.data(p,"imagesLoaded");if(o&&o.src===q){d(p,o.isBroken);return}if(p.complete&&p.naturalWidth!==b){d(p,p.naturalWidt
<?php
/**
* The Header for the template.
*
* @package WordPress
*/
$pp_theme_version = '1.0';
?><!DOCTYPE html>
<?php $args = array(
'numberposts' => -1,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'custom_post_type_here',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'custom_field_key_name',
@daltonrooney
daltonrooney / charlimit.js
Last active August 29, 2015 14:03
Visual character limit for textareas
(function($){
function addCharLimit(){
$('textarea').each(function(){
maxlength = $(this).attr("maxlength");
if ( maxlength !== undefined ) {
charContainer = $(this).parent().find('p.charleft').val();
if ( charContainer === undefined ) {
$(this).parent().append("<p class='charleft description'>");
}
charleft = maxlength - $(this).val().length;
@daltonrooney
daltonrooney / pagination.php
Created September 11, 2014 23:23
Numerical pagination for supplemental SearchWP engine
<!-- begin pagination -->
<?php if( $engine->maxNumPages > 1 ) :
echo '<nav class="pagination"><ul>';
$max = intval( $engine->maxNumPages );
/**ID of your custom search results page here**/
$permalink = get_permalink(479);
$prevPage = $swppg > 1 ? $swppg - 1 : false;
$nextPage = $swppg < $engine->maxNumPages ? $swppg + 1 : false;
@daltonrooney
daltonrooney / info.txt
Last active August 29, 2015 14:07
Add a downloadable product to a user's account when a WooCommerce Subscription is created
Let's say you run a WooCommerce subscription website, and you'd like to automatically add
a downloadable product to a subscriber's account when they activate their subscription.
Here's one way to do it:
@daltonrooney
daltonrooney / get_stores_by_location.php
Last active June 29, 2023 14:14
Store locator with Advanced Custom Fields
<?php
function mbn_get_stores_by_location( $zip, $radius ) {
global $wpdb;
$radius = intval( $radius );
// we first need to get the source coordinates
$sql = "SELECT `latitude`, `longitude` FROM `wp_zip_codes` WHERE `zipcode` = '%s'";
$coords = $wpdb->get_row( $wpdb->prepare( $sql, $zip ) );