Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / .editorconfig
Last active February 21, 2023 07:05
Editor Config for WordPress coding standards
# https://gist.github.com/rmpel/a54ffc349ecdba57c5dd7f33b81263dd
#
# This file is for unifying the coding style for different editors and IDEs
# Or at least; that is the plan. Currently FULLY supported IDEs are:
# - phpStorm
#
# Tried and failed;
# - VS Code (Supports .editorConfig, but does not support any extended rule-set)
#
# More information on the file format:
@rmpel
rmpel / wp_rewrite_rules.log
Created January 4, 2022 09:53 — forked from thenbrent/wp_rewrite_rules.log
Default WordPress Rewrite Rules
[rules] => Array (
[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/page/?([0-9]{1,})/?$] => index.php?tag=$matches[1]&paged=$matches[2]
[tag/([^/]+)/?$] => index.php?tag=$matches[1]
[type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?post_format=$matches[1]&feed=$matches[2]
@rmpel
rmpel / mu-plugin-backfill-missing-uploads.php
Created October 30, 2021 07:28
backfill missing wordpress uploads from a live website to a development copy
<?php
// Backfill missing uploads
// build your dev copy using plugins, theme and database
// don't download all uploads
// access an image on it, for example /wp-content/uploads/2021/10/some-image.png
// (of course, just loading a page with images on it will do)
// you will get 404s on all images
// place this file in mu-plugins folder
// try to access the url/page again
@rmpel
rmpel / crawl.php
Created March 10, 2021 09:37
File/Folder crawler; list all files and folders in a CSV file
<?php
/** QUICK AND VERY DIRTY */
header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename=crawl.csv');
?>
type,path,timestamp,date
<?php
___T(__DIR__);
function ___T($s) {
$l = array_merge( glob($s .'/.*'), glob($s .'/*') );
@rmpel
rmpel / .htaccess
Created January 22, 2021 13:34
multi-domain Access-Control-Allow-Origin .htaccess
<IfModule mod_headers.c>
SetEnvIf Origin "http(s)?://(www\.)?((subdomain.)?yourdomain.nl)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header merge Vary Origin
</IfModule>
@rmpel
rmpel / ga4.php
Last active November 17, 2021 14:06
GA4 Tracker mu-plugin
<?php // wp-content/mu-plugins/ga4.php - GA4 tracker boilerplate.
define('GA_NOT_LIVE', true); // remove for go
define('GA4_MEASUREMENT_ID', 'G-XXXXXXXXXX'); // required
define('UA_PROPERTY_ID', 'UA-XXXXXXX-YY'); // optional
define('GA_ANONYMIZE_IP', true); // optional
define('GA_TRACK_ADMINS', false); // optional, defaults to true
define('GA_TRACK_EDITORS', false); // optional, defaults to true
// we need GA as first thing in the body
@rmpel
rmpel / mu-plugin-migrate-webp-express-htaccess.php
Created October 16, 2020 11:09
WebP .htaccess files in wrong position causes problems with uploads-redirects
<?php
function migrate_webp_express_htaccess_files() {
$extra = [];
$uploads = wp_upload_dir();
$uploads = $uploads['basedir'];
$themes = WP_CONTENT_DIR .'/themes';
$plugins = WP_CONTENT_DIR .'/plugins';
@rmpel
rmpel / database-backup.sh
Last active September 23, 2020 11:39
Backup a WordPress database to a GIT repository to track changes over time
#!/usr/bin/env bash
###
# This script creates a backup using the WP-CLI tool and then stores it in a GIT repository.
# As GIT only saves the changes, you have a nice history of stuff that happened on your website.
# This is mostly an investigation tool and I have yet to determine the usefulness :)
#
# p.s., this does not work if git or wp-cli is installed; ergo; does NOT work with Local by Flywheel (unless you ssh into the docker and `sudo apt-get install git`.
##
@rmpel
rmpel / readme.md
Last active August 25, 2020 09:08
Migrate website out of multisite

To migrate a website out of a multisite (Yes, this is WordPress!!!!)

  1. determine site ID (for example: 5)
  2. create a spot where the new website will live (for example: /www/mywebsite.nl/public)
  3. install a new WordPress
cd /www/mywebsite.nl/public ; wp core download
  1. copy theme(s) and plugins
@rmpel
rmpel / _fuck-small-screens.scss
Last active February 27, 2020 10:28
Trouble making your website responsive below 375px?? fuck those small screens!
/** SCSS */
/** Fuck those small screens! */
@for $i from 0 through 16 {
@media all and (max-width: ( 375px - ($i*10px) )) {
body {
zoom: ( 375px - ($i*10px) ) / 385px;
}
}
}