Skip to content

Instantly share code, notes, and snippets.

View soderlind's full-sized avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / hardcode-number-of-items.php
Created August 28, 2023 08:27
WordPress Admin: Hardcode max number of items per page.
View hardcode-number-of-items.php
<?php
/**
* name
*
* @package Soderlind\MuPlugins\HardcodeNumberOfItems
* @author Per Soderlind
* @copyright 2021 Per Soderlind
* @license GPL-2.0+
*
@soderlind
soderlind / plausible-2f-fix.php
Last active May 25, 2023 09:53
Fix for Plausible Analytics %2f removal from shard link
View plausible-2f-fix.php
<?php
/**
* Plugin Name: Plausible 2f Fix
* Description: Fix for Plausible Analytics %2f removal from shard link.
* Plugin URI: https://gist.github.com/soderlind/6d6735baeab379b4d7e1e5497cd8581b
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
declare( strict_types = 1 );
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 April 7, 2022 11:37
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 February 28, 2022 16:58
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 December 22, 2021 08:59
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 September 25, 2021 20:33
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 July 5, 2021 21:10
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 March 16, 2021 22:57
WP Ajax transient demo.
View README.md
@soderlind
soderlind / expect-header-fix.php
Created March 10, 2021 23:17 — 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' : '';