Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / get_site_transient_keys_with_prefix.php
Last active Sep 23, 2021
WordPress Multisite, gets all site transient keys in the database with a specific prefix.
View get_site_transient_keys_with_prefix.php
<?php
/**
* Gets all site transient keys in the database with a specific prefix.
*
* Note that this doesn't work for sites that use a persistent object
* cache, since in that case, transients are stored in memory.
*
* Inspired by: https://kellenmace.com/delete-transients-with-prefix-in-wordpress/
*
* @param string $prefix Prefix to search for.
@soderlind
soderlind / hardwire-njnjaform-from.php
Created Jul 5, 2021
Hardwire Ninja Forms from name and from address.
View hardwire-njnjaform-from.php
<?php
/**
* Hardwire Ninja Forms from name and from address.
*/
add_filter( 'ninja_forms_run_action_settings', function ( $action_settings, $form_id, $action_id, $form_settings ) {
if ( 'email' === $action_settings['type'] ) {
$action_settings['from_name'] = 'from name';
$action_settings['from_address'] = 'from@name.tld';
@soderlind
soderlind / README.md
Last active Mar 16, 2021
WP Ajax transient demo.
View README.md
@soderlind
soderlind / expect-header-fix.php
Created Mar 10, 2021 — forked from carlalexander/expect-header-fix.php
WordPress "Expect" header fix
View expect-header-fix.php
<?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 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 Aug 4, 2021
WordPress: In the editor, using "Insert Link", insert link to a PDF file in the media library
View insert-link-to-pdf.php