Skip to content

Instantly share code, notes, and snippets.


Mike Schinkel mikeschinkel

View GitHub Profile
mikeschinkel / example.php
Last active Jul 27, 2021
How we might be able to move to using parameterized queries in WordPress core
View example.php
// Put this in wp-config.php
// A site builder who wants to use prepared statements and parameterized queries
// could run these in various hooks before $wpdb->query() below is run.
$question_fragment = $wpdb->prepare( '`question_id` = %d', $question_id );
$answer_fragment = $wpdb->prepare( '`answer_name` = %s', $new_answer );
$wpdb->compose('UPDATE %s polls SET vote = vote+1 WHERE %s AND %s',
mikeschinkel / make_literal.php
Created Jun 26, 2021
A make_literal() function to get around functions that use is_literal() over-zealously
View make_literal.php
$safe_var = 'all your base they belong to us';
file_put_contents('/tmp/exploit.txt',$safe_var );
// imagine lots of stuff going on here...
$safe_var = file_get_contents('/tmp/exploit.txt');
function make_literal(string $non_literal):string {
$literal = '';
mikeschinkel / try-break.php
Last active Mar 30, 2021
Illustrating the try-break pattern in action for PHP 8.x — hopefully to see PHP > 8.0 allow replacing `do{...}while(false};` with a naked `try{}`
View try-break.php
* This shows our try-break example in action.
function main() {
do {
$result = example(0,"hello");
if ($result->is_error() ) {
mikeschinkel / _main.php
Last active Mar 16, 2021
Strawman psuedo-code for set of potential autoloader related classes for PHP core for proposing to internals
View _main.php
use PHP\Autoload;
use PHP\ClassmapLoader;
use PHP\CallableLoader;
Autoload::set_loader(new ClassmapLoader([
"Foo" => "path/to/Foo.php",
"Bar" => "another/path/to/Bar.php",
"Baz" => "yet/another/path/to/Baz.php",
mikeschinkel / go.mod
Last active Feb 25, 2021
Simple GoLang App to demonstrate Mountebank's inability to support HTTP CONNECT method.
View go.mod
module proxy-client
go 1.15
require ( v17.0.0+incompatible v1.0.0 // indirect v0.0.0-20210220000619-9bb904979d93
mikeschinkel / 1.attributes-with-use.php
Last active Aug 18, 2020
Hypothetical example of using use statement for attributes
View 1.attributes-with-use.php
namespace MyNamespace;
// namespace use
use WpAttributes\PrimaryKey;
use WpAttributes\PostType;
use WpAttributes\TemplateVariable;
use PHP\VirtualReadonly;
mikeschinkel /
Last active May 17, 2020
Refactoring Pantheon_Sessions::initialize_session_override() using do{...}while(false);

Example use of do {...} while(false)

See this gist for background.

This example comes from my work here when looking for a solution for this issue related to this WordPress plugin.

I recognized I could make it clearer using the do {...} while(false) pattern so I wanted to document here.


mikeschinkel / Apis.php
Last active May 14, 2020
PHP Examples that could benefit from Try...Break (method excerpts from real production code)
View Apis.php
class Apis {
static function JsonGET( string $api_url, array $args = array() ) {
do {
$wp_error = null;
$args = wp_parse_args( $args, array(
'response_type' => ARRAY_A,
) );
mikeschinkel / form1.php
Last active May 6, 2020
Examples showing a huge array literal vs. many small array literals
View form1.php
class MembershipForm {
static function form() {
return array(
'type' => 'textfield',
'heading' => __( 'License Type ID' ),
'param_name' => 'license_type',
'description' => esc_attr__( 'Enter License Type ID', 'wds-vc-elements' ),
mikeschinkel /
Created Mar 16, 2020 from WordPress where decodeMPEGaudioHeader() is partially refactored from over 600 lines to ~200 lines.
/// getID3() by James Heinrich <> //
// available at //
// or //
// or //
// see readme.txt for more details //
// //