Skip to content

Instantly share code, notes, and snippets.

@Xunnamius
Xunnamius / cloudflare.conf
Last active October 6, 2024 21:46
Fail2ban action.d for Cloudflare meant to replace the version that ships with fail2ban currently. This updated version of the action uses Cloudflare's 2023 v4 API (free tier WAF + free tier WAF lists) to ban hostile IPs.
# This version works with CF WAF (using zone rulesets) and obsoletes previous
# versions. This works will all CF account types. This action depends on curl
# and jp and will add/remove IPs from the $known_hostile_ips list. Creating the
# WAF rules need only be done once per zone. Creating the list need only be done
# once per account.
#
# Author: Bernard Dickens III (Xunnamius)
#
# Inspired by work from: Mike Rushton
# https://github.com/fail2ban/fail2ban/blob/master/config/action.d/cloudflare.conf
@ashwebstudio
ashwebstudio / custom-featured-image-size.php
Last active August 22, 2023 10:23
WordPress: Make unique custom image size ONLY for featured image of a post
@RadGH
RadGH / wc-exclude-outofstock-query.php
Last active July 24, 2022 10:17
Exclude out of stock and hidden products from WooCommerce query with pre_get_posts (plus equivalent filter for Ajax Load More)
<?php
/*
Solution based on a Stack Overflow answer by patrickzdb:
https://stackoverflow.com/a/24514985/470480
Tax query solution for hidden products based on a WordPress Stack Exchange answer by kalle:
https://wordpress.stackexchange.com/a/262628/19105
Please note:
This file includes two functions/filters.
@igorbenic
igorbenic / add_metabox.php
Last active February 21, 2024 21:36
How to use the WordPress Code Editor in your Plugins or Themes | https://www.ibenic.com/wordpress-code-editor
<?php
add_action( 'add_meta_boxes', 'add_page_scripts' );
/**
* Register the metabox
*/
function add_page_scripts() {
add_meta_box( 'page-scripts', __( 'Page Scripts & Styles', 'textdomain' ), 'add_page_metabox_scripts_html', 'page', 'advanced' );
}
<?php
function bit_crp_add_fields( $fields, $post_id ) {
global $wpdb;
$match_title = strip_tags( get_the_title( $post_id ) );
$match_content = bit_get_the_matcher($post_id);
$field_score = ", ( ( MATCH($wpdb->posts.post_title) AGAINST ('%s') *5 ) + ( MATCH($wpdb->postmeta.meta_value) AGAINST ('%s') *10 ) ) as score ";
$field_score = $wpdb->prepare( $field_score, $match_title, $match_content ) ;

How to install php7.2-fpm with EasyEngine (Ubuntu)


Add php7.2 repository

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Install php7.2-fpm

Custom Gutenberg Block

This is a basic custom Gutenberg block. Files explained below.

  • block.js — We register Custom Gutenberg block here.
  • editor.css _ Block CSS for the editor.
  • style.css — Block CSS for the front end.
  • index.php — Enqueue block's assets for editor and the front end.
@daggerhart
daggerhart / wp-get-taxonomy-hierarchy.php
Last active December 18, 2022 03:22
WordPress function to get a complete taxonomy hierarchy of terms in PHP
<?php
/**
* Recursively get taxonomy and its children
*
* @param string $taxonomy
* @param int $parent - parent term id
* @return array
*/
function get_taxonomy_hierarchy( $taxonomy, $parent = 0 ) {
@archonic
archonic / wp_geo_products.php
Created May 22, 2015 22:16
WordPress Geo Products. Depends on ACF for location meta. Replaces product search to include distance query.
class WP_Query_Geo extends WP_Query {
private $lat = NULL;
private $lng = NULL;
private $distance = NULL;
/**
* Constructor - adds necessary filters to extend Query hooks
*/
public function __construct( $args = array() ) {
// Extract Latitude
@jdevalk
jdevalk / logging-helper.php
Last active December 9, 2021 16:25
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
<?php
/**
* This changes logging to only log fatal errors. This file should go in your mu-plugins directory.
*/
// Set the error logging to only log fatal errors
error_reporting( E_ERROR );
// Optional: change the location of your error log, it might be wise to put it outside your WP content dir.
// If you don't change it, the default place for this log is debug.log in your WP_CONTENT_DIR.