Skip to content

Instantly share code, notes, and snippets.

View mikeschinkel's full-sized avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / register-form-benchmark.php
Last active August 29, 2015 13:57
Benchmark for different approaches to registering forms.
<?php
include( __DIR__ . '/wp-load.php' );
const MAXTIMES = 10000;
class WP_Form {
static $forms = array();
var $object_id;
var $form_name;
@mikeschinkel
mikeschinkel / class-object-classifier.php
Last active August 29, 2015 13:57
Proposed WP_Object_Classifier for WordPress #metadata.
<?php
/**
* Class WP_Object_Classifier
*/
final class WP_Object_Classifier {
/**
* @var bool
*/
var $object_type = false;
@mikeschinkel
mikeschinkel / post-meta-api-proposal.md
Created May 14, 2014 04:49
Proposal for interface of Post Meta in the WordPress REST API. - Make comment at: http://wpapiteam.wordpress.com/2014/05/12/handling-post-meta/#comment-435

##Data: { "post_meta": [ { "ID": 33, "key": "my_key", "value": "value1" }, { "ID": 34,

@mikeschinkel
mikeschinkel / object-fail.php
Created June 21, 2015 16:36
PhpStorm incorrect flags class "Object" inside a Namespace with "Expected Object, got Object"
namespace Whatever {
class Object {
/**
* @param Object $object
*/
function foo( $object ) {
}
@mikeschinkel
mikeschinkel / unused-in-foo.php
Last active August 29, 2015 14:23
PhpStorm Inspection Claim Variable is Unused when it is Used
<?php
function get_foo( $state, $method ) {
$value = null;
if ( method_exists( $this, $method ) ) {
/**
* PhpStorm INCORRECTLY identifies $value as NOT being used later.
@mikeschinkel
mikeschinkel / 1-example.php
Last active August 29, 2015 14:24
Examples of implementing helper methods for WPLib as instance methods (vs. static methods)
<?php
if ( WPLib::is_development() ) {
define( 'WP_DEBUG', true );
} else {
define( 'WP_DEBUG', false );
/*
Makes WordPress' PressThis use vimeo short code instead of <object>/<embed> tags.
Add this to the WordPress theme's function.php file.
Addresses the Vimeo question from StackExchange here:
http://webapps.stackexchange.com/questions/3834/customizing-press-this-quick-posting-for-wordpress
*/
add_action('admin_print_footer_scripts','greatjakes_admin_print_footer_scripts');
function greatjakes_admin_print_footer_scripts() {
if ($_SERVER['PHP_SELF']=='/wp-admin/press-this.php') {
$script=<<<SCRIPT
<?php
/*
wp-all-posts-for-any-term-in-a-taxonomy.php
This is an example showing a hook used to add the ability to use "any" as a term to match all terms for a taxonomy.
It will run as a standalone file in the root of a WordPress 3.0 install with a URL that looks like:
http://example.com/wp-all-posts-for-any-term-in-a-taxonomy.php
It was written to address this question:
@mikeschinkel
mikeschinkel / gist:493178
Created July 28, 2010 01:57
Sample SQL file to return menu items for a post in WordPress 3.0
<?php
include "wp-load.php";
$post_id = $_GET['post'];
$menu_id = $_GET['menu'];
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare("SELECT t.term_id as menu_id,
t.name AS menu_name,
<?php
include "wp-load.php";
$post_id = $_GET['post'];
$menu_id = $_GET['menu'];
$term = get_term($menu_id, 'nav_menu');
$menu_items = new WP_Query(