Skip to content

Instantly share code, notes, and snippets.

View uamv's full-sized avatar
🏠
Working from home

Joshua Vandercar uamv

🏠
Working from home
View GitHub Profile
@uamv
uamv / gf-map-class-to-post-meta.php
Last active January 22, 2024 10:54
Save Gravity Form field data to post meta by adding a class to the field.
<?php
/**
* Save Gravity Form field data to post meta by adding a class to any field.
* Meta is mapped so that it is readable by Advanced Custom Fields
* Format class as…
* post_meta-{meta_key} -- for simple fields & writing lists as array to single meta record
* post_meta-{meta_key}-.3 -- for multi-input fields
* post_meta-{repeater_key}-1.{meta_key} -- for list fields mapped to meta readable by ACF
*/
// Run this function after the Gravity Form has created a post
// filter recurringly weekly notification to instead schedule as fortnightly
add_filter( 'gpns_schedule_timestamp', function ( $timestamp, $notification, $entry, $is_recurring, $current_time ) {
// properties for a recurring weekly notification
$form_id = 1;
$notification_id = '63595d7aecb08';
if ( (int) $entry['form_id'] !== $form_id || $notification['id'] !== $notification_id || ! $is_recurring ) {
return $timestamp;
}
// apply lowercase to email when saved
add_filter( 'gform_save_field_value', function( $value, $lead, $field, $form, $input_id ) {
if ( $field instanceof GF_Field_Email ) {
GFCommon::log_debug( current_filter() . ': transforming email to lowercase' );
return strtolower( $value );
}
// remap nested forms for multisite global forms
add_filter( 'gform_form_post_get_meta', function( $form ) {
if ( ! class_exists( 'GH_MGF' ) || is_main_site() ) {
return $form;
}
$primary_form_id = GH_MGF::get_primary_form_id( rgar( $form, 'id' ) );
foreach ( $form['fields'] as &$field ) {
@uamv
uamv / gf-custom-merge-tags.php
Last active May 26, 2022 01:12
Add custom merge tags to Gravity Forms
<?php
add_filter( 'gform_replace_merge_tags', 'typewheel_custom_merge_tags', 10, 7 );
function typewheel_custom_merge_tags( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
$custom_merge_tags = array(
'{date_ymd}' => date( 'Y.m-M.d', strtotime( $entry['date_created'] ) ),
'{timestamp}' => time(),
'{site_url}' => get_site_url(),
'{site_name}' => get_bloginfo( 'name' )
@uamv
uamv / mainwp-client-report-monthly.html
Created July 7, 2017 14:58
HTML Text Used for MainWP Monthly Client Report
<table style="width: 600px; margin: 0 auto; padding: 0; border-spacing: 0; border-collapse: collapse;"><tbody><tr><td style="background: #040404; margin-top: 0; padding: 0;"><img style="display: block; border: 0; line-height: 1;" src="https://typewheel.xyz/share/typewheel-email-banner.png" alt="Typewheel" width="600" /></td></tr><tr><td style="padding: 2em; background-image: linear-gradient( to bottom, #D7D7D7, #E7D3BA);"><p style="margin: 0 2em 2em;">Hello [client.contact.nickname]! Here's an overview of the things I am doing to keep your site updated, optimized, and secure.</p><p style="text-align: center; margin: 0 0 1.5em;"><img style="display: block; margin: 0 auto .5em;" src="[client.logo.url]" alt="[client.name] Logo" height="100" /><span style="text-align: center; font-size: 28px;"><strong>[report.daterange]</strong></span><br /><span style="text-align: center; font-size: 28px;"><strong><a style="color: #040404; text-decoration: none;" href="[client.site.url]">[client.site.domain]</a></strong></span><
@uamv
uamv / ticktick-kanban-styling.css
Created June 17, 2020 17:23
Style TickTick Kanban Boards
.column-list-view .column-list .column-list-content {
flex-direction: column;
flex-wrap: wrap;
max-height: calc( 100vh - 72px );
width: fit-content;
}
.column-list-view .column {
margin: 0 1.5em 2em 6px;
height: fit-content;
@uamv
uamv / gf-enter-prevent-submission.php
Last active May 22, 2019 08:14
Disables form submission when pressing Enter, unless user has tabbed to submit button or page advance button.
<?php
function twxyz_prevent_gform_submission( $form ) { ?>
<script type="text/javascript">
jQuery(document).bind('gform_post_render', function(){
jQuery(document).on( 'keypress', '.gform_wrapper', function (e) {
var code = e.keyCode || e.which;
if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) {
e.preventDefault();
return false;
@uamv
uamv / multi-column-list-populate.php
Last active April 11, 2019 15:50
Populate first column of Gravity Form multi-column list and mark as readonly
<?php
/*
Dynamically populates the first column of a Gravity Form multi-column list field
REQUIREMENTS
(1) The end of the the `gform_field_value_$parameter_name` filter must match the parameter you've set to allow field to be populated dynamically
(2) The key in each row's array element must match the header you have set for the column.
*/
add_filter( 'gform_field_value_certifications', 'typewheel_prefill_certifications_list' );
@uamv
uamv / gf-notification-interception.php
Created February 19, 2019 12:37
Send all Gravity Form notifications to specified email addres
<?php
add_filter( 'gform_notification', function ( $notification, $form, $entry ) {
$notification['toType'] = 'email';
$notification['to'] = 'email@example.com';
return $notification;
}, 10, 3 );