Skip to content

Instantly share code, notes, and snippets.

View nicomollet's full-sized avatar

Nico Mollet nicomollet

View GitHub Profile
@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 May 13, 2024 09:30
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.2
// ==/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 / woocommerce-mail-callback-params.php
Last active November 30, 2022 13:28
WooCommerce Mail Params: customize "To" recipient with billing firstname and lastname along to the email for better email delivrability
<?php
/**
* WooCommerce: override mail params
* @param $params
* @param WC_Email $email
*
* @return mixed
*/
public function custom_woocommerce_mail_callback_params( $params, \WC_Email $email ){
@nicomollet
nicomollet / woocommerce-most-sold-query.sql
Created January 20, 2022 14:23
WooCommerce most/least sold products Mysql query
# Exclude product variations since they don't include the "total_sales" meta key filled by WooCommerce
SELECT ID, post_title, post_status, post_modified, meta_value
FROM wp_posts
INNER JOIN wp_postmeta ON wp_postmeta.post_id=wp_posts.ID
AND wp_postmeta.meta_key='total_sales'
WHERE post_type='product'
ORDER BY CAST(`wp_postmeta`.`meta_value` as UNSIGNED) DESC;
@nicomollet
nicomollet / wp-versioncheck-disable.php
Created January 6, 2022 14:22
WordPress Core Updates: disable wp_version_check single event creation
<?php
/**
* Core Update: disable wp_version_check single event creation
*
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue adding the event.
* @param stdClass $event {
* An object containing an event's data.
*
* @type string $hook Action hook to execute when the event is run.
@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 / oembed_result_youtube_nosnippet.php
Last active March 8, 2021 10:26
WordPress: Add a "data-nosnippet" on oembed html (only for YouTube)
<?php
/**
* oEmbed HTML: Adds a "data-nosnippet" on oembed html (only for YouTube)
*
* @param string|false $data The returned oEmbed HTML (false if unsafe).
* @param string $url URL of the content to be embedded.
* @param array $args Optional arguments, usually passed from a shortcode.
*
* @return string
*/
@nicomollet
nicomollet / .lando.yml
Last active March 3, 2021 16:11
Lando Recipe for WordPress
name: SITENAME
recipe: wordpress
config:
webroot: .
env: dev
via: apache #nginx doesn't work, don't know why
php: 7.3
#xdebug: true
database: mysql
services:
@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: