Skip to content

Instantly share code, notes, and snippets.

Per Søderlind soderlind

Block or report user

Report or block soderlind

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@soderlind
soderlind / insert-link-to-pdf.php
Last active Sep 10, 2019
WordPress: In the editor, using "Insert Link", insert link to a PDF file in the media library
View insert-link-to-pdf.php
@soderlind
soderlind / add-nf-submissions-cap-capabilities.php
Created Jun 24, 2019
Ninja Forms, give Editor access to submissions
View add-nf-submissions-cap-capabilities.php
<?php
namespace Soderlind\NinjaForm\Capabilities;
add_filter( 'ninja_forms_admin_parent_menu_capabilities', __NAMESPACE__ . '\add_nf_submissions_cap_capabilities' );
add_filter( 'ninja_forms_admin_submissions_capabilities', __NAMESPACE__ . '\add_nf_submissions_cap_capabilities' );
add_filter( 'ninja_forms_admin_menu_capabilities', __NAMESPACE__ . '\add_nf_submissions_cap_capabilities' );
function add_nf_submissions_cap_capabilities( $cap ) {
return 'edit_posts'; // EDIT: User Capability
@soderlind
soderlind / get-ip.php
Last active May 7, 2019
PHP, Get IP behind trusted proxy
View get-ip.php
<?php
/**
* Inspired by https://raw.githubusercontent.com/zendframework/zend-http/master/src/PhpEnvironment/RemoteAddress.php
*/
//PHP 5.6
function get_ip( $trusted_proxies = [] ) {
if ( ! empty( $trusted_proxies ) && isset( $_SERVER['REMOTE_ADDR'] ) && ! in_array( $_SERVER['REMOTE_ADDR'], $trusted_proxies ) ) {
if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
@soderlind
soderlind / run-wp-cron.sh
Last active Apr 1, 2019 — 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 / activate-searchwp.php
Last active Apr 22, 2019
Activate SearchWP using code. Also available as a plugin for WordPress Multisite: https://github.com/soderlind/ms-searchwp-subsite-activate
View activate-searchwp.php
<?php
// Define the license key e.g. in wp-config.php
define( 'SEARCHWP_LICENSE_KEY', 'my-license-key-goes-here' );
// Programmatically activate the license and enable SearchWP.
add_action( 'admin_init', 'searchwp_activate' );
function searchwp_activate() {
if ( defined( 'SEARCHWP_LICENSE_KEY' ) && class_exists( '\SearchWP_License' ) && false === get_option( 'soderlind_searchwp_license_activated', false ) ) {
@soderlind
soderlind / .readme.md
Created Sep 5, 2018 — forked from morganestes/.readme.md
Create multiple sites with wp-cli in WordPress multisite for testing.
View .readme.md

These commands will install multiple dummy sites in a WordPress Multisite environment.

I wrote this to easily create an environment to work on https://core.trac.wordpress.org/ticket/15317.

Usage

Shell

In the terminal, inside your WordPress directory: simply copy, paste, and run the one-line command.

You can also add it to a location available in your $PATH and invoke the script from the shell.

@soderlind
soderlind / searchwp-custom-settings.php
Created Jul 11, 2018
On SearchWP activation, set the defaults for my custom post types.
View searchwp-custom-settings.php
<?php
namespace Soderlind\Demo\SearchWP;
add_filter( 'searchwp_custom_field_keys', __NAMESPACE__ . '\\on_searchwp_custom_field_keys' );
add_filter( 'searchwp_initial_engine_settings', __NAMESPACE__ . '\\on_searchwp_initial_engine_settings' );
/**
* Add custom fields to the search index
*
* @param array $keys
@soderlind
soderlind / Install.txt
Last active Sep 16, 2019
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 / site-url.php
Created Feb 5, 2018
Find WordPress subsite URL, supports Mercator and Domain Mapping plugin
View site-url.php
<?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 Jan 16, 2018
Mercator: Add Manage Aliases link to Sites in sites.php. Save fil in wp-content/mu-plugins
View mercator-add-manage-aliases-link.php
You can’t perform that action at this time.