Skip to content

Instantly share code, notes, and snippets.

View cr0ybot's full-sized avatar
🤖

Cory Hughart cr0ybot

🤖
View GitHub Profile
@cr0ybot
cr0ybot / use-max-brightness.hook.ts
Last active August 1, 2023 13:27
Expo Screen Brightness Hook (with React Navigation)
/**
* Screen brightness utility.
*/
import { useIsFocused } from "@react-navigation/core";
import * as Brightness from "expo-brightness";
import { useEffect, useState } from "react";
import { Platform } from "react-native";
/**
@cr0ybot
cr0ybot / README.md
Created June 1, 2023 15:32
Variable fonts in WordPress theme.json

Variable fonts in theme.json

Implementing variable fonts in theme.json can be tricky, but all you need are these things:

  1. A variable font in woff2 format (other formats are available but if you only have one, this is best)
  2. The font weight range (ie. thinnest to thickest values)
  3. The font variation settings (what you'd set via ont-variation-settings in CSS)

Now you can define different font families using the same font file in yout theme.json!

@cr0ybot
cr0ybot / Code.gs
Created November 16, 2022 23:59
SyncPersonalCalendar
/**
* Sync personal events with your work calendar.
*
* Setup:
* 1. From your personal calendar, add your work account in Calendar Settings > Share with specific people, you need at least "See all event details" access
* 2. Create an Apps Script project in your work Google account: https://script.google.com/u/0/home
* 3. Add this file and the appsscript.json file and customize the email addresses and other variables.
* 4. Add a trigger for the `sync` function:
* - Event source: From calendar
* - Event calendar details: Calendar updated
@cr0ybot
cr0ybot / recaptcha-jetpack-compat.php
Created August 22, 2022 23:34
This plugin is a Gutenberg compatibility layer for the reCAPTCHA Jetpack plugin v0.2.2: https://wordpress.org/plugins/recaptcha-jetpack/
<?php
/**
* Plugin Name: reCAPTCHA Jetpack Gutenberg Compatibility
* Description: Adds reCAPTCHA to Jetpack Gutenberg forms.
* Version: 1.0.0
* Author: Cory Hughart
* Author URI: https://coryhughart.com
* License: GPLv2 or later
*
* This plugin is a Gutenberg compatibility layer for the reCAPTCHA Jetpack plugin v0.2.2: https://wordpress.org/plugins/recaptcha-jetpack/
@cr0ybot
cr0ybot / nf-sub-update.sql
Created March 9, 2022 13:50
Update past Ninja Forms submission values to match changes in the form
# Had to deal with changing years worth of Ninja Forms submissions to match tweaks in the live form values a lot lately.
# There may be a "better" way to do this using Ninja Forms' "API", but running some SQL via phpmyadmin is quicker and doesn't require deploying code.
# You can inspect the field in the form builder to find the field ID, which will be in a `data-id` attribute. The `meta_key` is the field ID formatted like this: "_field_###".
# For Radio List fields, there is only a single value.
# If you're changing numerical values, be sure to start on one end so you don't end up changing values that were just changed by the previous step.
UPDATE wp_postmeta SET meta_value='0' WHERE meta_key='_field_200' AND meta_value='1';
UPDATE wp_postmeta SET meta_value='1' WHERE meta_key='_field_200' AND meta_value='2';
# For Checkbox List fields, the values are stored as serialized arrays. It means instead of just SETing we have to REPLACE.
@cr0ybot
cr0ybot / plugin.php
Created March 18, 2021 18:46
Remove parent term selector for hierarchical taxonomies
/**
* Fool WordPress into thinking this taxonomy isn't hierarchical so it doesn't show the parent dropdown on the add/edit term page
*/
function disable_parent_category_dropdown() {
global $wp_taxonomies;
$wp_taxonomies['my_taxonomy']->hierarchical = false;
}
add_action( 'my_taxonomy_pre_add_form', 'disable_parent_category_dropdown' );
add_action( 'my_taxonomy_pre_edit_form', 'disable_parent_category_dropdown' );
@cr0ybot
cr0ybot / functions.php
Last active April 22, 2022 14:22
Fix WordPress current_page_parent for Blog and Custom Post Type Archive Menu Links
/**
* Checks the current page to see if current_page_parent should be removed from the blog link or added to a cpt archive pagelink
*/
function cr0ybot_cpt_menu_highlight( $classes, $item, $args ) {
// Remove current_page_parent from Blog if not on a post
$cpp = array_search( 'current_page_parent', $classes );
if ( $cpp !== false && $item->type === 'post_type' ) {
$qo = get_queried_object();
if ( ( $qo instanceof WP_Post && $qo->post_type !== 'post' ) ||
@cr0ybot
cr0ybot / line-break.js
Created May 1, 2020 23:06
Gutenberg Line Break Format
/**
* Format: line break
*
* Adds a line break option to any Rich Text editor that adds a <br> tag
*/
const { __ } = wp.i18n;
const { insertObject, registerFormatType } = wp.richText;
const { RichTextToolbarButton } = wp.blockEditor;
@cr0ybot
cr0ybot / README.md
Last active February 10, 2020 20:57
Titanium IcoMoon Font Icons

Titanium IcoMoon Font Icons

IcoMoon is a fantastic service for putting together a lean collection of custom icons in a single font file for use on the web and, now in a Titanium app!

  1. On the IcoMoon Generate tab, make sure that the glyphs are named how you want to access them in the app. For instance, a gear icon might be named "settings".
  2. Generate and download your font files. Place you IcoMoon TTF font file and the selection.json file into app/assets/fonts.
  3. Place icon.js into your app/lib/ folder.
@cr0ybot
cr0ybot / .htaccess
Created September 6, 2019 19:00
WP local dev fetch images from staging
# Load uploads from staging server if they don't exist locally
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^example\.local$
RewriteRule ^wp-content/uploads/(.*)$ https://example.staging.com/wp-content/uploads/$1 [NC,L]
</IfModule>
# BEGIN WordPress