Skip to content

Instantly share code, notes, and snippets.

@EverythingSmartHome
EverythingSmartHome / All open windows and doors
Last active January 7, 2026 20:43
A collection of useful templates for Home Assistant dashboards
{{ states.binary_sensor
| selectattr('attributes.device_class', 'in', ['door','window'])
| selectattr('state', 'equalto', 'on')
| list | count }}
@Crocoblock
Crocoblock / custom-column-callback.php
Last active December 31, 2025 13:49
Add custom admin column callback to post type
<?php
/**
* Functions may be used as a custom post type column callback
*/
/**
* If the function name does not contain 'jet_engine_custom_cb' prefix,
* the callback takes only two arguments: column name and post ID
* You may use such callbacks if you do not need to specify any arguments
* Example: show post author in a column
@MjHead
MjHead / get-jet-engine-meta-fields.php
Last active May 20, 2025 22:56
JetEngine. Get registered meta fields by given context - post type, taxonomy or user
<?php
/**
* Get fields for the given context and object
* Should be called on hook 'init' with priority 11 or later
*/
// Fields for Post post type
$post_fields = jet_engine()->meta_boxes->get_fields_for_context( 'post_type', 'post' );
// Fields for Product post type
@growdev
growdev / refund.php
Created June 14, 2021 21:10
Bulk Refund WooCommerce Orders using CSV file input.
<?php
/**
* Bulk Refund Orders
*
* This script expects a csv file with following columns:
* - Order ID 1002
* - Reason for refund 'Item was oversold.'
* - Amount to refund '34.56'
* - Refund payment true/false
* - Restock item true/false
@msaari
msaari / wp_remote_get_with_cache.php
Last active December 15, 2021 21:13
wp_remote_get_with_cache – Fetches remote data with dual-layer caching
<?php
/**
* Fetches remote data with dual-layer caching.
*
* Uses wp_remote_get to fetch remote data. The data is cached twice: it's
* stored in a transient and an option. The transient is used as the main cache
* but if the transient has expired and the remote site doesn't respond,
* backup data from the option is returned.
*
@msaari
msaari / intermediary.php
Last active December 23, 2025 03:55
Relevanssi attachment indexing server intermediary script
<?php
/**
* Attachment processing intermediary to work between Relevanssi and a Tika server.
*
* Installation instructions:
* 1. Save this as index.php.
* 2. Change the Tika server URL in the constructor to point to your own Tika server.
* 3. Upload this file in a directory on your server.
*
* @author Mikko Saari ([email protected])
@sekanderb
sekanderb / add-more-to-cart.php
Created July 3, 2019 12:30
Adds the feature to add multiple products on WooCommerce Cart
class add_more_to_cart {
private $prevent_redirect = false; //used to prevent WC from redirecting if we have more to process
function __construct() {
if ( ! isset( $_REQUEST[ 'add-more-to-cart' ] ) ) return; //don't load if we don't have to
$this->prevent_redirect = 'no'; //prevent WC from redirecting so we can process additional items
add_action( 'wp_loaded', [ $this, 'add_more_to_cart' ], 21 ); //fire after WC does, so we just process extra ones
add_action( 'pre_option_woocommerce_cart_redirect_after_add', [ $this, 'intercept_option' ], 9000 ); //intercept the WC option to force no redirect
}
@LeMiira
LeMiira / Image ratio on featured image widget elementor.php
Created October 4, 2018 19:57
Image ratio on featured image widget elementor
@jchristopher
jchristopher / functions.php
Last active February 2, 2019 15:09
Use a supplemental engine when searching WooCommerce Orders. See https://searchwp.com/docs/kb/searching-woocommerce-orders/
<?php
/**
* When performing an admin search for WooCommerce Orders, use the 'Orders' SearchWP engine
*/
function my_searchwp_search_args( $args ) {
$search_in_admin = apply_filters( 'searchwp_in_admin', false );
if ( wp_doing_ajax() || empty( $_GET['post_type'] ) || ! is_admin() || empty( $search_in_admin ) ) {
return $args;
@YakovL
YakovL / creat_zip_download.php
Last active September 12, 2021 14:29 — forked from somatonic/creat_zip_download.php
create a zip file and send to browser
<?php
// this file is supposed to be in UTF-8 without BOM
function isRunningOnWindows() {
$os = php_uname('s'); //PHP_OS see https://stackoverflow.com/q/1482260/3995261
return preg_match('#win#i',$os) ? true : false;
}
function fixFilenameEncoding($name) {
// seemingly is needed on Windows only because filename encoding is not utf-8
return isRunningOnWindows() ? mb_convert_encoding($name, "windows-1251", "utf-8") : $name;
}