Skip to content

Instantly share code, notes, and snippets.

Mandi Wise mandiwise

Block or report user

Report or block mandiwise

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mandiwise
mandiwise / Gravity Forms and Fancybox
Last active Mar 8, 2016
Using Gravity Forms with a modal and ajax
View Gravity Forms and Fancybox
<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>
View Dynamically Populate Gravity Forms Text Field
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 Jan 29, 2019
Set a maximum upload size for a Gravity Forms image field
View Limit Gravity Forms Upload Size
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 Dec 26, 2018
Using gform_pre_render_[form ID] for Auto-population
View Dynamically Populate Gravity Forms Dropdown with CPT
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 Aug 29, 2015
Checking to see if the field contained "Vancouver" and failing validation if it does.
View Gravity Forms Custom Validation Example
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 Jan 27, 2017
Prevent a given form submitter from entering the same value in a form field twice (on multiple submits)
View functions.php
<?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 Jan 27, 2017
Save an option to the database containing unexpected output during plugin activation
View functions.php
<?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 Sep 13, 2014
Allows you to run LESS locally in Chrome by launching it from the terminal with the "allow-file-access-from-files" flag
View Launch Chrome with file access flag
$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
@mandiwise
mandiwise / Sync gh-pages + master branches
Last active Sep 13, 2019
Keep gh-pages up to date with a master branch
View Sync gh-pages + master branches
// 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 Mar 25, 2018
Create, display and save an URL field in a WP custom metabox
View functions.php
<?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
You can’t perform that action at this time.