Skip to content

Instantly share code, notes, and snippets.

@iandunn
iandunn / log-wp-rest-api-errors.php
Last active February 27, 2019 22:41
Log WordPress REST API errors
<?php
/**
* Log REST API errors
*
* @param WP_REST_Response $result Result that will be sent to the client.
* @param WP_REST_Server $server The API server instance.
* @param WP_REST_Request $request The request used to generate the response.
*/
function log_rest_api_errors( $result, $server, $request ) {
@iandunn
iandunn / reveal-clicker-compatibility.js
Created September 12, 2015 03:58
Make Reveal.js compatible with clickers that only have up/down buttons. See https://github.com/hakimel/reveal.js/issues/288
/**
* Treat up/down as page-up, page-down, so that clicker will step through each slide instead of only up/down slides
*/
document.addEventListener( 'keydown', function( event ) {
switch ( event.keyCode ) {
// k, up
case 75:
case 38:
Reveal.navigatePrev();
break;
@iandunn
iandunn / gist:606e8636b14794ab8048
Last active August 29, 2015 14:11
WordCamp.org inline SVGs
<?php
/*
* Allow a whitelisted set of inline SVGs via a shortcode.
*
* SVGs ARE NOT IMAGES, they're mini XML applications which can run JavaScript and embed arbitrary
* resources across domain boundaries. There are a lot of attack vectors, and they're not well
* understood yet. A lot of caution needs to be taken when allowing SVGs, so for now we're only
* whitelisting a handful of them when needed.
*
@iandunn
iandunn / gist:0c87245dca5c7ed48988
Last active August 29, 2015 14:11
WordPress.org Contributor Stat Snippets

All of these track the stats during a given year, so that they can be compared to stat collected during previous years.

Percent of code that is open source

Check out all the repositories into public and private folders inside a temp directory on your sandbox. Use your sandbox because some of the private repos contain passwords that you don't want on your laptop's hard drive.

Look at Slack_Trac::$tracs in api.wordpress.org for a list of Trac instances. Also look at https://github.com/wordpress in case there's anything there.

find -regex ".*\.\(php\|html\|js\|css\)" |xargs wc -l

/*
* This is old and doesn't always work correctly, see the following post for a better way:
*
* https://iandunn.name/flushing-rewrite-rules-on-all-sites-in-a-multisite-network/
*/
function flush_rewrite_rules_everywhere() {
global $wp_rewrite;
$sites = wp_get_sites( array( 'limit' => false ) );
@iandunn
iandunn / camptix-gravatar-badges.php
Last active August 5, 2022 14:26
CampTix Attendee Badges with Gravatars
<?php
/*
* Generate a CSV for InDesign with attendee info and Gravatars
*
* See http://plan.wordcamp.org/helpful-documents-and-templates/create-wordcamp-badges-with-gravatars/ for instructions
*
* input is a CSV export of CampTix attendees. Format is: "First Name","Last Name","E-mail Address","Twitter Username"
* the script downloads the attendee's Gravatars, and adds a column to the CSV with the filename of the image
* the CSV can then be used by InDesign to generate wordcamp badges with the attendee's gravatar
@iandunn
iandunn / supportflow-faster-cron.php
Created August 12, 2014 15:49
Make SupportFlow check for new messages every 30 seconds
/*
* Setup fast cron schedule for SupportFlow trial
*/
function sf_cron_schedules( $schedules ) {
$schedules['30-seconds'] = array(
'interval' => 30,
'display' => 'Once every 30 seconds',
);
return $schedules;
@iandunn
iandunn / wordcamp-payments.php
Last active November 7, 2015 21:33
WordCamp Payments prototype
<?php
/*
Plugin Name: CampPayments
Plugin URI: http://wordcamp.org/
Description: WordCamp payments stuff
Author: tellyworth, ...
Version: 0.0
*/
class CampPayments {
@iandunn
iandunn / reuse-wcorg-login-message.php
Created July 22, 2014 01:13
Example of reusing wcorg_login_message() in other contexts
function camptix_require_login_please_login_message( $message ) {
/** @var $camptix CampTix_Plugin */
global $camptix;
$please_login_message = sprintf(
__( 'Before purchasing your tickets, please <a href="%s">log in to your WordPress.org account</a>*.', 'wordcamporg' ),
wp_login_url( $camptix->get_tickets_url() )
);
$message = str_replace(
@iandunn
iandunn / global-login-endpoint.php
Created July 14, 2014 22:43
WordPress Global Login Endpoint
<?php
/**
* Plugin Name: Global Login Endpoint
* Plugin Description: Allows users to only log in on the root site, and not any of the other sites in the network.
*/
class Global_Login_Endpoint_Plugin {
function __construct() {
add_action( 'login_form_login', array( $this, 'login_form_login' ) );