Skip to content

Instantly share code, notes, and snippets.

Jany Martelli Jany-M

Block or report user

Report or block Jany-M

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Jany-M
Jany-M / wp_get_og_img.php
Last active Mar 7, 2018
[WP] Get an image for Open Graph
View wp_get_og_img.php
<?php
// Get an image for Open Graph - Uses WP Imager https://github.com/Jany-M/WP-Imager
if(is_singular()) {
global $post;
if(function_exists('wp_imager')) {
$img = wp_imager(1200, 630, 1, '', '', '', true );
} elseif(has_post_thumbnail($post->ID)) {
$img = get_the_post_thumbnail_url( $post->ID, array(1200,630));
}
} else {
@Jany-M
Jany-M / wp_add_body_classes.php
Last active May 22, 2019
[WP] Add custom body classes for better CSS customization
View wp_add_body_classes.php
<?php
function add_classes_to_body($classes) {
global $post;
// User Role
$user_info = get_currentuserinfo();
$classes[] = implode(' ', $user_info->roles);
// WPML
if ( function_exists('icl_object_id') ) {
@Jany-M
Jany-M / wp_rename_upload_files.php
Created Apr 19, 2017
[WP] Rename files in custom upload folder
View wp_rename_upload_files.php
<?php
/* ----------------------------------------------------------------------------------------------------------------------------
* PREFACE for this script
*
* A frontend custom form, allowing registered users to create a custom post type + upload images to ACF Gallery custom field,
* in a custom uploads folder, had a bug where it would replace any symbol with -,
* including replacing the file extensions (eg. .jpg and .png, in -jpg and -png).
* That resulted in various issues, even though browsers could still read the file as image.
* After fixing the form itself, this script was made, to fix all the uploads that had already been uploaded and their path.
@Jany-M
Jany-M / rename_all_files_in_subdirectories.php
Last active Apr 14, 2017
[PHP] Rename files in directory subdirectories
View rename_all_files_in_subdirectories.php
<?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
[WP] Select con Comuni per x Regione italiana, in Ajax
View wp_select_comuni.php
<?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 Feb 23, 2017
[WP] Regioni, Province, Comuni italiani - DB tables per WordPress
View wp_rp.php
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 Dec 11, 2017
[WP] htacces for best security & caching settings
View .htaccess
# ------------------------------------------------------------------------------------------
#
# CUSTOM SETUP
#
# ------------------------------------------------------------------------------------------
# Oauth 1.0 - WP REST API v2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
@Jany-M
Jany-M / wp_cf7_country-language_shortcode.php
Last active Jan 26, 2017 — forked from MatthewEppelsheimer/country-shortcode.php
[WP] Contact Form 7 shortcode with list of World Countries & Languages
View wp_cf7_country-language_shortcode.php
<?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 Dec 20, 2016
[WP][WooCommerce] SQL query for orders
View wp_wc_sql_order_query.sql
/* 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 Dec 7, 2016
[WP] Parse content for shortcode, extract & show it somewhere else, delete it from content
View wp_extract_slider_from_post.php
<?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.
You can’t perform that action at this time.