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
@ryelle
ryelle / remove-colors.js
Created April 22, 2020 23:03
PostCSS plugin to remove colors from a CSS file
const postcss = require( 'postcss' );
const getColors = require( 'get-css-colors' );
/* A size is any number, optionally with a unit. */
const isSize = ( value ) => /^\d+\s?([a-zA-Z]+)?$/.test( value.trim() );
/* If the value has a color in it, getColors will return an array. */
const isColor = ( value ) => null !== getColors( value );
/* A line style is from a set of values */
<?php
/**
* AMP Validation Error Logger plugin initialization file.
*
* @package AMP_Validation_Error_Logger
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin
@westonruter
westonruter / gist-wp-plugin-installation.md
Last active June 30, 2023 03:43
How to install a WordPress plugin from a Gist
@greatislander
greatislander / theme-testing.md
Last active December 14, 2018 15:30
Theme Testing
  • Proof of concept E2E testing using Jest + aXe (branch)
  • Proof of concept E2E testing using Jest + aXe in Docker (branch)
  • Create NPM package of test requirements
  • Improve formatting of reports from Jest + aXe
  • Different test commands for audit and pass/fail
  • Enable scaffolding basic E2E tests for themes (issue)
  • Enable running E2E tests locally via CLI (environment-agnostic)
  • Enable E2E tests for themes in CI (using Docker with sample content)
@westonruter
westonruter / list-document-images.js
Last active August 7, 2018 09:55
Prior to Performance Timeline API getting list of all images in document would require looking at document.images and inspectomg stylesheets to find any referenced background-images; but now with the Performance Timeline API it's easy to get a list of all images (assuming they have image filename extensions)
function getDocumentImages() {
return performance.getEntriesByType('resource')
.map( ( entry ) => entry.name )
.filter( ( url ) => {
const parsedUrl = new URL( url );
return /\.(png|jpe?g|gif|webp|svg)$/i.test( parsedUrl.pathname );
} );
}
@omarreiss
omarreiss / wpjs.md
Last active February 20, 2018 13:59

Setting up your development environment

[better title needed]

[insert table of contents]

System requirements

Node.js and npm

WordPress uses a JavaScript task runner called Grunt to build its files. It requires the most recent LTS version of the Node.js runtime. It also requires dependencies fetched via npm. npm is packaged with Node.js, so if your computer has Node.js installed you are ready to go.

@JayWood
JayWood / wpcli-posts-generator.php
Created May 6, 2016 14:14
A robust random posts generator with support for multisite, taxonomies, term counts, post counts, post types, featured images, featured image types, and more.
<?php
if ( defined( 'WP_CLI' ) && WP_CLI ) {
class JW_Random_Posts extends WP_CLI_Command {
private $args, $assoc_args;
/**
* Generates a Random set of posts
*
@danielbachhuber
danielbachhuber / disable-logged-out-users.php
Last active September 11, 2023 21:52
Disable WP REST API requests for logged out users
<?php
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'restx_logged_out', 'Sorry, you must be logged in to make a request.', array( 'status' => 401 ) );
}
return $result;
#!/bin/bash
REV=$1
svn up --ignore-externals . > /dev/null
svn merge -c$REV ../../trunk .
LOG=$(svn log -r$REV ../../trunk | grep -v '\-------' | tail -n +3)
BRANCH=$(basename $(pwd))
echo -en "$LOG\n\nMerges [$REV] to the $BRANCH branch." | pbcopy
echo ""
pbpaste