Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Shelob9 / serve-side-block.js
Last active February 4, 2024 20:38
Example Gutenberg block with server-side rendering. Gutenberg edit() block creates interface. Gutenberg saves settings automatically, the PHP function passed as `render_callback` to `register_block_type` is used to create HTML for front-end rendering of block.
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const el = wp.element.createElement;
registerBlockType( 'hiRoy/serverSide', {
title: __( 'Server Side Block', 'text-domain' ),
icon: 'networking',
category: 'common',
attributes: {
@Shelob9
Shelob9 / caldera_forms_submit_complete.php
Last active January 24, 2024 22:34
Change field value for field set by Caldera Forms incremental value processor using the caldera_forms_submit_complete action See: https://calderaforms.com/doc/caldera_forms_submit_complete/
<?php
/**
* Change field value for field set by Caldera Forms incremental value processor
*/
add_action( 'caldera_forms_submit_complete',function( $form, $referrer, $process_id, $entryid ){
//change form ID to match your form
if( 'CF111' === $form[ 'ID' ] ){
//change field to match field used with processor
$field_id = 'fl1345';

Install PHP 8.1, node 16 and Docker in Ubuntu.

These scripts can be run with the following commands, by a super user. This installs a lot of stuff, read first.

You can add -s -- --dry-run to then end to do a dry run first.

These are tested on an ec2 instance running vscode remote

Usage

@Shelob9
Shelob9 / blue.css
Created December 7, 2023 22:42
Tailwind CSS with links styled like links
@tailwind base;
@tailwind components;
@tailwind utilities;
a {
@apply underline text-blue-800 hover:text-blue-400 visited:text-purple-800
}
@Shelob9
Shelob9 / filter-wp-request.php
Last active December 1, 2023 14:54
Using pre_http_request filter to mock HTTP request responses in WordPress phpunit test https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-http.php#L240-L262
<?php
class Test extends TestCase {
public function test_function_that_makes_api_request(){
add_filter('pre_http_request', function(){
return [
'body' => [
'id' => 1,
],
export async function sendSkeet({ text, agent, attatchments }: {
text: string,
agent: bsky.BskyAgent,
attatchments?: Attatchments,
}) {
const rt = new RichText({ text });
await rt.detectFacets(agent);
const post: any = {
$type: 'app.bsky.feed.post',
add_action( 'wp_enqueue_scripts', 'my_custom_script_load' );
function my_custom_script_load(){
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/custom-scripts', array( 'jquery' ) );
}
@Shelob9
Shelob9 / foundation-interchange.php
Last active July 31, 2023 16:01
Function to use Foundation's Interchange to make WordPress images automatically responsive. Also included is a function to add Interchange to the theme if Foundation is not already being used. http://foundation.zurb.com/docs/components/interchange.html
add_filter('post_thumbnail_html', 'slug_responsive_img', 5, 5);
//Image sizes for Interchange
add_image_size( 'fd-lrg', 1024, 99999);
add_image_size( 'fd-med', 768, 99999);
add_image_size( 'fd-sm', 320, 9999);
function slug_responsive_img($html, $post_id, $post_thumbnail_id, $size, $attr) {
//make image links
$attachment_id = $post_thumbnail_id;
$default = wp_get_attachment_image_src($attachment_id);
import bsky from '@atproto/api';
const { BskyAgent, RichText } = bsky;
import * as dotenv from 'dotenv';
import process from 'node:process';
dotenv.config();
const agent = new BskyAgent({
service: 'https://bsky.social',
});