Skip to content

Instantly share code, notes, and snippets.

View soderlind's full-sized avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / README.md
Last active March 16, 2021 22:57
WP Ajax transient demo.
@soderlind
soderlind / expect-header-fix.php
Created March 10, 2021 23:17 — forked from carlalexander/expect-header-fix.php
WordPress "Expect" header fix
<?php
/**
* By default, cURL sends the "Expect" header all the time which severely impacts
* performance. Instead, we'll send it if the body is larger than 1 mb like
* Guzzle does.
*/
function add_expect_header(array $arguments)
{
$arguments['headers']['expect'] = !empty($arguments['body']) && strlen($arguments['body']) > 1048576 ? '100-Continue' : '';
@soderlind
soderlind / .codeclimate.yml
Created November 24, 2020 19:14
codeclimate config file for WordPress projects
---
engines:
csslint:
enabled: true
duplication:
enabled: true
config:
languages:
- javascript
- php
@soderlind
soderlind / functions.php
Created May 5, 2020 23:39
custom logo in wp-login.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 December 15, 2022 17:24
NGINX, WordPress Multisite and robots.txt, also tested with WordPress MU Domain Mapping
server {
# Add the following to your default server block:
rewrite /robots\.txt$ /index.php?robots=1 last;
}
@soderlind
soderlind / README.txt
Last active November 30, 2019 14:33
Install Ninja Forms Add-Ons using Composer
DOESN'T WORK SINCE THE TOKEN CHANGES
@soderlind
soderlind / block-script.js
Last active October 19, 2019 22:02
add_theme_support( 'disable_block_style') .. hide gutenberg block style.
/**
* 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 October 21, 2021 23:17
WordPress: In the editor, using "Insert Link", insert link to a PDF file in the media library
@soderlind
soderlind / add-nf-submissions-cap-capabilities.php
Created June 24, 2019 10:31
Ninja Forms, give Editor access to submissions
<?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 July 12, 2021 09:14
PHP, Get IP behind trusted proxy
<?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'] ) ) {