Skip to content

Instantly share code, notes, and snippets.

View philwonski's full-sized avatar

philwonski philwonski

View GitHub Profile
@philwonski
philwonski / extend-rest-api.php
Created November 28, 2022 16:40 — forked from mklasen/extend-rest-api.php
Update Custom Post Type Meta Fields with the WordPress REST API
<?php
register_meta('post', 'custom-field', [
'object_subtype' => 'custom-post-type',
'show_in_rest' => true
]);
@philwonski
philwonski / yoast_seo_sitemap_add_custom_type.php
Created January 27, 2022 19:50 — forked from amboutwe/yoast_seo_sitemap_add_custom_type.php
Filters and example code for Yoast SEO sitemaps
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Create Custom Yoast Sitemap
* Credit: Unknown
* Last Tested: Unknown
*********
* HOW TO USE
* Replace TYPE with your custom type
*/
@philwonski
philwonski / scroll-iframe-parent-from-child-plus-TW5.js
Last active January 24, 2022 01:05
Scroll iframe parent window from event inside child
//This works great for when the parent and child have different origins.
//in the parent
///////////////////////////////////////////
//<script>
function handleMessage(event) {
var accepted_origin = 'https://CHILDORIGIN.URL';
if (event.origin == accepted_origin){
@philwonski
philwonski / 1-promises.coffee
Created October 6, 2021 12:52 — forked from pketh/1-promises.coffee
Promises in Coffeescript
# Create a promise:
myCoolPromise = new Promise (resolve, reject) ->
# do a thing
success = true
if success
resolve 'stuff worked'
else
reject Error 'it broke'
@philwonski
philwonski / ArrayObjectDemo.coffee
Created September 19, 2021 21:15 — forked from frane/ArrayObjectDemo.coffee
Traversing arrays and objects in CoffeeScript
# Traversing arrays and objects in CoffeeScript
# The array and object we use for testing
arr = [1, 2, 3, 4, 5]
obj = {a: 1, b: 2, c: 3, d: 4, e: 5}
# 'in' has a different meaning in CoffeeScript than in JavaScript
# CS: element in array -> JS: array.indexOf(element) >= 0
console.log '5 in arr: ' + (5 in arr)
@philwonski
philwonski / request.coffee
Created September 19, 2021 00:01 — forked from wess/request.coffee
Basic and Simple to Use Request Class for CoffeeScript
#
# request.coffee
#
# Created by Wess Cope on 2012-01-30.
#
# Just a start. The basics in place and working
# to expand as elements are needed.
#
class Request
@philwonski
philwonski / app.coffee
Created September 18, 2021 23:40 — forked from seyhunak/app.coffee
Coffeescript - Ajax Request
$(document).ready ->
$.ajax '/items/get_list',
type: 'GET'
dataType: 'json'
beforeSend: ->
$('#loading').html "<img src='/assets/loading.gif' /> Now loading..."
error: (jqXHR, textStatus, errorThrown) ->
$('#items').html "Error: #{textStatus}"
success: (data, textStatus, jqXHR) ->
\define instructions()
With thanks to Tones (https://groups.google.com/g/tiddlywiki/c/avkbQnEd1UI/m/_sz6sEeFBwAJ)
Syntax
<<format-number n [t] [d] [p]>>
n is the number with or without decimal places (no default)t is the thousands separator (optional) - defaults to ","
(Can change default in format-number macro, set thousands-separator)
d is the decimal separator (optional) - defaults to "."
(Can change default in format-number macro, set decimal-separator)
p is the decimal places to use (optional) - defaults to "2"
@philwonski
philwonski / action-submitform.js
Created April 18, 2021 18:50
This is an archive of @OokTech 's Tiddlywiki plugin TW5-Submit-Form, for submitting xhr POST requests with URL parameters from TW5. Refer to similar gist(s) for slight modifications of this base for json payloads. I use this + a separate GET gist to do AJAX in TW5. POSTing from TW5 is cool because A) you can set it up to send flat json using the…
/*\
title: $:/plugins/OokTech/SubmitForm/action-submitform.js
type: application/javascript
module-type: widget
Action widget to send an XMLhttprequest with form data.
The widget takes two inputs, a url and the title of a data tiddler that contains the data to be sent. The indexes are the form element names and the value is the value for that element.
So if DataTiddler has this:
{
"givenname": Bjorn,
"familyname": Mallardson
@philwonski
philwonski / TW5-Login-WP
Last active April 18, 2021 18:38
This is (part of) a plugin for Tiddlywiki 5, for getting a token from a remote server and storing in cookies and local storage. This gist is exactly the same as @OokTech 's TW5-Login as of Apr2021 with the exception of changing the URL parameter on line 210 to match Wordpress convention of username/password as opposed to name/pwd in Ooktech's pl…
/*\
title: $:/plugins/OokTech/Login/login-widget.js
type: application/javascript
module-type: widget
A widget that creates a login interface for a restful server.
\*/
(function(){