Overview

The request from an established charitable organization was to create an event-based application tailored to the organization’s specific requirements. The application provided for easy upkeep by essentially untrained staff, alongside open, continual, collaborative customization. 

Variations on this application have now been used by this organization three times, at cumulative savings – or enhanced charitable proceeds – of tens of thousands of dollars compared to deployment of the most widely used premium applications used by charities.

Front End (User Experience)

Back End - Staff Interface [FORTHCOMING]

Back End - Developer Actions[FORTHCOMING]

Code Highlights

The chief requirements for custom coding on this application were for

  1. integrating Gravity Form submission with Advanced Custom Field updates,
  2. Adding Advanced Custom Field output as well as shortcodes using ACF outputs to Elementor custom post templates.
				
					<?php
/**
 * A dropdown team selector, to be inserted in an Event via Elementor
 */
add_shortcode( 'dcf_pepp_team_selector', 'dcf_pepp_team_selector' ) ;
function dcf_pepp_team_selector() {
	
	$args = array(
		'post_type'         => 'teams',
		'posts_per_page'    => -1,
		'orderby'           => 'title',
		'order'             => 'ASC',
		'fields'			=> 'ids',
		'category__not_in'	=> array( 54 )
	) ;
	
	$team_ids = get_posts( $args ) ;
	
	ob_start() ;
	
	?>
	
	<div id="team-selector__wrapper" class="team-selector__wrapper">
		<div id="team-selector" class="team-selector custom-select">
			<select onchange="window.document.location.href=this.options[this.selectedIndex].value;">
				<option selected="selected">Find your team...</option><!-- Initial option in dropdown select menu; must be before the while loop -->
				<?php
				foreach ( $team_ids as $team_id ) {
					?>
					<option class="team" value="<?php echo esc_url( get_permalink( $team_id ) ) ; ?>"> <?php echo get_the_title( $team_id ) ; ?>
					</option>
					<?php
				}
				?>
			</select>
		</div>
	</div>
	
	<?php 
	
	return ob_get_clean() ;
	
}
/** 
 * Get output values for Elementor "progress" thermometer added via shortcode to Team template
 */
add_shortcode( 'dcf_get_team_raised_so_far', 'dcf_get_team_raised_so_far' ) ;
function dcf_get_team_raised_so_far() {
	
	$post_id = get_the_ID() ; 
	
	$raised = get_field( 'field_6849f480d3a9b', $post_id ) ; 
	
	if ( $raised ) {
	
		return '<span>Raised so far:</span> $' . number_format( $raised, 2 )  ; 
	
	}
	
	return '<span>Raised so far:</span> $' . number_format( 0, 2 ) ; 
	
}
add_shortcode( 'dcf_get_team_fundraising_goal', 'dcf_get_team_fundraising_goal' ) ;
function dcf_get_team_fundraising_goal() {
	
	$post_id = get_the_ID() ; 
	
	$goal = get_field( 'field_6849f5dbc3cea', $post_id ) ; 
	
	if ( $goal ) {
	
		return '<span>Goal:</span> $' . number_format( $goal, 2 )  ; 
	
	}
	
	return '$' . number_format( 0, 2 ) ; 
	
}
/** 
 * Make team being viewed the default selection in Gravity Form dropdown
 */
add_filter( 'gform_pre_render_54', 'pepp_select_current_team_by_default' ) ;
function pepp_select_current_team_by_default( $form ) {
	
	if ( 'teams' != get_post_type() ) {
		
		return $form ; 
		
	}
	
	foreach( $form['fields'] as $field ) {
		
		if ( $field->id == 46 ) {
			
			$choices = $field['choices'] ;
			
			foreach ( $choices as $key => $value ) {
				
				if ( $value['value'] == get_the_ID() ) {
					
					$value['isSelected'] = true ;
					$choices[$key] = $value ; 
					
				}
			
			}
			
			$field->choices = $choices ; 
			
		}
		
	} 
	
	return $form ; 
	
}
/** 
 * Using Gravity Forms "Advanced Post Creation Add-On," update specific Advanced Custom Fields values and also clear WPRocket cache so that users view fresh content 
 */
/**
 * ADVANCED POST CREATION 
 */
add_action( 'gform_advancedpostcreation_post_after_creation_55', 'pepp_team_creation_add_key_values', 9, 4 );
function pepp_team_creation_add_key_values( $team_id, $feed, $entry, $form ) {
		
	$captain = rgar( $entry, '3.3' ) . ' ' . rgar( $entry, '3.6' ) ; 
	$goal = rgar( $entry, '10' ) ;  
	$new_amount = absint( rgar( $entry, '13' ) ) ;
	//DEBUGGING 
	$form_id = $form['id'] ;  
	
	update_field( 'field_6849f480d3a9b', $new_amount, $team_id ) ; //"end," raised so far
	update_field( 'field_6849f5dbc3cea', $goal, $team_id ) ; //goal
	update_field( 'field_6851fc9e856d8', $captain, $team_id ) ;  //captain
	update_field( 'field_685349240f485', $captain, $team_id ) ; //roster
	
	$old_amount = get_field( 'pepp_raised_so_far', 5382 ) ;
	$new_total = $new_amount + $old_amount ; 

	update_field( 'pepp_raised_so_far', $new_total, 5382 ) ;
	
	//clear WP Rocket Cache for PEPP 2025
	if ( function_exists( 'rocket_clean_post' ) ) {
		
		$cleaned = rocket_clean_post( 5382 ) ;
		$cleaned = rocket_clean_post( $team_id ) ;
		
	}
	
}
/** 
 * Add Member to Team on "Team Join" Submission 
 */
add_action( 'gform_after_submission_54', 'pepp_team_join_add_member', 10, 2 ) ;
function pepp_team_join_add_member( $entry, $form ) {
	 
	$team_id = rgar( $entry, '46' ) ; 
	
	//add member name 
	$member_name = trim( rgar( $entry, '2.3' ) . ' ' . rgar( $entry, '2.6' ) ) ; 
	$current_members = get_field( 'team_roster', $team_id ) ; 
	$members_array = array_map( 'trim', explode( ',', $current_members ) ) ;
	
	if ( ! in_array( $member_name, $members_array ) ) {
		$current_members = $current_members . ', ' . $member_name ;
	}
	
	update_field( 'team_roster', $current_members, $team_id ) ;
	
	//clear WP Rocket Cache for Team Post
	if ( function_exists( 'rocket_clean_post' ) ) {
		
		$cleaned = rocket_clean_post( $team_id ) ;
				
	}
	
}
/** 
 * Updated campaign totals after team creation, team join, or direct donation 
 * Use Gravity Forms API to log donations and reconcile totals if desired 
 */
add_action( 'gform_after_submission', 'pepp_2025_update_total_raised', 10, 2 ) ;
function pepp_2025_update_total_raised( $entry, $form ) {
	
	$form_id = $form['id'] ;
	$team_id = 0 ; 
	
	//prior array( '31', '32', '33' ) ) ) { //individual registration, team join
	if ( in_array( $form_id, array( '52', '54', '51' ) ) ) { //individual registration, team join, donation
		/** GET DATA FOR DEBUGGING AND RECONCILIATION
		custom_log( __FUNCTION__ ) ;
		custom_log(  GFAPI::get_entries( $form_id, array( 'status' => 'active' ), array(), array( 'offset'=> 0, 'page_size' => 200 ) ) ) ;
		**/
		$new_amount = rgar( $entry, '22' ) ; 
		$old_amount = get_field( 'pepp_raised_so_far', 5382 ) ;
		$new_total = $old_amount + $new_amount ; 
		
		/** 
		custom_log( 'OLD AMOUNT: ' . $old_amount ) ; 
		custom_log( 'NEW AMOUNT: ' . $new_amount ) ; 
		custom_log( 'NEW TOTAL: ' . $new_total ) ;
		**/
		
		update_field( 'pepp_raised_so_far', $new_total, 5382 ) ;
	
		if ( '54' == $form_id || '51' == $form_id ) {
			
			$team_id = rgar( $entry, '46' ) ;
			
		}
			
		if ( $team_id ) {
			
			$old_team_total = get_field( 'team_end', $team_id ) ; 
			$new_team_total = $old_team_total + $new_amount ; 
			update_field( 'team_end', $new_team_total, $team_id ) ;
			
		} 
		
		//clear WP Rocket Cache for PEPP 2025
		if ( function_exists( 'rocket_clean_post' ) ) {
			
			rocket_clean_post( 5382 ) ;
			
		}
		
	} 
	
}
				
			

Related Posts