Skip to content

Instantly share code, notes, and snippets.

View mandiwise's full-sized avatar

Mandi Wise mandiwise

  • Edmonton, Canada
View GitHub Profile
@mandiwise
mandiwise / Gravity Forms Custom Validation Example
Last active August 29, 2015 14:01
Checking to see if the field contained "Vancouver" and failing validation if it does.
function my_custom_validation( $validation_result ) {
$form = $validation_result["form"];
// Sorry, you don't get to live in Vancouver...
if ( $_POST['input_1'] == 'Vancouver' ) {
$validation_result["is_valid"] = false;
foreach ( $form["fields"] as &$field ) {
@mandiwise
mandiwise / Launch Chrome with file access flag
Created September 13, 2014 19:12
Allows you to run LESS locally in Chrome by launching it from the terminal with the "allow-file-access-from-files" flag
$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
@mandiwise
mandiwise / highlighting.bash
Created October 9, 2015 17:36
Use Highlight to copy and paste code with syntax highlight.
pbpaste | highlight -S css -O rtf --style moria | pbcopy
@mandiwise
mandiwise / hide-default-posts.php
Last active November 30, 2015 04:03
Hide post-related screens in the WordPress admin area, including Categories and Tags.
<?php
/**
* Plugin Name: Hide Default Posts
* Plugin URI: https://gist.github.com/mandiwise/2ea571ae0773b340af5a
* Description: Hide post-related screens in the WP admin area, including Categories and Tags.
* Version: 1.0.0
* Author: Mandi Wise
* Author URI: http://mandiwise.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@mandiwise
mandiwise / functions.php
Last active November 30, 2015 04:15
Customize archive title in WP
<?php
/**
* Customize the Product archive title
*/
function red_archive_title( $title ) {
if ( is_post_type_archive( 'product' ) ) {
$title = 'Our Products Are Made Fresh Daily';
} elseif ( is_tax( 'product-type' ) ) {
$title = sprintf( '%1$s', single_term_title( '', false ) );
} elseif ( is_post_type_archive( 'testimonial' ) ) {
@mandiwise
mandiwise / functions.php
Last active November 30, 2015 04:16
Auto-populate page title of previously-viewed page in a Gravity Form field
<?php
function awi_autopopulate_workshop_title( $value ){
$referer_id = url_to_postid( wp_get_referer() );
$workshop_title = get_the_title( $referer_id );
return $workshop_title;
}
add_filter( 'gform_field_value_workshop_title', 'awi_autopopulate_workshop_title' );
// Usage:
// Add code to functions.php or similar
@mandiwise
mandiwise / functions.php
Last active November 30, 2015 04:18
Custom WP excerpts (with allowed HTML tags and custom read more link)
<?php
/**
* Customize excerpt length and style.
*
* @param string The raw post content.
* @return string
*/
function red_wp_trim_excerpt( $text ) {
$raw_excerpt = $text;
@mandiwise
mandiwise / nav.js
Last active November 30, 2015 18:01
A simple nav-bar locking jQuery script.
/**
* Navbar Locking
*/
$(function () {
var $window = $(window),
$mainNav = $('.main-navigation'), // nav wrapper element
stickyNavTop = $mainNav.offset().top;
@mandiwise
mandiwise / .bash_profile
Created February 19, 2016 19:44
Customize bash prompt with highlighted git branch
txtcyn=$'\e[0;36m' # Cyan
txtred=$'\e[0;31m' # Red
txtwht=$'\e[0;37m' # White
txtrst=$'\e[0m' # Text Reset
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[$txtcyn\]\$(parse_git_branch) \[$txtrst\]\$ " # fancify Terminal prompt
@mandiwise
mandiwise / Gravity Forms and Fancybox
Last active March 8, 2016 19:21
Using Gravity Forms with a modal and ajax
<div id="voting-form" style="display:none">
<?php echo do_shortcode( '[gravityform id="6" title="false" description="false" ajax="true"]' ) ?>
</div>
<a href="#voting-form" class="fancybox button">Vote Now</a>