Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / Install.txt
Last active Sep 19, 2020
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 / dropzonejs-wp-rest-api-custom-endpoint.js
Created Feb 1, 2016
DropzoneJS & WordPress REST API with Custom Endpoint
View dropzonejs-wp-rest-api-custom-endpoint.js
// dropzoneWordpressRestApiForm is the configuration for the element that has an id attribute
// with the value dropzone-wordpress-rest-api-form (or dropzoneWordpressRestApiForm)
Dropzone.options.dropzoneWordpressRestApiForm = {
//acceptedFiles: "image/*", // all image mime types
acceptedFiles: ".jpg", // only .jpg files
maxFiles: 1,
uploadMultiple: false,
maxFilesize: 5, // 5 MB
init: function() {
console.group('dropzonejs-wp-rest-api:');
@soderlind
soderlind / mb_similar_text.php
Last active Jun 7, 2020
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];
}
View customize_dropzonejs.js
// dropzoneWordpressForm is the configuration for the element that has an id attribute
// with the value dropzone-wordpress-form (or dropzoneWordpressForm)
Dropzone.options.dropzoneWordpressForm = {
//acceptedFiles: "image/*", // all image mime types
acceptedFiles: ".jpg", // only .jpg files
maxFiles: 1,
uploadMultiple: false,
maxFilesize: 5, // 5 MB
//addRemoveLinks: true,
//dictRemoveFile: 'X (remove)',
@soderlind
soderlind / dropzonejs-wp-rest-api.js
Last active May 19, 2020
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 / functions.php
Created May 5, 2020
custom logo in wp-login.php
View functions.php
// Add CSS within in wp-login, place in (child) theme functions.php
add_action('login_enqueue_scripts', function(){
wp_enqueue_style('login-styles', get_stylesheet_directory_uri().'/login.css');
});
@soderlind
soderlind / server.conf
Last active May 5, 2020
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 / run-wp-cron.sh
Last active Mar 12, 2020 — forked from bjornjohansen/run-wp-cron.sh
Run all due cron events for WordPress with WP-CLI. Works with both single sites and multisite networks.
View run-wp-cron.sh
#!/bin/bash
# Copyright © 2015 Bjørn Johansen
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
# Modified by Per Søderlind
WP_PATH="/path/to/wp"
MAIN_SITE="http://www.domain.tld" # --url="$MAIN_SITE" below, prevents the Undefined index: HTTP_HOST error.
@soderlind
soderlind / a_faster_load_textdomain.php
Created Oct 26, 2015
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 / README.txt
Last active Nov 30, 2019
Install Ninja Forms Add-Ons using Composer
View README.txt
DOESN'T WORK SINCE THE TOKEN CHANGES
You can’t perform that action at this time.