Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / add_keys.sh
Created August 24, 2020 14:15
Shell: Adds ssh keys to ssh agent.
#!/usr/bin/env bash
function ssh-keys () {
if ssh-add -l | grep -q "$1"; then
echo "$1 key is ready"
else
/usr/bin/expect -c "
spawn /usr/bin/ssh-add $1;
expect 'Enter passphrase';
send $2\r;
@wpsmith
wpsmith / ssh_read_pass.sh
Created August 24, 2020 14:13
Shell: Reads a passcode.
#!/bin/bash
if [ $# -ne 2 ] ; then
echo "Usage: ssh-add-pass keyfile passfile"
exit 1
fi
eval $(ssh-agent)
pass=$(cat $2)
@wpsmith
wpsmith / .phpcs.theme.xml.dist
Created August 24, 2020 14:12
PHP: PHPCS for a WordPress theme.
<?xml version="1.0"?>
<ruleset name="WPS">
<description>Generally-applicable sniffs for WordPress plugins.</description>
<!-- What to scan -->
<file>.</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<!-- How to scan -->
@wpsmith
wpsmith / .phpcs.plugin.xml.dist
Created August 24, 2020 14:12
PHP: PHPCS for a WordPress plugin.
<?xml version="1.0"?>
<ruleset name="WPS">
<description>Generally-applicable sniffs for WordPress plugins.</description>
<!-- What to scan -->
<file>.</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<!-- How to scan -->
@wpsmith
wpsmith / auto-update-plugins.php
Created August 21, 2020 23:02
WP: Auto-update whitelisted set of plugins.
<?php
add_filter( 'auto_update_plugin', 'wps_auto_update_specific_plugins', 10, 2 );
function wps_auto_update_specific_plugins ( $update, $item ) {
// Array of plugin slugs to always auto-update
$plugins = array (
'akismet',
'enhanced-media-library',
'duplicate-page',
);
<?php
add_action( 'wp_enqueue_scripts', 'prefix_dequeue_all_woocommerce_styles_scripts_non_shop_pages', PHP_INT_MAX );
/**
* Disable all WooCommerce styles and scripts everywhere except WooCommerce pages.
*/
function prefix_dequeue_all_woocommerce_styles_scripts_non_shop_pages() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
// Styles
<div class="widget_shopping_cart_content">
<ul class="woocommerce-mini-cart cart_list product_list_widget">
<li class="woocommerce-mini-cart-item mini_cart_item">
<a aria-label="Remove this item" class="remove remove_from_cart_button" data-cart_item_key="abcdef12345some00hash67890uvwxyz" data-product_id="9999" data-product_sku="GRA000010" href="https://example.com?remove_item=abcdef12345some00hash67890uvwxyz&#038;_wpnonce=f5e62f5167">&times;</a> <a href="https://example.com/product/some-product"><img alt="" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" height="300" sizes="(max-width: 300px) 100vw, 300px" src="https://assets.example.com/shop/YYYY/MM/####/some-image-300x300.jpg" srcset="https://assets.example.com/shop/YYYY/MM/####/some-image-300x300.jpg 300w, https://assets.example.com/shop/YYYY/MM/####/some-image-150x150.jpg 150w, https://assets.example.com/shop/YYYY/MM/####/some-image-180x180.jpg 180w, https://assets.example.com/shop/YYYY/MM/####/some-image-600x600.jpg 600w,
Running checks 100% [===================================================================================] 0:00 / 0:00
+----------------------------------------------------+---------+-----------------------------------------------------+
| name | status | message |
+----------------------------------------------------+---------+-----------------------------------------------------+
| adminer-uninstalled | success | Plugin 'adminer' is 'uninstalled' as expected. |
| async-google-analytics-uninstalled | success | Plugin 'async-google-analytics' is 'uninstalled' as |
| | | expected. |
| backup-uninstalled | success | Plugin 'backup' is 'uninstalled' as expected. |
| backup-scheduler-uninstalled | success | Plugin
@wpsmith
wpsmith / install-wp-plugins.sh
Created August 18, 2020 23:53
WP: Install some debug plugins
wp install --skip-themes --skip-plugins \
debug-bar \
debug-bar-actions-and-filters-addon \
debug-bar-super-globals \
debug-bar-slow-actions \
health-check \
query-monitor \
wp-crontrol \
transients-manager
User-agent: mj12bot
crawl-delay: 10
User-agent: ahrefs
crawl-delay: 10