Skip to content

Instantly share code, notes, and snippets.

@marrisonlab
marrisonlab / rc.js
Last active December 18, 2025 13:49
random color
<script>
// 1. Seleziona tutti gli elementi con la classe 'bg-change'
const elements = document.querySelectorAll(".bg-change");
// 2. Itera su ogni elemento trovato
elements.forEach(element => {
// 3. GENERA UN NUOVO COLORE CASUALE AD OGNI ITERAZIONE del ciclo
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
@marrisonlab
marrisonlab / gist:7683a636349585f5d8848bcda25559c3
Created October 31, 2025 16:01
Filter jetengine grid by the current user’s role
add_filter( 'jet-engine/query-builder/query/items', function( $items, $query ) {
if ( empty( $items ) || ! is_array( $items ) ) {
return $items;
}
$taxonomy = 'authorizations';
$user = wp_get_current_user();
$user_role = $user->roles ? $user->roles[0] : 'guest';
sudo -v ; curl https://rclone.org/install.sh | sudo bash
rclone config
sudo -u pi HOME=/home/pi /usr/bin/rclone sync mega:download /srv/dev-disk-by-uuid-0A4865124864FDB7/Share/Mega --progress
@marrisonlab
marrisonlab / gist:84b54be6d77968cb98b2673f425d9d35
Created October 5, 2025 12:46
spegne il wifi dopo 10 minuti dall'avvio
#!/bin/bash
# Tempo di attesa in secondi dopo la sincronizzazione oraria (10 minuti)
TEMPO_ATTESA=600
echo "Inizio script disattivazione Wi-Fi..."
# 1. Attesa fissa per la sincronizzazione oraria (necessaria dato l'errore 404)
echo "Attendo 30 secondi per assicurare la sincronizzazione oraria e l'avvio completo della rete."
sleep 30
/**
* Shortcode to get the product categories IDs present in the cart.
* Hooked to 'wp_loaded' to ensure the cart is initialized.
* Returns a string of (numeric) IDs separated by commas.
*/
function get_cart_categories_ids_shortcode() {
// 1. Secure initialization and cart check
if ( ! function_exists( 'WC' ) || is_null( WC()->cart ) ) {
return '';
}
@marrisonlab
marrisonlab / gist:2d2b1e2423312076256e9def70ff931a
Last active December 21, 2025 17:05
Display Dokan Vendor meta in single product page and loop
/**
* Unified Snippet Dokan + Vendor
* Works with both generic User ID and product loop
* WPCode: PHP Snippet → Run Everywhere
*/
if ( ! function_exists( 'sn_get_product_from_context' ) ) {
function sn_get_product_from_context() {
global $product;
if ( isset( $product ) && is_object( $product ) ) return $product;
@marrisonlab
marrisonlab / gist:b02883c4a594ca733aedd3ce88406443
Created September 27, 2025 06:29
Display brand in single product page (woo)
function gl_brand_logo_shortcode( $atts ) {
if ( is_admin() ) return '';
$atts = shortcode_atts([
'size' => 'medium', // thumbnail|medium|large|full o 300x150
'class' => 'brand-logo',
'link' => 'yes', // yes|no
'tax' => '' // lascia vuoto per auto-rilevare
], $atts, 'brand_logo');
@marrisonlab
marrisonlab / gist:6183d08d62a3cd9496f1ccb0006bc4b9
Created September 26, 2025 16:06
Discount % in Jetengine product listing
add_shortcode( 'sale_percentage', function( $atts ) {
$atts = shortcode_atts( array(
'id' => get_the_ID(),
), $atts, 'sale_percentage' );
$product = wc_get_product( $atts['id'] );
if ( ! $product ) return '';
$max_percentage = 0;