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 / gitlab-ci.yml
Last active April 24, 2023 09:46
GitLab CI version for WPBP
image: jakzal/phpqa:alpine
cache:
paths:
- vendor/
stages:
- Code Quality
coding-standards:
@Mte90
Mte90 / backup.sh
Created July 7, 2020 14:17
Backup to webdav files and WordPress DB
#!/bin/sh
today=$(date +"%Y-%m-%d")
path=$(date +"%Y/%m/%d")
rm -rf ./backups
mkdir ./backups
tar --exclude='./public_html/cgi-bin' --exclude='*.zip' --exclude='./public_html/wp-content/cache' -zcvf ./backups/$today.tar.gz ./public_html > /dev/null
./wp db export --add-drop-table --path=./public_html/ - | gzip > "./backups/$today.sql.gz"
curl --user "user:pass" -T "./backups/$today.tar.gz" "https://domain.com/remote.php/webdav/folder/$path/domain-$today.tar.gz"
@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