Skip to content

Instantly share code, notes, and snippets.

View adamsilverstein's full-sized avatar
💭
Working remotely, as usual

Adam Silverstein adamsilverstein

💭
Working remotely, as usual
View GitHub Profile
build.sh (gitlab)
sed -i "s/COMMITHASH/$CI_COMMIT_SHORT_SHA/g" functions.php
functions.php
define( 'MS_RESEARCH_ASSET_VERSION', 'COMMITHASH' );
@adamsilverstein
adamsilverstein / action-on-save.js
Last active February 10, 2020 00:14
Gutenberg: Trigger action after save
import { select, subscribe } from '@wordpress/data';
const { isSavingPost } = select( 'core/editor' );
var checked = true; // Start in a checked state.
subscribe( () => {
if ( isSavingPost() ) {
// When all changes are saved, check again.
checked = false;
} else {
if ( ! checked ) {
@adamsilverstein
adamsilverstein / action-after-autosave.js
Last active February 10, 2020 00:18
Trigger after autosave completes.
import { select, subscribe } from '@wordpress/data';
const { isAutosavingPost } = select( 'core/editor' );
var checked = true; // Start in a checked state.
subscribe( () => {
if ( isAutosavingPost() ) {
// When all changes are saved, check again.
checked = false;
} else {
if ( ! checked ) {
@adamsilverstein
adamsilverstein / live-reload.php
Last active April 14, 2020 04:42
Livereload WordPress Plugin
<?php
/**
* Live Reload mini-plugin.
*
* @package wordpress
* @author Adam Silverstein, Google
* @link
* @license GPL-2.0-or-later
* @copyright 2020 Google Inc.
*
@adamsilverstein
adamsilverstein / site-kit-debugging.php
Created June 1, 2020 14:49
Mini plugin to enable Enable App logging in Site Kit
<?php
/**
* Add debugging information for Google Site Kit.
*
* @package Google\Site_Kit
* @copyright 2020 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*
* @wordpress-plugin
"modules::analytics:report::1cc2cfc3218eab9aa0d167f96fe944ea": [{
"nextPageToken": null,
"columnHeader": {
"dimensions": ["ga:channelGrouping"],
"metricHeader": {
"metricHeaderEntries": [{
"name": "Sessions",
"type": "INTEGER"
}, {
"name": "Users",
@adamsilverstein
adamsilverstein / analytics-step-mode.php
Last active July 29, 2020 20:54
Enabling Analytics Step Mode
<?php
/**
* Enable the 'analytics-step' setup mode.
*
* @copyright 2020 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*
* @wordpress-plugin
* Plugin Name: Analytics Step Setup
@adamsilverstein
adamsilverstein / web-vitals.php
Last active August 28, 2020 21:55
Measure Web Vitals in Analytics
<?php
/**
* Measure Web Vitals in Analytics
*
* @copyright 2020 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*
* @wordpress-plugin
* Plugin Name: Measure Vitals
* Description: Measure Web Vitals in Analytics
// Created by Adam Silverstein, based on original work by Rick Viscomi (@rick_viscomi)
// Adapted from https://ithoughthecamewithyou.com/post/automate-google-pagespeed-insights-with-apps-script by Robert Ellison
// @copyright 2020 Google LLC
var scriptProperties = PropertiesService.getScriptProperties();
var pageSpeedApiKey = scriptProperties.getProperty('PSI_API_KEY');
function queueAllDomains() { {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('Alerts');