Skip to content

Instantly share code, notes, and snippets.

View nawawi's full-sized avatar

Nawawi Jamili nawawi

View GitHub Profile
@nawawi
nawawi / override_wp_user_query.php
Created July 8, 2020 21:52 — forked from bosunolanrewaju/override_wp_user_query.php
How to remove the slow SQL_CALC_FOUND_ROWS from WP_User_Query and replace with standard COUNT() which is more performant.
<?php
/**
* Before sql query is generated, intercept `query_vars` and set `count_total` to false
* to prevent `SQL_CALC_FOUND_ROWS` from being added to the sql query.
* Also set our new `query_vars` attribute to true to track if count is required.
*/
add_action( 'pre_get_users', function($wpq) {
if ( isset($wpq->query_vars['count_total'] ) && $wpq->query_vars['count_total'] ) {
$wpq->query_vars['count_total'] = false;
$wpq->query_vars['run_count'] = true;
@nawawi
nawawi / serializetest
Created December 1, 2020 00:03 — forked from bwg/serializetest
testing serialize vs. json_encode vs. var_export vs. msgpack_pack
PHP Version 5.4.30
--------------------------------------------------
Testing 10 item array over 1,000 iterations:
serialize 2.1979808807373 ms
json_encode 1.3420581817627 ms
var_export 1.9409656524658 ms
msgpack_pack 1.5850067138672 ms
--------------------------------------------------
@nawawi
nawawi / pllstrings.php
Created June 1, 2021 14:29 — forked from davidwebca/pllstrings.php
Translate regular gettext and underscore functions with Polylang's strings
<?php
add_filter('gettext', function($translation, $text, $domain) {
if(is_admin()) {
return $translation;
}
if($domain == 'mythemedomain') {
if(function_exists('icl_register_string')){
$slug = sanitize_title($text);
icl_register_string($domain, $slug, $text);
@nawawi
nawawi / PseudoCrypt.php
Last active March 1, 2023 00:43 — forked from ethanpil/gist:94455f8de76671aa9024
PseudoCrypt.php
<?php
/**
* Reference/source: http://stackoverflow.com/a/1464155/933782
*
* I want a short alphanumeric hash that’s unique and who’s sequence is difficult to deduce.
* I could run it out to md5 and trim the first n chars but that’s not going to be very unique.
* Storing a truncated checksum in a unique field means that the frequency of collisions will increase
* geometrically as the number of unique keys for a base 62 encoded integer approaches 62^n.
* I’d rather do it right than code myself a timebomb. So I came up with this.
*