Skip to content

Instantly share code, notes, and snippets.

View LittleMikeNZ's full-sized avatar

Mike Little LittleMikeNZ

View GitHub Profile
@LittleMikeNZ
LittleMikeNZ / functions.php
Created March 17, 2023 03:05
Wordpress/Contact Form 7: Block form submissions from @gmail.com addresses
function cf7_check_email_field($result, $tags) {
$wpcf = WPCF7_ContactForm::get_current();
// Check if the current form ID is 9052
if ($wpcf->id !== 9052) {
return $result;
}
// Get the posted email data
$submission = WPCF7_Submission::get_instance();
@LittleMikeNZ
LittleMikeNZ / functions.php
Created March 14, 2023 18:54
Wordpress/WPForms: How to Block URLs Inside the Form Fields
/*
* Block URLs from inside form on Single Line Text and Paragraph Text form fields
*
* @link https://wpforms.com/developers/how-to-block-urls-inside-the-form-fields/
*/
function wpf_dev_check_for_urls( $field_id, $field_submit, $form_data ) {
if( strpos($field_submit, 'http') !== false || strpos($field_submit, 'www.') !== false ) {
wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'No URLs allowed.', 'wpforms' );
@LittleMikeNZ
LittleMikeNZ / dashboard.php
Last active March 13, 2023 20:16
Woocommerce: Display downloadable product table on account dashboard
<?php
/**
* My Account Dashboard
*
* Shows the first intro screen on the account dashboard.
*
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/dashboard.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
@LittleMikeNZ
LittleMikeNZ / functions.php
Created March 12, 2023 23:24
Woocommerce: Prevent a downloadable product forcing a download to browser on order completion
add_filter( 'woocommerce_download_file_redirect', 'stop_download_after_checkout', 10, 2 );
function stop_download_after_checkout( $redirect, $download_id ) {
$redirect = false;
return $redirect;
}
@LittleMikeNZ
LittleMikeNZ / sort_multidimension_array.php
Created June 29, 2015 21:46
Sorts a multi-dimension array by datetime. Can be ASC or DESC.
/*
Usage:
usort($array, array($this, "date_compare"));
To sort DESC use return $t2 - $t1
To sort ASC use return $t1 - $t2
*/
public function date_compare($a, $b)
{
@LittleMikeNZ
LittleMikeNZ / create_time_range.php
Last active August 29, 2015 14:23
PHP class to create a range of times suitable for form select dropdowns.
/*
Usage:
create array of time ranges
$times = create_time_range('9:30', '17:30', '30 mins');
more examples:
$times = create_time_range('9:30am', '5:30pm', '30 mins');
$times = create_time_range('9:30am', '5:30pm', '1 mins');
$times = create_time_range('9:30am', '5:30pm', '30 secs');