Skip to content

Instantly share code, notes, and snippets.

@ammist
Created September 21, 2018 23:25
Show Gist options
  • Save ammist/eef6fd2b1954d59fef8cb20b5e639d8c to your computer and use it in GitHub Desktop.
Save ammist/eef6fd2b1954d59fef8cb20b5e639d8c to your computer and use it in GitHub Desktop.
Gravity Forms Custom Fields (TL Event RSVP WordPress Plugin)
{"0":{"title":"Support Group RSVP","description":"Pre-register for the support group. If you are a member, log in and attend for free.","labelPlacement":"top_label","descriptionPlacement":"below","button":{"type":"text","text":"Register","imageUrl":"","conditionalLogic":null},"fields":[{"type":"email","id":2,"label":"Email","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"user_email","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","productField":"","emailConfirmEnabled":"","displayOnly":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false},{"type":"name","id":1,"label":"Name","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","nameFormat":"advanced","inputs":[{"id":"1.2","label":"Prefix","name":"","choices":[{"text":"Mr.","value":"Mr.","isSelected":false,"price":""},{"text":"Mrs.","value":"Mrs.","isSelected":false,"price":""},{"text":"Miss","value":"Miss","isSelected":false,"price":""},{"text":"Ms.","value":"Ms.","isSelected":false,"price":""},{"text":"Dr.","value":"Dr.","isSelected":false,"price":""},{"text":"Prof.","value":"Prof.","isSelected":false,"price":""},{"text":"Rev.","value":"Rev.","isSelected":false,"price":""}],"isHidden":true,"inputType":"radio"},{"id":"1.3","label":"First","name":"first_name"},{"id":"1.4","label":"Middle","name":"","isHidden":true},{"id":"1.6","label":"Last","name":"last_name"},{"id":"1.8","label":"Suffix","name":"","isHidden":true}],"formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","productField":"","displayOnly":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false},{"type":"date","id":4,"label":"Date","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"dateType":"datepicker","calendarIconType":"none","formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"event_date","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","calendarIconUrl":"","dateFormat":"mdy","productField":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"displayOnly":""},{"type":"product","id":5,"label":"Registration Fee","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":[{"id":"5.1","label":"Name","name":""},{"id":"5.2","label":"Price","name":"event_cost"},{"id":"5.3","label":"Quantity","name":""}],"inputType":"singleproduct","enablePrice":null,"formId":51,"description":"Note: This event is free for Tech Liminal subscribers. If you are a subscriber, log in, then RSVP.","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":[{"text":"First Choice","value":"First Choice","isSelected":false,"price":"$0.00"},{"text":"Second Choice","value":"Second Choice","isSelected":false,"price":"$0.00"},{"text":"Third Choice","value":"Third Choice","isSelected":false,"price":"$0.00"}],"conditionalLogic":{"actionType":"show","logicType":"all","rules":[{"fieldId":"10","operator":"is","value":"false"}]},"productField":"","basePrice":"$15.00","disableQuantity":true,"multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","displayAllCategories":false,"useRichTextEditor":false,"displayOnly":""},{"type":"total","id":7,"label":"Total","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":51,"description":"","allowsPrepopulate":false,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"","visibility":"","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","productField":"","displayOnly":""},{"type":"creditcard","id":8,"label":"Credit Card","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":[{"id":"8.1","label":"Card Number","name":""},{"id":"8.2_month","label":"Expiration Month","name":"","defaultLabel":"Expiration Date"},{"id":"8.2_year","label":"Expiration Year","name":""},{"id":"8.3","label":"Security Code","name":""},{"id":"8.4","label":"Card Type","name":""},{"id":"8.5","label":"Cardholder Name","name":""}],"formId":51,"description":"","allowsPrepopulate":false,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":{"actionType":"show","logicType":"all","rules":[{"fieldId":"10","operator":"is","value":"false"}]},"productField":"","creditCardStyle":"","creditCards":["amex","visa","discover","mastercard"],"displayOnly":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false},{"type":"hidden","id":10,"label":"Is Member","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"is_member","visibility":"visible","noDuplicates":false,"defaultValue":"false","choices":"","conditionalLogic":"","productField":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"displayOnly":""},{"type":"hidden","id":11,"label":"Event ID","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"event_id","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","productField":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"displayOnly":""},{"type":"hidden","id":12,"label":"Event Title","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"event_title","visibility":"visible","noDuplicates":false,"defaultValue":"Some Event","choices":"","conditionalLogic":"","productField":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"displayOnly":""},{"type":"hidden","id":13,"label":"Event Info","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":51,"description":"","allowsPrepopulate":true,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"event_info","visibility":"visible","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","productField":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"displayOnly":""}],"version":"2.2.3","id":51,"useCurrentUserAsAuthor":true,"postContentTemplateEnabled":false,"postTitleTemplateEnabled":false,"postTitleTemplate":"","postContentTemplate":"","lastPageButton":null,"pagination":null,"firstPageCssClass":null,"subLabelPlacement":"below","cssClass":"","enableHoneypot":false,"enableAnimation":false,"save":{"enabled":false,"button":{"type":"link","text":"Save and Continue Later"}},"limitEntries":false,"limitEntriesCount":"","limitEntriesPeriod":"","limitEntriesMessage":"","scheduleForm":false,"scheduleStart":"","scheduleStartHour":"","scheduleStartMinute":"","scheduleStartAmpm":"","scheduleEnd":"","scheduleEndHour":"","scheduleEndMinute":"","scheduleEndAmpm":"","schedulePendingMessage":"","scheduleMessage":"","requireLogin":false,"requireLoginMessage":"","confirmations":[{"id":"596566abe6aa3","name":"Default Confirmation","isDefault":true,"type":"message","message":"Thank you. Your registration is complete.\r\n\r\nPlease check your email for a confirmation. \r\n","url":"","pageId":0,"queryString":"","disableAutoformat":false,"conditionalLogic":[]}],"notifications":[{"id":"596566abe5a55","to":"{admin_email}","name":"Admin Notification","event":"form_submission","toType":"email","subject":"New submission from {form_title}","message":"{all_fields}"},{"isActive":true,"id":"596beaf7baba3","name":"User Notification","service":"wordpress","event":"form_submission","to":"2","toType":"field","bcc":"","subject":"RSVP Confirmed for {Date:4} - {Event Title:12}","message":"Hello {Name (First):1.3},\r\n\r\nYou are confirmed for <strong>{Event Title:12}<Strong>.\r\n\r\n<strong>{Event Info:13}<\/strong>\r\n\r\nVisit the event to get directions and see details: {embed_url}","from":"{admin_email}","fromName":"Tech Liminal","replyTo":"info@techliminal.com","routing":null,"conditionalLogic":null,"disableAutoformat":false}]},"version":"2.3.2"}
<?php
/*
Plugin Name: Tech Liminal Events Registration
Plugin URI: https://techliminal.com/plugins/events
Description: Register for an event at Tech Liminal
Version: 0.1
Author: anca
Author URI: http://anca.tv
Text Domain: techliminal
------------------------------------------------------------------------
Copyright 2017 TechLiminal LLC.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses.
*/
class TL_Event_RSVP{
function __construct() {
}
function init(){
// this requires a gravity form with these parameters configured in the right place.
add_filter( 'gform_field_value_event_date', array( &$this, 'get_event_date' ) );
add_filter( 'gform_field_value_event_cost', array( &$this, 'get_event_cost' ) );
add_filter( 'gform_field_value_user_email', array( &$this, 'get_user_email' ) );
add_filter( 'gform_field_value_first_name', array( &$this, 'get_user_first_name' ) );
add_filter( 'gform_field_value_last_name', array( &$this, 'get_user_last_name' ) );
add_filter( 'gform_field_value_is_member', array( &$this, 'is_user_member' ) );
add_filter( 'gform_field_value_event_id', array( &$this, 'get_event_id' ) );
add_filter( 'gform_field_value_event_title', array( &$this, 'get_event_title' ) );
add_filter( 'gform_field_value_event_info', array( &$this, 'get_event_info' ) );
}
function admin_init(){
}
// Gravity Forms Stuff
//Deal w/ the event into whose page we are embedded in
function get_event_date( $value, $post_id = null ){
if ( empty( $post_id ) ){
$post = get_queried_object();
$post_id = $post->ID;
}
$meta = get_post_meta( $post_id, '_EventStartDate', true );
if ( $meta ){
return date( 'm/d/Y', strtotime( $meta ) );
} else {
return $value;
}
}
// needed for the announcement email
function get_event_title(){
$post = get_queried_object();
return $post->post_title;
}
// needed for the announcement email
function get_event_info(){
$post = get_queried_object();
$event_date = get_post_meta( $post->ID, '_EventStartDate', true );
$event_start_time = date( 'g:iA', strtotime( $event_date ) );
$event_long_date = date( 'M d, Y', strtotime( $event_date ) );
$event_info = "Event Time: $event_start_time $event_long_date \r\n {$post->post_excerpt}";
return $event_info;
}
function get_event_id(){
// provide the event_id of the post this is embedded in.
$post = get_queried_object();
return $post->ID;
}
// get the event cost
function get_event_cost(){
$post = get_queried_object();
$event_cost = get_post_meta( $post->ID, '_EventCost', true );
return $event_cost;
}
function get_user_email($value, $user_id = null){
if ( empty( $user_id ) ){
$user = wp_get_current_user();
if ( empty ($user) ){
return $value;
} else {
return $user->user_email;
}
}
}
function get_user_first_name($value, $user_id = null){
if ( empty( $user_id ) ){
$user = wp_get_current_user();
if ( empty ($user) ){
return $value;
} else {
$user_id = $user->ID;
}
}
return get_user_meta( $user_id, 'first_name', true );
}
function get_user_last_name($value, $user_id = null){
if ( empty( $user_id ) ){
$user = wp_get_current_user();
if ( empty ($user) ){
return $value;
} else {
$user_id = $user->ID;
}
}
return get_user_meta( $user_id, 'last_name', true );
}
function is_user_member( $value, $user_id=null ){
if ( empty( $user_id ) ){
$user = wp_get_current_user();
//error_log('getting user roles ' . serialize($user->roles));
// check their roles
foreach( $user->roles as $r ){
//error_log( $r );
if ( 'administrator' === $r || 'member' === $r ){
return 'true';
}
}
}
return $value;
}
public static function activate(){
}
public static function deactivate(){
}
}
// Activation / Deactivation
$tl_rsvp = new TL_Event_RSVP;
$tl_rsvp->init();
/* ----------- Activate / Deactivate ------------- */
register_activation_hook( __FILE__, array( 'TL_Event_RSVP', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'TL_Event_RSVP','deactivate' ) );
@ammist
Copy link
Author

ammist commented Sep 21, 2018

Requires:

  • The Events Calendar Plugin (for listing events)
  • Gravity Forms
  • Gravity Forms Strip integration

To install this, download the .json file and import it into your Gravity Forms install. This will create the RSVP form. Embed this form into an Events Calendar (From Modern Tribe) event, and then you can charge for an event through Gravity Forms w/ Stripe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment