Skip to content

Instantly share code, notes, and snippets.

View wordpress-menu-cache.php
<?php
/**
* WordPress menu cache.
*
* @package BJ\Menu
* @author bjornjohansen
* @version 0.1.0
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License version 2 (GPLv2)
*/
@bjornjohansen
bjornjohansen / reorder-attributes.php
Created Jan 26, 2021
Reorder the visible attributes on the frontend.
View reorder-attributes.php
<?php
/**
* Reorder the visible attributes on the frontend.
*/
add_filter( 'woocommerce_product_get_attributes', function( $old_attributes, $obj ) {
$order = [ 'pa_colour', 'pa_size' ];
$new_attributes = [];
@bjornjohansen
bjornjohansen / sitemap-crawler.php
Last active Nov 17, 2020
Basic sitemap crawler to warm up a full page cache
View sitemap-crawler.php
#!/usr/bin/php
<?php
/**
* @license http://www.wtfpl.net/txt/copying/ WTFPL
*/
date_default_timezone_set( 'UTC' );
$sitemaps = array(
@bjornjohansen
bjornjohansen / run-wp-cron.sh
Last active Oct 16, 2020
Run all due cron events for WordPress with WP-CLI. Works with both single sites and multisite networks.
View run-wp-cron.sh
#!/bin/bash
# Copyright © 2015 Bjørn Johansen
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
WP_PATH="/path/to/wp"
# Check if WP-CLI is available
if ! hash wp 2>/dev/null; then
@bjornjohansen
bjornjohansen / auth.php
Last active Oct 16, 2020
Changes the expiration of the WordPress authentication cookie to 365 days if the user ticks the “Remember Me” checkbox.
View auth.php
<?php
/**
* Authentication customizations.
*
* @package BJ\Auth
*/
/**
* Filters the duration of the authentication cookie expiration period.
*
@bjornjohansen
bjornjohansen / logging.php
Last active Oct 16, 2020
Simple logging for WordPress
View logging.php
<?php
/**
* Simple logging for WordPress.
*
* @package BJ\Log
* @author bjornjohansen
* @version 0.1.0
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License version 2 (GPLv2)
*/
@bjornjohansen
bjornjohansen / class-assetspusher.php
Created Jan 29, 2018
HTTP/2 server push WordPress assets
View class-assetspusher.php
<?php
/**
* HTTP/2 server push WordPress assets.
*
* @package BJ\AssetsPusher
* @author bjornjohansen
* @version 0.1.0
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License version 2 (GPLv2)
*/
@bjornjohansen
bjornjohansen / maintenance.php
Created Aug 31, 2017
Custom WordPress maintenance mode page
View maintenance.php
<?php
wp_load_translations_early();
$protocol = wp_get_server_protocol();
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 30' );
?>
<!DOCTYPE html>
<html>
@bjornjohansen
bjornjohansen / gravityforms-privacyactions.php
Last active Aug 9, 2020
Personal data exporter and eraser for Gravity Forms.
View gravityforms-privacyactions.php
<?php
/**
* Personal data exporter and eraser for Gravity Forms.
*
* @package BJ\GravityForms\PrivacyActions
* @author bjornjohansen
* @version 0.1.1
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License version 2 (GPLv2)
*/
@bjornjohansen
bjornjohansen / top-wp.sh
Created Jan 18, 2017 — forked from kasparsd/top-wp.sh
Finding WordPress in Alexa top 1 million sites, see http://crawler.wproll.com
View top-wp.sh
#!/bin/bash
touch checked.csv
while IFS=',' read -r POS HOSTNAME; do
if cat checked.csv | grep -qxF "$HOSTNAME"; then
echo "Skipping $HOSTNAME, already checked."
continue
fi