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 / Count lines in Git repo
Last active April 27, 2024 06:00
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@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 February 11, 2021 01:14
Create, display and save an URL field in a WP custom metabox
<?php
/**
* Add the metabox.
*/
function my_url_add_metabox() {
add_meta_box(
'my_url_section', // The HTML id attribute for the metabox section
'My URL Metabox Title', // The title of your metabox section
@mandiwise
mandiwise / Sync gh-pages + master branches
Last active April 27, 2024 05:41
Keep gh-pages up to date with a master branch
// Reference: http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/
$ git add .
$ git status // to see what changes are going to be commited
$ git commit -m 'Some descriptive commit message'
$ git push origin master
$ git checkout gh-pages // go to the gh-pages branch
$ git rebase master // bring gh-pages up to date with master
$ git push origin gh-pages // commit the changes
@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 / functions.php
Last active January 27, 2017 21:26
Save an option to the database containing unexpected output during plugin activation
<?php
/**
* Usage: "echo get_option('plugin_error');" or look for the option the DB after activation
*
* @link http://thehungrycoder.com/wordpress/how-i-have-solved-the-the-plugin-generated-xxxx-characters-of-unexpected-output-during-activation-problem.html
*/
function save_error(){
update_option( 'plugin_error', ob_get_contents()) ;
@mandiwise
mandiwise / functions.php
Last active January 27, 2017 21:27
Prevent a given form submitter from entering the same value in a form field twice (on multiple submits)
<?php
function no_duplicate_votes($validation_result){
global $wpdb;
$nominee_field = 1;
$email_field = 2;
$form = $validation_result['form'];
foreach( $form["fields"] as &$field ) {
if ( $field['id'] == $email_field ) {
$email_value = rgpost("input_{$field['id']}");
@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 / Dynamically Populate Gravity Forms Dropdown with CPT
Last active March 22, 2023 12:40
Using gform_pre_render_[form ID] for Auto-population
function populate_concept_nominees( $form ){
foreach ( $form['fields'] as &$field ){
// Set a custom CSS class for your field and grab onto it here
if ( $field['type'] != 'select' || strpos( $field['cssClass'], 'populate-concept' ) === false )
continue;
// Query parameters for get_posts
@mandiwise
mandiwise / Limit Gravity Forms Upload Size
Last active January 16, 2022 14:12
Set a maximum upload size for a Gravity Forms image field
function limit_file_upload_size( $validation_result ) {
$form = $validation_result['form'];
foreach( $form['fields'] as &$field ){
// NOTE: Add a custom CSS class to your image upload field and grab onto it here...
if( strpos( $field['cssClass'], 'choose-file' ) === false )
continue;