Skip to content

Instantly share code, notes, and snippets.

Avatar

Andy Brudtkuhl abrudtkuhl

View GitHub Profile
@abrudtkuhl
abrudtkuhl / tracking.js
Created Oct 31, 2017
Basic gtag.js Event Tracking Example
View tracking.js
document.getElementById('search-submit').onclick = function() {
gtag('event', 'homepage_search', {
'event_category': 'Search',
'event_action': 'submit',
'event_label': 'Homepage Search'
});
};
@abrudtkuhl
abrudtkuhl / kramerbot.js
Last active Mar 24, 2016
Node.js class for a Slack bot using the WordPress REST API
View kramerbot.js
/* code inspired by Luciano Mammino via http://bit.ly/1KoCOjM */
'use strict';
var util = require('util');
var path = require('path');
var Bot = require('slackbots');
var WP = require( 'wordpress-rest-api' );
/**
@abrudtkuhl
abrudtkuhl / kramerbot.js
Created Mar 21, 2016
Slack bot in Node.js grabbing data from a WordPress REST API backend.
View kramerbot.js
'use strict';
var WP = require( 'wordpress-rest-api' );
var wp = new WP({ endpoint: 'http://local.dev/wp-json/' });
var Bot = require('slackbots');
var settings = {
token: XXXX,
name: 'kramerbot'
};
@abrudtkuhl
abrudtkuhl / plugin.php
Created Mar 21, 2016
WordPress REST API - Get Random Post endpoint
View plugin.php
<?php
/**
* Plugin Name: WP Slack REST API Backend
* Description: An example of using the WordPress REST API as a backend for a Slack Bot
* Author: Andy Brudtkuhl
* Author URI: http://youmetandy.com
* Version: 0.1
* Plugin URI: https://github.com/abrudtkuhl/heykramer
* License: GPL2+
@abrudtkuhl
abrudtkuhl / kramerbot.js
Created Mar 19, 2016
Basic Slack Bot Node.js
View kramerbot.js
'use strict';
var messages = [
'Giddyup',
'Isosceles. You know, I love the name Isosceles. If I had a kid, I would name him Isosceles. Isosceles Kramer.',
'You know what you are? You’re an anti-dentite! It starts with a few jokes and slurs… ‘HEY DENTY!’ Then you will say that dentists should have their own schools!',
'Have you ever met a proctologist? They usually have a very good sense of humor. You meet a proctologist at a party, don’t walk away. Plant yourself there because you will hear the funniest stories you’ve ever heard.',
'What do you think Junior? You think these hands – they’ve been soaking in Ivory Liquid?',
'http://i.giphy.com/aMh59aKR8vjdC.gif'
];
@abrudtkuhl
abrudtkuhl / plugin.php
Last active Mar 11, 2016
Extending the WordPress REST API to return message to Slack
View plugin.php
<?php
/**
* Plugin Name: WP Slack Slash Command Example
* Description: An example of using the WordPress REST API as a backend for a Slack Slash Command
* Author: Andy Brudtkuhl
* Author URI: http://youmetandy.com
* Version: 0.1
* Plugin URI: https://github.com/abrudtkuhl/wp-slack-slash-command
* License: GPL2+
@abrudtkuhl
abrudtkuhl / single-{category}.php
Created Sep 25, 2015
WordPress Single Page Template For Categories
View single-{category}.php
<?php
// CATEGORY SINGLE TEMPLATES :: single-{category_slug}.php
add_filter( 'single_template',
create_function( '$t', 'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-{$cat->slug}.php";
} return $t;' ) );
// Example
@abrudtkuhl
abrudtkuhl / CreatePost.cs
Last active Aug 18, 2018
Using WordPressSharp To Publish A Post
View CreatePost.cs
// create a new Post in WordPress
var post = new Post
{
PostType = "post", // "post" or "page"
Title = "Using WordPressSharp",
Content = "WordPressSharp is a C# utility for interfacing with the WordPress XML-RPC API",
PublishDateTime = DateTime.Now,
Status = "publish" // "draft" or "publish"
};
@abrudtkuhl
abrudtkuhl / index.html
Last active Mar 6, 2018
Simple KnockoutJS paging with DataTables
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Simple KnockoutJS Paging With DataTables.net</title>
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
@abrudtkuhl
abrudtkuhl / wp-open-files-new-window.js
Last active Aug 29, 2015
jQuery Open Files In New Window
View wp-open-files-new-window.js
// Regex via http://stackoverflow.com/a/6582227/12442
// jQuery Filter idea via http://stackoverflow.com/a/193787/12442
jQuery(function() {
jQuery('a').filter(function() {
return this.href.match(/\.([0-9a-z]+)(?:[\?#]|$)/i);
}).prop('target', '_blank');
});
You can’t perform that action at this time.