Skip to content

Instantly share code, notes, and snippets.

View ihorvorotnov's full-sized avatar
🇺🇦
Working remotely since 1999

Ihor Vorotnov ihorvorotnov

🇺🇦
Working remotely since 1999
View GitHub Profile
@mishterk
mishterk / CustomOrderEmail.php
Last active July 1, 2020 11:21
Registering custom emails for WooCommerce
<?php
class CustomOrderEmail extends \WC_Email {
// This is a just a simple example. See \WC_Email and child classes for more examples
public function __construct() {
$this->id = 'custom_order_email';
$this->title = 'Custom Order Email';
@mishterk
mishterk / LocalValetDriver.php
Last active March 1, 2024 22:00
A local Valet driver for proxying images to a remote host
<?php
/**
* Class LocalValetDriver
*
* This class demonstrates how we might go about proxying any missing local images to a remote host. i.e; the production
* site. This has been created with WordPress in mind but could be adjusted to work with any other system.
*/
class LocalValetDriver extends WordPressValetDriver {
@tomjn
tomjn / tomjn_http2_push.php
Created January 25, 2019 23:43
A naive and incomplete, but functional approach to http2 push
<?php
/**
* Plugin name: HTTP2 Push scripts
* Author: Tom J Nowell
*/
function tomjn_get_dep_url( /*\WP_Dependency*/ $dep ) {
global $wp_version;
$relative = str_replace( site_url(), '', $dep->src );
$ver = $dep->ver;
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active May 22, 2024 08:34
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@charrondev
charrondev / loose-obj.php
Last active March 26, 2022 11:34
PHP Object vs Array memory usage with random values
<?php
include_once "./randomString.php";
$s = [];
for ($x = 0; $x < 100000; $x++) {
$obj = new stdClass();
$obj->name = randomString();
$obj->age = rand(1, 100);
$s[] = $obj;
<?php
# Check: https://onexa.nl/wordpress/toolbar-link-redis-object-cache/
/**
* Add a link to the Admin Toolbar to easily flush the Redis cache (Redis Object Cache plugin)
*
* @author Hiranthi Herlaar, onexa.nl
* @version 2.0
*
<?php
/**
* Class BenchMarker
* @author Phil Kurth <phil@philkurth.com.au>
*
* A simple benchmarking utility. Easiest way to use this:
*
* BenchMarker::start();
*
* … run stuff here …
@Propaganistas
Propaganistas / MailHog configuration
Last active March 13, 2024 14:26
Laravel MailHog SMTP configuration
# Mailhog
MAIL_MAILER=smtp
MAIL_HOST=0.0.0.0
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
@mishterk
mishterk / post-revision-meta.sql
Last active July 1, 2020 11:23
Useful SQL snippets for WordPress DB analysis
# Lists revision post IDs and their meta data count in descending order
SELECT post_id, count(*) AS count FROM wp_postmeta LEFT JOIN wp_posts ON post_id = ID WHERE post_type = 'revision' GROUP BY post_id ORDER BY count DESC;
# Tells you how many (total figure) meta rows belong to revision posts
SELECT count(*) as total_revision_meta FROM wp_postmeta INNER JOIN wp_posts ON post_id = ID WHERE post_type = 'revision';
# Lists the post_id number of revisions for posts in descending order by number of revisions
SELECT post_parent as post_id, count(*) AS n_revisions FROM wp_posts WHERE post_type = 'revision' GROUP BY post_parent ORDER BY n_revisions DESC;
@hiranthi
hiranthi / woo-checkout.php
Last active August 26, 2021 00:52
WooCommerce checkout steps
<?php
/**
* Display the checkout steps so the customer knows where they are.
*
* The output uses classes of Bootstrap 4 and the icons of FontAwesome (Free)
**/
function onx_woocommerce_checkout_steps()
{
echo '<nav id="woo-checkout-steps" class="nav nav-pills nav-justified mb-4" role="navigation">';