Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / auto-update-plugins.php
Created Aug 21, 2020
WP: Auto-update whitelisted set of plugins.
View auto-update-plugins.php
<?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',
);
View functions-disable-cart-fragments-except-shop.php
<?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
View get-refreshed-fragments-example-1.html
<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,
View wp-doctor-plugin-status.log
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 Aug 18, 2020
WP: Install some debug plugins
View install-wp-plugins.sh
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
View robots.txt
User-agent: mj12bot
crawl-delay: 10
User-agent: ahrefs
crawl-delay: 10
@wpsmith
wpsmith / .htaccess
Created Aug 18, 2020
WP: Disable xmlrpc.php
View .htaccess
# BEGIN Custom
# Block XMLRPC - Security.
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>
# END Custom
View wp-doctor.sh
wp package install git@github.com:wp-cli/doctor-command.git
wp doctor check --all
Running checks 100% [=================================================================================] 4:19 / 0:05
+----------------------------+---------+--------------------------------------------------------------------+
| name | status | message |
+----------------------------+---------+--------------------------------------------------------------------+
| core-verify-checksums | success | WordPress verifies against its checksums. |
| file-eval | success | All 'php' files passed check for 'eval\(.*base64_decode\(.*'. |
@wpsmith
wpsmith / functions.php
Created Aug 17, 2020
WP: Remove the WP Heartbeat
View functions.php
<?php
add_action( 'init', 'stop_heartbeat', 1 );
/**
* Stop the heartbeat altogether.
*/
function stop_heartbeat() {
wp_deregister_script( 'heartbeat' );
}
View access-log-sample.log
9.999.999.99 domain.com - [11/Aug/2020:14:29:37 +0000] "GET /path-to-
my-awesome-page/ HTTP/1.1" 503 2676 "https://domain.com/my-awesome-
blog/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:79.0)
Gecko/20100101 Firefox/79.0" | TLSv1.3 | 0.037 0.041 0.041 MISS
W NC:000000 UP:1