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 / 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 / .zshrc
Last active January 7, 2024 20:05
ZSH w/ Oh-My-ZSH config file with bash alias
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
@chuckreynolds
chuckreynolds / Gravity Forms Reset Styles
Created October 14, 2016 18:17 — forked from forgeandsmith/Gravity Forms Reset Styles
Gravity Forms SCSS reset styles for easy style editing and management
///////////////////////////////////////////////
////// GRAVITY FORMS RESET STYLES //////
///////////////////////////////////////////////
// These styles are made in mind to be used with SCSS or LESS
// If you use these styles, you must go to the Gravity Forms settings in the WordPress back end and set Output CSS to No.
////----- Core Containers
.gform_heading,
.gform_body,
@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 / extend-wordpress-user-session.php
Created July 13, 2016 11:16
This will extend the user login session auth cookie (session_tokens row in wp_usermeta) when the user is an Administrator and checks the Remember Me checkbox on login. Needed this for admins only, and all posts out there I found only did it for all users, and current_user_can didn't work so used user_can with ID.
<?php
/**
* Extend expiration length of the auth cookie for Administrators when hey check Remember Me
*
* @param int $expiration Cookie expiration passed by auth_cookie_expiration() hook
* @return int 90 days in seconds
*/
function chuck_extend_admins_login_session( $expiration, $user_id, $remember ) {
if ( $remember && user_can( $user_id, 'manage_options' ) ) {
@chuckreynolds
chuckreynolds / wp-local-media-nginx.txt
Last active October 6, 2023 09:01
Local NGINX WordPress Media Uploads Fallback. Substitute {PROD} for the domain to use images from.
location ~* ^.+\.(svg|svgz|jpg|jpeg|gif|png|ico|bmp)$ {
try_files $uri @image_fallback;
}
location @image_fallback {
proxy_pass http://{PROD};
}
@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 / get_image_tag_class.php
Last active June 23, 2016 09:02
Adds classes to attached images when saving a new image in the post editor. Doesn't add for old images.
<?php
function foo_no_print_class( $class ) {
return $class . ' print-no';
}
add_filter( 'get_image_tag_class', 'foo_no_print_class' );
@chuckreynolds
chuckreynolds / unregister-simple-social-buttons-plus.php
Last active June 28, 2016 07:08
Simple Social Buttons Plus loads CSS & JS on every page, testing this to start to remove that stuff on anything but is_single()
<?php
/*
* Unregistering Simple Social Buttons Plus plugin test
*/
function XX_deregister_styles() {
if ( ! is_single() ) {
wp_deregister_style( 'ssbp_styles' );
}
}
add_action( 'wp_print_styles', 'XX_deregister_styles', 100 );
@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