Skip to content

Instantly share code, notes, and snippets.

View nicomollet's full-sized avatar

Nico Mollet nicomollet

View GitHub Profile
@nicomollet
nicomollet / polylang-langswitcher-shortcode.php
Last active January 17, 2024 11:25
Polylang shortcode for lang switcher
<?php
/**
* Polylang Shortcode - https://wordpress.org/plugins/polylang/
* Add this code in your functions.php
* Put shortcode [polylang_langswitcher] to post/page for display flags
*
* @return string
*/
function custom_polylang_langswitcher() {
$output = '';
@nicomollet
nicomollet / gravity-forms-use-woocommerce-email-template-for-notifications.php
Last active December 12, 2023 04:49
Gravity Forms: Use WooCommerce emails templates for notifications
<?php
/**
* Gravity Forms: Use WooCommerce emails templates for notifications.
*
* @param string $template
*
* @return string
*/
public function custom_gform_html_message_template_pre_send_email( string $template ) {
@nicomollet
nicomollet / button-datamodal.js
Last active November 14, 2023 13:29
WordPress block editor: add data-modal attribute to button block.
/**
* Button block, add a "data-modal" attribute.
*
* @author Nicolas Mollet, inspired by Marie Comet
* @see https://mariecomet.fr/en/2021/12/14/adding-options-controls-existing-gutenberg-block/
*/
const { __ } = wp.i18n;
// Enable custom attributes on Button block
const enableSidebarSelectOnBlocks = [
@nicomollet
nicomollet / YoutubeMusicScript.user.js
Last active October 18, 2023 13:18
YouTube Music userscript: moves the Save to library button in the player bar
// ==UserScript==
// @name YouTubeMusicScript
// @description YouTubeMusicScript
// @include http://music.youtube.com/*
// @autho Nicolas Mollet
// @version 1.0
// ==/UserScript==
// Observe play-button clicks.
@nicomollet
nicomollet / catch-plugin-deactivation-cause.php
Last active September 29, 2023 07:54
WordPress: catch plugin deactivation and write log of cause of deactivation.
<?php
/**
* Catch plugin deactivation and write log of cause of deactivation (manual or error).
*
* Examples:
* [29-Sep-2023 07:40:40 UTC] Plugin antispam-bee/antispam_bee.php was disabled manually.
* [29-Sep-2023 07:47:29 UTC] Plugin antispam-bee/antispam_bee.php was disabled because Plugin file does not exist.
*
* @param string $plugin Path to the plugin file relative to the plugins directory.
@nicomollet
nicomollet / .lando.yml
Last active June 16, 2023 02:18
Lando Recipe for Yii2 (for yii2-starter-kit in multiple domains mode, with nginx)
name: SITENAME
recipe: lemp
config:
env: dev
php: '7.1'
composer_version: '1.10.19'
database: mysql
webroot: .
xdebug: false
config:
@nicomollet
nicomollet / addthis-customurl.html
Last active June 9, 2023 13:14
Addthis: sharing buttons with custom URL
<div class="addthis_sharing_toolbox" data-url="http://customurl.com" data-title="customtitle"></div>
<script type="text/javascript">
var addthis_share = addthis_share || {};
addthis_share = {
passthrough: {
twitter: {
via: 'twitteraccount',
text: 'lorem ipsum'
}
@nicomollet
nicomollet / homeicon.php
Created July 25, 2017 13:05
Replace Home menu item by home icon
<?php
/**
* Replace Home menu item by home icon
*
* @param $sorted_menu_items
*
* @return mixed
*/
function homeicon_nav_menu_objects( $sorted_menu_items )
{
@nicomollet
nicomollet / admin-scheme.php
Last active June 9, 2023 13:14
Wordpress Admin Color Scheme
<?php
// Generate an admin scheme using the generator here: http://themergency.com/generators/admin-color-scheme-generator/
// Copy the css file in css/admin.css
// Then include this function in your functions.php
// And setup the four hexadecimal colors
function custom_admin_color_schemes() {
$theme_dir = get_template_directory_uri();
wp_admin_css_color( 'nameofscheme', 'Name of Scheme',
$theme_dir . 'css/admin.css',
@nicomollet
nicomollet / woocommerce-local-pickup-only.php
Last active June 9, 2023 12:52
WooCommerce: hide shipping when products marked as "local pickup only" are in the cart
<?php
/**
* WooCommerce: hide shipping when products marked as "local pickup only" are in the cart
* Tested with WordPress 5.3.4 and WooCommerce 4.2.0
*
* The shipping class "local-pickup-only" needs to be created first.
* Then assign the products that are have "local pickup only" to this class
*
* @param array $rates
* @param array $package