Hefta-Gaub Development Blog

April 14, 2008

Notes on Mysql Master/Slave

Filed under: Amazon Web Services, aws, development, mysql — Tags: — zappoman @ 11:33 pm

Here’s a good link from or friend Paul Moen on how to promote a slave to a master.


The basic idea hear, is to simply tell the slave to no longer pay attention to the master… and things should work as is.

Kind of obvious really.


September 21, 2007

June 8, 2007

Crazy Globals Bug in Recent Posts Widget

Filed under: bug, development, recent posts, themes, widgets, Wordpress plugins, WordpressMU — zappoman @ 7:42 am

I’ve just discovered and fixed a small problem in the “Recent Posts” widget.

Basically this widget creates a second “loop” and will side effect several of the post globals (like $id and $post). The result will effect any downstream plugin that thinks it can count on these globals being available. This can also manifest in any theme (like Tarski) that has post related template calls AFTER the side bar widget.

I’ve fixed this problem but saving $post in a local variable and then resetting it after the loop call. I also call setup_postdata() to restore the other globals.

I just checked the latest version of widgets.php from “http://svn.wp-plugins.org/widgets/trunk/” and it still has this issue in it.

Here’s the new function…

function widget_recent_entries($args) {
    // This global $post is side effected by the call to $r->the_post()
    // and so in order to protect any uses of $post after our widget is
    // instantiated, we will save the value of the global and restore
    // it at the end of our function.
    global $post;
    $save_global_post = $post;

	$title = __('Recent Posts', 'widgets');
	$r = new WP_Query('showposts=10');
	if ($r->have_posts()) :
		<?php echo $before_widget; ?>
			<?php echo $before_title . $title . $after_title; ?>
			<?php  while ($r->have_posts()) : $r->the_post(); ?>
			<li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
			<?php endwhile; ?>
		<?php echo $after_widget; ?>
    $post = $save_global_post; // restore the global that was side effected by $r->the_post()
    setup_postdata($post); // and restore the other globals that we also side effected when $r->the_post() called setup_postdata()

May 27, 2007

Common Themes Directory for Multiple Instances of WordPress?

Filed under: development, themes, Wordpress plugins, WordpressMU — zappoman @ 7:39 am

I have multiple installs of WordPress and WordPressMU running in the same system, and I want them to share a common Themes. I’ve been diligently updating the same theme in multiple directories… and frankly it sucks. Then I came across this forum post and was blown away!

So, I’ve implemented a plugin that allows you to set an absolute or relative path to a common themes directory.

Installation: Download the code from the link below. Rename the file to common-themes.php and place it in your plugins directory. Activate it.

Download: You can get a copy of the code here.

Usage: Set options in “Options->Theme Root Options”. Enjoy.

May 26, 2007

Improved WordPress to WordPress Importer

I’ve been playing around with importing WordPress blogs from one instance to another, and I’ve been frustrated by some of the default features of the built in WordPress to WordPress importer.

So, I’ve implemented a new version of the importer that has the following features:

  • Attachments – This importer will download and “insert” the actual image files of an attachment record. So for example, if you’ve uploaded images to your WordPress blog, then they will be listed as attachments. The normal importer will store these records but no do anything with the actual image. So you basically end up with dead links. Not anymore. Now if the image is an attachment, the importer will attempt to download it and insert it into the new blog. All of this downloading happens on your server, so you don’t actually have the files download to your client machine.
  • Links – Links to your own blog are remapped. This is particularly important for image links to attachments (obviously) or else the attachment feature described above would be pretty whacked! But it also applies to cross links between your own blog posts. Seems like an obvious feature right? I thought so. This also applies to internal ping backs.
  • Spam Comments – For some reason the default importer decides to import comments tagged as spam. I guess I can imagine a few cases where this might make sense… but nah… I don’t think so. So this importer will discard any comments marked as spam.

Installation: Download the code from the link below. Rename the file to zappo_wordpress.php and place it in your wp-admin/import directory.

Download: You can get a copy of the code here.

Usage: Same as any other importer, go to Manage->Import. Enjoy.

By the way, I really only tested this on WordPressMu, but there isn’t anything about it that I would expect to fail on standalone WordPress. Feel free to report bugs if you see issues.

Hey Zappo – This thing is really chatty, what gives? Do you think you could make it not print out so much noise? – You

No. But you can. Enjoy! – Me

Latest wpmu-topposts plugin

Filed under: development, sql, Wordpress plugins, WordpressMU — zappoman @ 10:14 am

Version 0.42.4 of wpmu-topposts plugin now available…

Lots of changes:

  • Added support for top_blogs(), same calling convention as top_posts() but returns
    top blogs based on total hits to the blog for all posts on the blog.
  • Added a couple new arguments to top_posts() include a new max_per_blog which if set
    to 1 will limit the posts to 1 per blog.
  • Added days_back argument which will limit the stats to a certain number of days
    into the past.
  • Added many new formatting arguments to make it easyer to use the get_*_html functions
    and get the formating you want.
  • Fixed a couple bugs that would cause cache corruption (removed a call to
    update_post_caches() which was definitley corrupting the post cache)
  • Also correctly call switch_to_blog() in the get_*_html functions so that the
    blog template tags actually work properly.

Definitely my favorite new feature is the max_per_blog since it uses cool nested queries in SQL. yummy!

Here are some usage examples:

This will give you top posts in an ORDERED list, with hits included surrounded by square brackets.


This will give you top blogs in an UNORDERED list, without hits included.


As always, get the latest code here

April 26, 2007

New Version of Sub-directory Plugin… now acts more like WordPress

Filed under: development, Wordpress plugins, WordpressMU — zappoman @ 10:47 pm

I’ve updated the subdir-mu-plugins Plugin to behave a little bit more like WordPress’s plugins and a little less like WordPress MU’s plugins. The latest version (0.42.2) can be found here.

Here’s a little background:

WordPress single instance will only load files that have the “Plugin Name:” directive. This is partly related to the fact that WordPress supports disabling plugins through a user interface. WordPressMU supports this feature as well for the plugins placed in the “wp-content/plugins” directory. But these plugins are enabled and disabled on a blog by blog basis. For those plugins in “wp-conten/mu-plugins” it will load all PHP files. So for example, if a plugin has extra support PHP files that aren’t safe to load all the time (but can be loaded at the right time by the plugin for example) these types of plugins don’t work well in WordPressMU.

My original version of this subdirectory plugin was intended to mimic the original WordPressMU behavior of loading all php files. Well, this seemed like a good idea at the time, but really the point of this plugin was to allow you to use more WordPress (non-MU) designed plugins… those that lived in subdirectories. And well, many of those plugins also depend on WordPress’s behavior of not loading PHP files that don’t contain the “Plugin Name:” directive. So I’ve decided this original behavior wasn’t the best idea.

The new version will scan subdirectories and attempt to read the plugin-info from all PHP files and only load those PHP files who have a “Plugin Name” directive.

I’ve now changed the behavior of this subdirectory loading plugin to behave a little more like WordPress. Namely it will only load files from subdirectories that have a “Plugin Name” directive.

April 24, 2007

The Case of the Disappearing TinyMCE

I’ve been having off and on problems with my TinyMCE rich text editor disappearing from WordPress… At first it seemed very random, sometimes it was there sometimes it wasn’t. Then it seemed like the problem went away, as in TinyMCE didn’t go away, and then the problem came back, as in TinyMCE was nowhere to be found.

Well, this weekend I finally figured out at least one thing that would cause this problem to happen.

Apparently one of my plugins was outputting an extra couple lines of non-php at the end of the file. Although this seems like a perfectly innocuous thing it causes big trouble for TinyMCE specifically the gzip support built in to the wordpress/tinyMCE integration.

So imagine this…

* Example of PHP that does nothing, except
* break TinyMCE.
* Notice that after the 'end php tag' there are
* two blank lines.

These two extra lines will break TinyMCE. I haven’t found a minimal reproduce case yet, but I am sure this is related to the call to ob_start(“ob_gzhandler”); This sort of makes sense in that ob_start() is a relatively sensitive function insofaras you can’t call echo or other functions that output to the main output stream from within a callback function, but we’re not really doing that. I suspect there is some kind of a bug in ob_start() or in the ob_gzhandler handler that doesn’t like these kind of non-PHP outputs in the middle of a PHP stream.

Another case I found which creates this same behavior is…

* Example of PHP that does nothing, except
* break TinyMCE
* Notice that a single space outside of the
* php context.

?> <?php


Anyway, if you see your TinyMCE disappearing on you, then it may be that you have a plugin with a couple extra blank lines at the end of the file outside the context of the PHP script processor.

April 10, 2007

Creative Common License Chosen

Filed under: development — zappoman @ 8:09 am

I have decided to utilize the “Creative Commons Attribution-Noncommercial-Share Alike 3.0 License” for all code released on this blog. I will be updating all the source shortly to reflect this change.

Creative Commons License

This work is licensed under a:

Creative Commons Attribution – Noncommercial – Share Alike 3.0 License.

My reasoning behind this choice is as follows:

  • I intend for these posts to be informative and educational. They are not intended to be fully functioning implementations. They are intended to represent reusable ideas. Therefore, you shouldn’t need more than this license to learn from what I’m presenting here.
  • If you are planning on using this as is, then I would like you to give me the appropriate level of credit. And if you see me on the street, please introduce yourself and say “Thanks Man!”
  • If you are planning on using this code as is for commercial purposes, then, well, please contact me. I make my living as a technologist, and if you’re making money off my hard work, then I want some control over that. That being said, I don’t mind teaching you what I’ve learned, and so please feel free to read my code, learn from it, and go about your business as you see fit.


April 6, 2007

Update to WPMU- Top Posts Plugin

Filed under: development, Wordpress plugins, WordpressMU — zappoman @ 12:51 am

Note, I’ve updated the code to 0.42.1 with the following changes…

  • Small bug fix to ‘maybe_create_table’ behavior. Namely, we used to try to load it if this function wasn’t available, and now we simply check that the function is available.
  • Added blog_id to the posts returned by get_top_posts. This can be useful in forming correct permalinks to your blog posts.
  • Added function zap_setup_post_globals() which in some cases will setup the globals for other wordpressmu templates to work, but this doesn’t always reliably work

You can get the latest code here.

Older Posts »

Blog at WordPress.com.