Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
leepettijohn / airtable_to_download_button.php
Last active January 10, 2022 16:34
Airtable API call to create a button to download results in CSV format
<?php
function replaceSpace($string){
$string = str_replace('%20',' ',$string);
return str_replace(' ','+',$string);
}
// C.I.N.N. = Comment if not needed
// Find a copy of the js file here - https://github.com/Airtable/airtable.js/blob/master/build/airtable.browser.js
$ATJS = 'https://yoursite.com/wp-content/themes/Divi/js/airtable.js';
// Table and data variables
@leepettijohn
leepettijohn / airtable_to_vega.php
Created June 11, 2021 13:30
Airtable to Vega Lite Graph
function replaceSpace($string){
return str_replace(' ','+',$string);
}
// Table and data variables
$baseid = '###'; //Required
$apikey = '###'; //Required
$tablename = '###'; //Required
$view = ''; //Optional
$lookupfieldname = ''; //Optional 1a
@leepettijohn
leepettijohn / graph.html
Created April 1, 2021 12:27
Airtable API and Vega Lite Rendering in a Web Page
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
<script src="/airtable.js"></script> // https://github.com/Airtable/airtable.js/blob/master/build/airtable.browser.js
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
// this variable allows you to pull variables from the URL - https://www.learningjquery.com/2012/06/get-url-parameters-using-jquery
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i;
@leepettijohn
leepettijohn / airtableapi.html
Last active April 1, 2021 12:04
Simple Airtable API pull to web page
<div id="results"></div>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
<script src="/airtable.js"></script> // https://github.com/Airtable/airtable.js/blob/master/build/airtable.browser.js
<script>
// this allows you to pull variables from the URL - https://www.learningjquery.com/2012/06/get-url-parameters-using-jquery
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
@leepettijohn
leepettijohn / custom.js
Created March 9, 2021 13:34
Divi - Disable jquery in Visual Builder
jQuery(document).ready(function($){
var isvisbuild = $('.et-fb-iframe-ancestor').length;
if (isvisbuild == 0){
// code to not run
}
});
@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);