Skip to content

Instantly share code, notes, and snippets.

@davewardle
davewardle / functions.php
Created November 1, 2019 15:49
Hack to load a different theme based on URL
<?php
add_filter( 'template', 'switch_to_new_theme' );
add_filter( 'stylesheet', 'switch_to_new_theme' );
function switch_to_new_theme( $template ) {
$request = $GLOBALS['_SERVER']['REQUEST_URI'];
if (
@davewardle
davewardle / functions.php
Created February 25, 2019 17:30
Basic spam protection for Gravity Forms
<?php
// simple spam protection - drop any submissions where email is in a blacklist
// note: this function assumes that form has honeypot field enabled.
function pre_validation_handler( $form ) {
// blacklist is an array of bad email addresses or spam phrases
// for now, just a single (real) spammer
$blacklist = [ 'atouchofawesomeness@gmail.com' ];
@davewardle
davewardle / functions.php
Created January 24, 2019 11:54
Sets a default retention policy
<?php
function default_gravity_forms_retention_policy( $form, $is_new ) {
if ( $is_new ) {
$form['personalData']['preventIP'] = true;
$form['personalData']['retention'] = [
'policy' => 'delete',
'retain_entries_days' => 45
];
GFAPI::update_form( $form );
}
@davewardle
davewardle / functions.php
Last active December 23, 2021 08:22
Updates retention policy for all existing Gravity Forms
<?php
function enforce_gravity_forms_retention_policy() {
// only load for admin panel
if ( is_admin() && class_exists( 'GFForms' ) ) {
// load all forms
$forms = GFAPI::get_forms();
// loop through each form
foreach ( $forms as $form ) {
@davewardle
davewardle / keybase.md
Created March 15, 2017 17:19
keybase.md

Keybase proof

I hereby claim:

  • I am davewardle on github.
  • I am davewardle (https://keybase.io/davewardle) on keybase.
  • I have a public key ASCHPjeZZbvwtztpwSJM5vdQuzhbUdV1Ca2cSjrGktF6tgo

To claim this, I am signing this object: