Skip to content

Instantly share code, notes, and snippets.

View soderlind's full-sized avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / Install.txt
Last active September 20, 2023 19:52
macOS DoH! (DNS over HTTPS) using cloudflared
View Install.txt
1) Install cloudflared using homebrew:
brew install cloudflare/cloudflare/cloudflared
2) Create /usr/local/etc/cloudflared/config.yaml, with the following content
proxy-dns: true
proxy-dns-upstream:
- https://1.1.1.1/dns-query
- https://1.0.0.1/dns-query
@soderlind
soderlind / hardcode-number-of-items.php
Created August 28, 2023 08:27
WordPress Admin: Hardcode max number of items per page.
View hardcode-number-of-items.php
<?php
/**
* name
*
* @package Soderlind\MuPlugins\HardcodeNumberOfItems
* @author Per Soderlind
* @copyright 2021 Per Soderlind
* @license GPL-2.0+
*
@soderlind
soderlind / a_faster_load_textdomain.php
Created October 26, 2015 22:08
A faster load_textdomain for WordPress
View a_faster_load_textdomain.php
<?php
/*
Plugin Name: A faster load_textdomain
Version: 0.0.1
Description: While we're wating for https://core.trac.wordpress.org/ticket/32052.
Author: Per Soderlind
Author URI: https://soderlind.no
Plugin URI: https://gist.github.com/soderlind/610a9b24dbf95a678c3e
License: GPL
@soderlind
soderlind / mb_similar_text.php
Last active June 27, 2023 03:28
Multibyte Similar Text for PHP, mb_similar_text()
View mb_similar_text.php
<?php
/*
* solves the problem at http://stackoverflow.com/questions/31002690/how-to-use-similar-text-php-code-in-arabic, not that I know Arabic, but Norwegian also has multibyte charachters: æøåÆØÅ
*/
//from http://www.phperz.com/article/14/1029/31806.html
function mb_split_str($str) {
preg_match_all("/./u", $str, $arr);
return $arr[0];
}
@soderlind
soderlind / plausible-2f-fix.php
Last active May 25, 2023 09:53
Fix for Plausible Analytics %2f removal from shard link
View plausible-2f-fix.php
<?php
/**
* Plugin Name: Plausible 2f Fix
* Description: Fix for Plausible Analytics %2f removal from shard link.
* Plugin URI: https://gist.github.com/soderlind/6d6735baeab379b4d7e1e5497cd8581b
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
declare( strict_types = 1 );
@soderlind
soderlind / class-google-maps-oembed-provider.php
Last active February 1, 2023 08:15
WordPress Google Maps oEmbed Provider using the Google Maps Embed API
View class-google-maps-oembed-provider.php
<?php
/**
* Create a Google Maps oEmbed Provider using the Google Maps Embed API
*
* @see https://developers.google.com/maps/documentation/embed/
* @link https://gist.github.com/soderlind/db6dae8a73253329bc97ac50d7ebedef
* @since 1.0.0
* @package Google_Maps_oEmbed_Provider
*/
class DSS_oEmbed_Add_Provider {
@soderlind
soderlind / server.conf
Last active December 15, 2022 17:24
NGINX, WordPress Multisite and robots.txt, also tested with WordPress MU Domain Mapping
View server.conf
server {
# Add the following to your default server block:
rewrite /robots\.txt$ /index.php?robots=1 last;
}
@soderlind
soderlind / dropzonejs-wp-rest-api.js
Last active November 28, 2022 00:33
DropzoneJS & WordPress REST API
View dropzonejs-wp-rest-api.js
/*
Uploading images is a two step process (from https://github.com/WP-API/WP-API/issues/1768#issuecomment-160540932):
POST the data to /wp/v2/media - this can either be as the request body, or in multipart format. This will upload the file, and give you a 201 Created response with a Location header. This header points to the post object for the attachment that has just been created.
PUT the post data to the endpoint returned in the Location header (which will look something like /wp/v2/media/{id}).
I do step 2 (PUT), if POST is a success, in myDropzone.on("success", function(file, response){}
*/
// dropzoneWordpressRestApiForm is the configuration for the element that has an id attribute
@soderlind
soderlind / mu-super-admin-all-sites-menu.php
Last active April 7, 2022 11:37
Fast REST Response for Super Admin All Sites Menu (https://github.com/soderlind/super-admin-all-sites-menu), save in mu-plugins
View mu-super-admin-all-sites-menu.php
<?php
/**
* name: Fast REST Response for Super Admin All Sites Menu
*
* @package Soderlind\Multisite\MU
* @author Per Soderlind
* @copyright 2021 Per Soderlind
* @license GPL-2.0+
*
* @wordpress-plugin
View mu-example-rest-response.php
<?php
add_action( 'muplugins_loaded',function() : void {
$my_rest_endpoint = '/wp-json/super-admin-all-sites-menu/v1/sites/';
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
/**
* Bail if not the correct request.
*/