Skip to content

Instantly share code, notes, and snippets.

@richaber
richaber / README.md
Created January 27, 2023 17:24
Connect PhpStorm to Local “Lightning” MySQL database via TCP/IP

PhpStorm does not support connecting to MySQL via socket.

To connect via TCP/IP instead, you will need to allow the DB_USER to connect to MySQL over TCP/IP, for each site that you want to connect to.

You will need the DB_USER, DB_PASSWORD, and DB_NAME values from you WP-Config, for each site you want to connect to.

Right-click on a site you want to connect to in Local’s sidebar and choose “Open Site Shell.”

In the resulting terminal, run the following commands
Be sure to replace DB_USER and DB_PASSWORD in these commands with their values from WP-Config!:

@richaber
richaber / post-format-counts.md
Created January 23, 2023 17:03
Get count of posts for "non-standard" post formats in MySQL
mysql> SELECT 
    ->     t1.slug, t2.count
    -> FROM
    ->     local.wp_terms AS t1
    ->         INNER JOIN
    ->     local.wp_term_taxonomy AS t2 ON t1.term_id = t2.term_id
    -> WHERE
    ->     t2.taxonomy = 'post_format';
+---------------------+-------+
@richaber
richaber / keybase.md
Created November 20, 2022 17:15
keybase.md

Keybase proof

I hereby claim:

  • I am richaber on github.
  • I am richaber (https://keybase.io/richaber) on keybase.
  • I have a public key ASAVg9Gp2ucOvyUIWlNkZEDYZMSmqkUob5tT2uoqf1dZ4wo

To claim this, I am signing this object:

@richaber
richaber / SelectOptions.js
Created November 9, 2022 16:30
components/SelectOptions.js
/**
* SelectOptions is a child Component
* for use with WordPress' SelectControl Component
* to easily implement Optgroups.
* See the {@link Option} and {@link Optgroup} typedefs for the expected data shape(s).
*
* SelectControl doesn't appear to natively support an optgroup data shape
* (as of @wordpress/components v 22.0.0 anyway),
* and the SelectControl documentation
* only provides a lone optgroup example using hardcoded markup.
@richaber
richaber / AspectRatioUtility.php
Created September 15, 2022 21:34
PHP Aspect Ratio Utility
<?php
namespace App\Utility;
class AspectRatioUtility
{
/**
* Get the aspect ratio.
*
* @param int $width The width.
@richaber
richaber / get_row-wpdb_posts.md
Created July 8, 2022 19:48
WPDB, get_row for a post with the given post_title of the given post_type (uncached, just for analysis)
global $wpdb;

$query = "
SELECT *
FROM   $wpdb->posts
WHERE  $wpdb->posts.post_title=%s
AND    $wpdb->posts.post_type=%s
LIMIT  1
@richaber
richaber / tribe_get_venue_object.md
Created June 28, 2022 16:50
tribe_get_venue_object() example var dump
@richaber
richaber / wp_upload_dir.md
Created June 27, 2022 15:23
wp_upload_dir() example var dump
@richaber
richaber / wp_get_registered_image_subsizes.md
Created June 27, 2022 15:18
wp_get_registered_image_subsizes() example var dump
@richaber
richaber / SideLoad.php
Created June 23, 2022 17:06
WP-CLI Sideload media command class, should work for images that don't have a file extension via Symfony\Component\Mime\MimeTypes
<?php
/**
* SideLoad command class file.
*
* @package VendorName\ProjectName\Commands
*/
namespace VendorName\ProjectName\Commands;
use Symfony\Component\Mime\MimeTypes;