Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / multisite-cron.sh
Last active April 23, 2024 09:01
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 / in-your-application.php
Last active April 22, 2024 18:45
WordPress REST-API in website, NONCE problems when authenticating or de-authenticating (login / logout)
<?php
// sent an updated nonce to the front-end on each request
add_filter( 'rest_post_dispatch', function( WP_REST_Response $response, WP_REST_Server $rest, WP_REST_Request $request) {
$response->header('X-WP-Nonce', wp_create_nonce( 'wp_rest' ));
return $response;
}, PHP_INT_MAX, 3);
// wp_create_nonce relies on user-id from global user object, and authentication cookie.
// both are INCORRECT after programmatic log-in or log-out.
// Really, WordPress? You should do this for us!
@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 / translate-custom-post-type-archive-slug.php
Last active October 30, 2023 08:39
Translate post-type-archive-slug when different from post-type-slug. WPML allows translating custom post-type slug, but not the custom post-type-archive slug
<?php
/**
* Translate post-type-archive-slug when different from post-type-slug.
*
* You can have your archive slug set to, for example /books and the singles on /book/title by setting
* $args['rewrite'] => [ 'slug' => 'book', ... ];
* $args['has_archive'] => 'books';
* when registering your post_type
*
@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 / lbl.sh
Last active October 14, 2023 09:26
Local Lightning - The unofficial CLI for the new Local 5.x and 6.x version - this is work in progress.
#!/usr/bin/env bash
#########
## Configration:
## Set your primary and secondary development paths.
## YOU CANNOT HAVE SPACES IN THE PRIMARY PATH - If you have, then most tooling here will fail because of limitations in macOS Terminal.
## AND NO - This tool is not built to use a different terminal.
##
PRIMARY_LOCATION=~/Development
SECONDARY_LOCATION=/Volumes/Macintosh\ SD/Development
@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 / remove-sep.sql
Created May 15, 2018 08:40
Remove LSEP from database
update wp_posts SET post_title = REPLACE(post_title, UNHEX('e280a8'), '') WHERE post_title LIKE concat('%', UNHEX('e280a8'), '%');
update wp_posts SET post_content = REPLACE(post_content, UNHEX('e280a8'), '') WHERE post_content LIKE concat('%', UNHEX('e280a8'), '%');