Skip to content

Instantly share code, notes, and snippets.

@iandunn
iandunn / IDDescribeVar
Created April 22, 2014 04:33
This was in a repo, but moving to a Gist and deleting the repo because it's no longer useful.
<?php
/*
* Outputs the type, length and contents of a variable in a readable format, which can be useful for debugging.
* Output can be sent to echo(), die() / wp_die(), returned, a WordPress transient or a WordPress admin notice
* (via the IDAdminNotice class, not included). There are extra output methods for use in a WordPress environment,
* but it will also work on it's own.
*/
/*
@iandunn
iandunn / activate-camptix-core-module
Created May 30, 2014 21:46
Activate CampTix core module
<?php
// In an mu-plugin...
function activate_default_camptix_module( $modules ) {
global $camptix;
$modules[] = $camptix->get_default_addon_path( 'require-login.php' );
return $modules;
}
@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

@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 / 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' ) );
@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;
/*
* 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 / 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(