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 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>
@mandiwise
mandiwise / Dynamically Populate Gravity Forms Text Field
Last active May 20, 2017 00:33
Using gform_field_value_{param}
function my_city_population_function( $value ){
return 'Vancouver';
}
add_filter( 'gform_field_value_my_city', 'my_city_population_function' );
@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;
@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 / 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 / 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 / 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 / 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 / Sync gh-pages + master branches
Last active January 6, 2024 21:57
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 / 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