Skip to content

Instantly share code, notes, and snippets.

@iandunn
iandunn / programmatic_login.php
Last active March 7, 2023 18:18
Programmatically log in a WordPress user
/**
* Programmatically logs a user in
*
* @param string $username
* @return bool True if the login was successful; false if it wasn't
*/
function programmatic_login( $username ) {
if ( is_user_logged_in() ) {
wp_logout();
@iandunn
iandunn / web-crypto-password-generator.js
Last active January 18, 2023 16:23
Cryptographically secure random password using `crypto.getRandomValues`
// ⚠️ I have not verified that this is secure; I just cleaned it up to try it out.
// Use at your own risk. I ended up using https://www.npmjs.com/package/@automattic/generate-password instead.
/**
* Generate a cryptographically secure random password in the browser.
*
* This is a modified version of https://stackoverflow.com/a/43020177/450127 that aims to
* to improve readability, and increase the length and character pool. The results should be
* the same as the original.
@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 / qtmono.sh
Created June 5, 2017 02:07
Alias to convert a stereo recording to mono
# Alias to convert a stereo recording to mono
#
# $1 - The input filename
function qtmono {
basename=$(basename "$1")
filename="${basename%.*}"
extension="${basename##*.}"
ffmpeg -i $1 -codec:v copy -af pan="mono: c0=FL" $filename-mono.$extension
}
@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 / phpmailer-send-via-mail.php
Created August 17, 2016 19:26
Disable PHPMailer sending via SMTP, so that MailCatcher can catch outbound messages from dev environments
/**
* Configure PHPMailer to send via PHP's mail()
*
* @param PHPMailer $phpmailer
*/
function phpmailer_send_via_mail( $phpmailer ) {
$phpmailer->IsMail();
}
add_action( 'phpmailer_init', 'phpmailer_send_via_mail', 999 );
@iandunn
iandunn / test-nearby-events.php
Last active May 11, 2017 18:09
mu-plugin to test nearby events
<?php
// type "error" into the city name field to simulate an HTTP request error
function nearbywp_trigger_error( $request, $request_args, $request_url ) {
$url_params = explode( '&', parse_url( $request_url, PHP_URL_QUERY ) );
if ( in_array( 'location=error', $url_params ) ) {
$request = new WP_Error( 'test', 'testing error condition' );
}
@iandunn
iandunn / nearby-events.diff
Last active May 9, 2017 16:08
nearby events merge patch
moved to https://core.trac.wordpress.org/ticket/40702
@iandunn
iandunn / remove-red-notification-dot-from-trello-favicon.js
Last active January 20, 2017 18:42
Remove Red Notification Dot from Trello Favicon
// ==UserScript==
// @name Remove Red Notification Dot From Trello Favicon
// @namespace https://iandunn.name
// @version 0.1
// @description Trello adds a red dot to their favicon when new notifications are available, which I find useless and distracting. This restores the original icon after a few seconds, so that you normally see the favicon without the dot.
// @author Ian Dunn
// @match https://trello.com/*
// @grant none
// ==/UserScript==