Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
BronsonQuick / wp_cli_command_to_delete_all_woocommerce_users
Created April 16, 2015 04:32
WP-CLI command to delete all WooCommerce users
wp user list --field=ID --role=customer | xargs wp user delete --yes
@BronsonQuick
BronsonQuick / remove-default-patterns.php
Created June 30, 2023 22:19
Remove the default Patterns included into WordPress
<?php
/**
* Prevent the loading of patterns from the WordPress.org Pattern Directory
*/
add_filter( 'should_load_remote_block_patterns', '__return_false' );
/**
* Remove patterns that ship with WordPress Core.
*/
function bbfs_remove_core_block_patterns() {
@BronsonQuick
BronsonQuick / theme.json
Created June 30, 2023 22:18
Client Proof WordPress blocks
{
"$schema": "https://schemas.wp.org/wp/6.2/theme.json",
"version": 2,
"settings": {
"appearanceTools": false,
"border": {
"color": false,
"radius": false,
"style": false,
"width": false
@BronsonQuick
BronsonQuick / delete_all_woocommerce_subscriptions.php
Last active June 19, 2023 14:37
Delete All WooCommerce Subscriptions
<?php
/*
Plugin Name: Delete All Subscriptions
Plugin URI:
Description: Delete all of those bad boys
Author:
Author URI:
Version: 1.0
*/
function mystic_delete_all_subscriptions() {
@BronsonQuick
BronsonQuick / gravity_forms_validation.php
Created April 12, 2012 09:51
Change the default validation message and add validation on default values in Gravity Forms
<?php
//This is a filter to change the default validation message that Gravity Forms generates
add_filter('gform_validation_message', 'change_validation_message', 10, 2);
function change_validation_message($message, $form)
{
return "<div class='validation_error'><strong>Oops!</strong> Looks like there’s something wrong. Please review the form above.</div>";
}
// Often forms in Gravity Forms to need to start with default values and we need to check the form in case the user hasn't entered new data and give them a validation message back
@BronsonQuick
BronsonQuick / clear_gravity_form_default_values.js
Last active September 25, 2022 08:26
Clear default values in Gravity Forms and place them back in on blur if they are empty
jQuery(document).ready(function($) {
jQuery.fn.cleardefault = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
this.value = "";
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
@BronsonQuick
BronsonQuick / loop_through_post_attachments.php
Created March 4, 2012 06:56
A WordPress loop to display post/page attachments
<?php /*
* This is just a simple loop to display 7 attachments attached to a post or page in WordPress
* You can change 'medium' and 'thumbnail' to add sizes you have definied in your theme by the add_image_size function
* in WordPress
*/
?>
<div id="thumbs" class="pic_list">
<ul class="thumbs">
<?php /* Time to create a new loop that pulls out the first 7 image attachments for this post */
$args = array( 'post_type' => 'attachment', 'numberposts' => 7, 'post_status' => null, 'post_parent' => $post->ID );
@BronsonQuick
BronsonQuick / populate_gravity_forms_pre_submission.php
Created May 30, 2012 06:39
Populate a hidden field in Gravity Forms before submission
<?php
/* gform_pre_submission will do all forms. gform_pre_submission_1 will do a form with an ID of 1
* Keep an eye on the priority of the filter. In this case I used 9 because the Salesforce plugin we used ran a presubmission filter at 10 so we needed this to happen before it
*/
add_filter( "gform_pre_submission_1", "add_salesforce_campaign_id_footer", 9 );
function add_salesforce_campaign_id_footer( $form ){
foreach($form["fields"] as &$field)
if($field["id"] == 2){
/* Set the variable you want here - in some cases you might need a switch based on the page ID.
* $page_id = get_the_ID();
@BronsonQuick
BronsonQuick / functions.php
Created March 26, 2012 05:59
Add a Gravity Forms validation filter to check default values
<?php
// Append the Gravity Forms ID to the end of the filter so that the validation only runs on this form
add_filter('gform_validation_1', 'custom_validation');
function custom_validation($validation_result){
$form = $validation_result["form"];
foreach($form['fields'] as &$field){
/* Check that the value of the field that was submitted. e.g. the name="input_1" that is generated by Gravity Forms */
if($_POST['input_1'] == "Your First Name"){
// set the form validation to false
$validation_result["is_valid"] = false;
@BronsonQuick
BronsonQuick / featured_custom_post_type_widget.php
Created March 5, 2012 04:00
A widget to display a Featured Custom Post Type in WordPress
<?php
/*
Plugin Name: Featured Custom Post Type Widget
Plugin URI: http://www.sennza.com.au
Description: Lists out all the custom post type posts in a dropdown so the user can selected a CPT to feature.
Version: 1.0
Author: Bronson Quick
Author URI: http://www.sennza.com.au
License: GPL2