Skip to content

Instantly share code, notes, and snippets.

View danielbachhuber's full-sized avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
@danielbachhuber
danielbachhuber / gist:9123282
Last active August 29, 2015 13:56
Show editorial comments on "Edit Comments"
<?php
/**
* Add editorial comments to the Edit Comments list view
*/
add_filter( 'comments_clauses', 'efx_add_editorial_comments' );
function efx_add_editorial_comments( $clauses ) {
global $pagenow;
if ( 'edit-comments.php' != $pagenow ) {
return;
@danielbachhuber
danielbachhuber / gist:9508957
Created March 12, 2014 15:13
Helpful P2 comment settings
<?php
/**
* Permit anyone to post HTML in the comments
* Because ThunderP2 is only accessible by qualified users,
* this is just fine.
*/
add_action( 'init', function() {
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
add_filter( 'pre_comment_content', 'wp_filter_post_kses' );
@danielbachhuber
danielbachhuber / gist:c1554c1777dbb0460bfb
Created May 12, 2014 21:58
Serve a subset of terms at /term-slug instead of /tag/term-slug
<?php
/**
* 'special-term' is a unique butterfly
*/
function dbx_get_special_terms() {
return array( 'special-term' );
}
/**
<?php
/*
* Hack to restore the post_name that get_default_post_to_edit() noops
* Our assigned post_name via wp_insert_post_data can get fubar on post-new.php
*
* @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/post.php#L588
*/
add_filter( 'post_updated_messages', function( $messages ) {
global $pagenow, $post;
@danielbachhuber
danielbachhuber / gist:218df6da18f79ba2b854
Created April 16, 2015 21:09
Character countdown for Fieldmanager
this.setupMaxLengthCountdown();
$('.fm-item').on('fm_added_element', $.proxy( this.setupMaxLengthCountdown, this ) );
/**
* Set up max length countdown
*/
setupMaxLengthCountdown: function() {
$('.fm-element[data-fusion-enable-max-length-countdown]').each( function(){
var el = $(this);
@danielbachhuber
danielbachhuber / Create new MySQL database
Created May 3, 2010 22:44
Create new MySQL database
CREATE DATABASE databasename;
GRANT ALL PRIVILEGES ON databasename.* TO username@localhost IDENTIFIED BY "password";
FLUSH PRIVILEGES;
EXIT;
@danielbachhuber
danielbachhuber / Show author metadata if available
Created May 16, 2010 03:58
Shows WordPress author metadata if available
<?php $author = get_post_meta($post->ID, 'author', true);
if ($author) { echo $author; } else { the_author(); } ?>
<?php $images = get_post_meta($post->ID, 'image');
if ($images) {
foreach ($images as $image) {
$image = explode('{}', $image);
echo '<div class="image"><img src="/media' . $image[0] . '" />';
if ($image[1]) {
echo '<p class="credit">' . $image[1] . '</p>';
}
echo '</div>';
}
@danielbachhuber
danielbachhuber / gist:756687
Created December 27, 2010 23:16
Disable email notifications of post status changes
<?php
// Handy method to remove the hook for email notifications of custom post status changes
function ef_remove_post_status_notifications() {
global $edit_flow;
// Edit Flow originally hooks into 'transition_post_status' to know when to send custom post status notifications
remove_action( 'transition_post_status', array( &$edit_flow->notifications, 'notification_status_change' ), 10, 3 );
}
// Hook this action into init so Edit Flow is already loaded
add_action( 'init', 'ef_remove_post_status_notifications' );
?>
@danielbachhuber
danielbachhuber / load_site_headlines.html
Created February 24, 2011 21:59
Loads the most recent headline and excerpt from each website in the array
REPLACE THIS WITH ANY ASSIGNMENT INTRODUCTION TEXT YOU WANT
<div class="assignment-headlines"></div>
<script type="text/javascript" src="http://static.journalism.cuny.edu/useful_js/load_site_headlines.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
// Load all of the websites in an array
var websites = new Array();
websites[0] = 'http://ernest.entrepreneurial.2011.journalism.cuny.edu/';
websites[1] = 'http://hong.entrepreneurial.2011.journalism.cuny.edu/';