Skip to content

Instantly share code, notes, and snippets.

View kingkool68's full-sized avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
@kingkool68
kingkool68 / changelog.sh
Last active September 17, 2023 21:08
Bash script to generate a markdown change log of GitHub pull requests between tagged releases
#!/bin/bash
# Generate a Markdown change log of pull requests from commits between two tags
# Author: Russell Heimlich
# URL: https://gist.github.com/kingkool68/09a201a35c83e43af08fcbacee5c315a
# HOW TO USE
# Copy this script to a directory under Git version control
# Make the script executable i.e. chmod +x changelog.sh
# Run it! ./changelog.sh
# Check CHANGELOG.md to see your results
@kingkool68
kingkool68 / cdn-integration.php
Created November 11, 2013 22:15
I wanted to run my entire WordPress site through a CDN so this is what I had to do to make it work. cdn-integration.php is a plugin file that you shouldn't have to change. wp-config.php is some configuration details you'll need to put in wp-config.php Most CDNs let you control the TTL of how long to hold on to assets from the caching headers set…
<?php
/*
Plugin Name: RH CDN Integration
Description: Making Origin Pull Work. Heavilty inspired by https://github.com/markjaquith/WP-Stack/blob/master/WordPress-Dropins/wp-stack-cdn.php
Version: 0.1
Author: Russell Heimlich
Author URI: http://www.russellheimlich.com
*/
// Convenience methods
@kingkool68
kingkool68 / svg-functions.php
Created August 4, 2017 03:22
SVG helper functions for WordPress
<?php
// Throw this in your theme and include it in your functions.php file
/**
* Helper function for fetching SVG icons
*
* @param string $icon Name of the SVG file in the icons directory
* @return string Inline SVG markup
*/
function wp_svg_icon( $icon = '' ) {
@kingkool68
kingkool68 / all-post-type-archives.php
Created June 2, 2023 14:49
Adds /all/ URL after a post type archive to be able to show all items for that archive.
<?php
/**
* Plugin Name: Show All Post Type Archives
* Description: Add support for /all/ after a post type archive
* Version: 0.0.1
* Plugin URI: https://gist.github.com/kingkool68/efa01ecff91bc722cd3f667ae509a37b
* Author: Russell Heimlich
* Author URI: https://github.com/kingkool68
*/
class RH_Show_All_Archives {
@kingkool68
kingkool68 / class-coderpad-text-image-block.php
Last active May 19, 2023 15:24
How I use Advanced Custom Fields' Blocks to make custom components for WordPress sites. Logic is all in PHP, HTML templating is done in Twig via https://github.com/kingkool68/sprig This is in response to a tweet https://twitter.com/Gravnetic/status/1517511382102540288
<?php
/**
* A block with an image and text on the side
*/
class CoderPad_Text_Image_Block {
/**
* Get an instance of this class
*/
public static function get_instance() {
@kingkool68
kingkool68 / instagram-fetch.php
Last active April 8, 2023 22:43
A brief example of working with an external API in WordPress
<?php
// In this brief example we'll scrape an Instagram post and save it as a WordPress post
// Go to a URL and get the contents back
// See https://developer.wordpress.org/reference/functions/wp_remote_get/
$instagram_request = wp_remote_get( 'https://www.instagram.com/p/BSBvNVIF8tI/' );
// If it's succesful, the payload of the request will be in $instagram_request['body']
$instagram_html = $instagram_request['body'];
@kingkool68
kingkool68 / maybe-sideload.php
Created November 21, 2020 04:19
Two WordPress functions for maybe side loading URLs to the media library. Useful for content migrations that need to be run multiple times without producing duplicate downloads.
<?php
/**
* Example useage:
*
* maybe_sideload_image( 'https://dummyimage.com/600x400/000/fff.png' ); // Downloads image to the media library and returns an attachment ID
* maybe_sideload_image( 'https://dummyimage.com/600x400/000/fff.png' ); // Returns an attachment ID as the image has already been downloaded and added to the media library
*/
/**
@kingkool68
kingkool68 / .htaccess
Last active October 12, 2022 17:50
Remove the User endpoints from the WordPress Rest API
<IfModule mod_rewrite.c>
RewriteEngine On
# Block _method=GET query string used for compatibility in the REST API
# See https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_method-or-x-http-method-override-header
RewriteCond %{QUERY_STRING} \b_method=GET\b [NC]
RewriteRule ^ - [F]
</IfModule>
@kingkool68
kingkool68 / README.MD
Last active July 15, 2022 14:39
Configure WordPress Coding Standards Linting/Formatting in VSCode

This assumes you're editing a WordPress theme which is the root of your VSCode workspace. In other words if your theme lived in /wp-content/themes/my-awesome-theme. You would drag the directory my-awesome-theme into VSCode and start editing files from there. This also assumes you're using Composer.

If this doesn't work for you check out https://www.edmundcwm.com/setting-up-wordpress-coding-standards-in-vs-code/ which details installing the PHP Code Sniffer tools globally instead of in a project.

We need to require dependencies in our project.

composer require --dev squizlabs/php_codesniffer
composer require --dev dealerdirect/phpcodesniffer-composer-installer
composer require --dev wp-coding-standards/wpcs
@kingkool68
kingkool68 / index.js
Created November 14, 2017 18:33
AWS Lambda Function for Proxying Requests to S3
/**
* This is a simple AWS Lambda function that will look for a given file on S3 and return it
* passing along all of the headers of the S3 file. To make this available via a URL use
* API Gateway with an AWS Lambda Proxy Integration.
*
* Set the S3_REGION and S3_BUCKET global parameters in AWS Lambda
* Make sure the Lambda function is passed an object with `{ pathParameters : { proxy: 'path/to/file.jpg' } }` set
*/
var AWS = require('aws-sdk');