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 7, 2024 05:45
macOS DoH! (DNS over HTTPS) using cloudflared
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 / site-url.php
Created February 5, 2018 15:54
Find WordPress subsite URL, supports Mercator and Domain Mapping plugin
<?php
$sites = array_map( 'get_object_vars', get_sites( array( 'deleted' => 0 ) ) ); //WP 4.6+
foreach ( $sites as $site ) {
switch ( $site['blog_id'] ) {
// If you are using Mercator (https://github.com/humanmade/Mercator) and domain mapping is active
case class_exists( '\Mercator\Mapping' ) && $mappings = \Mercator\Mapping::get_by_site( $site['blog_id'] ) :
foreach ( $mappings as $mapping ) {
if ( $mapping->is_active() ) {
$site_url = $mapping->get_domain();
@soderlind
soderlind / mercator-add-manage-aliases-link.php
Last active January 16, 2018 16:23
Mercator: Add Manage Aliases link to Sites in sites.php. Save fil in wp-content/mu-plugins
@soderlind
soderlind / anonymize-comment-ip.php
Last active May 20, 2018 05:02
GDPR: Anonymize WordPress user IP address in comments, supports IP4 and IP6
<?php
if ( true == apply_filters( 'is_gdpr', true ) ) {
add_filter( 'pre_comment_user_ip', function( $ip ) {
$packed_in_addr = inet_pton( $ip );
if ( 4 == strlen( $packed_in_addr ) ) {
return inet_ntop( inet_pton( $ip ) & inet_pton( '255.255.0.0' ) );
} else {
return inet_ntop( inet_pton( $ip ) & inet_pton( 'ffff:ffff:ffff:ffff:0000:0000:0000:0000' ) );
}
@soderlind
soderlind / README.md
Last active December 15, 2021 17:06
VS Code: PHP Code Beautifier and Fixer (phpcbf) and Short Array Syntax Converter task runners.

PHP Code Beautifier and Fixer (phpcbf)

phpcbf is included when you install PHP_CodeSniffer. Tom McFarlin has written a nice guide on how to install PHP_CodeSniffer and the WordPress Coding Standards Rules for VSCode. If you follow this guide, phpcbf will be installed in the project root, in ./vendor/bin/phpcbf

PHP 5.4 Short Array Syntax Converter

You'll find the convert.php script at GitHub

@soderlind
soderlind / no.json
Created December 6, 2017 13:38
The Norwegian flag - more flags at https://github.com/soderlind/css-flags
"no": {
"background": "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTAwIDgwMCI+DQo8cGF0aCBmaWxsPSIjZWYyYjJkIiBkPSJtMCwwaDExMDB2ODAwaC0xMTAweiIvPg0KPGcgZmlsbD0iI2ZmZiI+DQo8cGF0aCBkPSJtMzAwLDBoMjAwdjgwMGgtMjAweiIvPg0KPHBhdGggZD0ibTAsMzAwaDExMDB2MjAwaC0xMTAweiIvPg0KPC9nPg0KPGcgZmlsbD0iIzAwMjg2OCI+DQo8cGF0aCBkPSJtMzUwLDBoMTAwdjgwMGgtMTAweiIvPg0KPHBhdGggZD0ibTAsMzUwaDExMDB2MTAwaC0xMTAweiIvPg0KPC9nPg0KPC9zdmc+DQo=')",
"renderer": {
"landscape": {
"height": "100%",
"width": "137.5%"
},
"portrait": {
"height": "72.727272727273%",
"width": "100%"
@soderlind
soderlind / add-superadmin-to-new-site.php
Last active November 23, 2017 00:20
Add All WordPress Super-Admins to a New Site, put file in wp-content/mu-plugins
<?php
/**
* Plugin Name: Add All Super-Admins to a New Site
* Description: Will attempt to add all super-admins to a site when it's created.
* Version: 0.1.0
* Plugin URI: https://gist.github.com/soderlind/b0a7abc91eaa2646db38b81acfb532a1
* Author: Per Soderind
* Author URI: https://soderlind.no
* Requires PHP: 7.0.0
*/
@soderlind
soderlind / add-lang-to-customizer-previewer.php
Last active July 5, 2017 07:42
Polylang: Set WordPress Customizer preview url
<?php
add_action( 'customize_controls_enqueue_scripts', 'add_lang_to_customizer_previewer' );
/**
* If Polylang activated, set the preview url
*
* @author soderlind
* @version 1.0.0
*/
function add_lang_to_customizer_previewer() {
@soderlind
soderlind / cloudinary-jpg-minify.php
Last active December 5, 2017 00:48
WordPress snippet: Use Cloudinary JPGmini add-on to minify jpg site icons and jpg in content.
<?php
add_filter( 'the_content', function ( $content ) {
$doc = new DOMDocument();
// modify state
$libxml_previous_state = libxml_use_internal_errors( true );
$doc->loadHTML( $content );
// handle errors
libxml_clear_errors();
// restore
@soderlind
soderlind / convert-gif-to-video.php
Last active February 20, 2017 07:07
Use cloudinary to convert animated gif to video and reduce file size. Learn more at http://cloudinary.com/blog/reduce_size_of_animated_gifs_automatically_convert_to_webm_and_mp4
<?php
add_filter( 'the_content', function ( $content ) {
$doc = new DOMDocument();
// modify state
$libxml_previous_state = libxml_use_internal_errors( true );
$doc->loadHTML( $content );
// handle errors
libxml_clear_errors();
// restore