Skip to content

Instantly share code, notes, and snippets.

@isotrope
isotrope / example-menu-item.css
Last active March 22, 2022 06:42
Add (a) Polylang switcher menu item(s) to any menu.
/*
Example CSS of how I was showing one OR the other, based on brwoser-width
*/
@media (max-width: @grid-float-breakpoint-max) {
.language-code {
display: none;
}
}
@isotrope
isotrope / iso_gf_min_sum_validation.php
Last active April 28, 2021 20:44
Sum total of all fields with a class of XXXX and throw a validation error if the sum is == 0
<?php
//Don't forget to change the _1 in the hook to the ID of your form
add_filter('gform_validation_1', 'iso_min_sum_validate');
// Most code taken from http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook
function iso_min_sum_validate($validation_result) {
// We'll base our loop on CSS class
@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'] ] ): ("");