Skip to content

Instantly share code, notes, and snippets.

View charliesjc's full-sized avatar

Dale Rider charliesjc

View GitHub Profile
@charliesjc
charliesjc / cloudflare-zone-ip-access.conf
Last active May 19, 2023 02:18
Fail2Ban action configuration for Cloudflare. The current one that ships, by default, with Fail2Ban uses IP Access rules at User level. This one restricts it to a specific Zone (domain).
# Fail2Ban action configuration file for CloudFlare REST API V4 using Authorization Bearer Token
#
# Author: Dale Rider
#
# This action depends on curl, python, jq, and xargs.
#
# To get your CloudFlare Authorization Bearer Token: https://dash.cloudflare.com/profile/api-tokens
# Your Authorization Bearer Token must have read-write-delete access to your firewall rules.
#
# CloudFlare API firewall rules documentation: https://developers.cloudflare.com/api/operations/ip-access-rules-for-a-zone-create-an-ip-access-rule
@charliesjc
charliesjc / functions.php
Created August 7, 2021 15:32
Change order status to on-hold immediately after payment
<?php
/*
* Change payment status straight to on-hold after successful payment
*
* By using this hook instead of 'woocommerce_thankyou' you intercept the order status change before emails are sent.
* By doing it this way the only email that will be sent to the customer is the one for an on-hold order.
*/
add_filter('woocommerce_payment_complete_order_status', 'semper_woocommerce_payment_complete_order_status', 10, 2 );
function semper_woocommerce_payment_complete_order_status( $order_status, $order_id ) {
@charliesjc
charliesjc / .htaccess
Created July 19, 2021 06:14
Redirect Wordpress uploads folder to a different domain. (Very useful on local dev environment to avoid having to download the entire uploads folder)
# Redirect Wordpress uploads folder to a different domain.
# (Very useful on local dev environment to avoid having to download the entire uploads folder)
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$
RewriteRule ^(.*)$ http://domain.com/$1 [QSA,L]
@charliesjc
charliesjc / functions.php
Last active July 24, 2021 14:00
Hide prices for logged-out users, filtering by category, and change add-to-cart buttons to login redirect.
<?php
/*
Hide normal add-to-cart buttonsfor logged-out users, filtering by category, and change add-to-cart buttons to login redirect.
*/
add_filter('woocommerce_is_purchasable', 'semper_modify_purchasable');
function semper_modify_purchasable( $is_purchasable ) {
if ((has_term('hoodies', 'product_cat') && !is_user_logged_in())) {
if (is_singular()) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
@charliesjc
charliesjc / functions.php
Last active July 19, 2021 06:32
Remove Google reCaptcha badge on Wordpress
<?php
function semper_load_recaptcha_badge() {
if ( !is_page( array( 'checkout', 'login' ) ) ) {
wp_dequeue_script('google-recaptcha');
}
}
add_action( 'wp_enqueue_scripts', 'semper_load_recaptcha_badge', 100 );