Skip to content

Instantly share code, notes, and snippets.

# Delete all users with a role of "subscriber" from a WordPress database.
#
# Assumes the `wp_` table prefix
DELETE FROM wp_users WHERE ID IN ( SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%' );
DELETE FROM wp_usermeta WHERE user_id IN ( SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%' );
@philipjohn
philipjohn / scroll-snap.html
Created October 12, 2022 08:58
Testing scroll snap
<html>
<head>
<title>Scroll Snap</title>
<style type="text/css">
* {
box-sizing: border-box;
}
.scroll-container {
max-height: 100vh;
overflow-y: scroll;
<?php
/*
Migrate from WP User Avatar to Simple Local Avatars
Allows sites to easily move away from the WP User Avatar plugin and switch to Simple Local Avatars instead.
Run by invoking with WP CLI like so:
`wp eval-file migrate-wp-user-avatar.php`
Author: Philip John
@philipjohn
philipjohn / rename-comments.php
Created October 1, 2019 12:04
Rename Comments PoC
<?php
/**
* Plugin Name: Rename Comments
* Description: Provides themes with the ability to allow users to rename comments.
* Version: 0.1.0
* Author: Philip John, Automattic
* Author URI: https://automattic.com
* Text Domain: rename-comments
* Domain Path: /languages
@philipjohn
philipjohn / time-to-publish.php
Created September 25, 2018 13:05
A WordPress plugin for tracking the time to publish for posts.
<?php
/*
Plugin Name: Time to Publish
Plugin URI: https://vip.wordpress.com
Description: Track "Time to Publish" on your WordPress site.
Version: 0.1.0
Author: WordPress.com VIP
Author URI: http://vip.wordpress.com
Text Domain: time_to_publish
Domain Path: /languages
add_filter( 'pre_update_option', 'll_kill_frontend_rewrite_rules_update', 10, 3 );
function ll_kill_frontend_rewrite_rules_update( $value, $option, $old_value ) {
// We're only concerned with the rewrite rules option.
if ( 'rewrite_rules' !== $option ) {
return $value;
}
// We want to concentrate on frontend requests only.
if ( ! is_admin() && ! is_user_logged_in() ) {
@philipjohn
philipjohn / suffusion-translate-https.diff
Created February 4, 2015 11:14
Fixes mixed content issues with Google Translate in Suffusion theme
Index: functions/actions.php
===================================================================
--- functions/actions.php (revision 43062)
+++ functions/actions.php (working copy)
@@ -1004,8 +1004,9 @@
}
if (!is_admin() && is_active_widget('Suffusion_Google_Translator', false, 'suf-google-translator', true)) {
+ $protocol = is_ssl() ? 'https' : 'http';
// For some reason the translation widget fails if we load the JS in the header. Hence we are overriding the header/footer JS setting
@philipjohn
philipjohn / import.sh
Last active August 29, 2015 14:10
Grabs a list of blogs and runs some tasks on each to set up a new multisite
if [ ! -f menus.wxr ]; then
echo "You need to export the menus for the menu setting to work, export to a menus.wxr file"
echo "remember to export the 'nav_menu_item' post type to a menus.wxr file before running"
exit;
fi
# Get a list of blogs to loop through
blogs=$(wp site list --fields="site_id,blog_id,url" --format="csv" --path="../../repository/htdocs/wp")
for entry in $blogs
@philipjohn
philipjohn / pj_error_log.function.php
Last active August 29, 2015 14:04
A useful error logging function intended for use with WordPress. Simply add to your wp-config.php, or other non-version controlled PHP file.
<?php
if ( ! defined( 'PJID' ) ) define( 'PJID', uniqid() );
function pj_error_log(){
// Get line numbers and such
$bt = debug_backtrace();
$caller = array_shift($bt);
// First we check if we're being asked to print a pretty message
if ( func_num_args() == 2 && is_string( func_get_arg(0) ) ) {
[30-Jul-2014 08:22:42 UTC] PHP Strict standards: Redefining already defined constructor for class GADAdminDashboard in /srv/www/test/htdocs/wp-content/plugins/google-analytics-dashboard/gad-admin-dashboard.php on line 29
[30-Jul-2014 08:22:42 UTC] PHP Stack trace:
[30-Jul-2014 08:22:42 UTC] PHP 1. {main}() /srv/www/test/htdocs/wp-admin/customize.php:0
[30-Jul-2014 08:22:42 UTC] PHP 2. require_once() /srv/www/test/htdocs/wp-admin/customize.php:12
[30-Jul-2014 08:22:42 UTC] PHP 3. require_once() /srv/www/test/htdocs/wp-admin/admin.php:30
[30-Jul-2014 08:22:42 UTC] PHP 4. require_once() /srv/www/test/htdocs/wp-load.php:29
[30-Jul-2014 08:22:42 UTC] PHP 5. require_once() /srv/www/test/htdocs/wp-config.php:60
[30-Jul-2014 08:22:42 UTC] PHP 6. include_once() /srv/www/test/htdocs/wp-settings.php:210
[30-Jul-2014 08:22:42 UTC] PHP Strict standards: Redefining already defined constructor for class GADAdminDashboardUI in /srv/www/test/htdocs/wp-content/plugins/google-analytics-dashboard/gad-admin-dashboar