Skip to content

Instantly share code, notes, and snippets.

View bestwebsite's full-sized avatar

James bestwebsite

View GitHub Profile
@bestwebsite
bestwebsite / functions.php
Created September 11, 2022 00:45
Filter out spam messages on Gravity Forms using the Comment Blacklist
/** Filter out spam messages on Gravity Forms using the Comment Blacklist
*
* @author Best Website
* @link https://bestwebsite.com/
*
* Usage: Add spammy terms to Settings > Discussion > Disallowed Comment Keys to block form submissions
*
* @param string $is_spam, true if entry contains spam
* @param array $form
* @param array $entry
@bestwebsite
bestwebsite / wc-rename-checkout-coupon-field.php
Created March 11, 2021 22:09
WooCommerce - rename the "Have a Coupon?" message and "Apply Coupon" field on cart and checkout pages
<?php
add_filter( 'gettext', 'bw_rename_coupon_field_on_cart', 10, 3 );
add_filter( 'woocommerce_coupon_error', 'bw_rename_coupon_label', 10, 3 );
add_filter( 'woocommerce_coupon_message', 'bw_rename_coupon_label', 10, 3 );
add_filter( 'woocommerce_cart_totals_coupon_label', 'bw_rename_coupon_label',10, 1 );
add_filter( 'woocommerce_checkout_coupon_message', 'bw_rename_coupon_message_on_checkout' );
function bw_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
@bestwebsite
bestwebsite / functions.php
Created August 11, 2017 00:21
Add featured image column to WordPress admin post and page lists
add_image_size( 'bestwebsite-admin-post-featured-image', 120, 120, false );
// Add the posts and pages columns filter. They can both use the same function.
add_filter('manage_posts_columns', 'bestwebsite_add_post_admin_thumbnail_column', 2);
add_filter('manage_pages_columns', 'bestwebsite_add_post_admin_thumbnail_column', 2);
// Add the column
function bestwebsite_add_post_admin_thumbnail_column($bestwebsite_columns){
$bestwebsite_columns['bestwebsite_thumb'] = __('Featured Image');
return $bestwebsite_columns;
@bestwebsite
bestwebsite / conditional-text-based-on-time.php
Created April 5, 2017 16:22
Conditional text based on site time for WordPress functions.php
<?php
//add this to your functions.php file to change all occurrences of the word 'Welcome' to 'Good Morning' in page content when viewed before 11am
function replace_text_based_on_time($content)
{
//get current time - site time
$current_site_time = current_time('mysql');
//split the time string and get a time
$current_site_time = explode(' ', $current_site_time);
$current_site_time = explode(':', $current_site_time[1]);
remove_action( 'admin_notices', 'woothemes_updater_notice' );
add_filter('gettext', function($text){
if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){
if('Username' == $text){
return 'Email';
}
}
return $text;
}, 20);
add_filter('authenticate', function($user, $email, $password){
//Check for empty fields
if(empty($email) || empty ($password)){
//create new error object and add errors to it.
$error = new WP_Error();
if(empty($email)){ //No email
$error-&gt;add('empty_username', __('<strong>ERROR</strong>: Email field is empty.'));
}
remove_filter('authenticate', 'wp_authenticate_username_password', 20);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>bwCounter HTML and JavaScript Timer</title>
<script type="text/javascript">
/**************************************
* bwCounter script by bestwebsite.com *
**************************************/
function bwCounter(initDate,id){
this.beginDate = new Date(initDate);