Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bhays on github.
  • I am bhays (https://keybase.io/bhays) on keybase.
  • I have a public key whose fingerprint is 8833 BDFF 8365 C003 10C9 559A D681 0C00 7868 739C

To claim this, I am signing this object:

@bhays
bhays / WP-Translate-Strings
Last active December 20, 2015 13:09
Translate selected strings in WordPress. Originally from http://www.viper007bond.com/2011/07/13/changing-core-wordpress-strings/
// Translate theme strings
function mytranslate_filter_gettext( $translated, $original, $domain ) {
// Array of original strings and what they should be replaced with
$strings = array(
'Contribute Now' => 'Donate Now',
);
if ( isset( $strings[$original] ) ) {
$translations = &get_translations_for_domain( $domain );
@bhays
bhays / GF Submit Disable
Created July 30, 2013 08:59
Change 'Submit' button to 'Processing...' and disable it
add_filter('gform_pre_render', 'disable_submit');
function disable_submit($form) {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#gform_submit_button_<?php echo $form['id']; ?>').on('click', function(event){
var submitCopy = $(this).clone();
submitCopy.prop('id', '').prop('disabled', true).prop('value', 'Processing...').insertAfter($(this));
$(this).hide();
@bhays
bhays / email-only-password-reset.php
Last active February 26, 2018 05:13
Allow email only for WordPress password reset requests
// Return error if email is not set for password retrieval
add_action( 'lostpassword_post', 'email_only_lostpassword_post', 10, 1 );
function email_only_lostpassword_post( $errors ){
if( !is_email($_POST['user_login']) ){
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid email addreess.'));
return $errors;
}
}
// Translate some login page text
@bhays
bhays / Typeahead-BS3-css
Created August 2, 2013 13:54
Bootstrap 3 style fixes for using Typeahead.js
.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
margin-bottom: 0;
}
.tt-hint {
display: block;
width: 100%;
height: 38px;
padding: 8px 12px;
font-size: 14px;
@bhays
bhays / brh-tec-demote.php
Created May 22, 2019 21:50
WordPress plugin that will set Tribe Events Calendar events to draft status 1 day after event ends.
<?php
/**
* Plugin Name: TEC Demote Events
* Plugin URI:
* Description: Set expired events as drafts one day after end date.
* Version: 1.0.0
* Author: Ben Hays
* Author URI: http://benjaminhays.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@bhays
bhays / Quantity Discounts
Last active December 5, 2020 21:38
Auto discount prices based on quantities in Gravity Forms. Uses a percentage based approach.
(function($){
$.fn.quantityDiscounts = function(options) {
// set up default options
var defaults = {
discountColor: '#FF0000',
discounts: [
{ limit: 174, discount: .75, text: "25% Discount Applied"},
{ limit: 139, discount: .80, text: "20% Discount Applied"},
@bhays
bhays / acf-page-by-template.php
Last active January 31, 2022 11:32
ACF extension to select pages by specified page template only. Include file in functions.php
<?php
function include_field_types_acf_pages_by_template( $version ) {
include_once('acf-pages-by-template.php');
}
add_action('acf/include_field_types', 'include_field_types_acf_pages_by_template');
// exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;
// check if class already exists
@bhays
bhays / add-class-to-hidden-gravityforms-field.php
Last active October 19, 2023 06:29
Add inputName as class to hidden fields and inputs for Gravityforms
add_filter( 'gform_field_css_class', 'hidden_field_css_class', 10, 3 );
function hidden_field_css_class( $classes, $field, $form ) {
if( $field->type == 'hidden' ){
$classes .= ' '.$field->inputName;
}
return $classes;
}