Skip to content

Instantly share code, notes, and snippets.

View mikeschinkel's full-sized avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / post-type--not-in.php
Last active February 12, 2022 07:12
Post_Type__Not_In class to add a 'post_type__not_in' parameter to WP_Query.
<?php
/**
* This class will cause WP_Query to ignore a 'post_type' parameter when 'post_type__not_in' is set.
*
* Class Post_Type__Not_In
*/
class Post_Type__Not_In {
/**
*
@mikeschinkel
mikeschinkel / benchmark_slice_aggregation.go
Last active February 3, 2022 23:00
GoLang benchmark for aggregating of multiple slice elements into a single slice
package test
//
// Initial source for benchmark from https://stackoverflow.com/a/40678026/102699
// Added BenchmarkConcatAppendPreAllocate()
//
import "testing"
func BenchmarkConcatCopyPreAllocate(b *testing.B) {
for n := 0; n < b.N; n++ {
B = concatCopyPreAllocate(slices)
@mikeschinkel
mikeschinkel / hide-taxonomy-in-admin-menu.php
Created November 27, 2010 06:24
Hide a Taxonomy in the WordPress Admin Menu
<?php
/*
See http://lists.automattic.com/pipermail/wp-hackers/2010-November/036174.html
Also: http://mikeschinkel.com/websnaps/skitched-20101127-012515.png
Author: Mike Schinkel
*/
add_action('admin_menu','yoursite_admin_menu');
function yoursite_admin_menu() {
global $submenu;
Function GrantLogonAsAService([string]$Username) {
Write-Host "Grant Logon-as-a-Service for $Username"
$SecurityId = $null
try {
$Principal = new-object System.Security.Principal.NTAccount $Username
$SecurityId = $Principal.Translate([System.Security.Principal.SecurityIdentifier]).Value.ToString()
} catch {
Write-Host "Attempt to access SecurityID failed."
$SecurityId = $null
<?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 / Type.php
Created October 5, 2021 17:28
A reimagining of Sebastian Bergmann's Type.php if PHP had a "function list" declaration.
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
@mikeschinkel
mikeschinkel / functions.php
Created February 3, 2012 07:43
Master WordPress Custom Post Types - WordCamp Atlanta 2012
<?php
/*
* Code Examples for Master WordPress Custom Post Types - WordCamp Atlanta 2012
*
* Author: Mike Schinkel
* Author URI: http://about.me/mikeschinkel
*
*/
add_action( 'init', 'mikes_theme_init' );
function mikes_theme_init() {
@mikeschinkel
mikeschinkel / example.php
Last active July 27, 2021 12:52
How we might be able to move to using parameterized queries in WordPress core
<?php
// Put this in wp-config.php
define('PREPARED_SQL_REQUIRED',true);
// 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
mikeschinkel / make_literal.php
Created June 26, 2021 12:55
A make_literal() function to get around functions that use is_literal() over-zealously
<?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
mikeschinkel / class-custom-hooks.php
Last active June 17, 2021 04:42
Classes providing "hooks" (actions and filters) that work with WordPress or free-standing PHP-based apps.
<?php
class Custom_Hooks {
/**
* Adds a filter hook for an object
*
* Custom_Hooks::add_filter( 'filter_data', array( $this, 'filter_data' ) );
* Custom_Hooks::add_filter( 'filter_data', array( $this, 'filter_data' ), 11 );
* Custom_Hooks::add_filter( 'filter_data', 'special_func' );
* Custom_Hooks::add_filter( 'filter_data', 'special_func', 11 );