Skip to content

Instantly share code, notes, and snippets.

View danielkellyio's full-sized avatar

Daniel Kelly danielkellyio

View GitHub Profile
@danielkellyio
danielkellyio / Phone Number Pattern
Created April 21, 2016 12:25
Regex to detect valid us phone numbers (no country code)
[\(]?\d{3}[\)]?[\-]?\d{3}[\-]?\d{4}
@danielkellyio
danielkellyio / open_duped.php
Created July 28, 2016 17:34
Open a duped form in Gravity Forms
//Open Duped to Edit
add_action( 'gform_after_duplicate_form', 'open_new_form', 10, 2 );
function open_new_form($form_id, $new_id){
$url = $_SERVER['SERVER_NAME'] . "/wp-admin/admin.php?page=gf_edit_forms&id=" . $new_id;
echo "<script>window.location = 'http://$url&duped=true'</script>";
}
@danielkellyio
danielkellyio / duped_notification.php
Created July 28, 2016 17:43
Provide notification of duplication in gravity forms.
//Show Notification of Duped
add_action("gform_editor_js", 'notify_of_dupe');
function notify_of_dupe(){
if($_GET['duped'] === 'true'): ?>
<script>
(function($){
var notification = '<div style="border-left-color:#46b450" class="updated_base gform_editor_status" id="after_update_dialog">' +
'<strong>Form duplicated successfully.</strong>' +
@danielkellyio
danielkellyio / duplicate_form_auto_open.php
Created July 28, 2016 17:45
Auto open a duplicated form for editing in gravity forms
<?php
//Open Duped to Edit
add_action( 'gform_after_duplicate_form', 'open_new_form', 10, 2 );
function open_new_form($form_id, $new_id){
$url = $_SERVER['SERVER_NAME'] . "/wp-admin/admin.php?page=gf_edit_forms&id=" . $new_id;
echo "<script>window.location = 'http://$url&duped=true'</script>";
}
@danielkellyio
danielkellyio / index.php
Created July 28, 2017 20:05
custom gf fields
<?php
/*
* Recruiting Specific Field Buttons
*
* @author - Daniel Kelly
* @date - August 15, 2016
* @notes-
* https://www.gravityhelp.com/documentation/article/gform_add_field_buttons/
* button will not display until action "gform_editor_js_set_default_values" is set
@danielkellyio
danielkellyio / DriverConnect.php
Last active August 31, 2017 17:27
Call Tracking Metrics API Call
/**
* Make a Call to the Call Metrics API
*
* @author Daniel Kelly
* @return void
*/
private function makeAPICall(){
header('Access-Control-Allow-Origin: *');
$curl = curl_init();
curl_setopt_array($curl, array(
@danielkellyio
danielkellyio / bad-conditional.js
Last active June 26, 2019 17:29
How not to set a single variable based on multiple conditions
let friendly_timezone;
if( tz_timezone === 'America/New_York' ){
friendly_timezone = 'Eastern';
}else if( tz_timezone === 'America/Chicago'){
friendly_timezone = 'Central';
}else if( tz_timezone === 'America/Denver'){
friendly_timezone = 'Mountain';
}else if( tz_timezone === 'America/Los_Angeles'){
friendly_timezone = 'Pacific';
}else{
@danielkellyio
danielkellyio / just-as-bad-conditional.js
Last active June 26, 2019 17:32
Another bad way to set a variable based on multiple conditions
let friendly_timezone;
switch( tz_timezone ) {
case 'America/New_York':
friendly_timezone = 'Eastern';
break;
case 'America/Chicago':
friendly_timezone = 'Central';
break;
case 'America/Denver':
friendly_timezone = 'Mountain';
@danielkellyio
danielkellyio / best-conditional.js
Last active June 26, 2019 17:43
The best way I've found to to set a variable based on multiple conditions
//In helper file with global helper functions
function switchMap(before_value, map={}, default_value=false){
return Object.keys(map).includes(before_value) ? map[before_value] : default_value;
}
//In code where condition is needed
var friendly_timezone = switchMap(tz_timezone, {
'America/New_York': 'Eastern',
'America/Chicago': 'Central',
'America/Denver': 'Mountain',
@danielkellyio
danielkellyio / nuxt-js-social-meta-tags.js
Last active July 6, 2019 21:36
Array of social sharing meta tags for use in Nuxt.js
{
meta: [
{
hid: 'description',
name: 'description',
content: this.description,
},
{
hid: 'og:description',
property: 'og:description',