
I finally got Denise to start working on Herrick Design. We’re enjoying playing with WordPress and sub-theming TwentyEleven.

I finally got Denise to start working on Herrick Design. We’re enjoying playing with WordPress and sub-theming TwentyEleven.
Stop custom editing core WordPress files… It’s all here: http://codex.wordpress.org/Writing_a_Plugin. It only seems like a small mountain the first time through. ;-)
I just whipped up some PHP and threw it in the root of a brand new WordPress 2.9.2 install:
Voila. The post appeared when navigating to the .php file.
See: http://prex.wordpress.org/Function_Reference/wp_insert_post.
For more creativity, get into the database: http://prex.wordpress.org/Function_Reference/wpdb_Class
From time to time I find myself wanting to replace a bit of text, in multiple files, throughout a huge directory tree (particularly in the case of a WordPress migration).
Here’s a method I frequently use (other examples I’ve seen out there make use of perl, xargs, grep, etc.):
user@host:~$ cd Directory_To_Start_From user@host:~$ find . -type f -exec sed -i 's/Text_To_Find/Replacement_Text/g' {} ;
The find command will return a list of all the files in the directory tree and execute the sed command on each one it locates. In the example below, I added the “-name” option to the find command to allow for working only on files with the .js extension:
user@host:~$ cd website user@host:~$ find . -type f -name "*.js" -exec sed -i 's/var pageName="example page";/var pageName="Final Page";/g' {} ;
In the next one, the text to find and replace has special characters (in this case the ‘/’ in the URL).
user@host:~$ cd website user@host:~$ find . -type f -exec sed -i 's/http://www.example.com/old_directory//http://newsubdomain.example.com/new_directory//g' {} ;
See the following links to read more about escaping special characters:
After wanting to test WordPress 3.0 on a 1and1 hosting account, I ran into the following issue… the particular setup I was dealing with had only one database available, and it wasn’t MySQL 5, but instead MySQL 4… furthermore, it was a version lower than 4.1.2, which more recent versions of WordPress require as a minimum.
So after doing a bit of research on what others had done, I went about fixing the problem. Interestingly enough, 1and1 could have made some money in this situation if they would allow customers to simply purchase another database to add to their packages, but no, they want an entire upgrade to be purchased.
The first step was to backup the website and database. I ssh’ed into the web host:
username@localhostname:~$ ssh $username@example.com
Then I backed up the database. The command below will dump all of the databases on the host (in this case, only one MySQL 4.x database) into a dated bzip file, in the home directory.
username@remotehostname:~$ mysqldump -C -A -u $databaseUsername -h $databaseHostName -p$databasePassword | bzip2 -cq9 > ~/`date +%F-%I-%M-%p`-db-backup.sql.bz2
Now to backup the site itself (not only in case disaster struck, but this would get a local copy of the sql dump I just made as well). On a local OS X workstation (or Ubuntu, if that suits your tastes) I ran something similar to the following:
username@localhostname:~$ mkdir ~/website_backups username@localhostname:~$ rsync -avz --exclude="logs" $username@example.com: ~/website_backups/
From there, I was able to log into the 1and1 control panel and delete the existing database. This allowed me to setup a new one, and in particular, choose MySQL 4 or 5 as the type.
Back to the 1and1 hosting account:
username@localhostname:~$ ssh $username@example.com
I uncompressed the sql dump:
username@remotehostname:~$ bunzip2 2010-01-14-01-59-PM-db-backup.sql.bz2
and was greeted with the raw sql in the file, “2010-01-14-01-59-PM-db-backup.sql”. From here it was only a hop skip and a jump away to restoration. It was necessary to edit the sql file in order to have it restore properly to the newly created database that was just created:
username@remotehostname:~$ nano -w 2010-01-14-01-59-PM-db-backup.sql
And I changed the $oldDatabaseName to $newDatabaseName.
-- -- Current Database: `$oldDatabaseName` --
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `$oldDatabaseName`;
USE `$oldDatabaseName`;
ctrl+o, enter, and ctrl+x, to save the file and exit nano. The sql dump was now ready to restore to the new database.
username@remotehostname:~$ mysql -u $databaseUsername -h $databaseHostName -p$databasePassword $databaseName < 2010-01-14-01-59-PM-db-backup.sql
The only other things to do were to update any existing applications that needed the new database name, username, hostname, and password.
As a note, if you are updating a WordPress install to point to a new database, this info can be changed in the file, wp-config.php.
I have gathered some of the better work that I have done over the years, took some screenshots, and posted them to a running instance of MooFlow.
See it at the following url: http://karlherrick.com/demo/pub/mooflow/
OpenOffice Base makes it incredibly easy to hook up to a MySQL database. Once this is accomplished you can easily create a front end to browse through your data, edit it, report on it, etc. Below are a few steps I took to create a functional setup:
What I did was:
By default, on two of my installs of reCAPTCHA Plugin for WordPress – v2.7, I receive no error message if the captcha is entered incorrectly… the user of the weblog is to assume that they made a mistake I guess…
That is until I wrote this script to check for error messages being passed around on the URL by the plugin:
if (window.location.search != "") { var searchArray = window.location.search.split("&"); for (var i=0; i < searchArray.length; i++) { var searchSubArray = searchArray[i].split("="); if (searchSubArray[0] == "rerror" && searchSubArray[1] == "incorrect-captcha-sol") { document.write("<p>The two words in the picture were typed incorrectly.</p>"); } } }
Just drop that snippet into your “comments.php” template. When the captcha is filled in incorrectly, the plugin adds “rerror=incorrect-captcha-sol” to the url. This checks for that string, and if found, writes an error message in red.
I implemented reCAPTCHA on this blog because of comment spam. If you are having issues leaving a comment let me know. ;-)
Installing a CAPTCHA implementation on WordPress is quite easy when using the reCAPTCHA plugin, however the styling is hard coded into the main php file included.
Goto the installation directory, for example, “wp-content/plugins/recaptcha-wordpress-2.7″ and edit recaptcha.php. Look for the line that embeds the theme type and change it.
var RecaptchaOptions = { theme : "red", tabindex : 5 };
I used the “clean” theme. There are other options and ideas for editing the code with css changes.