Skip to content

Instantly share code, notes, and snippets.

View roykho's full-sized avatar
👋
Focusing

Roy Ho roykho

👋
Focusing
View GitHub Profile
/**
* WordPress dependencies
*/
import { PanelBody, ToggleControl } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
/**
* Renders the Advanced Features sidebar panel and toggle for the alley feature flag.
* Reads and updates post meta via core/editor; does not persist to server (editor save does).
<?php
/**
* Registers a REST API endpoint that returns post counts by status,
* cached per capability (editor vs non-editor) to avoid repeated database queries.
*/
add_action( 'rest_api_init', function () {
register_rest_route(
'alley/v1',
'/post-metrics',
[
@roykho
roykho / gist:738d7745e562cf14558ee44f9eb69282
Created August 3, 2025 15:19
React - Handy click outside container handler
import { useEffect, useRef } from 'react';
const useClickOutside = (callback: () => void) => {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
// If the ref exists and the clicked element is not inside the ref's element
if (ref.current && !ref.current.contains(event.target as Node)) {
callback(); // Execute the provided callback function