Skip to content

Instantly share code, notes, and snippets.

View peterwilsoncc's full-sized avatar

Peter Wilson peterwilsoncc

View GitHub Profile
@peterwilsoncc
peterwilsoncc / shim.php
Created October 27, 2023 22:39
Demonstration of how plugin land deals with deprecations while supporting multiple versions of WordPress.
View shim.php
<?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.
View unlimited-posts-for-admins.php
<?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;
View remove-orderby-when-counting-comments.php
<?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
View safe-css-featured-image-block-fix.php
View an-unsplit-term.php
<?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 July 25, 2023 03:48
Backport a WP commit without having to check out the entire repo.
View backport.sh
#!/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.
View .htaccess
# 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
View 40878.php
<?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.
View composer.json
{
"name": "awesomemotive/seedprod-plugins",
"type": "project",
"require-dev": {
"wordpress/wporg-code-analysis": "1.0.0"
},
"scripts": {
},
"repositories": [
{
View 48556-testing-plugin.php
<?php
/**
* A testing plugin for trac ticket #48556.
*
* As a testing plugin, this includes a nasty hack to allow for easily
* viewing WP_Query dumps.
*
* **THIS SHOULD NEVER BE RUN ON A PUBLIC FACING SITE**
*/
namespace Trac\WPQ_Update;