Skip to content

Instantly share code, notes, and snippets.

View nielslange's full-sized avatar
👨‍💻
Moving bits and bytes around the globe

Niels Lange nielslange

👨‍💻
Moving bits and bytes around the globe
View GitHub Profile
@nielslange
nielslange / simple-translation.js
Last active November 8, 2021 13:18
Translating strings
import { __ } from '@wordpress/i18n';
__( 'Hello, Luigi!', 'woo-gutenberg-products-block' );
@nielslange
nielslange / wp-theme-stats.js
Last active March 24, 2021 17:17
Get all WordPress.org themes with more than 100.000 active installs
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);
@nielslange
nielslange / composer.json
Created January 15, 2021 11:08
Installing plugins and themes on a VIP Go site
{
"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 January 6, 2021 12:32
JavaScript: Validate IPv4 address
// 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 January 4, 2021 04:15
WordPress: Check enqueued scripts and styles
<?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 / functions.php
Last active January 4, 2021 04:04
WordPress: Bulk-delete featured images
<?php
global $wpdb;
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id'" );
@nielslange
nielslange / functions.php
Created September 17, 2020 13:40
Reorder EU VAT field on checkout page
<?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;
<?php
function find_uniq($a) {
sort($a);
return ($a[0] === $a[1]) ? end($a) : current($a);
}
<?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 November 9, 2019 12:58
Set maximum character length of function GROUP_CONCAT() to 10000.
# Set maximum character length of function GROUP_CONCAT() to 10000.
SET SESSION group_concat_max_len = 10000;