Skip to content

Instantly share code, notes, and snippets.

View gmazzap's full-sized avatar

Giuseppe Mazzapica gmazzap

View GitHub Profile
@gmazzap
gmazzap / get_term_related_terms.php
Last active August 29, 2015 14:00
WordPress (monster) function that retrieve terms from one or more taxonomies having posts "in common" with given term(s) form a different taxonomy.
@gmazzap
gmazzap / index.html
Last active August 29, 2015 14:02
Muschiatini
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Muschiatini Dixit</title>
<meta name="description" content="Muschiatini Dixit">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
</head>
@gmazzap
gmazzap / queried_posts_terms
Created August 25, 2014 05:52
A WordPress template tag that retrieve terms from specific taxonomies attached to the all the currently queried posts (in main query).
function queried_posts_terms( $taxonomies = 'category' ) {
global $wp_query, $wpdb;
if ( empty( $wp_query->posts ) ) return FALSE;
$ids = wp_list_pluck( $wp_query->posts, 'ID' );
$taxonomies = array_filter( (array) $taxonomies, function( $tax ) {
if ( is_string( $tax ) ) {
$tax = sanitize_title( $tax );
return taxonomy_exists( $tax ) ? esc_sql( $tax ) : NULL;
}
} );
@gmazzap
gmazzap / loop.php
Last active August 29, 2015 14:07 — forked from tomjn/loop.php
<?php
array_walk($GLOBALS['wp_query']->posts, function($post, $i, $wp_query) {
$GLOBALS['post'] = $post;
$wp_query->the_post();
// loop code
the_title();
the_content();
@gmazzap
gmazzap / gm_optimum.php
Last active August 29, 2015 14:11
Optimum: a class to filter arrays with callbacks.
<?php namespace GM;
use SplObjectStorage;
class Optimum
{
private $data;
private $raw;
private $map;
private $storage;
@gmazzap
gmazzap / Arraize.php
Created January 20, 2015 01:25
Recursively convert an array or a traversable object into a nested array. Optionally convert all "atomic" items to strings and optionally HTML-encode all strings.
<?php namespace GM;
use Traversable;
use JsonSerializable;
/**
* Stateless class that recursively convert an array or a traversable object into a nested array.
* Optionally convert all "atomic" items to strings and optionally HTML-encode all strings.
* Array and traversable objects are all recursively converted.
* Non-traversable objects are converted to array, in 1st available among following methods:
<?php
/**
* @author Giuseppe Mazzapica <giuseppe.mazzapica@gmail.com>
* @license http://opensource.org/licenses/MIT MIT
*/
class MetaboxStealer
{
/**
* @var bool
@gmazzap
gmazzap / amu.php
Created April 17, 2014 03:37
Attach My Upload is a WordPress plugin that allow to create an attachment post from a file already uploaded to uploads folder. Was wrote to answer a WPSE question here: http://wordpress.stackexchange.com/questions/141509/
<?php
/**
* Plugin Name: Attach My Upload
* Description: Allow to create an attachment post from a file already uploaded to uploads folder.
* Plugin URI: http://wordpress.stackexchange.com/questions/141509/
* Author: G. M.
* Author URI: http://wordpress.stackexchange.com/users/35541/g-m
*
*/
/*
@gmazzap
gmazzap / gm-fsdfm.php
Last active November 20, 2015 07:03
WordPress plugins that allows to use the distraction-free mode that was active pre 4.1 WP version.
<?php namespace GM\FSDFM;
/**
* Plugin Name: Fullscreen Distraction-Free Mode (pre v4.1)
* Description: Allows to use the distraction-free mode that was active pre 4.1 WP version.
* Plugin URI: https://gist.github.com/Giuseppe-Mazzapica/c081ce03a68b00d983d5
* Author: Giuseppe Mazzapica
* Author URI: https://gm.zoomlab.it
* License: MIT
* Version: 1.0.0
*/
@gmazzap
gmazzap / GMNextGenPreviewImage
Last active December 20, 2015 12:59
A plugin for Wordpress and NexGen Gallery that use a metabox to select a NextGEN Gallery and use this gallery Preview Image as Post Featured Image
<?php
/**
* @package GMNextGenPreviewImage
* @version 0.1.0
*/
/**
Plugin Name: GM NextGen Preview Image
*
Author: Giuseppe Mazzapica
Version: 0.1.0