Skip to content

Instantly share code, notes, and snippets.

View herewithme's full-sized avatar
🎯
Focusing

Amaury Balmer herewithme

🎯
Focusing
View GitHub Profile
@herewithme
herewithme / bench-memcached.php
Created December 3, 2015 23:47
Benchmark for test memcached performance
<?php
// Initialize values: 1000000 keys of 20 bytes with 40 bytes of data
$c = 1000000;
$values = array();
for ($i=0;$i<$c;$i++) $values[sprintf('%020s',$i)]=sha1($i);
// Memcached
$m = new Memcached();
$m->addServer('10.0.101.82', 11211);
$start = microtime(true);
@herewithme
herewithme / rankmath-wpjobmanager.php
Created February 20, 2020 12:30
Add jobs listing page on rankMath breadcrumb
<?php
/*
Plugin Name: RankMath & WP Job Manager
Version: 1.0.0
Plugin URI: https://beapi.fr
Description: Add jobs listing page on rankMath breadcrumb
Author: Be API
Author URI: https://beapi.fr
*/
@herewithme
herewithme / log-http-requests-backtrace.php
Created June 1, 2020 04:36
Add backtrace to log-http-requests WordPress plugin
<?php
add_filter( 'lhr_log_data',
function ( $data ) {
$backtrace = wp_debug_backtrace_summary();
$data['request_args'] = json_decode( $data['request_args'] );
$data['request_args']->backtrace = $backtrace;
$data['request_args'] = json_encode( $data['request_args'] );
@herewithme
herewithme / wpforms-pattern-french-phone.php
Last active July 2, 2020 13:34
An addon for WPForms plugin, allow to force and valid french format phone number for the field with the class: "wp-forms-check-phone-number"
<?php
/**
* Plugin Name: WPforms - French Phone Validation
* Plugin URI: https://beapi.fr
* Description: Add JS and PHP check for validate french number, supported formats : +33123456789 and 0123456789
* Version: 0.2
* Author: BE API
* Author URI: https://beapi.fr
*/
@herewithme
herewithme / sugar-calendar-gutenberg.php
Last active September 9, 2020 06:00
Add support of Gutenberg to Sugar Calendar with minor tweaks
<?php
/**
* Plugin Name: Sugar Calendar - Gutenberg
* Description: Add support of Gutenberg to Sugar Calendar with minor tweaks
* Author: Be API Team
* Author URI: http://beapi.fr/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
* @see: https://gist.github.com/herewithme/f1c377377cc3dcedc8388dd97196fdb6
@herewithme
herewithme / search-files.php
Last active July 28, 2021 10:28
Search files with PHP Script - Help for find malware in uploads folder
<?php
$base_dir = dirname(__FILE__);
$extension_restriction = array(
'js',
'php'
);
$it = new RecursiveDirectoryIterator($base_dir);
foreach (new RecursiveIteratorIterator($it) as $file) {
if (in_array(strtolower(pathinfo( $file, PATHINFO_EXTENSION )), $extension_restriction)) {
@herewithme
herewithme / script.sh
Created November 19, 2018 16:13
Set a role for each users for all sites for WordPress Multisite
for url in $( wp site list --allow-root --field="url" --url="https://XXX" );
do
echo $url;
wp --allow-root user list --network --url="https://XXX" --field=id | xargs -I % wp --allow-root user set-role % administrator --url=$url
done;
@herewithme
herewithme / wp-rocket-purge-all.php
Last active May 6, 2022 12:08
Purge all WP rocket cache when a post is modified/edited
<?php
/*
Plugin Name: Purge all WP Rocket cache
Plugin URI: http://www.beapi.fr
Description: Purge all WP rocket cache when a post is modified/edited
Version: 1.0
Author: BeAPI
Author URI: http://www.beapi.fr
Network: true
*/
@herewithme
herewithme / wpcli-db-charset.sh
Created February 20, 2019 05:38
Convert all WordPress tables to UTF8MB4 with WP-CLI
#!/usr/bin/env bash
# Author Amaury Balmer - BEAPI.fr
# See: https://wordpress.stackexchange.com/questions/195046/relaunch-4-2-utf8mb4-databse-upgrade/244992#244992
# Purpose - Convert all tables to UTF8MB4 with WP-CLI
# Create array of all tables
WPTABLES=($(wp db tables --all-tables))
# loop through array and alter tables
for WPTABLE in ${WPTABLES[@]}