Skip to content

Instantly share code, notes, and snippets.

View mikeschinkel's full-sized avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / wp-config.php
Last active February 19, 2019 03:30
Update candidate for wp-config.php in WPLib Box per https://github.com/wplib/wplib-box/issues/579
<?php
if ( getcwd()=='/var/www' && isset( $_SERVER[ 'HTTP_HOST' ] ) ) {
$hostname = $_SERVER[ 'HTTP_HOST' ];
} else if ( is_file( __DIR__ . '/../HOSTNAME' ) ) {
$hostname = file_get_contents( __DIR__ . '/../HOSTNAME' );
} else {
$hostname = 'wplib.box';
}
@mikeschinkel
mikeschinkel / _about.md
Last active January 9, 2019 18:20
PHP module for use in WordPress to display Bibblio v3.9 related posts element.

The code in feature-bibblio-related-posts.php does not work and I think there is a bug in Bibblio's JS file.

prepareModuleOptions() calls getCustomUniqueIdentifierFromUrl() but does not pass it the options argument.

Note: feature-bibblio-related-posts.php is using a very thin framework called RPLib that I wrote. It auto-loads "modules" where different type modules have different traits available.

@mikeschinkel
mikeschinkel / reading-time.php
Last active November 9, 2018 09:06
Number of seconds to read an image, per Medium's algorithm: https://blog.medium.com/read-time-and-you-bc2048ab620c
<?php
function image_reading_seconds( $count ) {
// Every image start with 3 seconds
$reading_seconds = $count * 3;
// The first 9 images also add the cumulative
// amount of seconds calculated by 10 seconds
// minus the image count for each image.
$reading_seconds += 9 >= $count
@mikeschinkel
mikeschinkel / forms_model.php
Created October 27, 2018 20:00
Proposal for GravityForms to add a 'gform_custom_field_name_clauses' filter.
<?php
class GFFormsModel {
public static function get_custom_field_names() {
global $wpdb;
$clauses = apply_filters( 'gform_custom_field_name_clauses', array(
'found_rows' => '',
'distinct' => 'DISTINCT',
'fields' => 'meta_key',
@mikeschinkel
mikeschinkel / fix-gravity-forms.php
Created October 27, 2018 19:46
Fix GravityForms GFFormsModel::get_custom_field_names() for large numbers of posts and post meta by limiting to post_type='page'
<?php
/**
* Class Fix_Gravity_Forms
*/
class Fix_Gravity_Forms {
const POST_TYPE = 'page';
const SQL_MARKER = "WHERE meta_key NOT BETWEEN '_' AND '_z'";
@mikeschinkel
mikeschinkel / pimple-example.php
Created October 18, 2018 19:05
The Problems with Pimple - What's wrong with this picture?
<?php
$container = new Pimple();
$container['auth'] = function($c) {
return new OAuth();
};
$container['db'] = function($c) {
return new DB();
};
$container['tweet_service'] = function($c) {
$twService = new TwitterService();
@mikeschinkel
mikeschinkel / args-example.php
Created October 17, 2018 15:53
Example passing optional $args
<?php
/**
* @param array $args
*
* @return string
*/
function get_banner_image_html( $size = 'medium', $args = array() ){
$args = array_merge( array(
'before' => '<figure class="show__banner-image">',
'after' => '</figure>',
@mikeschinkel
mikeschinkel / Example\Query.php
Last active October 18, 2018 23:16
Rough First Draft of Proposal for DI Container built into PHP
<?php
namespace Example
class Query {
/**
* @var string
*/
public $name;
@mikeschinkel
mikeschinkel / alt-generics.md
Created September 29, 2018 23:32
An Alternate to Generics in GoLang

An Alternate to Generics in GoLang

@mikeschinkel
mikeschinkel / IntOrString.class.php
Last active September 28, 2018 01:04
Potential Union Types in PHP
<?php
class intOrString {
public $value;
function __construct( $value ) {
$this->value = $value;
}
function toInt(): int {