Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Søderlind soderlind

View GitHub Profile
View mu-example-rest-response.php
<?php
add_action( 'muplugins_loaded',function() : void {
$my_rest_endpoint = '/wp-json/super-admin-all-sites-menu/v1/sites/';
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
/**
* Bail if not the correct request.
*/
@soderlind
soderlind / mu-super-admin-all-sites-menu.php
Last active Apr 7, 2022
Fast REST Response for Super Admin All Sites Menu (https://github.com/soderlind/super-admin-all-sites-menu), save in mu-plugins
View mu-super-admin-all-sites-menu.php
<?php
/**
* name: Fast REST Response for Super Admin All Sites Menu
*
* @package Soderlind\Multisite\MU
* @author Per Soderlind
* @copyright 2021 Per Soderlind
* @license GPL-2.0+
*
* @wordpress-plugin
@soderlind
soderlind / webpack.config.js
Last active Feb 28, 2022
Add a banner to build/index.js, when running "wp-scripts build"
View webpack.config.js
"use strict";
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const packageJSON = require("./package.json");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
...defaultConfig,
module: {
...defaultConfig.module,
@soderlind
soderlind / deploy-develop.yml
Last active Dec 22, 2021
GitHub Action: Deploy WordPress to Azure Container Registry
View deploy-develop.yml
name: Development deploy
on:
repository_dispatch:
types: trigger-development-deploy
workflow_dispatch:
push:
branches:
@soderlind
soderlind / example.php
Last active Sep 25, 2021
WordPress Multisite, gets all site transient keys in the database with a specific prefix.
View example.php
<?php
foreach ( get_site_transient_keys_with_prefix( 'my_tranients_prefix_' ) as $transient ) {
delete_site_transient( $transient );
}
@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');
});