Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@joshuadavidnelson
joshuadavidnelson / custom-route-notification-multiple-fields.php
Last active December 8, 2017 20:04
Per emailed question, utilizing the example in my blog post "User Dropdown List & Custom Notification Routing in Gravity Forms" for multiple fields that have the custom 'user-emails' CSS class to email multiple people
<?php
/**
* Change the sent to email address in the notification
*
* @author Joshua David Nelson, josh@joshuadnelson.com
**/
// Route to user address from drop down list, update the '1' to the ID of your form
add_filter( 'gform_notification_1', 'route_user_email_notification', 10, 3 );
function route_user_email_notification( $notification, $form , $entry ) {
@joshuadavidnelson
joshuadavidnelson / gist:57210d6218e4039288973d0045a10159
Created May 5, 2017 20:07 — forked from dustyf/gist:b6e72a7a7fd05de9598e
Example WordPress Simple JSON Endpoint Plugin
<?php
/**
* Plugin Name: WDS GIF API
* Plugin URI: http://webdevstudios.com
* Description: Adds a Custom Post Type to store GIFs and an API JSON Endpoint to access GIFs by a tag.
* Author: WebDevStudios
* Author URI: http://webdevstudios.com
* Version: 1.0.0
* License: GPLv2
*/
<?php
/**
* Associate an uploaded file with a post on form submission in Gravity Forms
*
* This is specific to a comment on my post about connecting GF with ACF
*
* @see https://joshuadnelson.com/connect-gravity-forms-file-upload-to-acf-gallery-field/#comment-13186
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
$gravity_form_id = 1; // gravity form id, or replace {$gravity_form_id} below with this number
@joshuadavidnelson
joshuadavidnelson / gf-upload-file-to-media-library.php
Last active April 29, 2020 19:42
Create a media file on upload, requires the JDN_Create_Media_File class from https://gist.github.com/joshuadavidnelson/164a0a0744f0693d5746
<?php
/**
* Create a new media library entry with a file upload on gravity form submission.
* @see https://joshuadnelson.com/connect-gravity-forms-file-upload-to-acf-gallery-field/
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
$gravity_form_id = 1; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter( "gform_after_submission_{$gravity_form_id}", 'jdn_add_image_to_media_library', 10, 2 );
function jdn_add_image_to_media_library( $entry, $form ) {
<?php
/**
* Connect a Gravity Form File Upload Field to an ACF Image Field.
* @see https://joshuadnelson.com/connect-gravity-forms-file-upload-to-acf-gallery-field/
*/
$gravity_form_id = 1; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter( "gform_after_submission_{$gravity_form_id}", 'jdn_set_acf_gallery_field', 10, 2 );
function jdn_set_acf_gallery_field( $entry, $form ) {
$gf_images_field_id = 7; // the upload field id
@joshuadavidnelson
joshuadavidnelson / get-responsive-image.php
Last active August 7, 2023 13:16
Generate a img tag for responsive images in WordPress
<?php
/**
* Get the responsive image.
*
* @param string $image_id
* @param string $image_size optional
*
* @return string $output
*/
function get_responsive_image( $image_id, $size = 'medium' ) {
<?php
// Route to user address from drop down list, update the '1' to the ID of your form – I am using this on 6 forms so I have removed the ID requirement
add_filter( 'gform_notification', 'welcome_email', 10, 3 );
function welcome_email( $notification, $form , $entry ) {
foreach( $form['fields'] as &$field ) {
// Similar to above, find the right field
if( $field['type'] != 'select' || strpos($field['cssClass'], 'user-emails') === false )
continue;
// Pull out the user id selected, by the field id and the $entry element
@joshuadavidnelson
joshuadavidnelson / git-commit-after-plugin-update.php
Last active June 27, 2020 05:02
Create a commit for every plugin update.
<?php
/**
* Plugin Name: Commit on Update
* Plugin Author: Joshua David Nelson
**/
defined( 'ABSPATH' ) or die( 'Nope!' );
class Commit_On_Update {
@joshuadavidnelson
joshuadavidnelson / allow-shortcodes-in-genesis-archive-intro.php
Created January 27, 2017 03:55
Allow shortcodes in the intro text output of Genesis archives.
<?php
/**
* Allow shortcodes in genesis archive intro text.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
**/
// Custom Post Type Archive Intro Text
add_filter( 'genesis_cpt_archive_intro_text_output', 'do_shortcode' );