Skip to content

Instantly share code, notes, and snippets.

View ChrisHardie's full-sized avatar

Chris Hardie ChrisHardie

View GitHub Profile
@ChrisHardie
ChrisHardie / keybase.md
Created July 19, 2014 20:53
Keybase identity proof

Keybase proof

I hereby claim:

  • I am ChrisHardie on github.
  • I am chrishardie (https://keybase.io/chrishardie) on keybase.
  • I have a public key whose fingerprint is 20C3 E523 5B67 AB60 9F3C 1024 FFB4 0D5A 25D9 BA70

To claim this, I am signing this object:

@ChrisHardie
ChrisHardie / jetpack-test.php
Created January 23, 2018 20:16 — forked from delputnam/jetpack-test.php
A simple WordPress plugin to allow testing of Jetpack's Related Posts module
<?php
/**
* @package Jetpack_Test
* @version 1.0
*/
/*
Plugin Name: Jetpack Test
Description: Allows certain Jetpack modules that would otherwise require a connection to WordPress.com to be run in a local development environment.
Author: Del Putnam
@ChrisHardie
ChrisHardie / class-jch-portfolio-postmeta.php
Created July 5, 2018 12:55
Extend the Jetpack Portfolio CPT to allow specifying a project URL that can be linked to instead of the portfolio item itself
<?php
/**
* Class JCH_Portfolio_Postmeta
* Create meta boxes, post meta fields and archive link filters for portfolio items
* With some help from https://gist.github.com/carlodaniele/121841f92956c3304436
*/
class JCH_Portfolio_Postmeta {
@ChrisHardie
ChrisHardie / functions.php
Last active August 21, 2018 19:41
Example function to load plugins within wp-content/themes/mytheme/plugins/
/**
* Add in-theme plugins
*/
function my_theme_plugins() {
$plugins_to_include = array(
'wordpress-fieldmanager/fieldmanager.php',
);
if ( count( $plugins_to_include ) ) {
@ChrisHardie
ChrisHardie / functions.php
Created September 12, 2018 17:06
Override Jetpack development mode to activate modules for testing in WordPress
/**
* Modify Jetpack module properties for testing/development
*
* @param array $mod Module to look at modifying the properties of.
* @return boolean
*/
function jp_module_override( $mod ) {
switch ( $mod['name'] ) {
case 'Related posts':
$mod['requires_connection'] = false;
@ChrisHardie
ChrisHardie / functions.php
Created September 24, 2018 16:19
WordPress one-time role/capability fix for Yoast SEO on Multisite
if ( ! function_exists( 'my_add_seo_caps' ) ) {
function dnc_add_seo_caps() {
// Get admin role
$role = get_role( 'administrator' );
// Add YOAST SEO Roles
$role->add_cap( 'wpseo_manage_options' );
$role->add_cap( 'wpseo_edit_advanced_metadata' );
$role->add_cap( 'wpseo_manage_redirects' );
$role->add_cap( 'wpseo_bulk_edit' );
}
@ChrisHardie
ChrisHardie / rss.pl
Created January 10, 2019 20:38
Generate an RSS feed in Perl
#!/usr/bin/perl
use XML::RSS;
use strict;
my @event_array = <SQL MAGIC GOES HERE>;
my $rss = new XML::RSS;
$rss->channel( title => 'Your Title Here', link => 'https://...',
description => 'Your description here.' );
@ChrisHardie
ChrisHardie / multisite_attachment_url.php
Created March 18, 2019 01:27
Example WordPress plugin to help simplify attachment URLs on multisite sites with mapped domains
<?php
/**
* Plugin Name: Multisite Domain Mapping Attachment URL Fixes
* Description: Update attachment URLs to use mapped domain and remove mention of "sites" path.
* Author: Chris Hardie
*
* Rewrite attachment URLs (and related srcset URLs) to the non-multisite, mapped domain version if a domain is mapped
* Requires that the related nginx config that maps the non-multisite URL to the multisite URL be in place
**/
add_filter( 'wp_get_attachment_url', 'jch_attachment_url_with_domain_mapping' );
@ChrisHardie
ChrisHardie / get-facebook-events.php
Created October 8, 2019 13:07
Proof of concept, retrieve publicly-available Facebook page event data.
<?php
/**
* Proof of concept, retrieve publicly-available Facebook page event data.
* Chris Hardie <[email protected]>
*
* To use, first add Guzzle as a dependency:
* $ commposer require guzzlehttp/guzzle
*
*/
@ChrisHardie
ChrisHardie / storycorps-to-rss.php
Created October 14, 2019 16:41
Example PHP script to generate an RSS feed of a StoryCorps Archives interview search result
<?php
$storycorps_archive_html = file_get_contents( 'https://api.storycorps.me/wp-json/interviews?filter[places]=richmond,indiana' );
$storycorps_archive = json_decode( $storycorps_archive_html, true );
$xml = new SimpleXMLElement('<rss/>');
$xml->addAttribute("version", "2.0");
$channel = $xml->addChild("channel");