Skip to content

Instantly share code, notes, and snippets.

View mikeselander's full-sized avatar
:shipit:
Shipping

Mike Selander mikeselander

:shipit:
Shipping
View GitHub Profile
@mikeselander
mikeselander / gf-convert-to-timestamp.php
Created July 10, 2014 16:44
Gravity Forms doesn't offer a function to export a date field as a UNIX timestamp. This function will find all exported dates in a GF submission & convert it to UNIX, and then update the postmeta to the proper format - as is, it will ONLY work if you're using the Gravity Forms + Custom Post Types plugin to create or edit a post
add_action( 'gform_after_submission', '_convert_date_to_timestamp', 10, 2 ); // Extend
function _convert_date_to_timestamp( $entry, $form ) {
date_default_timezone_set ( "America/Denver" );
// Make sure that we're submitting a post before running the code
if ( $entry['post_id'] ){
foreach ( $entry as $key => $value ){
@mikeselander
mikeselander / clean_phone_numbers.php
Created July 8, 2014 21:20
Clean up phone numbers to return as a linkable object grabbed and adapted from: http://stackoverflow.com/questions/4708248/formatting-phone-numbers-in-php
function _otm_clean_phone_number( $number ){
$phoneNumber = preg_replace('/[^0-9]/','',$number);
if(strlen($phoneNumber) > 10) {
$countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10);
$areaCode = substr($phoneNumber, -10, 3);
$nextThree = substr($phoneNumber, -7, 3);
$lastFour = substr($phoneNumber, -4, 4);
@mikeselander
mikeselander / PHPtoICS.php
Created July 5, 2014 03:37 — forked from jakebellacera/ICS.php
Script to create an iCal file from a php event with a UNIX timestamp
<?php
// Variables used in this script:
// $summary - text title of the event
// $datestart - the starting date (in seconds since unix epoch)
// $dateend - the ending date (in seconds since unix epoch)
// $address - the event's address
// $uri - the URL of the event (add http://)
// $description - text description of the event
// $filename - the name of this file for saving (e.g. my-event-name.ics)
//
@mikeselander
mikeselander / resize-partners.js
Created July 2, 2014 23:32
Maintain an exact size & margin between an unknown number of images within a parent div - useful for situations where a user can add multiple (unknown) number of logos to a box (generally footer)
function adjust_header_banner(){
var footer = $('.footer');
count = 0;
totalWidth = 0;
// Calculate distance between partner images
$('.partners img').each(function() {
totalWidth += $(this).width();
count += 1;
@mikeselander
mikeselander / restrict-failed-login.php
Created July 2, 2014 23:27
On front-end login form, keep user from being re-directed to an admin login page when a field fails
/**
* Keep a failed login attempt on the same page instead of re-directing to backend
* @access public
* @since 0.1.0
*/
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); // hook failed login
function my_front_end_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
@mikeselander
mikeselander / remove-admin-bar.php
Created July 2, 2014 23:25
Remove admin bar & keep end users out of the WordPress backend
/**
* Remove admin bar & admin access for non-managers & non-admins
* @access public
* @since 0.1.0
*/
add_action('admin_init', 'no_mo_dashboard');
add_action('after_setup_theme', 'remove_admin_bar');
function no_mo_dashboard() {
if ( ! current_user_can( 'edit_others_posts' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( site_url() ); exit;
@mikeselander
mikeselander / Pre_Render_Object.php
Created June 19, 2014 16:29
A function to automatically fill in an edit gravity form with the appropriate data from a custom table object
add_filter('gform_pre_render_3', 'populate_fields_contact'); // Document Form
function populate_fields_contact( $form ){
// Make sure we're editing the object correctly
if ( $_GET['update_contact'] ){
// Set our default values
$data_type = "contact";
$data_type_length = 8; // 'contact_' = 8 char
function make_comparer() {
// Normalize criteria up front so that the comparer finds everything tidy
$criteria = func_get_args();
foreach ($criteria as $index => $criterion) {
$criteria[$index] = is_array($criterion)
? array_pad($criterion, 3, null)
: array($criterion, SORT_ASC, null);
}
return function($first, $second) use (&$criteria) {
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
@mikeselander
mikeselander / css-cheatsheet.css
Created June 6, 2014 04:02
Basic CSS Selector Cheatsheet
/* Basic Selectors */
#name /* <div id='name'> */
.name{} /* <div class='name'> */
.parent.name{} /* <div class='parent name'> */
.parent .child{} /* Child Element <div class='parent'> <div class='child'> */
.parent > .child{} /* Direct Child Element ONLY (grandchildren will be ignored) */
.one + .two{} /* Directly Adjoining Elements <div class='one'></div> <div class='two'></div> */
.one ~ .two{} /* Any Following Elements */
/* dynamic selectors */