Skip to content

Instantly share code, notes, and snippets.

View cr0ybot's full-sized avatar
🤖

Cory Hughart cr0ybot

🤖
View GitHub Profile
@cr0ybot
cr0ybot / how_to_organize_css.md
Last active January 29, 2026 22:13
How to Organize CSS

How to Organize CSS

Just use Sass (SCSS specifically).

The actual most important rule is to co-locate styles for a selector, which is easier with Sass than without. The "traditional" method of placing all styles for a particular breakpoint in a single @media query at the bottom of the file (or eve worse, a different file entirely) is a good way to end up with spaghetti CSS that is difficult to override and impossible to maintain without introducing regressions.

Consider an everyday task for a CSS developer: "Go make the logo bigger/smaller on X screen size". How do you figure out where to put the new/changed styles? I suspect you might inspect the element in your browser to see how it displays at certain screen sizes, and then you go look for the selector (likely a class name) in the codebase. What happens if there are 12 results for .logo? Now you have to go scrolling around in the code to figure out which ones are nested inside of media queries in order to find the right place. Or maybe you just gi

@cr0ybot
cr0ybot / README.md
Created July 16, 2025 20:33
Fix unresponsive Gravity Forms editor (Uncaught TypeError: gform.addAction is not a function)

Lots of topics from the Gravuty Forms community forum show up when searching Google for a variation on gform.addAction is not a function (like this one), so I figured I'd publish a solution that worked in my particular case. TL;DR I think the team should take another look at the admin script dependencies.

Note that this applies to version 2.9.10 of the plugin, it is possible that a future version may fix this specific issue (I hope).

The Problem

The form edit screen loads a gforms_hooks.js file and inserts it as an inline script attached to the gform_gravityforms script enqueue with id gform_gravityforms-js-before. This script begins with if ( ! gform ) { ..., so if gform has been defined in the window scope already this script will not add the addAction and other functions that additional scripts rely on. However, at least in my case, a script with id gform_gravityforms_libraries is loaded

@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 May 2, 2025 08:23
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;