Skip to content

Instantly share code, notes, and snippets.

@isotrope
isotrope / zero-tax-najman.php
Last active February 23, 2021 23:19
Calculer si on a assez de produits d'une catégorie X. Si oui, ajuster leur status de taxe
<?php
add_action( 'woocommerce_before_calculate_totals', 'naj_apply_conditionally_taxes', 20, 1 );
function naj_apply_conditionally_taxes( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
@isotrope
isotrope / cache-busting-enqueues-like-a-boss.php
Created February 20, 2021 15:26
How to add a query var based on the asset's file mod time.
<?php
/*
* These two techniques add a query var with the modified filetime of the CSS file
*
* It works great for cache-busting at the browser level
* It won't help with Cloudflare cache. That one needs to be purged as even with the query var,
* it will decide to send the old file contents.
*
* Of course, if you're using a cache plugin and tell it to discard the query vars,
@isotrope
isotrope / Jennings-Condolences.php
Created December 8, 2020 20:06
A few filters used to adjust most of the text regarding comments
<?php
add_filter( 'genesis_post_info', 'tj_post_info_filter' );
function tj_post_info_filter( $post_info ) {
// we didn't want to "count" condolences, so we hacked it slightly to simply ALWAYS say "Leave your condolences"
return '[post_comments zero="Leave your condolences" one="Leave your condolences" more="Leave your condolences"]';
}
add_filter( 'comment_form_defaults', 'tj_comment_form_atts' );
function tj_comment_form_atts( $atts ) {
<?php
$classes = [];
// bunch of code
if( some condition) {
$classes[] = 'has-thumbs';
}
@isotrope
isotrope / vidtute.js
Created November 13, 2020 00:12
An old version of a video tutorial with sliding pages
(function ($) {
VIDTUTE = {};
VIDTUTE.Utils = {
timecodeToSeconds: function (strTimecode) {
arrTime = strTimecode.split(':');
//console.log(arrTime);
<?php
$args = [
'post_type' => [ 'product' ],
'post_status' => [ 'published' ],
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'product_cat',
'terms' => '164',
'field' => 'term_id',
<?php
$my_var = 'Something
on multiple
lines';
$cleaned_var = str_replace( [ "\r", "\n", chr( 10 ), chr( 13 ) ], '', $my_var );
// comme Oleg dit, juste au cas où tu te bats contre des quotes
$cleaned_var = str_replace('"', '&quot;', $cleaned_var);
@isotrope
isotrope / ternary-hell.php
Created April 7, 2020 17:46
When Ternary Logic Goes Bad
<?php
$subfield['value'] = ( $blank ) ? ("") : ( isset( $args['value'][ $row ][ $subfield['id'] ] )) ? ($args['value'][ $row ][ $subfield['id'] ] ): ("");
@isotrope
isotrope / iso_get_random_unsplash.php
Created April 1, 2020 13:51
Get a random image or image src from Unsplash
<?php
/**
* Grab a placeholder image from Unsplash
* https://source.unsplash.com/
*
* @author Michal Bluma
*
* @param int $width Desired width
* @param int $height Desired height
<?php
class Get_Words {
public static $meta_compiled_words = 'awesome_words_compiled';
public static $repeater_name_left = 'awesome_words_repeater_left';
public static $repeater_name_right = 'awesome_words_repeater_right';
public static $repeater_subfield = 'words';