Skip to content

Instantly share code, notes, and snippets.

Avatar

Timothee Moulin timotheemoulin

View GitHub Profile
@timotheemoulin
timotheemoulin / wp-add-categories-in-body-classes.php
Last active Nov 24, 2020
[WP] Add the page/post categories in the body classes
View wp-add-categories-in-body-classes.php
<?php
/**
* Add the post/page categories in the body class list.
*
* @param string[] $classes An array of body class names.
*
* @return array
*/
function timwp_add_category_name_to_body_classes( array $classes ): array {
@timotheemoulin
timotheemoulin / wp-woocommerce-add-space-currency.php
Last active Nov 24, 2020
woocommerce add space between currency and price
View wp-woocommerce-add-space-currency.php
<?php
/**
* Add a spcae after the CHF currency in WooCommerce.
*
* @param string $currency_symbol
* @param string $currency
*
* @return string
*/
@timotheemoulin
timotheemoulin / wp-acf-force-json-load-translation.php
Last active Nov 24, 2020
Force ACF fields loaded over JSON fiels to be translated though gettext
View wp-acf-force-json-load-translation.php
<?php
/**
* Force ACF fields loaded over JSON fiels to be translated though gettext
*/
add_filter( 'acf/load_field',
/**
* Force ACF to try to translate fields even when they come from JSON.
*
@timotheemoulin
timotheemoulin / wp-core-translation-override-fr_FR.php
Last active Nov 24, 2020
Nasty way to override the core WordPress translations (PHP, gettext, JS, React)
View wp-core-translation-override-fr_FR.php
<?php
// Load the translations and store them in the session
/**
* Define the string messages to override
*/
if ( ! isset( $_SESSION['translation-override']['fr_FR'] ) ) {
$_SESSION['translation-override']['fr_FR'] = [];
}
@timotheemoulin
timotheemoulin / disable-fullscreen.js
Last active Nov 24, 2020
Gutenberg disable fullscreen as the default editor
View disable-fullscreen.js
/**
* This checks if the fullscreen mode is "on" on page load and toggle it off.
*/
(function (wp) {
const isFullscreenMode = wp.data.select('core/edit-post').isFeatureActive('fullscreenMode');
if (isFullscreenMode) {
wp.data.dispatch('core/edit-post').toggleFeature('fullscreenMode');
}
})(window.wp);
@timotheemoulin
timotheemoulin / php-coalesce-operator.php
Last active Apr 8, 2020
Check what really does the coalesce operator
View php-coalesce-operator.php
<?php
// undefined variable
echo "?? prints 'default'";
echo "<br>";
var_dump($a ?? 'default');
echo "<br><br>";
echo "?: sends a notice 'undefined variable' and prints 'default'";
View Microsoft.PowerShell_profile.ps1
# Powershell Custom Functions
# Timothée Moulin
#
# Change directory to the root workspace directory
Function tim-goto-workspace-tim {
cd ~/www
ls
}
Set-Alias -Name www -Value tim-goto-workspace-tim
@timotheemoulin
timotheemoulin / switch-vs-if-else.php
Created May 1, 2019
Avoid if else structure when possible
View switch-vs-if-else.php
<?php
global $i;
$i = 0;
function test() {
global $i;
var_dump(++$i);
return $i;
}
switch (test()) {
@timotheemoulin
timotheemoulin / ssh-compile
Last active Mar 28, 2019
SSH config files compilation from multiple files
View ssh-compile
# Include this snippet in your .zshrc or .bashrc file to compile multiple ssh config files into one.
# Put the file anywhere and source it from your .zshrc or .bashrc file with : source /path/to/ssh-compile
# This can be useful if you share a config file among several people like in your company and also some private hosts.
# call ssh-compile-config to get all the files matching ~/.ssh/.config* and combine them into the final ~/.ssh/config file
alias ssh-compile-config='echo -n > ~/.ssh/.config && cat ~/.ssh/config* > ~/.ssh/.config'
ssh-compile-config
# fetch all the configured hosts
h=()
You can’t perform that action at this time.