Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / convert-to-multisite.sh
Created June 3, 2025 13:45
Convert a stand-alone WordPress site to a multisite without using the MS Setup (and therefore bypassing the disable plugins restriction)
#!/usr/bin/env bash
# Convert a stand-alone WordPress site to a multisite without using the MS Setup.
# The Set-Up wizard requires you to deactivate all plugins, but you might not want to do that.
# This script helps.
#
# NOTE: No warranty, use at own risk. Has no checks for existing multisite, it assumes this is a single site installation
# This script ASSUMES YOU KNOW WHAT YOU ARE DOING, and so do I.
CTM_DB_PREFIX="$1"
@rmpel
rmpel / patch-idea-workspace.sh
Created May 30, 2025 13:25
Patch phpStorm workspace.xml to not break on a global script, like LocalWPs auto-prepended script.
#!/usr/bin/env bash
# example usage: cd ~/Local\ Sites ; find ./*/app/.idea/workspace.xml -exec patch-workspace.sh {} \;
[ -z "$1" ] && echo "Usage: $0 filepath-to-workspace.xml" >&2 && exit 1;
xmlpath="$1"
[ ! -f "$xmlpath" ] && echo File not found: $1 && echo "Usage: $0 filepath-to-workspace.xml" >&2 && exit 2;
cp "$xmlpath" "$xmlpath.bak"
@rmpel
rmpel / emailtest.php
Created May 20, 2025 05:38
Test SSL on email (IMAP) servers.
<?php
// This tool is 80% ChatGPT code. Just so you know.
error_reporting( -1 );
ini_set('display_errors', 'on');
// === CONFIGURATION ===
$config = [
'servers' => [ 'srv1.mail.example.com', 'srv2.mail.example.com', ],
'timeout' => 10, // seconds
@rmpel
rmpel / .config-ohmyposh.json
Created May 16, 2025 12:48
My OhMyPosh config
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"palette": {
"black": "#262B44",
"blue": "#4B95E9",
"green": "#59C9A5",
"orange": "#F07623",
"red": "#D81E5B",
"white": "#E0DEF4",
"yellow": "#F3AE35"
@rmpel
rmpel / build-changelog.sh
Created April 10, 2025 09:30
Build a changelog from the previous tag to head in a composer based website
#!/bin/bash
# A script to generate a changelog by comparing composer packages and project commits.
#
# Disclaimer:
# - Using this script is at your own risk. This script only uses READ operations, but I still
# do not take any responsibility.
#
# License:
# - BSD 2-Clause — Free to use with attribution. No warranty provided.
#
@rmpel
rmpel / Combat CORS issues in WordPress Multisite.php
Created March 17, 2025 07:25
Combat CORS issues in WordPress Multisite
<?php
// Make local URLs domainless, for all styles and scripts, to combat CORS issues.
// Ideally, we fix this in .htaccess using conditional headers, but in case of nginx, that's not available.
add_filter( 'script_loader_src', 'make_local_urls_domainless', 10 );
add_filter( 'style_loader_src', 'make_local_urls_domainless', 10 );
function make_local_urls_domainless( $url ) {
global $wpdb;
$all_domains = $wpdb->get_col( "SELECT domain FROM {$wpdb->blogs} ORDER BY blog_id DESC" );
@rmpel
rmpel / Login a user during a rest call - example-code.php
Last active March 27, 2025 11:49
WORDPRESS REST API - Login a user during a rest call - incompatible with caching
<?php
/**
* Maybe login by cookie.
* This function will log in a user by their authentication cookie, if they have one.
* This will use a full authentication, so it is safe from cookie-faking.
* Cookie hijacking is still a possibility, however, that's a WordPress issue, not a plugin issue.
* (To combat this; prefix the salts in wp-config.php with $_SERVER['REMOTE_ADDR']. This is not watertight,
* but always better than not)
*
* Call this function in your `permission_callback`, or in case of `__return_true` in your `callback` for getting items.
@rmpel
rmpel / LocalWP crash on dns_get_record fix
Last active May 22, 2025 06:58
Is your LocalWP crashing (service unavailable) when using dns_get_record? Try this;
# changes-to--php.ini.hbs
...
disable_functions = dns_get_record
...
auto_prepend_file = /path/to/the/dns_get_record_polyfill.php
...
# Changelog:
# - May 22nd, 2025;
# - - updated to support wildcard domain registrations, seems CloudFlare does not handle that themselves.
@rmpel
rmpel / zsh-auto-localwp.sh
Last active June 6, 2025 20:04
zsh automatic LocalWP context switcher when navigating folders of projects on MacOS
# this is a zsh script to automatically switch to the localwp shell when you enter a
# directory that contains a LocalWP website installation
# it is designed to trigger on any directory deeper or exactly the app/ folder of a localwp site.
# this code is FAR FROM perfect, but it works! Feel free to suggest/improve/etc
#
# this file is to be sourced in your .zshrc .
#
# Suggested install method:
# cd ~ ; mkdir -p .zsh ; git clone https://gist.github.com/f5c220b5e49baf0df4f5bbf5b7e76fdf.git .zsh/zsh-auto-localwp
# echo "source ~/.zsh/zsh-auto-localwp/zsh-auto-localwp.sh" >> ~/.zshrc
@rmpel
rmpel / i18n.sh
Created November 22, 2024 08:37
Universal po mo php file script for WordPress plugins
#!/usr/bin/env bash
cd "$(dirname $0)/.."
[ -z "$1" ] && echo "Usage: $0 command" && echo "commands:" && echo "make-pot : re-generate POT file from source" && echo "update-po : update PO files from POT file" && echo "make-mo : generate MO and l10n.php files from PO files" && exit 1
# find textdomain from ./*php
for file in $(find . -name '*.php'); do
if grep -q "Text Domain:" "$file"; then
TEXTDOMAIN=$(grep -o "Text Domain:\s*\([^'\"]*\)" "$file" | sed "s/Text Domain:\s*\([^'\"]*\)/\1/")