Skip to content

Instantly share code, notes, and snippets.

View peterwilsoncc's full-sized avatar
🌻

Peter Wilson peterwilsoncc

🌻
View GitHub Profile
@peterwilsoncc
peterwilsoncc / wpSalt.php
Last active June 4, 2024 00:46
Unit tests for https://github.com/WordPress/wordpress-develop/pull/6720 -- the `wp_salt()` function uses a static variable so it's not possible to include these in the test suite.
<?php
/**
* @group pluggable
*
* @covers ::wp_salt
*/
class Tests_Pluggable_wp_salt extends WP_UnitTestCase {
/**
* Test that the signature options of wp_salt() are primed in a single database call (single site).
@peterwilsoncc
peterwilsoncc / shim.php
Created October 27, 2023 22:39
Demonstration of how plugin land deals with deprecations while supporting multiple versions of WordPress.
<?php
/**
* Shim to account for WordPress 5.8 changes to widgets screen.
*
* This code was written to avoid the block widgets screen from throwing
* notices in WordPress 5.8 while allowing custom block plugins to support
* WordPress 5.1 and earlier.
*
* The original gist was a private gist with identifying information of the
* the plugin I was working on for my employer at the time. I've republished
@peterwilsoncc
peterwilsoncc / unlimited-posts-for-admins.php
Last active September 19, 2023 22:51
Allow administrators to view all posts on the posts archive page.
<?php
/**
* Plugin Name: Unlimited Posts For Admins
* Description: Allow administrators to view all posts on the posts archive page.
* Version: 1.0.0
* Update URI: false
* Plugin URI: https://aus.social/@peterwilsoncc/111094215185643333
*/
namespace PWCC\UnlimitedPostsForAdmins;
<?php
/**
* Plugin Name: Remove orderby when counting comments.
*/
namespace PWCC\Test58368;
/**
* Remove orderby when counting comments.
*
@peterwilsoncc
peterwilsoncc / safe-css-featured-image-block-fix.php
Last active October 26, 2022 01:51
Fix object-fit/featured image block bug introduced in WP 6.0.3
<?php
/**
* Prevent the term splitting job from being fired.
*/
add_filter(
'pre_schedule_event',
function( $pre, $event ) {
if ( $event->hook === 'wp_split_shared_term_batch' ) {
return false;
@peterwilsoncc
peterwilsoncc / backport.sh
Last active June 28, 2024 02:06
Backport a WP commit without having to check out the entire repo.
#!/bin/bash
# Use:
# backport.sh 12345
#
# Based on https://gist.github.com/johnbillion/22dcc4ae736a3e8d022c
# Modifications
# - Uses the format recommended in the handbook
# - Pulls the current branch from `svn info` rather than using the directory basename
#
@peterwilsoncc
peterwilsoncc / .htaccess
Last active April 10, 2022 00:27
Root directory of WP sub-directory install.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@peterwilsoncc
peterwilsoncc / 40878.php
Created November 8, 2021 00:08
Notes for WP ticket #40878
<?php
register_post_type(
'nav_menu_item',
[
// Unlisted items remain unchanged.
'map_meta_cap' => true,
'capabilities' => [
// Meta Capabilities.
'edit_post' => 'edit_post',
@peterwilsoncc
peterwilsoncc / composer.json
Last active October 18, 2021 01:08
Using WP.org MVP sniffs in a project.
{
"name": "awesomemotive/seedprod-plugins",
"type": "project",
"require-dev": {
"wordpress/wporg-code-analysis": "1.0.0"
},
"scripts": {
},
"repositories": [
{