We’re getting the band back together!

I met my wife 5 years ago at the beginning of a run of the Sondheim musical Assassins at ART here in Portland. I played John Hinckley, Jr., the guy who shot Reagan in ’81. It was an amazing show, and not just because I met the love of my life. The show itself is great, the cast was stellar, we won a bunch of Drammies… its one of the best things I ever did as an actor.

I can hardly believe it, but thanks to Stumptown Stages and Cerimon House we get to do it again! Next Tuesday and Wednesday I’m singing in a benefit concert along with almost the whole cast of the ’06 Assassins, with the addition of legendary Portland performers Susannah Mars and Margie Boule. If you missed it the first time, you gotta check this out!

Posted in Musings | Tagged | Leave a comment

Clever checkbox handling with PHP

An unchecked checkbox returns nothing when a form is submitted, but most of the time you want it to return something, so you can work with that $_POST variable. This is easy with the addition of a hidden input with the same name as your checkbox:

<?php
    // If the box was checked, keep it checked
    if ( isset($_POST['yes']) && $_POST['yes'] == 'Yes' ) {
         $checked = 'checked="checked"';
    } else {
         $checked = '';
     }
?>

<form method="post" action="">
    <label for="yes">Yes?</label>

    <!-- Notice both inputs have the same name value -->
    <input type="hidden" value="No" name="yes" />
    <input type="checkbox" value="Yes" name="yes" <?php echo $checked ?> />

    <input type="submit" value="submit">
</form>

If the button is left unchecked, the checkbox will return false and $_POST['yes'] will equal the value of the hidden input. If the box is checked, the value of the checkbox will be returned. Neat!

Posted in Musings | Leave a comment

Lightbox + jQuery UI Dialog + IE8 = conflict city

It worked fine in Firefox, Safari, Chrome, and even IE7, but for some reason if you have the Lightbox 2 plugin installed and you enqueue jQuery UI Dialog you will get a whole mess of errors in Internet Explorer 8 when you create a dialog.

The solution is simple: disable Lightbox 2 and install the WP jQuery Lightbox plugin instead. Conflicts be gone!

Posted in Musings | Tagged , , , | Leave a comment

The cobbler has shoes! Finally!

After years of using the plain-jane but wonderful Thematic default theme for my personal site, I’ve finally gotten around to designing a theme of my very own. Its a child theme of Thematic like all my sites these days. The colors are from the Tango icons color palette. It was drawn in Inkscape and Gimp. The fancy font is from the open-source Google Web Font library. Its called “Lobster” and its my new favorite. Hope you like it!

Posted in Musings | Tagged , | Leave a comment

Show the jQuery version number

This prints the version of jQuery you’re using:

$.jquery();

Which is handy in situations where you don’t have direct access to the script itself. In Firebug you might do something like this:

console.log('jQuery version: ', $.jquery());

Posted in Musings | Tagged | Leave a comment

Control error reporting level in WordPress

When you enable error reporting in WordPress you automatically get all errors, notices, warnings and what have you written to your wp-content/debug.log. One of my plugins was creating so many undefined index errors it made the log impossible to read. I needed to fine tune my error reporting.

WordPress error reporting bypasses your php.ini settings and I couldn’t get .htaccess to have any effect on it either. The only thing that worked was hacking wp-includes/load.php.

Line 260 of wp-includes/load.php reads like this:

error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );

Which will show all errors. I changed it to this:

error_reporting( E_ERROR | E_WARNING | E_PARSE & ~E_DEPRECATED & ~E_STRICT );

Which will leave out notices but catch really important stuff like fatal errors. This will get overwritten on upgrades but I only use it on my development server anyway.

Happy debugging!

Posted in Musings | Tagged , | Leave a comment

Serve web pages from your home directory in Ubuntu 10.04

This guide assumes that you have lamp installed already (which is super easy in Ubuntu).

Enable the userdir mod

  1. $ cd /etc/apache2/mods-enabled
  2. $ sudo ln -s ../mods-available/userdir.conf
  3. $ sudo ln -s ../mods-available/userdir.load

Enable php parsing from a user directory

  1. $ sudo nano /etc/apache2/mods-available/php5.conf
  2. Comment out this code:
    <IfModule mod_userdir.c>
    <Directory /home/*/public_html>
    php_admin_value engine Off
    </Directory>
    </IfModule>
  3. So it looks like this:
    # <IfModule mod_userdir.c>
    # <Directory /home/*/public_html>
    # php_admin_value engine Off
    # </Directory>
    # </IfModule>

Make a public_html/ directory

  1. $ mkdir /home/username/public_html
  2. Your site will go in a sub-folder of this directory.  Lets call it mysite/.
  3. And while your at it, add a file to that public_html/ directory called index.html.  At the end of this, if all goes well, this is file will show up when you point your browser to: http://localhost/~username.  If you don’t put an index.html file in there, your browser will show a directory listing.  No biggy either way.

Set groups and permissions

  1. Add your user to the group www-data: $ sudo adduser username www-data
  2. Change your user’s home directory group to www-data: $ sudo chown username:www-data /home/username
  3. Add group read and execute permissions to your user’s home directory: $ sudo chmod 750 /home/username

Set up your site

  1. Create a new virtual host site: $ sudo touch /etc/apache2/sites-available/mysite.dev
  2. You can cut and paste the following into the file you just made, making the appropriate changes to reflect your own site.  The only difference between this and a file hosted in /var/www/ (your regular web root) is the DocumentRoot directive, which has to point to your public_html directory:

    <VirtualHost *:80>
    ServerName mysite.dev
    ServerAlias mysite.dev
    ServerAdmin me@email.com
    DocumentRoot /home/username/public_html/mysite/
    </VirtualHost>
  3. $ cd ../sites-enabled
  4. $ ln -s ../sites-available/mysite.dev mysite.dev

Add your site to the hosts file

The /etc/hosts file is the first place your browser checks when it tries to resolve a domain name to an IP address. In order for your browser to find your new development site, you have to add an entry in there.

  1. $ sudo nano /etc/hosts
  2. Add this line: 127.0.0.1     mysite.dev

Restart Apache

  1. $ sudo service apache2 restart

Check to see if it worked!

  1. In your browser, navigate to http://mysite.dev. You might have to reload and clear your cache (Shift+Ctrl+R in Firefox)
  2. Celebrate because your site showed up!
Posted in Musings | Tagged , , | Leave a comment

A fix for WP e-Commerce error: “The following directories are not writable”

If you get this error:

The following directories are not writable:

    * /var/www/mysite/wp-content/uploads/wpsc/downloadables/
    * /var/www/mysite/wp-content/uploads/wpsc/previews/
    * /var/www/mysite/wp-content/uploads/wpsc/product_images/
    * /var/www/mysite/wp-content/uploads/wpsc/product_images/thumbnails/
    * /var/www/mysite/wp-content/uploads/wpsc/category_images/
    * /var/www/mysite/wp-content/uploads/wpsc/upgrades/

You won't be able to upload any images or files here.
You will need to change the permissions on these directories
 to make them writable.

When you click on “Products” in WP e-Commerce, then I am about to make your day.

The fix

For whatever reason, the plugin isn’t able to create those directories itself. So first create the following files:

  • mysite/wp-content/uploads/
  • mysite/wp-content/uploads/wpsc/
  • mysite/wp-content/uploads/wpsc/category_images/
  • mysite/wp-content/uploads/wpsc/downloadables/
  • mysite/wp-content/uploads/wpsc/previews/
  • mysite/wp-content/uploads/wpsc/product_images/
  • mysite/wp-content/uploads/wpsc/upgrades/

Then set those files to the correct permissions:

$ chmod -R 777 mysite/wp-content/uploads/wpsc/

Now click on “Products” and the error should be gone!.

One more thing

Edited 3/14/2011

The final step is to secure your installation:

$ chmod -R 775 mysite/wp-content/uploads/wpsc/

Posted in Solutions | Tagged , | 4 Comments

Your WordPress blog already has custom feeds

I was this close to wasting a ton of time coding a plugin to produce a feed for a single category when I came across this:

http://codex.wordpress.org/WordPress_Feeds

Which let me know that WordPress already does what I need. Say you have a category, ‘events’, that you want to make into a feed. Here’s the URL:

http://www.exampleblog.com/category/events/feed

Done!

Posted in Musings | Leave a comment

Make your phpMyAdmin session persist… forever!

Or for a year, which is a pretty long time.

NOTE: This is for local development purposes only, cause it’s not safe enough for production servers.

  1. Open up /etc/phpmyadmin/config.inc.php in your favorite text editor (you must have root priviliges)
  2. Add the following lines to this file just inside the first if clause:
    /*
    * Prevent timeout for a year at a time.
    * (seconds * minutes * hours * days * weeks)
    */
    $cfg['LoginCookieValidity'] = 60*60*24*7*52;
    ini_set('session.gc_maxlifetime', $cfg['LoginCookieValidity']);
  3. Save the file and restart your server: $ sudo service apache2 restart

Thanks!

Thanks to Agaric’s Open Data blog for helping me find this Ubuntu Forums post.

Posted in Musings | Tagged , | Leave a comment