Skip to content

Instantly share code, notes, and snippets.

View micc83's full-sized avatar

Alessandro Benoit micc83

View GitHub Profile
@micc83
micc83 / gist:5875218
Last active December 19, 2015 01:19
Find current client IP
<?php
/**
* Trova l'ip del cliente
*/
function mc_get_user_ip() {
// Tiro giù l'ip del client
if ( isset( $_SERVER["REMOTE_ADDR"] ) ) {
$ip = $_SERVER["REMOTE_ADDR"];
} elseif ( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
@micc83
micc83 / gist:5875231
Created June 27, 2013 09:37
Current page url
<?php
/**
* RITORNA L'URL CORRENTE
*/
function curPageURL() {
$pageURL = 'http';
if ( isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") $pageURL .= "s";
$pageURL .= "://";
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
@micc83
micc83 / var_dump.js
Created July 2, 2013 14:06
Javascript var_dump (for diehard PHP coder)
function varDump( Obj ) {
this.eplode = function( theObj ){
var output = ("<ul style='list-style:none;padding-left:20px;margin:0;color:#02adea;'>");
if( typeof theObj == 'object' ){
for( var p in theObj ){
output += "<li style='font-size:12px;'>";
if( theObj[p] &&
( theObj[p].constructor == Array || theObj[p].constructor == Object ) ){
@micc83
micc83 / create_admin.php
Created July 2, 2013 14:11
Create a new admin user in WordPress
<?php
// ADD NEW ADMIN USER TO WORDPRESS
// ----------------------------------
// Put this file in your Wordpress root directory and run it from your browser.
// Delete it when you're done.
require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');
// CONFIG
@micc83
micc83 / index.html
Last active January 4, 2019 07:15
Multifile uploader with images preview
<form method="post" id="tiribi" enctype="multipart/form-data">
<input id="fileuploader" type="file" name="file[]" multiple="" >
<ul class="filelist"></ul>
<input type="submit" class="button" name="multi_post_submit" value="Upload files" id="submit_button" />
</form>
@micc83
micc83 / gist:5964192
Last active January 4, 2019 07:14
WordPress Gists embed Shortcode
<?php
/**
* WordPress Gists Shortcode
*
* To include a Gist you have different possibilities:
* [gists id="5964192"]
* [gists]https://gist.github.com/micc83/5964192[/gists]
* [gists id="5964192" file="index.html"]
* [gists file="index.html"]https://gist.github.com/micc83/5964192[/gists]
@micc83
micc83 / gist:6413451
Last active March 17, 2016 19:54
Export WordPress Posts by category or custom taxonomy with attachments
<?php
/**
* Export WordPress Posts by category or custom taxonomy with attachments
*
* Add the needed select boxes to the ui
*/
add_action( 'export_filters', 'export_custom_taxonomy_fields' );
function export_custom_taxonomy_fields() {
?>
<!-- Styles -->
@micc83
micc83 / gist:6446989
Last active December 22, 2015 08:48
Proxy check
<?php
/**
* Controlla che non si tratti di un proxy
*/
function ipProxyPortCheck( $ip ){
//timeout you want to use to test
$timeout = 5;
// ports we're going to check
@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)
@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);