Skip to content

Instantly share code, notes, and snippets.

@davewardle
davewardle / functions.php
Created Nov 1, 2019
Hack to load a different theme based on URL
View functions.php
<?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 Feb 25, 2019
Basic spam protection for Gravity Forms
View functions.php
<?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 Jan 24, 2019
Sets a default retention policy
View functions.php
<?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 Jan 24, 2019
Updates retention policy for all existing Gravity Forms
View functions.php
<?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 ) {
View 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:

You can’t perform that action at this time.