Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / .codeclimate.yml
Created Nov 24, 2020
codeclimate config file for WordPress projects
View .codeclimate.yml
---
engines:
csslint:
enabled: true
duplication:
enabled: true
config:
languages:
- javascript
- php
@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 / README.txt
Last active Nov 30, 2019
Install Ninja Forms Add-Ons using Composer
View README.txt
DOESN'T WORK SINCE THE TOKEN CHANGES
@soderlind
soderlind / block-script.js
Last active Oct 19, 2019
add_theme_support( 'disable_block_style') .. hide gutenberg block style.
View block-script.js
/**
* Hide block styles
*/
wp.domReady(() => {
if (_.isObject(oDelBlockStyles)) {
_.map(oDelBlockStyles, (styleVariationName, blockName) => {
styleVariationName.forEach((style) => {
wp.blocks.unregisterBlockStyle(blockName, style);
});
});
@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 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 / 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 ) ) {
You can’t perform that action at this time.