Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Moving bits and bytes around the globe

Niels Lange nielslange

👨‍💻
Moving bits and bytes around the globe
View GitHub Profile
@nielslange
nielslange / composer.json
Created Jan 15, 2021
Installing plugins and themes on a VIP Go site
View composer.json
{
"name": "niels/vip-go-site",
"description": "VIP Go test site of Niels Lange",
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
"require": {
@nielslange
nielslange / isValidIPv4.js
Last active Jan 6, 2021
JavaScript: Validate IPv4 address
View isValidIPv4.js
// Validate IPv4 address
function isValidIPv4(string) {
const octet = '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)';
const regex = new RegExp(`^${octet}\\.${octet}\\.${octet}\\.${octet}$`);
return regex.test(string) ? true : false;
}
@nielslange
nielslange / functions.php
Last active Jan 4, 2021
WordPress: Bulk-delete featured images
View functions.php
<?php
global $wpdb;
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id'" );
@nielslange
nielslange / functions.php
Created Sep 17, 2020
Reorder EU VAT field on checkout page
View functions.php
<?php
/**
* Reorder EU VAT field on checkout page
*
* @param $fields array The original array with the checkout fields
* @return $fields array The updated array with the checkout fields
* @see https://woocommerce.com/products/eu-vat-number/
*/
function smntcs_reorder_eu_vat_field( $fields ) {
$fields['billing']['billing_vat_number']['priority'] = 35;
@nielslange
nielslange / functions.php
Last active Jan 4, 2021
WordPress: Check enqueued scripts and styles
View functions.php
<?php
// Check enqueued scripts
add_action( 'wp_enqueue_scripts', 'nl_check_enqueued_scripts', 99999 );
function nl_check_enqueued_scripts() {
global $wp_scripts;
var_dump( $wp_scripts );
}
// Check enqueued styles
@nielslange
nielslange / wp-theme-stats.js
Last active Mar 24, 2021
Get all WordPress.org themes with more than 100.000 active installs
View wp-theme-stats.js
let url = 'https://api.wordpress.org/themes/info/1.2/?action=query_themes&request[search]=%20&request[fields][downloaded]=true&request[fields][active_installs]=true&request[per_page]=-1';
let results = await fetch( url )
.then( response => response.json() )
.then( data => data.info.results )
.catch(err => console.log( err ) );
console.log(results);
let max = 1000;
let pages = Math.ceil(results / max);
View find_uniq.php
<?php
function find_uniq($a) {
sort($a);
return ($a[0] === $a[1]) ? end($a) : current($a);
}
View find_uniq.php
<?php
function find_uniq(array $array): int {
sort($array);
if ( $array[0] === $array[1] ) rsort($array);
return $array[0];
}
@nielslange
nielslange / query.sql
Last active Nov 9, 2019
Set maximum character length of function GROUP_CONCAT() to 10000.
View query.sql
# Set maximum character length of function GROUP_CONCAT() to 10000.
SET SESSION group_concat_max_len = 10000;
View style.css
/* Replace site logo based on language | NL-***-hc */
html[lang="en-US"] .custom-logo-link {
background: url(IMAGE-URL);
height: 150px;
width: 300px;
display: block;
margin: auto;
}
html[lang="en-US"] .custom-logo-link img.custom-logo {
display: none;