Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
leepettijohn / functions.php
Created September 25, 2017 20:29
Gravity Forms - Limit checkbox choices after chosen
<?
// Change 'XXX' to your form id
$location_form_id = XXX;
add_filter( 'gform_pre_render_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_pre_validation_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_pre_submission_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_pre_submission_filter_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_admin_pre_render_'.$location_form_id, 'limit_choices' );
function limit_choices( $form ) {
@leepettijohn
leepettijohn / functions.php
Created July 28, 2017 18:10
Gravity Forms - File / Image Upload to Featured Image
<?php
form_id = 1;
add_action("gform_post_submission_".$form_id, "add_new_post_featured_image");
function add_new_post_featured_image($entry){
$title_id = 1;
$content_id = 2;
$file_id = 3;
$new_post = array(
'post_title' => $entry[$title_id],
@leepettijohn
leepettijohn / functions.php
Last active March 19, 2020 16:37
Gravity Forms - dynamically populate fields
<?php
/* *** replace "your_parameter" with the parameter in the advanced tab
https://docs.gravityforms.com/using-dynamic-population/ */
add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
return 'boom!';
}
/*Use this for a real estate form */
@leepettijohn
leepettijohn / functions.php
Created October 26, 2019 00:51
Admin View of Post Type - Add ACF field to column
<?php
/* *** add fields from ACF to columns in admin view ****
https://pluginrepublic.com/add-acf-fields-to-admin-columns/
CHANGE
- manage_model_posts_columns (replace "model" with post type slug)
- manage_model_posts_custom_column (replace "model" with post type slug)
- model_order (replace with ACF slug)
*/
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
@leepettijohn
leepettijohn / functions.php
Last active October 25, 2019 21:52
ACF - Populate Dropdown in Repeater Field - with Post Name and ID
<?php
/*
https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/#example-2
*** CHANGE ***
- child_field (this is the dropdown inside the repeater field)
- post_slug
*/
function acf_pre_populate_repeater_dropdown ( $field ) {
$field['choices'] = array();
$args = array('post_type' => 'post_slug');
@leepettijohn
leepettijohn / functions.php
Last active October 19, 2019 19:19
Gravity Forms - get value from field in previous page
<?php
// https://docs.gravityforms.com/gform_pre_render/#3-populate-field-with-values-from-earlier-page
add_filter( 'gform_pre_render_8', 'populate_user_dropdown_info' );
add_filter( 'gform_pre_validation_8', 'populate_user_dropdown_info' );
add_filter( 'gform_pre_submission_filter_8', 'populate_user_dropdown_info' );
//add_filter( 'gform_admin_pre_render_8', 'populate_user_dropdown_info' );
function populate_user_dropdown_info( $form ) {
$current_page = GFFormDisplay::get_current_page( $form['id'] );
@leepettijohn
leepettijohn / functions.php
Created June 22, 2019 01:53
Gravity Forms - Update User Info Meta and Password
add_action( 'gform_post_submission_6', 'update_user_info', 10, 2 );
function update_user_info( $entry, $form ) {
$userid = rgar($entry,'6');
$email = rgar($entry,'5');
$first_name = rgar($entry,'1.3');
$last_name = rgar($entry,'1.6');
$company = rgar($entry,'4');
$address = rgar($entry,'3');
$password = rgar($entry,'7');
$user_id = wp_update_user( array(
@leepettijohn
leepettijohn / functions.php
Created June 21, 2019 22:25
Gravity Forms - Populate the Name Field from a GET variable which is the user ID
add_filter( 'gform_pre_render_6', 'populate_user_info' );
add_filter( 'gform_pre_validation_6', 'populate_user_info' );
add_filter( 'gform_pre_submission_filter_6', 'populate_user_info' );
add_filter( 'gform_admin_pre_render_6', 'populate_user_info' );
function populate_user_info( $form ) {
$userid = sanitize_text_field($_GET['userid']);
foreach ( $form['fields'] as &$field ) {
if ($field->type == 'name'){
$field->inputs[1]['defaultValue'] = get_first_name($userid);
@leepettijohn
leepettijohn / functions.php
Last active June 11, 2019 16:34
Gravity Forms - Dropdown populated with posts
// https://docs.gravityforms.com/dynamically-populating-drop-down-fields/
/* Instructions
- Create a form
- Add a "Dropdown" field
- Add "populate-posts" as the CSS class
*/
add_filter( 'gform_pre_render_51', 'populate_posts' );
add_filter( 'gform_pre_validation_51', 'populate_posts' );
@leepettijohn
leepettijohn / functions.php
Created June 24, 2016 18:10
Genesis - Add search icon to search box and change search text
<?php
//* Do NOT include the opening php tag
//* Enqueue Dashicons
//* CHECK YOUR functions.php FILE FIRST!
add_action( 'wp_enqueue_scripts', 'b3m_enqueue_dashicons' );
function b3m_enqueue_dashicons() {
wp_enqueue_style( 'dashicons' );
}