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 / 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 / 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 / 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 / wpcli-wpaep.php
Created June 29, 2019 17:23
A WP-CLI command for refresh existing export (trigger|processing) from WP All Export Pro plugin
<?php
/*
Plugin Name: WP-CLI - WP All Export Pro
Plugin URI: http://www.beapi.fr
Description: Add a WP-CLI command for refresh existing export (trigger|processing) from WP All Export Pro plugin
Author: Be API
Author URI: http://www.beapi.fr
Version: 0.1
----
@herewithme
herewithme / wp-cli-wc-update-network.sh
Created June 29, 2019 16:34
WP-CLI, update WooCommerce for each sites of network
wp site list --field=url --url="NETWORK" | xargs -I {} wp wc update --url={}
@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[@]}
@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 / 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 / acf-functions-helper.php
Last active July 24, 2024 17:59
ACF template helper - Checks if at least one field is completed by BO for display or not a block
<?php
/**
* This function checks if at least one field is completed by BO
*
* @param array|string $fields the list of ACF fields to test, an array or a string of text separated by a comma
* @param mixed $object the post_id of which the value is saved against
* @param bool $is_sub_field
*
* @return bool
*/
@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);