Skip to content

Instantly share code, notes, and snippets.

View felixarntz's full-sized avatar

Felix Arntz felixarntz

View GitHub Profile
@felixarntz
felixarntz / perflab-server-timing-examples.php
Last active November 24, 2022 00:29
Some example use-cases for the Server Timing API in the Performance Lab plugin (see https://github.com/WordPress/performance/pull/553). A previous version for an older implementation of the API can be found at https://gist.github.com/felixarntz/c343a33242b6527ad3f446c8f7f4fec2.
<?php
add_action(
'plugins_loaded',
function() {
// Utility function that returns a measuring callback for an action hook,
// which should be registered as a metric within the action as early as possible
// (see PHP_INT_MIN usage below).
$get_measure_action_callback = function( $action_hook ) {
return function( $metric ) use ( $action_hook ) {
$metric->measure_before();
@felixarntz
felixarntz / perflab-server-timing-examples.php
Last active October 31, 2022 23:14
Some example use-cases for the Server Timing API in the Performance Lab plugin (see https://github.com/WordPress/performance/pull/553). This example is outdated (see comment below)!
<?php
add_action(
'perflab_server_timing_init',
function( $server_timing ) {
// Utility function that returns a measuring callback for an action hook.
$measure_action = function( $action ) {
return function ( $metric ) use ( $action ) {
$start_time = null;
// If action is already running, at least measure the remainder.
@felixarntz
felixarntz / wp-lazyload-lcp-fix.php
Last active March 11, 2024 22:13
Prototype plugin used for lazy-load LCP analysis in WordPress
<?php
/**
* Plugin initialization file
*
* @wordpress-plugin
* Plugin Name: Lazyload LCP Fix
* Plugin URI: https://gist.github.com/felixarntz
* Description: Omits the first content image from being lazy-loaded, to improve LCP performance.
* Version: 1.0.0
* Author: Felix Arntz, Google
<?php
/**
* Ensures Site Kit ignores contextual home URL path modifications added by certain multilingual plugins.
*
* @author Felix Arntz, Google
* @license Apache 2.0
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Fix Site Kit Canonical Home URL Multilingual
@felixarntz
felixarntz / custom-analytics-widget.js
Last active March 16, 2021 22:33
Example of using the Site Kit Widgets API
const { useSelect } = window.googlesitekit.data;
const {
registerWidget,
WIDGET_WIDTHS,
} = window.googlesitekit.widgets;
function CustomAnalyticsWidget( props ) {
const {
Widget,
WidgetNull,
<?php
/**
* Temporary fix Site Kit opcache_reset call, in case the function is not defined.
*
* @author Felix Arntz, Google
* @license Apache 2.0
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Site Kit Fix Opcache Call (temporary)
@felixarntz
felixarntz / clear-opcache-simple.php
Last active January 21, 2020 10:18
Clears PHP OpCache when visiting the Plugins admin screen (wp-admin/plugins.php).
<?php
/**
* Clear OpCache Simple.
*
* @author Felix Arntz, Google
* @license Apache 2.0
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Clear OpCache Simple
.color-accent,.color-accent-hover:hover,.color-accent-hover:focus,.has-accent-color,.has-drop-cap:not(:focus):first-letter,.wp-block-button.is-style-outline,a { color: #c13030; }blockquote,.border-color-accent,.border-color-accent-hover:hover,.border-color-accent-hover:focus { border-color: #c13030; }button:not(.toggle),.button,.faux-button,.wp-block-button__link,.wp-block-file__button,input[type="button"],input[type="reset"],input[type="submit"] { background: #c13030; }.bg-accent,.bg-accent-hover:hover,.bg-accent-hover:focus,.has-accent-background-color,.comment-reply-link,.edit-comment-link { background-color: #c13030; }.fill-children-accent,.fill-children-accent * { fill: #c13030; }button,.button,.faux-button,.wp-block-button__link,.wp-block-file__button,input[type="button"],input[type="reset"],input[type="submit"],.comment-reply-link,.edit-comment-link { color: #ffe8e8; } { background: #ffe8e8; }body,.entry-title a { color: #000000; }cite,figcaption,.wp-caption-text,.post-meta,.entry-content .wp-block-arc
/*
* Set background for:
* - featured image :before
* - featured image :before
* - post thumbmail :before
* - post thumbmail :before
* - Submenu
* - Sticky Post
* - buttons
* - WP Block Button
@felixarntz
felixarntz / google-site-kit-track-comments.php
Last active November 21, 2019 10:25
WordPress mini plugin as an extension to Site Kit that tracks WordPress comment form submissions via Google Analytics.
<?php
/**
* Site Kit by Google Track Comments plugin file.
*
* @package Google\Site_Kit_Track_Comments
* @author Felix Arntz, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin