Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / validate-acf-php-files.php.sh
Created October 9, 2025 12:51
ACF-PHP File validator
#!/usr/bin/env php
<?php
function acf_add_local_field_group($data) {
foreach ( $data as $array_key => $array_value ) {
if ( is_array($array_value) ) {
acf_add_local_field_group( $array_value );
}
else {
if ( 'key' === $array_key && false === strpos( $array_value, 'layout_' ) ) {
@rmpel
rmpel / .htaccess
Created September 18, 2025 09:01
WordPress compatible Content-Security-Policy/Content-Type-Options rules Apache 2.4+
# BEGIN WP Security
<IfModule mod_headers.c>
#set header for all
Header set Content-Security-Policy "default-src 'self' *.googlesyndication.com vimeo.com *.vimeo.com *.vimeocdn.com *.amazonaws.com *.google-analytics.com *.yoast.com yoast.com *.diffuse.tools; connect-src 'self' *.googlesyndication.com google.com *.google.com vimeo.com *.vimeo.com *.linkedin.com *.vimeocdn.com *.amazonaws.com *.google-analytics.com *.yoast.com yoast.com *.diffuse.tools; frame-src 'self' vimeo.com *.vimeo.com *.vimeocdn.com youtube.com *.youtube.com *.googletagmanager.com *.youtube-nocookie.com *.google.com *.doubleclick.net; script-src 'unsafe-inline' 'unsafe-eval' 'self' *.yoast.com yoast.com *.gstatic.com google.com *.google.com googletagmanager.com *.googletagmanager.com *.googleapis.com google-analytics.com *.google-analytics.com *.googlesyndication.com code.diffuse.nl adservice.google.nl adservice.google.com *.googleadservices.com browser-update.org *.facebook.net snap.licdn.com *.doubleclick.net; style-src 'unsafe
#!/usr/bin/env bash
# usage; cron entry to run this script every minute.
# the script will take 3 snaps at most, at run, run+20, run+40. Next minute is a new iteration.
# script construction allows changes between snaps, as the script runs itself 3x.
cd "$(dirname "$0")"
# Set default values for environment variables
: "${HTTP_URL:=https://webcam.connect.prusa3d.com/c/snapshot}"
: "${DELAY_SECONDS:=20}"
@rmpel
rmpel / mu-plugin-mdms-prevent-password-rehashing.php
Created July 18, 2025 06:59
Prevent forced re-login on Multi-Domain Multisite in WordPress 6.8 and up
<?php
add_filter( 'password_needs_rehash', 'mu_plugin_mdms_prevent_password_rehashing', 11, 3 );
/**
* Maybe prevent password rehashing, limit rehashing to a set-up time-slot.
* This filter is only effective in WordPress 6.8 and up, and when not overriding the $wp_hasher global variable.
* This is to prevent the password rehashing from happening too often, which WILL cause users forced being logged in every time they switch to a different domain subsite.
*
* @param bool $needs_rehash Whether the password needs rehashing, defaults to true.
* While this could also be false; the way WordPress is set-up,
@rmpel
rmpel / wp-search-by-title-only
Last active June 25, 2025 07:15
WordPress Admin Post search by title only
<?php
// mu-plugin or included in theme/plugin
add_filter( 'posts_search', 'maybe_search_by_title_only', 10, 2 );
// add query var 'title_only' to the allowed query vars.
add_filter( 'query_vars', function ( $vars ) {
$vars[] = 'title_only';
return $vars;
@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.
#