Skip to content

Instantly share code, notes, and snippets.

View Mte90's full-sized avatar
🎯
Creating new open source stuff that you will like

Daniele Scasciafratte Mte90

🎯
Creating new open source stuff that you will like
View GitHub Profile
@Mte90
Mte90 / gist:4117ec381a577df04793
Last active August 29, 2015 14:01
Modal in javascript vanilla
//Based on http://jsfiddle.net/i_like_robots/W2DA8/
(function(name, context, definition) {
if (typeof define === 'function' && define.amd) {
define(definition);
}
else if (typeof module !== 'undefined' && module.exports) {
module.exports = definition();
}
else {
@Mte90
Mte90 / script.php
Last active May 21, 2016 22:42
Table from array in PHP
<?php
function table_from_array( $cols, $tableclass = 'info' ) {
$content = "<table class=\"" . $tableclass . "\">\n";
$i = 1;
foreach ( $cols as $key => $value ) {
if ( !empty( $value ) ) {
$i++;
if ( $i % 2 === 0 ) {
$content .= "<tr>";
}
@Mte90
Mte90 / ff-check.js
Last active March 23, 2017 12:43
Check if Firefox/Firefox OS/Firefox for Android
//With locationbar.visible check if not in a webview (like an open web app)
if (locationbar.visible) {
//mozApps used for the open web app and with the user agent check if have MObile (used in Firefox OS)
if (navigator.userAgent.indexOf('Firefox') > -1 && navigator.userAgent.indexOf("Mobile") > -1) {
//Check Firefox OS
} else if (navigator.userAgent.indexOf('Firefox') > -1 && navigator.userAgent.indexOf("Android") > -1) {
//Check Firefox for Android
} else if (navigator.userAgent.indexOf("Firefox") > -1) {
//Check Firefox Desktop
}
@Mte90
Mte90 / snippet.php
Last active May 22, 2017 13:57
Order array multidimensional using a reference array
<?php
function sortArrayByArray( $array, $orderArray ) {
$order = array();
foreach ( array_keys( $array ) as $index ) {
foreach ( array_keys( $orderArray ) as $key ) {
$order[ $index ][ $key ] = $array[ $index ][ $key ];
}
}
return $order;
@Mte90
Mte90 / freemius.php
Created February 21, 2018 13:28
Freemius integration for OpenSupports
<?php
echo "Parsing Freemius Webhook";
// Get Freemius data
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if( isset($data['objects']['user']) ) {
// Let's call our opensupports instance
$name = $data['objects']['user']['first'] . ' ' . $data['objects']['user']['last'];
@Mte90
Mte90 / ffos-check
Last active July 13, 2018 20:45
Check Firefox OS version
function getVersion() {
if (navigator.userAgent.match(/(mobile|tablet)/i)) {
var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
if (ffVersionArray.length === 2) {
//Check with the gecko version the Firefox OS version
//Table https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
var hashVersion = {
'18.0': '1.0.1',
'18.1': '1.1',
'26.0': '1.2',
@Mte90
Mte90 / replace-po-wp-to-cp.sh
Last active December 17, 2018 14:49
ClassicPress i18n
#!/bin/bash
locale=$1
function replace() {
sed -i.bak s#https://"$1".wordpress.org/forums/#https://forums.classicpress.net/c/support#g /tmp/"$1"-"$2".po
sed -i.bak s/WordPress.org/ClassicPress.net/g /tmp/"$1"-"$2".po
sed -i.bak s/WordPress/ClassicPress/g /tmp/"$1"-"$2".po
}
@Mte90
Mte90 / freemius-to-slack.php
Last active May 31, 2019 01:15
Freemius to slack notification
<?php
// Get Freemius data
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if( isset( $data['objects'] ) ) {
slack($data);
}
function slack($data) {
@Mte90
Mte90 / block-wprestapi-loggedonly-orbykeyword.php
Created November 26, 2019 10:55
Block WordPRess rest api except logged user or if there is a parameter in the url
<?php
add_filter('rest_authentication_errors', function ($result) {
if (!empty($result)) {
return $result;
}
$access = is_user_logged_in();
if ( !$access ) {
if ( !isset($_GET['iwantthem']) || isset($_GET['iwantthem']) && $_GET['iwantthem'] !== 'yes' ) {
@Mte90
Mte90 / alter-login.php
Created December 3, 2019 14:02
Send email to user if not logged after 3 weeks
<?php
/**
* Plugin Name: Alert Last Login
* Plugin URI:
* Description:
* Version: 1.0.0
* Author: Codeat
* Author URI: http://codeat.it
* License: GPL-2.0+