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 / remove_gutenberg_block.php
Created June 11, 2020 15:51
Remove WordPress Gutenberg block in content
<?php
function remove_block_gutenberg( $content, $blockname ) {
$blockname = str_replace('/', '\/',preg_quote($blockname));
return preg_replace('/\<\!\-\- ' . $blockname . '[^)]+\/' . $blockname . ' \-\-\>/', '', $content);
}
// Based on this ticket https://wordpress.org/support/topic/strip-table-of-content-from-excerpt/
// There is a block that we don't want on excerpt automatically generated,
// Automatic excerpt cut the content and this can generate a broken content
@Mte90
Mte90 / snippet.php
Created April 30, 2020 16:50
W3TC generate minified filename by checksum
<?php
// Based on https://wordpress.org/support/topic/how-to-change-minified-css-file-name/
// Get all the files, read them, concat them, get a md5 hash, cut at 10 and generate a new filename
// Why?
// W3TC generate the hashname based on the filenames so not invalidate the cache if there are changes
add_filter('w3tc_minify_urls_for_minification_to_minify_filename', 'w3tc_filename_filter', 20, 3);
function w3tc_filename_filter($minify_filename, $files, $type ){
$path_parts = pathinfo( $minify_filename );
$content = '';
@Mte90
Mte90 / clean.sh
Created March 17, 2020 19:58
Clips dataset parser and cleaner
#!/usr/bin/env bash
function extract() {
echo "Estraggo $1.rar"
unrar e "./$1.rar" \*.txt \*.wav './clips-mitads/' -o+
}
if [ ! -d './clips-mitads' ]; then
mkdir './clips-mitads'
fi
@Mte90
Mte90 / Customfile
Last active December 10, 2021 14:55
2 new commands for VVV
class VVVScripts < Vagrant.plugin(2, :command)
def self.synopsis
"Execute script from /config/homebin/"
end
def execute
with_target_vms(nil, single_target: true) do |vm|
@env.ui.output "#{$yellow}Executing #{$red}#{ARGV[1]}#{$creset}\n"
vm.action(:ssh_run, ssh_run_command: "/srv/config/homebin/#{ARGV[1]}" )
end
@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+
@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 / opensupport-cron.sh
Last active September 15, 2020 09:30
OpenSupports Cron to activate users
#!/bin/bash
mysql --user='[users]' --password='[psw]' --database='[db]' --execute="UPDATE user SET verification_token = NULL WHERE user.verification_token IS NOT NULL;"
@Mte90
Mte90 / update-bot.sh
Last active January 28, 2021 09:55
Auto update Mozilla Italia bot and restart them on unix system
#!/usr/bin/env bash
cd /opt/mozita/
cd ./mozitaantispam_bot/
git fetch --all
if [[ $(git rev-list HEAD...origin/master --count) -ne 0 ]]; then
pkill -f antispam_mozita.py
git stash
git pull
@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) {