Skip to content

Instantly share code, notes, and snippets.

@charmoney
charmoney / wp_shortcodes_in_fse_blocks.php
Last active March 13, 2025 21:39
WordPress Full Site Editor navigation blocks don't render shortcodes. This gist will execute shortcodes in FSE navigation block attributes.
<?php
namespace charmoney;
/**
* Execute shortcodes in FSE navigation block attributes.
*
* Supports wp:navigation-link and wp:navigation-submenu plus potentially others.
*
* @param array $items Navigation block items.
* @return array Filtered block items.
@charmoney
charmoney / kinsta_phpcs_wordpress.sh
Created February 28, 2025 16:22
Kinsta hosting: Install PHP Code Sniffer with WordPress coding standard
#
# Working process as of 02/2025 using Kinsta's default ~/.profile
#
# Composer global installation.
composer global require "squizlabs/php_codesniffer=*"
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev wp-coding-standards/wpcs:"^3.0"
# Configure phpcs default.
@charmoney
charmoney / maybe-cache.php
Last active July 9, 2024 20:04 — forked from vanaf1979/maybe-cache.php
Snippet #008 Using WordPress transients to cache data. https://since1979.dev/snippet-008-using-transients-to-cache-data/
<?php
/**
* Check if transient cache exist, else set it.
*
* Refactored by https://github.com/charmoney for PHP_CodeSniffer WordPress Standards compliance and WP_Error handling.
*
* @see https://since1979.dev/snippet-008-using-transients-to-cache-data/
*
* @uses get_transient() https://developer.wordpress.org/reference/functions/get_transient/
* @uses is_callable() https://www.php.net/manual/en/function.is-callable.php
<?php
/*
* The ActionScheduler WordPress plugin removes 20 complete & canceled status actions older than
* the filtered `action_scheduler_retention_period` value in seconds. In large scale applications
* generating more than 20 actions per minute on average, this can cause run away growth of the
* wp_actionscheduler_actions and wp_actionscheduler_logs tables.
*
* This gist adds a second cleanup pass every time AS normally cleans up & runs the queue.
*
* No support provided. No warranties expressed or implied.
@charmoney
charmoney / M&D wp-config.php
Last active May 1, 2018 16:24 — forked from ltitus210/M&D wp-config.php
Support http and https concurrently in wp-config
<?php
/**
* Determine if the current request is SSL. Set $_SERVER['HTTPS'] for WordPress' build in is_ssl().
*
* @return True if the site uses ssl directly or through a load balancer
*/
function greenpeace_is_ssl() {
$is_ssl = (isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] )
|| (isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'])
@charmoney
charmoney / rocket-dreampress-expires.php
Last active March 3, 2017 23:12 — forked from remyperona/rocket-dreampress-expires.php
Adjust expiration on HTML to prevent WP Rocket issue with DreamPress Varnish cache
<?php
add_filter('rocket_htaccess_mod_expires', 'wp_rocket_adjust_html_expire_dreampress');
/**
* Adjust expiration on HTML to prevent issue with Varnish cache
*
* @param string $rules htaccess rules.
* @return Updated htaccess rules
*/
function wp_rocket_adjust_html_expire_dreampress( $rules ) {
@charmoney
charmoney / process_csv.php
Last active February 11, 2016 19:56
The memory efficient PHP 5.3.1+ library Goodby CSV provides numerically indexed access to the parsed row data. For CSV files starting with header rows, this technique uses the header row as associative array keys for parsed row data.
<?php
/**
* Parse and process a CSV file using the Goodby CSV library,
* using a header row as associative array keys for the data
*
* https://github.com/goodby/csv
* @param string $csv_path Path to the CSV file
*/
function process_csv($csv_path) {