Skip to content

Instantly share code, notes, and snippets.

Avatar

Felix Arntz felixarntz

View GitHub Profile
@felixarntz
felixarntz / perflab-server-timing-examples.php
Last active Nov 24, 2022
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.
View perflab-server-timing-examples.php
<?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 Oct 31, 2022
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)!
View perflab-server-timing-examples.php
<?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 Jul 16, 2021
Prototype plugin used for lazy-load LCP analysis in WordPress
View wp-lazyload-lcp-fix.php
<?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
View fix-site-kit-canonical-home-url-multilingual.php
<?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 Mar 16, 2021
Example of using the Site Kit Widgets API
View custom-analytics-widget.js
const { useSelect } = window.googlesitekit.data;
const {
registerWidget,
WIDGET_WIDTHS,
} = window.googlesitekit.widgets;
function CustomAnalyticsWidget( props ) {
const {
Widget,
WidgetNull,
View site-kit-fix-opcache-call-temporary.php
<?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 Jan 21, 2020
Clears PHP OpCache when visiting the Plugins admin screen (wp-admin/plugins.php).
View clear-opcache-simple.php
<?php
/**
* Clear OpCache Simple.
*
* @author Felix Arntz, Google
* @license Apache 2.0
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Clear OpCache Simple
View twentytwenty-customizer-style.css
.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
View twentynineteen-customizer-style.css
/*
* 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 Nov 21, 2019
WordPress mini plugin as an extension to Site Kit that tracks WordPress comment form submissions via Google Analytics.
View google-site-kit-track-comments.php
<?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