Skip to content

Instantly share code, notes, and snippets.

View chuckreynolds's full-sized avatar
🤖
building things

Chuck Reynolds chuckreynolds

🤖
building things
View GitHub Profile
@chuckreynolds
chuckreynolds / wp-local-media-apache.txt
Created July 1, 2016 22:04
Local WordPress Media Uploads Fallback. Substitute {PROD} for the domain to use images from.
<IfModule mod_rewrite.c>
RewriteEngine on
# Attempt to load files from production if
# they're not in our local version
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule wp-content/uploads/(.*) \
http://{PROD}/wp-content/uploads/$1 [NC,L]
</IfModule>
@chuckreynolds
chuckreynolds / wordpress-get-child-page-ids.php
Created February 5, 2019 11:43
Gotta be a better way to get an array of Child Page IDs than this. WordPress
<?php
// basic idea here is a common function to pass a parent page ID
// and get back an array of it and its child page IDs only
function getChildPageIDs( $id ) {
$child_pages = get_pages('child_of='.$id);
$ids_to_remove = array($id); // we want to remove parent id too
foreach($child_pages as $child) {
array_push($ids_to_remove,$child->ID); // for every child add the id into array
}
@chuckreynolds
chuckreynolds / wordpress-change-domain-migration.sql
Last active February 10, 2023 18:56
UPDATE: Use WP-CLI find-replace command to edit URLs in your database. https://developer.wordpress.org/cli/commands/search-replace/ Use this SQL script when changing domains on a WordPress site. Whether you’re moving from an old domain to a new domain or you’re changing from a development domain to a production domain this will work. __STEP1: al…
/* Use WP-CLI instead https://developer.wordpress.org/cli/commands/search-replace/ */
SET @oldsite='http://oldsite.com';
SET @newsite='http://newsite.com';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);
/* only uncomment next line if you want all your current posts to post to RSS again as new */
@chuckreynolds
chuckreynolds / nightbot-commands-reference.md
Last active December 12, 2022 08:33
Nightbot commands reference for Twitch and sometimes youtube gaming. Most are accessible via google and reading many docs but I like to keep things in one location for reference. If you want to see something here lmk on Twitter: https://twitter.com/chuckreynolds or comment below.

General stuff

Add, Edit, Delete Commands

  • !addcom !keyword New text here
  • !editcom !keyword Edited version of the text here
  • !delcom !keyword

Reference the user whom entered command

  • $(user)

Reference user-entered text

@chuckreynolds
chuckreynolds / current-weather-openweathermap.js
Created March 12, 2019 08:05
Open Weather Map API Current Weather, node js, javascript, axios
// API specific settings https://openweathermap.org/current
const API_URL = 'https://api.openweathermap.org/data/2.5/weather';
const API_KEY = '';
const LOCATION_CODE = '';
const FULL_API_URL = `${API_CURRENT_URL}?id=${LOCATION_CODE}&appid=${API_KEY}`;
axios
.get(FULL_API_CURRENT_URL)
.then(response => {
// Assign vars to response data
@chuckreynolds
chuckreynolds / wordpress-remove-block-suggestions.php
Created October 7, 2022 17:30
WordPress Remove Block Suggestions when viewing the Block Directory in WP Admin.
// Remove Block Suggestions in wp-admin Block Directory
function chuckdev_remove_block_directory() {
wp_add_inline_script(
'wp-block-editor',
"wp.domReady( () => wp.plugins.unregisterPlugin( 'block-directory' ) )"
);
}
add_action( 'admin_enqueue_scripts', 'chuckdev_remove_block_directory' );
@chuckreynolds
chuckreynolds / local-dev-remote-images.php
Created April 3, 2015 06:22
WordPress local dev environment plugin and config to use images from a live server instead of looking on local url path
<?php
/*
* Plugin Name: Local Dev Remote Images
* Description: this will allow a local dev environment to call all images in uploads from a remote server
* Version: 0.1
* License: GPL
* Author: @chuckreynolds
* Author URI: https://chuckreynolds.us
*/
@chuckreynolds
chuckreynolds / disable-rest-endpoints.php
Created February 20, 2017 02:03
WordPress: Disable WP REST API JSON endpoints if user not logged in
<?php
/*
* Disable WP REST API JSON endpoints if user not logged in
*/
function chuck_disable_rest_endpoints( $access ) {
if( ! is_user_logged_in() ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@chuckreynolds
chuckreynolds / stopwatch.php
Created July 27, 2016 22:56
Simple "StopWatch" class to measure PHP execution time. The class can handle multiple separate timers at the same time
<?php
class StopWatch {
/**
* @var $startTimes array The start times of the StopWatches
*/
private static $startTimes = array();
/**
* Start the timer
*
@chuckreynolds
chuckreynolds / .editorconfig
Created June 8, 2017 02:16
my default starter editorconfig file.
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true