Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Hardie ChrisHardie

View GitHub Profile
@ChrisHardie
ChrisHardie / instagram-to-rss.php
Created Oct 14, 2019
Sample PHP script to scrape an Instagram public profile and generate an RSS feed
View instagram-to-rss.php
<?php
$target_accounts = array(
'bikes_as_transportation',
);
foreach ( $target_accounts as $target_user ) {
$target_user = urlencode( $target_user );
@ChrisHardie
ChrisHardie / storycorps-to-rss.php
Created Oct 14, 2019
Example PHP script to generate an RSS feed of a StoryCorps Archives interview search result
View storycorps-to-rss.php
<?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");
@ChrisHardie
ChrisHardie / twitter-timeline-to-rss-feed.php
Last active Apr 6, 2021
Example PHP script to generate an RSS feed from a user's timeline for tweets that match a certain set of criteria
View twitter-timeline-to-rss-feed.php
<?php
/**
* Generate an RSS feed from a Twitter user's timeline
* Chris Hardie <chris@chrishardie.com>
*/
require "/path/to/vendor/autoload.php" ;
use Abraham\TwitterOAuth\TwitterOAuth;
@ChrisHardie
ChrisHardie / jch-flickr-fixer.php
Created Feb 18, 2020
Flickr-to-WordPress: a plugin to use a WordPress powered API to find/replace Flickr references in another WordPress site
View jch-flickr-fixer.php
<?php
/**
* Plugin Name: Flickr Fixer
* Plugin URI: https://chrishardie.com/
* Description: Find/replace Flickr references
* Version: 1.0
* Author: Chris Hardie
* Author URI: https://chrishardie.com/
*/
@ChrisHardie
ChrisHardie / multisite_attachment_url.php
Created Mar 18, 2019
Example WordPress plugin to help simplify attachment URLs on multisite sites with mapped domains
View multisite_attachment_url.php
<?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 / class-api-routes.php
Created Feb 18, 2020
Flickr-to-WordPress: a class defining a REST API endpoint to determine the local WordPress equivalent of an imported Flickr photo
View class-api-routes.php
<?php
/**
* Class JCHPhotos_Plugin_API_Routes
*
* Handles API endpoints for looking up Flickr-to-WordPres translation stuff.
*/
class JCHPhotos_Plugin_API_Routes {
@ChrisHardie
ChrisHardie / check-for-results.php
Created Nov 5, 2019
A PHP script to check for results in the Wayne County, Indiana 2019 Mayoral Election
View check-for-results.php
<?php
require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
$output_messages = array();
$wayneco_results_html = file_get_contents( WAYNECO_RESULTS_URL );
$state_results_html = file_get_contents( STATE_RESULTS_URL );
@ChrisHardie
ChrisHardie / get-facebook-events.php
Created Oct 8, 2019
Proof of concept, retrieve publicly-available Facebook page event data.
View get-facebook-events.php
<?php
/**
* Proof of concept, retrieve publicly-available Facebook page event data.
* Chris Hardie <chris@chrishardie.com>
*
* To use, first add Guzzle as a dependency:
* $ commposer require guzzlehttp/guzzle
*
*/
@ChrisHardie
ChrisHardie / rss.pl
Created Jan 10, 2019
Generate an RSS feed in Perl
View rss.pl
#!/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 / functions.php
Created Sep 24, 2018
WordPress one-time role/capability fix for Yoast SEO on Multisite
View functions.php
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' );
}