Skip to content

Instantly share code, notes, and snippets.

View jsit's full-sized avatar
👾

Jay Sitter jsit

👾
View GitHub Profile
@jsit
jsit / wp-all-import-events-manager.php
Last active March 5, 2020 17:35
Allow WP All Import to create events with Events Manager
// Create a proper EM_Event object in the database when an event-type post is
// imported with WP All import
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($post_id) {
if (class_exists(EM_Event)) {
$event_post = get_post($post_id);
// Only create a new event entry if the imported post is of type event and
// there is not an existing event for this post
$existing_event = em_get_event($event_post->ID, 'post_id');
@jsit
jsit / soundcloud.php
Last active June 7, 2021 05:12
PHP preg_replace strings for AMP HTML extensions
$body = preg_replace( '/<iframe\b[^>]*soundcloud.com\/tracks\/(\d*).*"[^>]*>(.*?)>/', '<amp-soundcloud height=300 layout="fixed-height" data-trackid="$1" data-visual="true"></amp-soundcloud>', $body );
@jsit
jsit / functions.php
Last active May 29, 2022 17:03
Customize WordPress comment form output
<?php
/**
* Rewrite the HTML for the author, email, and url comment fields
*/
function custom_comment_fields( $fields ) {
// https://codex.wordpress.org/Function_Reference/comment_form
$commenter = wp_get_current_commenter();
@jsit
jsit / sieve.sieve
Last active May 9, 2023 05:56
Notifications / mailing lists / bulk email sieve code (for e.g. Fastmail et al.)
if
# Tests for "Mailing Lists"
anyof(
header :is "X-ME-VSCategory" "community:mailing-list",
header :contains "X-Mailer" "Sympa",
exists [
"List-Id",
"List-Help",
"List-Subscribe",
"List-Unsubscribe",
@jsit
jsit / pinboard-bookmarklet.js
Last active May 3, 2024 21:04
Pinboard Bookmarklet -- Use text selection for description if available, otherwise use meta description, and include referrer in description if exists.
javascript: q = location.href;
q = q.replace(/[?&]utm_[^&]*/g, "");
q = q.replace(/[?&]mc_[^&]*/g, "");
q = q.replace(/[?&]src=[^&]*/g, "");
q = q.replace(/[?&]ref=[^&]*/g, "");
desc = "";
if (document.getElementsByName("description").length > 0) {
desc = document.getElementsByName("description")[0].getAttribute("content")
"\n\n"
} else if (document.getElementsByName("Description").length > 0) {
@jsit
jsit / functions.php
Last active April 17, 2017 16:06
Allow WordPress editors to post unfiltered HTML
function allow_editors_to_post_html() {
$role_object = get_role( 'editor' );
$role_object->add_cap( 'unfiltered_html' );
}
add_filter( 'admin_init', 'allow_editors_to_post_html' );
@jsit
jsit / functions.php
Created April 17, 2017 16:17
Allow CodePen attributes in <p> tags
<?php
function add_allowed_tags($tags, $context) {
if ($context === 'post') {
$tags['p'] = array(
'data-height' => true,
'data-theme-id' => true,
'data-slug-hash' => true,
'data-default-tab' => true,
@jsit
jsit / .stylelintrc
Created August 7, 2017 15:19
.stylelintrc / stylelint-order rules for SMACSS property sort order
"order/properties-order": [
{ "properties": [ "content", "quotes" ] },
{ "properties": [ "display", "visibility" ] },
{ "properties": [ "position", "z-index", "top", "right", "bottom", "left" ] },
{ "properties": [ "box-sizing" ] },
{ "properties": [ "flex", "flex-basis", "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap", "align-content", "align-items", "align-self", "justify-content", "order" ] },
{ "properties": [ "width", "min-width", "max-width", "height", "min-height", "max-height" ] },
{ "properties": [ "margin", "margin-top", "margin-right", "margin-bottom", "margin-left" ] },
{ "properties": [ "padding", "padding-top", "padding-right", "padding-bottom", "padding-left" ] },
@jsit
jsit / GitHub File View Bookmarklets.md
Created December 20, 2018 19:35
GitHub File View Bookmarklets

GitHub File View Bookmarklets

Collapse JS

javascript:var%20files%20=%20document.querySelectorAll('.file-header[data-path$=".js"]%20.js-details-target[aria-expanded=true]');%20for%20(i%20=%200;%20i%20<%20files.length;%20i++)%20{%20files[i].click();%20}

Expand JS

javascript:var%20files%20=%20document.querySelectorAll('.file-header[data-path$=".js"]%20.js-details-target[aria-expanded=false]');%20for%20(i%20=%200;%20i%20<%20files.length;%20i++)%20{%20files[i].click();%20}

Show all comments

javascript:var%20files%20=%20document.querySelectorAll('.js-toggle-file-notes:not(:checked)');%20for%20(i%20=%200;%20i%20&lt;%20files.length;%20i++)%20{%20files[i].click();%20}

@jsit
jsit / ag-filename-match.vim
Last active September 18, 2019 17:29
Native Vim search with Ag, including second parameter for filename match pattern
function! ParseAgList(...)
let l:string = join(a:000)
" http://vpaste.net/qTrzV
" Thanks irc://chat.freenode.net/m_ben,isnick
let l:pat = '\v%([^\\]\\)@<!\s+|([''"])%(.{-})\\@<!\1\zs\s*'
let l:args = split(l:string, pat)
if len(l:args) > 1
" sanitize