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 / rh-get-widget-data-for-all-sidebars.php
Last active February 15, 2021 03:51
WordPress function to get raw widget data for all of the widgets in a given sidebar
<?php
function rh_get_widget_data_for_all_sidebars() {
global $wp_registered_sidebars;
$output = array();
foreach ( $wp_registered_sidebars as $sidebar ) {
if ( empty( $sidebar['name'] ) ) {
continue;
}
$sidebar_name = $sidebar['name'];
@kingkool68
kingkool68 / Serial Array Search and Replace WordPress plugin
Created March 13, 2013 12:58
Search and replace values in serialized arrays in specific tables. Thanks to http://interconnectit.com/124/search-and-replace-for-wordpress-databases/ for sharing.
<?php
/*
Plugin Name: Pew Serial Array Search and Replace
Description: Search and replace values in serialized arrays in specific tables. Thanks to http://interconnectit.com/124/search-and-replace-for-wordpress-databases/ for sharing.
Version: 1.0
Author: Russell Heimlich
Author URI: http://www.russellheimlich.com
*/
/********************/
@kingkool68
kingkool68 / Seamless Git Deployment
Last active December 17, 2015 05:09
To push code changes to text servers I do this.
We have a private Git running on a server somewhere which we consider our central repository. Inside the .git/hooks/post-recieve is the following:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
@kingkool68
kingkool68 / gist:6609735
Created September 18, 2013 14:13
Filter to make the <!--more --> tag do it's thang anywherez.
add_filter('the_excerpt', 'we_aint_got_time_for_more');
function we_aint_got_time_for_more($the_original_excerpt) {
global $post;
return explode('<!--more-->', $post->post_content)[0];
}
@kingkool68
kingkool68 / pew_add_sitemap_urls_to_robots_txt
Last active December 24, 2015 08:29
Add sitemap links to your robots.txt file using the BWP Google Sitemap Plugin for WordPress.
//BWP Google Sitemap Plugin doesn't add sitemap links to robots.txt files so I guess I'll do it myself...
function pew_add_sitemap_urls_to_robots_txt() {
echo "\nSitemap: " . get_site_url() . "/sitemap.xml";
echo "\nSitemap: " . get_site_url() . "/post_google_news.xml";
echo "\n\n";
return $txt;
}
add_action( 'do_robotstxt', 'pew_add_sitemap_urls_to_robots_txt' );
@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 / pew-infinite-scroll.js
Last active January 4, 2018 21:27
Plugin for handling the URLs to make infinite scrolling work properly on pages like this http://www.pewresearch.org/category/publications/
jQuery(document).ready(function() {
//Set-up some constants.
var scrollTimeout;
var scrollUsePushStateInstead = false; //Set to true to make the history stack of the browser include every point when posts were loaded. It's kind of annoying.
var scrollDelay = 200; //Milliseconds
var scrollLoading = false;
var triggerOffset = $(document).height() - $('#pagination').siblings().eq(-4).offset().top; //The point of this is to do one calculation up front instead of multiple calculations every time the infinite scroll is triggered.
// Simple feature detection for History Management (borrowed from Modernizr)
function supportsHistory() {
<?php
/*
Plugin Name: Pew Scripts
Description: Scripts that are used on multiple sites can be registered and maintained in one place through this plugin.
Version: 1.2
Author: Russell Heimlich
Author URI: http://www.russellheimlich.com
*/
function pew_register_global_scripts() {
function chris_coyiers_super_awesome_feed_image_magic( $content ) {
$doc = new DOMDocument();
$doc->LoadHTML( $content );
$images = $doc->getElementsByTagName('img');
foreach ($images as $image) {
// Set the new attribute.
$image->setAttribute( 'style', 'max-width:480px;' );
}
@kingkool68
kingkool68 / Pew Research Archive listing to CSV
Created April 21, 2014 18:58
Download the URL, title, and date for all of the posts on a given archive page URL such as http://www.pewresearch.org/category/publications/fact-tank/project/u-s-politics/2014/pages/all/ Copy and paste this into the Console of the developer tools.
jQuery( document ).ready( function($) {
var csv = "data:text/csv;charset=utf-8,";
var csvData = [];
$('#content .post').each(function() {
$this = $(this);
csvData.push( [this.href, $this.find('h2').text(), $this.find('.meta span:last-of-type').text() ] );
});
for( i=0; i < csvData.length; i++ ) {
var row = '"' + csvData[i].join('","') + '"';