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 / 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_select_comuni.php
Last active May 22, 2019 16:26
[WP] Select con Comuni per x Regione italiana, in Ajax
<?php
// Richiede la creazione ed il popolamente delle tabelle https://gist.github.com/Jany-M/7b75ac99f46aaf13ef04587e5e9dd882
// Richiede la libreria JS Bootstrap Select https://github.com/silviomoreto/bootstrap-select
/* --------------------------------------------------------------------------------
*
* functions.php
*
-------------------------------------------------------------------------------- */
@Jany-M
Jany-M / wp_rp.php
Last active February 23, 2017 14:04
[WP] Regioni, Province, Comuni italiani - DB tables per WordPress
This file has been truncated, but you can view the full file.
<?php
$prefisso = ''; // le tabelle non avranno nessun prefisso e saranno: regioni, province, comuni - altrimenti scegliere qualcos'altro tipo $wpdb->prefix.'rpc_'
define('PREFISSO_TABELLA', $prefisso);
// Questione funzione crea e popola le tabelle necessarie nel db
// Può essere agganciata come azione all'hook init nel functions.php, va caricato una volta sola e poi tolta dal file
function rpc_crea_tabelle(){
global $wpdb;
@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_cf7_country-language_shortcode.php
Last active June 6, 2021 16:22 — forked from MatthewEppelsheimer/country-shortcode.php
[WP] Contact Form 7 shortcode with list of World Countries & Languages
<?php
/*
UPDATED: 23 Jan 2017.
Modifications:
- Truncated the longest country names, including:
-- British Indian Ocean Territories (Chagos Archipelago) -> British Indian Ocean Territories
-- South Georgia and the South Sandhich Islands -> South Georgia & S. Sandwich Islands
@Jany-M
Jany-M / wp_wc_sql_order_query.sql
Created December 20, 2016 19:17
[WP][WooCommerce] SQL query for orders
/* List of useful SQL queries */
SELECT * FROM wp_posts where post_type = 'shop_order' and post_status = 'wc-pending';
SELECT * FROM wp_posts where post_type = 'shop_order';
@Jany-M
Jany-M / wp_extract_slider_from_post.php
Last active December 7, 2016 23:03
[WP] Parse content for shortcode, extract & show it somewhere else, delete it from content
<?php
/* Example with Visual Composer and an add-on for Slides
|
| We want to remove the slider from the post content,
| while keeping it in the backend post editor VC content,
| then place it somewhere else, like the header.
|
| In our case, the slider always sits at the top of the
| post content editor, as first item, in its own row.
@Jany-M
Jany-M / greyscale_colorize_wp_post_images.php
Last active November 14, 2019 16:25
[WP] Colorize (after greyscale), depending on post type, a post image (either feat, parsed or external) and save it as new to uploads
<?php
// This script assumes we are in a Post Loop
// Get the image you need however you like, I use https://github.com/Jany-M/WP-Imager
$image_orig = wp_imager($img_w, $img_h, 3, '', true, '', true, null, null, true);
// Check for image headers to avoid Error 400 - if all images come always from same server/site you dont need this
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$ch = curl_init ($image_orig);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@Jany-M
Jany-M / php_regex.php
Last active June 6, 2021 16:23
[PHP] Common RegEx
<?php
// Let's be honest, RegEx is not fun, so these may come in handy
// I'll update this in case I write/find more
$text = '[video mp4="http://somevideo.com/abc"]';
preg_match_all("\bmp4="(.+)\b", $text, $matches);
var_dump($matches[0]);
// http://somevideo.com/abc
@Jany-M
Jany-M / fixed_width_columns_table.html
Created September 1, 2016 14:34
[HTML] Fixed column width table
<table style="table-layout: fixed;">
<colgroup>
<col span="1" style="width: 10%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 40%;">
<col span="1" style="width: 40%;">
</colgroup>
<tbody>