Skip to content

Instantly share code, notes, and snippets.

View tomdevisser's full-sized avatar
🎯
Focusing

Tom de Visser tomdevisser

🎯
Focusing
View GitHub Profile
<?php
// Add your Google Maps API key, preferrably in wp-config.php or in the database.
define( 'GOOGLE_MAPS_API_KEY', '' );
function acf_google_map_api( $api ) {
$api['key'] = GOOGLE_MAPS_API_KEY;
return $api;
}
add_filter( 'acf/fields/google_map/api', 'acf_google_map_api' );
const hubspot = require("@hubspot/api-client");
const { config } = require("dotenv");
config();
/**
* The HubSpot class lets you interact with the HubSpot API.
* @see https://github.com/HubSpot/hubspot-api-nodejs
*/
class HubSpot {
constructor(accessToken) {
const { OpenAI: client } = require("openai");
const { config } = require("dotenv");
config();
/**
* Class for interacting with OpenAI API.
*/
class OpenAI {
constructor({ apiKey }) {
this.client = new client({ apiKey });
const { Pinecone: PineconeClient } = require("@pinecone-database/pinecone");
const { config } = require("dotenv");
config();
/**
* Class for interacting with Pinecone API.
*/
class Pinecone {
constructor() {
try {
/**
* The BlockKitBuilder class is a utility class that helps you build
* blocks for the Slack Block Kit. While the Block Kit is a JSON-based
* DSL (Domain Specific Language), this class provides a more readable
* and maintainable way to construct blocks.
*/
class BlockKitBuilder {
addSection({ text, type = "mrkdwn" }) {
return {
@tomdevisser
tomdevisser / taxonomy-meta-box-without-adder-with-radio-inputs.php
Last active February 9, 2025 22:04
Requires the custom walker class found in class-walker-taxonomy-radio-list.php.
<?php
/**
* Displays a custom taxonomy meta box with radio inputs.
*
* @param WP_Post $post Current post object.
* @param array $box Categories meta box arguments.
* @return void
*/
function toms_custom_meta_box_with_radio_inputs( WP_Post $post, array $box ): void {
$tax_name = esc_attr( $box['args']['taxonomy'] );
<?php
add_action( 'init', 'toms_custom_taxonomy' );
/**
* Registers a custom taxonomy with a custom meta box callback, and without
* an edit functionality within Quick Edit.
*
* @return void
*/
function toms_custom_taxonomy(): void {
<?php
/**
* Walker class to output an unordered list of taxonomy radio input elements.
*/
class Walker_Taxonomy_Radio_List extends Walker {
public $db_fields = array(
'parent' => '',
'id' => 'term_id',
);
<?php
/**
* Displays a custom taxonomy meta box without adder.
*
* @param WP_Post $post Current post object.
* @param array $box Categories meta box arguments.
* @return void
*/
function toms_custom_meta_box_without_adder( WP_Post $post, array $box ): void {
$tax_name = esc_attr( $box['args']['taxonomy'] );
<?php
add_action( 'pre_get_posts', 'toms_restrict_media_library_to_user_list_view' );
add_action( 'pre_get_posts', 'toms_restrict_media_library_to_user_tile_view' );
/**
* Restrict media library to user's own uploads in list view.
*
* @param WP_Query $query
* @return void
*/