Skip to content

Instantly share code, notes, and snippets.

View petenelson's full-sized avatar

Pete Nelson petenelson

View GitHub Profile
@petenelson
petenelson / raw-rewite-rules.txt
Created December 10, 2019 16:07
WordPress Default rewrite_rules option value
a:89:{s:11:"^wp-json/?$";s:22:"index.php?rest_route=/";s:14:"^wp-json/(.*)?";s:33:"index.php?rest_route=/$matches[1]";s:21:"^index.php/wp-json/?$";s:22:"index.php?rest_route=/";s:24:"^index.php/wp-json/(.*)?";s:33:"index.php?rest_route=/$matches[1]";s:52:"blog/category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$";s:52:"index.php?category_name=$matches[1]&feed=$matches[2]";s:47:"blog/category/(.+?)/(feed|rdf|rss|rss2|atom)/?$";s:52:"index.php?category_name=$matches[1]&feed=$matches[2]";s:28:"blog/category/(.+?)/embed/?$";s:46:"index.php?category_name=$matches[1]&embed=true";s:40:"blog/category/(.+?)/page/?([0-9]{1,})/?$";s:53:"index.php?category_name=$matches[1]&paged=$matches[2]";s:22:"blog/category/(.+?)/?$";s:35:"index.php?category_name=$matches[1]";s:49:"blog/tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$";s:42:"index.php?tag=$matches[1]&feed=$matches[2]";s:44:"blog/tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$";s:42:"index.php?tag=$matches[1]&feed=$matches[2]";s:25:"blog/tag/([^/]+)/embed/?$";s:36:"index.php?tag=$matc
@petenelson
petenelson / gist:f314edc59a422fdf8e940fdd45c03050
Created October 11, 2019 14:07
WordPress Cache Incrementor
/**
* Gets or updates the cache incrementor for a post type.
*
* @param string $post_type The post type.
* @param bool $update Whether to force an incrementor update.
* @return string
*/
function post_type_cache_incrementor( $post_type, $update = false ) {
$group = 'post_type_cache_incrementor';
@petenelson
petenelson / reset-term-order-bug.php
Last active March 26, 2019 18:58
wp_update_post() resetting term order
<?php
// Sample code to demonstrate a possible bug in core where
// wp_update_post() is resetting the term_order.
global $wp_taxonomies;
// Let core set the term_order field automatically.
$wp_taxonomies['category']->sort = true;
$post_id = wp_insert_post(
@petenelson
petenelson / class-estimator.php
Last active March 15, 2019 00:26
Time Left Estimator
<?php
/**
* Estimator class to get estimated time left.
*/
class Estimator {
public $total = 0;
public $count = 0;
public $start_time = 0;
@petenelson
petenelson / object-cache.php
Last active February 21, 2024 22:40
object-cache.php for memcached
<?php
/**
* Adds a value to cache.
*
* If the specified key already exists, the value is not stored and the function
* returns false.
*
* @link http://www.php.net/manual/en/memcached.add.php
*
* @param string $key The key under which to store the value.
@petenelson
petenelson / ssh-mysql-tunnel-test.php
Created July 13, 2017 16:10
WordPress: MySQL PDO command via SSH tunnel
<?php
/**
* Plugin Name: SSH Remote Test
*/
add_action( 'admin_init', 'ssh_remote_test', 1 );
function ssh_remote_test() {
@petenelson
petenelson / ssh-remote-command.php
Created July 12, 2017 21:27
WordPress: Run SSH command remotely
<?php
/**
* Plugin Name: SSH Remote Test
*/
add_action( 'admin_init', 'ssh_remote_test', 1 );
function ssh_remote_test() {
@petenelson
petenelson / bacon.sh
Last active May 3, 2017 21:53
Get paragraphs of garbage content from baconipsum.com
#!/bin/bash
#####################
# bacon.sh
#
# Client to get paragraphs of garbage content from baconipsum.com
#
# usage:
# bacon.sh <paragraph-count>
#####################
@petenelson
petenelson / userhtml.wcc
Created March 15, 2017 07:27
UserHTML - Some Wildcat BBS code I wrote back in 1995
// USERHTML - Wildcat User List to HTML Converter
// By: Pete Nelson (pete@terminal-one.com)
dim urec as userrecord
dim today as date, now as time, domain as string
if not exists("userhtml.cfg") then
cls
print "@0A@What is your domain name@07@: " defcolor;
@petenelson
petenelson / rest-api-route-array-schema.php
Created February 27, 2017 19:46
WordPress: Example of REST API route with schema type of array
<?php
register_rest_route( 'test', '/v1/schema-test', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\handle_endpoint',
'args' => array(
'mybools' => array(
'required' => true,
'type' => 'array', // We require an array of items.
'items' => array(