Skip to content

Instantly share code, notes, and snippets.

View michaelstoffer's full-sized avatar
:octocat:

Michael Stoffer michaelstoffer

:octocat:
View GitHub Profile
<?
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Backup a site files to to a gzipped tarball just above the document root
// 1. Place this file in the document root
// 2. Access the URL of this file to create a gzipped tarball of the current directory
// Create a gzipped tarball
$filename = './_MDG-backup-'.date('Y-m-d').'.tgz';
<?
namespace MDG;
class SiteSettings {
public
$favicon,
$logos,
$social_media,
$recaptcha,
$google_tag_manager,
(function($) {
// Extend jQuery's native selector with :inview to capture elements that are in the viewport
$.extend($.expr[':'], {
inview:function(el) {
let wintop = $(window).scrollTop(),
winbtm = $(window).scrollTop() + $(window).height(),
eltop = $(el).offset().top,
elbtm = $(el).offset().top + $(el).height();
return elbtm >= wintop && eltop <= winbtm;
<?php
add_shortcode('SITEMAP', 'html_sitemap');
add_shortcode('SITE_MAP', 'html_sitemap');
if (!function_exists('html_sitemap')) {
function html_sitemap() {
$ret = '';
$exclude = $output = [];
$post_types = ['page', 'post', 'staff', 'portfolio']; // Update your post types
//////////////////////// ROW & COLUMN UTILITY CLASSES ////////////////////////
.row {
.display-flex;
.flex-justify-content-space-between;
// Columns
&.col-1 { @width:percentage(1/12); width:@width; .flex(0, 0, @width); }
&.col-2 { @width:percentage(2/12); width:@width; .flex(0, 0, @width); }
&.col-3 { @width:percentage(3/12); width:@width; .flex(0, 0, @width); }
&.col-4 { @width:percentage(4/12); width:@width; .flex(0, 0, @width); }
function get_url_param(key, url) {
if (url === undefined) url = window.location.href;
url = new URL(url);
return url.searchParams.get(key)
}
<?
// Split joined results of posts and postmeta
if (!function_exists('split_posts_and_meta')) {
// Example usage:
global $wpdb;
$post_type = 'location';
$locations = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE p.post_type = %s AND p.ID)", $post_type));
if (!empty($locations)) {
$locations = split_posts_and_meta($locations, $meta_keys);
}
<?
// Validate SEO titles and descriptions
$site_url = site_url('/');
if (isset($_GET['validate-seo'])) {
add_action('wp', function() {
global $wpdb;
$file = __DIR__ . '/SEO-meta-descriptions.tsv'; // File used to compare SEO meta values
if (($handle = fopen($file, 'r')) !== FALSE) {
$header_row = fgetcsv($handle, 1000, "\t");
while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
<?
/**
* Register image sizes and optionally generate sizes for pixel densities with add_image_size() function
* @param string $prefix Image size name (or prefix if using pixel density)
* @param integer|array $baseline Width (or width/height array) of smallest image size
* @param integer|boolean $density Pixel density (optional) to generate _1x, _2x, _3x suffixes
* @param array|boolean $crop Crop positioning array
* @uses add_image_size()
*/
function register_image_set($prefix, $baseline, $density = 3, $crop = false) {
<?
namespace seagate;
// Dev URLs for reference:
// https://www.icontact.com/developerportal/documentation/advanced-users
class iContact {
public $debug = false;
// iContact data