Skip to content

Instantly share code, notes, and snippets.

View georgestephanis's full-sized avatar

George Stephanis georgestephanis

View GitHub Profile
@georgestephanis
georgestephanis / command.xml
Created May 30, 2013 23:09
How to upload a file to a WordPress site via the XML-RPC API. Pretty easy, no? The attachment page if you want a html wrapper to present the file can be found at the following URL: http://yoursite.com/?attachment_id=722 (I left the ID the successful response in as an example)
<?xml version='1.0' encoding='utf-8'?>
<methodCall>
<methodName>wp.uploadFile</methodName>
<params>
<param><value><string>1</string></value></param>
<param><value><string>username</string></value></param>
<param><value><string>password</string></value></param>
<param>
<value>
<struct>
@georgestephanis
georgestephanis / get_all_file_hashes.php
Created July 13, 2015 19:53
A PHP function to recursively get the files and hashes of all files in a given directory and in its subdirectories.
<?php
function get_all_file_hashes( $directory, $relative_to = null ) {
$directory = rtrim( $directory, '/\\' ) . '/';
$relative_to = $relative_to ? $relative_to : $directory;
$preg_quote_relative = preg_quote( $relative_to, '#' );
$files = glob( $directory . '*' );
$return = array();
foreach ( $files as $file ) {
@georgestephanis
georgestephanis / client.js
Last active March 1, 2024 09:12
This is an example client app to integrate with the WordPress 5.6 Application Passwords system. It walks the user through authenticating, and then queries and enumerates all users on the site.
(function($){
const $root = $( '#root' );
const $stage1 = $( '.stage-1', $root );
const $stage2 = $( '.stage-2', $root );
// If there's no GET string, then no credentials have been passed back. Let's get them.
if ( ! window.location.href.includes('?') ) {
// Stage 1: Get the WordPress Site URL, Validate the REST API, and Send to the Authentication Flow
const $urlInput = $( 'input[type=url]', $stage1 );
<?php
/**
* This code's purpose is to ensure that any clones of a
* site hosted on Atomic are run safely so that processes
* meant to happen only on production (emailing customers,
* api calls, cron jobs, etc) are properly removed and that
* Safety Net is appropriately configured.
*/
$cached_ATOMIC_SITE_ID = get_option( 'team51_ATOMIC_SITE_ID' );
@georgestephanis
georgestephanis / fourletters.php
Last active October 23, 2023 10:05
Implementation of Four Letters Word Game from BJ Homer's flash talk at Division Meetup
<?php
define( 'DICT_FILE', '/usr/share/dict/words' );
$allwords = file_get_contents( DICT_FILE );
$qty = preg_match_all( '/^\w{4}$/m', $allwords, $matches );
echo "\r\n\e[32mLoaded \e[37m{$qty}\e[32m four-letter words in from \e[37m" . DICT_FILE . "\e[32m ...\r\n\e[0m";
$fourletter = $matches[0];
@georgestephanis
georgestephanis / slack-afk-automator.php
Created November 21, 2022 16:22
don't forget to add in the bearer token on line 23
<?php
function set_myself_afk() {
$tz = date('I') ? 'EST' : 'EDT';
$expiration = strtotime( "+1 Weekday 9am {$tz}" );
$weekday = array(
'status_text' => 'AFK for the evening.',
'status_emoji' => ':family:',
'status_expiration' => $expiration,
<?php
class WP_Metatags {
private static $tags = array();
public static function set_tag( $handle, $content, $type = 'name' ) {
if ( ! is_array( self::$tags ) ) {
return new WP_Error( 'metatags_already_printed', __( 'The HTML `meta` tags have already been printed.' ) );
}
@georgestephanis
georgestephanis / datasheets.html
Last active April 11, 2023 14:42
An initial attempt at creating a css framework for rendering 40k 10th ed datasheets in credit-card sized references.
<!DOCTYPE html>
<html lang="en">
<head>
<title>40k Datacard Testing</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="datacard">
<header>
<h2>Terminator Squad</h2>
<?php
/**
* Function to sanitize CSS color inputs to ensure we're not using out anything dangerous.
*
* This function can sanitize Named Colors, Hex Colors, RGB, RGBA, HSL, and HSLA.
*
* @param string $color The color to sanitize.
*
* @return string|null Null if it failed sanitization, the printable string if it passed.
*/
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE muclient>
<muclient>
<plugin name="LotJ_Race_Exporter" author="@Daljo" id="d75f227c34fe0f9af2f20f66" language="Lua" purpose="Export race data." requires="4.73" version="0.1" save_state="y">
<description trim="y">
<![CDATA[
-- Race Scraper / Exporter --
]]>