Skip to content

Instantly share code, notes, and snippets.

View davidwebca's full-sized avatar

David Lapointe Gilbert davidwebca

View GitHub Profile
@davidwebca
davidwebca / svg-functions.php
Last active January 26, 2021 19:50 — forked from kingkool68/svg-functions.php
SVG helper functions for WordPress
<?php
/**
* Include inline svg with + allow custom attributes as php function arguments
*
* Based on
* https://gist.github.com/kingkool68/6d72977fe8c82eeb9a85295ac3623cde#file-svg-functions-php
*
*/
/**
@davidwebca
davidwebca / pllstrings.php
Created June 1, 2021 13:46
Translate regular gettext and underscore functions with Polylang's strings
<?php
add_filter('gettext', function($translation, $text, $domain) {
if(is_admin()) {
return $translation;
}
if($domain == 'mythemedomain') {
if(function_exists('icl_register_string')){
$slug = sanitize_title($text);
icl_register_string($domain, $slug, $text);
@davidwebca
davidwebca / tailwind-jit-dynamic-scoping.md
Last active December 9, 2021 05:15
Tailwind JIT Dynamic Scoping

Tailwind Dynamic Scoping

This is a quick and dirty simple method to allow dynamic scoping in Tailwind CSS. It happens on-the-fly thanks to the JIT engine and doesn't need any new config when you want to add a new scope.

Generate this

.admin .scope-\[\.admin\|bg-red-500\+underline\] {
  --tw-bg-opacity: 1;
 background-color: rgb(239 68 68 / var(--tw-bg-opacity));
@davidwebca
davidwebca / block-style-locations.php
Last active December 21, 2021 00:38
Block style locations for ACF
<?php
/**
THIS IS NOW A FULL GITHUB REPO: https://github.com/davidwebca/acf-block-style-location
*/
add_filter('acf/location/rule_values/acf_block_style', function ($choices) {
@davidwebca
davidwebca / wp-global-post-count.php
Last active April 24, 2022 16:13
Global current_post counter, WP_Query agnostic
<?php
/**
* Create a globally accessible counter for all queries
* Even custom new WP_Query! Include inside functions.php in your theme.
* This allows you to have a post counter available in your sub-templates
* accessible even if you use get_template_part();
*
* Example
*
* global $current_loop_post_index;
@davidwebca
davidwebca / lazyblock-tailwind-cache.php
Last active June 24, 2022 00:09
Create tmp files for Lazy Block to allow Tailwind CSS to watch for CSS class names and create / purge properly
<?php
/**
* Allows HTML + Handlebars or database-saved PHP code to be
* cached into files so that Tailwind CSS can detect and watch
* for classes used and purge unecessary ones.
*
* @see https://github.com/nk-crew/lazy-blocks/
* @see https://github.com/nk-crew/lazy-blocks/issues/246
*/
@davidwebca
davidwebca / fix-woo-learndash-sub-rollback.php
Created September 26, 2022 21:24
Fix learndash_woocommerce.php + WooCommerce Subscription rollback issue
<?php
/**
* Theme filters.
*/
namespace App;
/**
* Fix checkout bug with learndash_woocommerce
*
* learndash_woocommerce.php:580
@davidwebca
davidwebca / mamp-php-apache.md
Last active November 18, 2022 17:15
Use MAMP's Apache selected PHP version on CLI

How to set your command line to MAMP's version

Since Mac OS comes with PHP bundled, even if you have MAMP, you'll find out that you can't use MAMP's versions on the command line. This is only true if you use the free version of MAMP since MAMP pro seems to have a feature to add that to the cli automatically.

Open your ~/.bash_profile file or ~/.zshrc if using ZSH

In this file, you might see nothing or only a few configurations already. You can safely ignore them and add this lower:

PHP_VERSION=$(grep "^[^#\;]" "/Applications/MAMP/conf/apache/httpd.conf" | grep "LoadModule php" | awk -F'[\/]' '{print $6}')
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
export PATH=/Applications/MAMP/Library/bin:$PATH
@davidwebca
davidwebca / override-wp-core-blocks-sage-10.php
Last active March 6, 2023 20:40
Add blade / override core block views in Sage 10.
<?php
/**
* Add this to your filters.php file in a Sage 10 theme.
* It will look at "resources/views/core/{blockname}.blade.php
* and render the view with "block_content" and "block" as variables.
*
* You can also use View Composers built in Sage 10 to pass more
* data to the block as you wish. For ACF blocks, I recommend
* generoi/sage-acfblocks which is definitely the cleanest
* method to include ACF blocks in Sage 10 I found so far.
@davidwebca
davidwebca / JsondTwigExtension.php
Last active March 17, 2023 13:28
JsondTwigExtension to fix some weird json_encode issues
<?php
/**
* Based on Indigo Viking's Twig Extension
* @see https://github.com/IndigoViking/Jsond/
*/
namespace modules\twigextensions;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;