Skip to content

Instantly share code, notes, and snippets.

View micc83's full-sized avatar

Alessandro Benoit micc83

View GitHub Profile
@micc83
micc83 / wp_sync_roles.php
Last active August 29, 2015 14:07
Sync roles between different WordPress Blog inside the same schema on first login
<?php
/**
* Sync roles between different WordPress Blog
*
* Tables must be inside the same schema and you have to define
* custom user tables on wp-config.php in the SLAVE blog as follow:
+ define('CUSTOM_USER_TABLE', 'myprefix_users');
+ define('CUSTOM_USER_META_TABLE', 'myprefix_usermeta');
* Sync is run only at the first login on the alternative blog, any following
* role change must be manually sync.
@micc83
micc83 / Restfulizer.js
Created September 25, 2014 14:55
Ruby like delete links on laravel
/**
* Restfulizer
*
* Restfulize any hiperlink that contains a data-method attribute by
* creating a mini form with the specified method and adding a trigger
* within the link.
* Requires jQuery!
*
* Ex:
* <a href="post/1" data-method="delete">destroy</a>
@micc83
micc83 / skip-to-check-out.php
Last active April 11, 2024 00:13
Skip cart and redirect to direct checkout on WooCommerce
<?php
/**
* Skip cart and redirect to direct checkout
*
* @package WooCommerce
* @version 1.0.0
* @author Alessandro Benoit
*/
// Skip the cart and redirect to check out url when clicking on Add to cart
@micc83
micc83 / tutorial-chat-app.html
Created July 16, 2014 08:04
Tutorial: Creare una chat in tempo reale con Firebase e login facebook
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MyApp</title>
<style>
@micc83
micc83 / default.vcl
Created July 4, 2014 07:39
WordPress custom Varnish configuration
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost";
"127.0.0.1";
}
@micc83
micc83 / iframe-height.js
Created June 23, 2014 17:01
Set iframe height based on content
jQuery('iframe.inpagedemo').load(function () {
var iframe = jQuery(this);
jQuery(window).resize(function() {
iframe.height(iframe[0].contentWindow.document.body.scrollHeight + 40);
});
jQuery(window).trigger('resize');
});
@micc83
micc83 / gist:9665159
Created March 20, 2014 14:37
Wordpress return 404
<?php
function return_page_404() {
global $wp_query;
$wp_query->set_404();
status_header(404);
}
jQuery(document).ready( function($) {
function send_popup( title, text, popup_class, delay ) {
// Initialize parameters
title = title !== '' ? '<span class="title">' + title + '</span>' : '';
text = text !== '' ? text : '';
popup_class = popup_class !== '' ? popup_class : 'update';
delay = typeof delay === 'number' ? delay : 20000;
@micc83
micc83 / gist:6550016
Created September 13, 2013 12:27
Relative date by @Pellegrom
<?php
function relative_time($date, $postfix = ' ago', $fallback = 'F Y')
{
$diff = time() - strtotime($date);
if($diff < 60)
return $diff . ' second'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/60);
if($diff < 60)
return $diff . ' minute'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/60);
@micc83
micc83 / gist:6451181
Created September 5, 2013 14:49
Set cookie in wp
<?php
function set_newuser_cookie() {
if (!isset($_COOKIE['sitename_newvisitor'])) {
setcookie('sitename_newvisitor', 1, time() + HOUR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN, false);
}
}
add_action( 'init', 'set_newuser_cookie');
/**
* MINUTE_IN_SECONDS = 60 (seconds)