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_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 / 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 / random_masonry.js
Last active November 14, 2019 16:14
Masonry image size randomizer (with PHP, LESS and isotope.js)
$('.grid').isotope({
itemSelector: '.grid-item',
//percentPosition: true,
masonry: {
columnWidth: 100
}
})
@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 / manage_paragraphs.php
Last active November 26, 2019 12:10
[WP][PHP] Split first paragraph from main content, display it elsewhere
<?php
// Grab the first paragraph, show it where you need it, then take the rest of the content and remove the first paragraph and show it elsewhere
// The script uses WordPress functions/content but can be used in any PHP script, just replace the WP functions
// First Paragraph
global $post;
$p1 = wpautop( $post->post_content );
$p1 = substr( $p1, 0, strpos( $p1, '</p>' ) + 4 );
//$p1 = strip_tags($p1, '<a><strong><em><h3><h2><i>'); // in case you need to remove some tags, add the ones you want to KEEP here
@Jany-M
Jany-M / expires.conf
Last active January 27, 2020 13:10
[Apache] mod_expires conf
# etc/httpd/conf.d/expires.conf
# https://support.plesk.com/hc/en-us/articles/115001711985-How-to-enable-leverage-browser-caching-in-Plesk
# https://support.plesk.com/hc/en-us/articles/213380049-How-to-enable-gzip-compression-on-nginx-on-Plesk-server
LoadModule expires_module modules/mod_expires.so
ExpiresActive on
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
@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 / 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 / WP_flush_cache_and_transients.php
Last active June 2, 2020 09:31
[WordPress] Flush Object Cache (Memcached) & Transients - Admin buttons
<?php
// Flush Cache from Admin bar
function flush_memcache_button() {
global $wp_admin_bar;
// If User isnt even logged in or if admin bar is disabled
if ( !is_user_logged_in() || !is_admin_bar_showing() )
return false;
@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' ) );