Skip to content

Instantly share code, notes, and snippets.

View sivel's full-sized avatar
😏

Matt Martz sivel

😏
View GitHub Profile
<?php
/*
Plugin Name: feed-pseudo-widget
Plugin URI: http://wordpress.org/#
Description: feed-pseudo-widget
Author: Matt Martz
Version: 1.0
Author URI: http://sivel.net/
*/
<?php
add_filter('wp_list_pages_excludes', 'remove_others_children');
function remove_others_children($excludes = array()) {
$all_pages = get_pages();
$all_children = (array) get_page_children(true, $all_pages);
foreach ( $all_children as $child )
$excludes[] = $child->ID;
if ( ! is_page() )
return $excludes;
<?php
$attachments = get_children('&post_type=attachment&post_mime_type=image&post_parent=true');
foreach ( $attachments as $attach )
echo "<a href='" . get_permalink($attach->post_parent) . "'><img src='" . wp_get_attachment_thumb_url($attach->ID) . "' alt='' /></a>";
?>
@sivel
sivel / sivel-cdn.php
Created May 17, 2010 20:29
Simple WordPress plugin for repointing resource URLs to a CDN pull style host
<?php
/*
Plugin Name: Sivel CDN
Plugin URI: http://sivel.net/
Description: Points media urls at a CDN
Version: 1.0
Author: Matt Martz
Author URI: http://sivel.net/
*/
@sivel
sivel / better-cache-bust.php
Created May 13, 2011 20:28
Improve WordPress cache busting to move the version into the URL path, instead of as a query variable
<?php
/*
Plugin Name: Better Cache Bust
Plugin URI: http://sivel.net/
Description: Moves the resource version in the URL path instead of as a query var
Version: 1.0
Author: Matt Martz
Author URI: http://sivel.net/
*/
@sivel
sivel / the-queries.php
Created June 14, 2011 17:14
Output or log queries generated by WordPress
<?php
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
add_action( 'wp_footer', 'the_queries' );
function the_queries() {
global $wpdb;
if ( defined( 'LOGQUERIES' ) && LOGQUERIES ) {
foreach ( $wpdb->queries as $query )
error_log( trim( $query[0] ) . "\n", 3, WP_CONTENT_DIR . '/debug.log' );
} else {
@sivel
sivel / migrate_patch.py
Created December 6, 2016 21:44
Migrate mailbox patch for ansible repo merge
import re
import sys
import requests
DIFF_GIT_RE = re.compile(r'^(diff --git a/)([^ ]+ b/)([^ ]+)$', re.M)
STAT_RE = re.compile(r'^(\s+)([^ ]+\s+\|\s+\d+\s+[+-]+)$', re.M)
MINUS_PLUS_RE = re.compile(r'^((?:-|\+){3} [ab]/)(.+)$', re.M)
E123 closing bracket does not match indentation of opening bracket's line
E124 closing bracket does not match visual indentation
E127 continuation line over-indented for visual indent
E128 continuation line under-indented for visual indent
E201 whitespace after '('
E202 whitespace before '}'
E203 whitespace before ','
E211 whitespace before '('
E221 multiple spaces before operator
E222 multiple spaces after operator
@sivel
sivel / output.txt
Last active January 26, 2017 18:48
Ansible callback plugin to print the number of remaining hosts in a task
changed: [localhost3]
4 hosts remaining: localhost0, localhost1, localhost2, localhost4
changed: [localhost2]
3 hosts remaining: localhost0, localhost1, localhost4
changed: [localhost1]
2 hosts remaining: localhost0, localhost4
changed: [localhost0]
1 hosts remaining: localhost4
changed: [localhost4]
All hosts complete