Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@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 June 8, 2023 06:40
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.
*/
@rmpel
rmpel / build.sh
Last active March 21, 2023 11:19
Universal build script for themes/plugins - WORK IN PROGRESS
#!/usr/bin/env bash
# Usage: /path/to/build.sh target-environment-using-a-pipelines-variable
# Example: /path/to/build.sh production
# Expected behaviour; in production, build for production, for all else build uncompressed.
# For local (argo; NO environment given, or local specified) buld in debug mode.
### CONFIGURATION
NODE_VER=14
BUILD_TASK_PROD=production
BUILD_TASK_LOCAL=dev
@rmpel
rmpel / karabiner.json
Created March 16, 2023 22:20
My custom Karabiner map; swap ` and § for consistency with ANSI keyboards, disable CAPS unless used with Left CMD
{
"global": {
"ask_for_confirmation_before_quitting": true,
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false,
"unsafe_ui": false
},
"profiles": [
{
@rmpel
rmpel / widget-context-menu-widget.php
Created January 12, 2023 07:51
WordPress + Widget Context -> For use with a widget with a menu, to show the widget only on pages in that menu.
<?php
add_filter( 'widget_contexts', function ( $contexts ) {
$contexts['menu_content'] = [
'label' => 'Menu-widget content',
'description' => 'Show only on pages that have its url/page/post listed in a menu',
'weight' => 11,
];
return $contexts;
}, 10, 2 );
@rmpel
rmpel / .htaccess
Last active March 13, 2023 09:27
Fast image 404 in WordPress
# WordPress will serve a rich 404 page for missing images, in case of lots of images, this will put
# heavy load on the server and the 404 messages cannot be shown anyways
# So just send a light-weight Apache 404 message
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpg|jpeg|png|gif|svg)$ - [R=404,NC,L]
# Alternative version; send a 410 Gone, which is even faster.