Skip to content

Instantly share code, notes, and snippets.

View danielbachhuber's full-sized avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
@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/';
<script type="text/javascript">var host = (("https:" == document.location.protocol) ? "https://secure." : "http://");document.write(unescape("%3Cscript src='" + host + "wufoo.com/scripts/embed/form.js' type='text/javascript'%3E%3C/script%3E"));</script>
<script type="text/javascript">
var p7p1q1 = new WufooForm();
p7p1q1.initialize({
'userName':'cunyjschool',
'formHash':'p7p1q1',
'autoResize':true,
'height':'340',
'ssl':true});
@danielbachhuber
danielbachhuber / gist:1106704
Created July 26, 2011 13:04
WordPress admin improvements
<?php
/**
* Random set of improvements
*/
/**
* Tidy up the admin and remove options we don't need
*/
function db_clean_up_admin() {
@danielbachhuber
danielbachhuber / gist:1117115
Created July 31, 2011 19:31
Set WordPress user display name
<?php
require_once('./wp-load.php');
$all_users = get_users();
foreach( $all_users as $user ) {
if ( $user->user_login == $user->display_name ) {
$user_info = get_userdata( $user->ID );
$new_display_name = $user_info->first_name . ' ' . $user_info->last_name;
@danielbachhuber
danielbachhuber / p2-resolved-posts.php
Created November 10, 2011 01:03 — forked from nacin/p2-resolved-posts.php
P2 Resolved Posts
<?php
/* Plugin Name: P2 Resolved Posts
* Description: Allows you to mark P2 posts for resolution.
* Author: Andrew Nacin
* Author URI: http://andrewnacin.com/
*/
/* WARNING about studying and copying this code:
*
* P2 is not currently an ideal platform for developing extensions. Some of this
@danielbachhuber
danielbachhuber / gist:1409229
Created November 30, 2011 14:23
Handling WordPress search
<?php
/**
* Give the user a 404 if they do an internal WP search
*/
function db_unresolve_search() {
global $wp_query;
if ( $wp_query->is_search )
$wp_query->is_404 = true;
}
add_action( 'template_redirect', 'db_unresolve_search' );