Skip to content

Instantly share code, notes, and snippets.

View JasonTheAdams's full-sized avatar

Jason Adams JasonTheAdams

View GitHub Profile
@JasonTheAdams
JasonTheAdams / piklist-relationships-to-metabox.sql
Created December 17, 2021 22:22
Migrates post relationships from Piklist to MetaBox
set @row_num:=0;
INSERT INTO wp_mb_relationships
(
`to`,
`type`,
`order_from`,
`order_to`,
`from`
)
@JasonTheAdams
JasonTheAdams / DynamicProperties.php
Last active November 15, 2021 19:02
A backwards-compatible trait for deprecated dynamic properties in 8.2
<?php
/**
* This is a very simple and basic trait for overcoming the deprectation of dynamic properties in 8.2, and broken in 9.0.
*
* If using a 8.2 or later, use the #[AllowDynamicProperties] attribute instead of this.
*
* I suggest this is better than traditional dynamic properties for the simple fact that it's excplicit and therefore
* intentional. If your class already has magic methods then you don't need this. This will work in 8.2 or later and as far
* back as 5.4, so it should cover most sensible cases.
@JasonTheAdams
JasonTheAdams / ChairFactory.php
Last active September 13, 2019 17:34
Example of the Abstract Factory Design Pattern
<?php
class ChairFactory
{
public function createChair(bool $cheap, bool $fancy): ChairInterface
{
if ($cheap && $fancy) {
return new ModernChair();
} elseif ($fancy) {
return new VictorianRockingChair();
@JasonTheAdams
JasonTheAdams / PostStatus.php
Last active October 10, 2019 17:23
Enumeration example of the Object Value Design Pattern
<?php
class PostStatus
{
const PRIVATE = 'private';
const DRAFT = 'draft';
const PUBLISHED = 'published';
const TRASHED = 'trash';
/**
@JasonTheAdams
JasonTheAdams / Temperature.php
Last active September 26, 2019 18:02
Example of the Value Object Design Pattern
<?php
class Temperature
{
const KELVIN = 'kelvin';
const FAHRENHEIT = 'fahrenheit';
const CELSIUS = 'celsius';
private $unit;
private $value;