Skip to content

Instantly share code, notes, and snippets.

Mike Schinkel mikeschinkel

Block or report user

Report or block mikeschinkel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mikeschinkel
mikeschinkel / _readme.md
Last active Nov 19, 2019
Examples for how a __toArray() magic method could be useful in PHP.
View _readme.md

Examples for how a __toArray() magic method could be useful in PHP.

In a nutshell, __toArray() would not be as useful when you have full control over the entire codebase.

But where __toArray() would be extremely useful is in interfacing with existing code that expects arrays and wants those arrays to be a specific format. Using classes and type-hinted methods allow to encapsulate the intelligence into the class, and using __toArray() makes for a nature use-case.

View instrument-hooks.php
<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/
if (isset($_GET['instrument']) && $_GET['instrument']=='hooks') {
@mikeschinkel
mikeschinkel / proposal-for-union-class-types-in-php.md
Last active Sep 17, 2019
Proposal for Union Class Types in PHP
View proposal-for-union-class-types-in-php.md
View functions.php
<?php
/*
Description: Adds a taxonomy filter in the admin list page for a custom post type.
Written for: http://wordpress.stackexchange.com/posts/582/
By: Mike Schinkel - http://mikeschinkel.com/custom-workpress-plugins
Instructions: Put this code in your theme's functions.php file or inside your own plugin. Edit to suite your post types and taxonomies. Hope this helps...
*/
add_filter('manage_listing_posts_columns', 'add_businesses_column_to_listing_list');
function add_businesses_column_to_listing_list( $posts_columns ) {
if (!isset($posts_columns['author'])) {
@mikeschinkel
mikeschinkel / _readme.md
Last active Sep 1, 2019
Typical example of header.php code use in WordPress templates.
View _readme.md

This is in reference to: https://twitter.com/ramsey/status/1167954877814730755

The following header.php file comes directly from a client site, developed by someone else, with all identifying and account information replaced.

Any of the <?php tags could hypothetically be replaced by a tag that would indicate a different set of rules for only that segment of code, e.g. <?p8 could be introduced to support all the strictness that the advocates of strictness desire. This would give them the strictness where they want it and let everyone else continue to stick with <?php for use in PHP 8.

@mikeschinkel
mikeschinkel / test-get-comment-replies.php
Created Sep 23, 2010
get_comment_replies() function for WordPress with a working example that returns a WordPress comment object for a given comment ID annotated with "reply_count" and "replies" properties.
View test-get-comment-replies.php
<?php
/*
* test-get-comment-replies.php
*
* Returns a comment object for a given comment ID annotated with "reply_count" and "replies" properties:
*
* reply_count: count of all replies including sum of child replies.
* replies: array of child comment objects also annotated with "reply_count" and "replies" properties, recursively.
*
* Examples:
@mikeschinkel
mikeschinkel / create-funcs.txt.sh
Last active Jul 29, 2019
List of funcs in GoLang 1.12.6 SDK w/over declarations over 100 characters long
View create-funcs.txt.sh
# This is how I created funcs.txt
# I also manually edited out anything that was not a func declaration
find /usr/local/opt/go/libexec/src/. | grep "\.go" | grep -v syscall | xargs awk '{print length, $0}' |grep func |grep -v "="|grep -v "//" |sort -nr | head -1000 > funcs.txt
@mikeschinkel
mikeschinkel / index.php
Created Jul 21, 2019
Example PHP showing how to "return" a value from a require()
View index.php
<?php
$version = require(__DIR__.'/version.php');
echo "The current version is {$version}";
View gist:503778
<?php
/*
* Example code showing how to hook WordPress to add fields to the taxonomny term edit screen.
*
* This example is meant to show how, not to be a drop in example.
*
* This example was written in response to this question:
*
* http://lists.automattic.com/pipermail/wp-hackers/2010-August/033671.html
*
@mikeschinkel
mikeschinkel / .readme.txt
Last active May 8, 2019
Proof-of-concept example of Swift using The Break/Continue Guard Clause pattern
View .readme.txt
Here is an example of using what I am currently calling the Break/Continue Guard Clause pattern.
See:
1. https://mikeschinkel.me/2019/better-alternative-to-return-early-php-wordpress/
2. https://thatthinginswift.com/guard-statement-swift/
You can’t perform that action at this time.