Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / switch-php.sh
Last active November 12, 2024 14:18
php version switch for pipeline
#!/usr/bin/env bash
[ -z "$1" ] && echo example usage: $0 8.1 >&2 && exit 1
[ ! -f /usr/bin/php${1} ] && echo "No support for this version" >&2 && ls -la /usr/bin/php* >&2 && exit 2
cd ~/.local/bin
rm php
ln -s /usr/bin/php${1} php
hash -r
@rmpel
rmpel / acf-deduplication.php
Last active August 9, 2024 10:16
ACF FieldGroups Deduplication
<?php
/**
* Sometimes, shit happens and you end up with duplication of ACF FieldGroups.
* This mu-plugin will fix that.
* It is also compatible with ACF-to-PHP.
*/
add_action( 'admin_init', 'deduplicate_acf_data' );
@rmpel
rmpel / mu-plugin-dnt-video.php
Created August 9, 2024 06:11
Privacy friendly video embeds in WordPress
<?php
// This will make WordPress ALWAYS use privacy friendly embeds, implemented here are YouTube and Vimeo.
// Other services can be implemented by using this code as inspiration.
add_filter( 'oembed_dataparse', 'myproject_patch_oembed_urls', 11 );
function myproject_patch_oembed_urls( $html ) {
// find vimeo.com urls and add ?dnt=1 to them.
$urls = wp_extract_urls( $html );
foreach ( $urls as $old_url ) {
if ( false !== strpos( $old_url, 'vimeo.com' ) ) {
$new_url = add_query_arg( 'dnt', 1, $old_url );
@rmpel
rmpel / fix-author-dropdown.php
Last active June 3, 2024 14:26
Fix WordPress Author dropdown in multi-role set-up
<?php
/**
* If your website has custom roles and capabilities, and post-types with custom edit_posts capabilities,
* the dropdown on the _overview_ page, _quick edit_ is CORRECT.
* however, the dropdown on the _create new post_ or _edit existing post_ pages is NOT.
* This code fixes that.
*
* @package FixesByRemonPel
* @subpackage FixesByRemonPel/RestUserQuery
*/
@rmpel
rmpel / class-uploads.php
Last active March 21, 2024 08:16
The definitive way to add more filetypes to WordPress Media.
<?php
/**
* Filters that assist in uploading additional filetypes.
*
* @package Your_Package
* @subpackage Your_Package/Includes
*/
namespace Your_Package\Includes;
@rmpel
rmpel / mu-cookie-law-info.php
Created March 19, 2024 07:49
CookieYes (cookie-law-info) with Composer based website - fix the Website URL
@rmpel
rmpel / mu-plugin-prevent-redirect-loop.php
Last active October 24, 2023 13:07
Prevent redirect loops in WordPress
<?php
/**
* Plugin Name: Prevent Redirect Loop
* Description: Prevent redirect loops if user adds a redirect to the same page in Yoast SEO Premium or other plugins.
* Version: 1.0.0
* Author: Remon Pel
*/
// Prevent redirect loops.
add_filter(
@rmpel
rmpel / multisite-cron.sh
Last active September 17, 2024 09:12
WordPress Multisite universal cron.sh
#!/usr/bin/env bash
# place file one folder above the public_html to prevent access from world.
cd "$(dirname "$0")/public_html"
for subsite in $(wp site list --format=csv --fields=url 2>/dev/null | tail -n+2); do
echo $subsite;
wp cron event run --due-now --url=$subsite 2>/dev/null
done
## IF YOUR SERVER tail DOES NOT SUPPORT OFFSET;
@rmpel
rmpel / README.md
Last active July 20, 2023 14:24
Is this branched merged?

A script to check if your feature branches are merged.

Usage:

gitmerged.sh

Shows all open feature branches and their respective merge status to common root branches; master, main, staging, acc, develop

gitmerged.sh master staging

@rmpel
rmpel / proxy.php
Created April 28, 2023 06:26
A simple proxy in PHP
<?php
/**
* @file proxy.php Proxy requests to a different server. Very useful for example to set-up Let's Encrypt on a new server without the domain resolving to it.
*
* Step 1: set-up a domain pointer on the target server that DOES resolve to the same webspace as the original domain.
* Step 2: place code in the .htaccess in the source server as well as this php file.
* Step 3: configure the $target_domain to point to your newly set-up domain pointer.
*
* Final note: the 'verbose' function is for debugging this code only. It will probably be of no use to you.
*/