Skip to content

Instantly share code, notes, and snippets.

@etiennetremel
etiennetremel / functions.php
Last active December 14, 2015 22:19
Allow admin people or custom visitor IP to visit the site, otherwise, people are redirected to a specific page such as coming-soon.html Code to copy/past in functions.php in theme folder.
<?php
/**
* REDIRECT TO COMING SOON PAGE FOR NOT ALLOWED VISITORS
* Allow admin people or custom visitor IP to visit the site, otherwise,
* people are redirected to a specific page such as coming-soon.html
* Code to copy/past in functions.php in theme folder.
*/
// Disallow access to website if not admin:
remove_filter('template_redirect','redirect_canonical');
@etiennetremel
etiennetremel / class-limit-login-attempts.php
Last active December 16, 2015 05:29
Prevent Mass WordPress Login Attacks by setting locking the system when login fail.
<?php
/**
* CLASS LIMIT LOGIN ATTEMPTS
* Prevent Mass WordPress Login Attacks by setting locking the system when login fail.
* To be added in functions.php or as an external file.
*/
if ( ! class_exists( 'Limit_Login_Attempts' ) ) {
class Limit_Login_Attempts {
var $failed_login_limit = 3; //Number of authentification accepted
@etiennetremel
etiennetremel / WooCommerce, Delete all products from DB
Last active February 27, 2021 14:55
WooCommerce, Delete all products from DB
# Delete Product term relationships
DELETE
term_relationships.*,
term_taxonomy.*,
terms.*
FROM wp_term_relationships AS term_relationships
INNER JOIN wp_term_taxonomy AS term_taxonomy
ON term_relationships.term_taxonomy_id=term_taxonomy.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON term_taxonomy.term_id=terms.term_id
@etiennetremel
etiennetremel / content-single-product.php
Last active June 27, 2023 00:43
WooCommerce Upsells Upsells as checkbox. When product is deleted from the cart, upsells are also deleted.
<?php
/**
* The template for displaying product content in the single-product.php template
*
* Override this template by copying it to yourtheme/woocommerce/content-single-product.php
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
@etiennetremel
etiennetremel / functions.php
Last active December 23, 2015 20:59
WooCommerce Allow Shipping Countries: Make orders to be shipped only in specific country, display message if the customer don't choose an allowed one.
<?php
/**
* WOOCOMMERCE ALLOW SHIPPING COUNTRIES
* Make orders to be shipped only in specific country, display message if the customer don't choose an allowed one.
*/
function custom_checkout_process() {
global $woocommerce;
// Block orders to be shipped to other country than New Zealand, United States and Australia
$allowed_shipping_countries = array( 'AU', 'NZ', 'US' );
@etiennetremel
etiennetremel / update-wordpress.sh
Last active December 24, 2016 06:26
Update WordPress folder with the latest version, backup files and SQL Usage: sh update-wordpress "wordpress-directory-to-update"
#!/bin/bash
# Update WordPress folder with the latest version, backup files and SQL
# Usage: sh update-wordpress "wordpress-directory-to-update"
# Define variables
BLOG_DIR=/home
BACK_DIR=/home/wp-backups
DATE=`date +%Y%m%d`
INSTANCE=${1}
@etiennetremel
etiennetremel / delete.bat
Created November 11, 2013 22:36
Batch keep files from txt file list, delete others The batch file is asking you to enter the folder name which contain all the files to check, and the name of the file which contain the list of files to keep. Files.txt list files to keep (one per line)
@echo off
setlocal
set /p folder="Enter name of the folder where the files are: " %=%
set /p excludeFile="Enter txt file name where the list of files to keep are: " %=%
for /f "eol=: delims=" %%F in ('dir /b /a-d %folder% ^| findstr /vibg:%excludeFile%') do (
echo "Deleting file %folder%\%%F"
del "%folder%\%%F"
)
@etiennetremel
etiennetremel / Gruntfile.js
Created May 28, 2014 12:52
Grunt partials injection task
'use strict';
// Replace html comment tag by content of file, e.g:
// e.g: "<!-- partial: partials/header.html -->" will be replaced by the content of "partials/header.html"
// Then using grunt in command line: "grunt partials"
// Not the best idea ever, but when you have sometimes restriction or to simulate server-side SSI (Server Side Includes), that can be useful.
module.exports = function (grunt) {
grunt.initConfig({
partials: {
@etiennetremel
etiennetremel / commands.sh
Created March 10, 2016 09:06
Useful commands
# Get all IPs, count
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' ./**/*.json | sort | uniq -c | sort -nr > ips.txt
# Whois on each ips
cat ips.txt | awk '{print $2}' | head -n 50 | xargs -n1 whois
@etiennetremel
etiennetremel / 2016-04-11 - JSTACK profiling.log
Last active April 12, 2016 17:27
GoCD 16.3.0 high CPU logs
This file has been truncated, but you can view the full file.
2016-04-11 09:02:14
Full thread dump OpenJDK 64-Bit Server VM (25.72-b15 mixed mode):
"Attach Listener" #2961 daemon prio=9 os_prio=0 tid=0x00007fee500d9800 nid=0x145b waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"BrokerService[go-server] Task-93" #2960 daemon prio=5 os_prio=0 tid=0x00007fee45fbe000 nid=0x144a waiting on condition [0x00007fedd69e8000]