Commenter IP vs. the Load Balancer

I have always thought the support for WordPress has been amazing because it is so readily available, but this support went to a new level yesterday.  When I went to fix my most recent issue, I found that the solution was archived in a comment in the WordPress core (in this case, comment.php).  Troubleshooting doesn't get any easier than that.

The Problem

 I have a WordPress installation running on load balanced servers.  Whenever someone leaves a comment, instead of saving the Commenter's IP address to the database, WordPress saves the IP address of the load balancer.

Line 1310-1313 of comment.php provided the answer in a comment:

* We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure * that it is properly set, such as in wp-config.php, for your environment. * See {@link}

The ticket linked to a solution by Andrew Nacin that grabs the commenter's IP address from the server, checks to make sure it is the appropriate format, and sets the variable that comment.php will need to save the correct address.  The way our servers work, this solution worked by swapping out  HTTP_X_FORWARDED_FOR with HTTP_CLIENT_IP.


If you have a problem with WordPress, read its code.

Plotting Locations in Google Earth from 1960s Army Map Service Maps

I am new to using maps in my humanities reserach and I have found the maps created by the U.S. Army Map Service (AMS) in the 1960s pretty user-friendly.  When trying to plot MGRS coordinates in Google Earth, I ran into a few problems.  The free version of Google Earth does not accept MGRS coordinates, so I had to convert the coordinates to latitude and longitude using an web application.  Once I got the Lat/Lng for a location, I found that it was in the wrong place--Google Earth's  satellite view showed the location in the wrong grid square.  After quite a bit of searching, I think I have found the answer (although it may still turn out to be wrong).  At the bottom of the AMS map I was using, it said "Horizontal Datum: Indian Datum 1960."  Once I found a tool that allowed you to specify a datum, the converted coordaintes seemed to be in the correct place.

Change a Value in a .CSV with PHP

After downloading a number of .CSV files from the National Archives, I found that I needed to add a colon to some of the fields.  In fields that listed times, they were formatted as "900" and I wanted them to be "9:00."  While there are a number of a ways to get this done, I figured I could do it manually in a few minutes with Excel.  After about a half hour, I realized I was wrong and set out to do the same thing with PHP.  The problem was that I had already added the colon to some of the fields in the .CSV.  This is what I needed to do:

  1. Use PHP to open the .CSV
  2.  Determine if there was already a colon in the field I needed to edit
  3. If there is a colon, write the entire line to a new .CSV file.  If there wasn't a colon, add one in the appropriate spot and write the altered line to the new .CSV file
//without this line, the script placed all the lines 
//of the original .CSV into a single array
//rather than creating a new array for each line
ini_set("auto_detect_line_endings", true);

$input_csv = fopen('original_file.csv','r');
$output_csv = fopen('output.csv', 'w');

while($csv_line = fgetcsv($input_csv)) {
//see if the desired value contains a colon
$raw_time = $csv_line[17];
$position = strpos($raw_time, ':');

if ($position === false) {
//if the value does not contain a colon, insert it
//and write it to the new file
$csv_line[17] = substr_replace($raw_time, ":", -2,0);
fputcsv($output_csv, $csv_line);
} else {
//if the value already is formatted correctly,
//write it to the new file

Contributing to the WordPress Codex

Since starting to use WordPress in 2008, I have been meaning to contribute to it in some way.  There are many ways to contribute, so I figured it would be easy to help.  Initially, I found the idea of releasing a theme or plugin most appealing.  Submitting a patch seemed too intimidating, and writing documentation for the WordPress Codex did not sound fun.  However, I quickly learned that plugin and theme development moves fast.  By the time I got something together to release there were already other plugins or themes releases that solved the same problem.  So I continued to do my daily tasks of supporting various people's WordPress sites and put off contributing until later. After a few failed attempts at contributing something, I decided to take a different approach.  Every week I received several emails about using WordPress.  Most of these emails came from new site administrators who had little experience with WordPress and the Web in general.  I found I didn't have the time to individually reply to, or meet with, everyone who needed help.  In order to offer support in a more manageable way, I started writing tutorials for basic WordPress procedures.

Around the time I started writing tutorials, I signed up for the wp-docs listserve.  Wp-docs allows anyone who is interested to email one another about maintaining and creating the WordPress documentation in the Codex.  At first, I was intimidated by the prospect of emailing the group.  Mostly, I didn't feel like I had anything interesting to contribute.  However, in December 2011, an exchange of emails went out over the listserv that I found intriguing.  Lorelle (of Lorelle on WordPress) mentioned the abundance of  "WordPress guides" that institutions write to get their users started using WordPress.  As someone who had starting writing tutorials that could categorized as some sort of guide, I felt like this might be a place I could help.

After Lorelle's initial email, I waited about a month to see if anyone replied to it--I was still a little intimidated to email the group.  Eventually, I told myself to get over it and I asked about the status of the "guide" project.  After a few exchanges both on and off list, Lorelle told me that this idea wasn't going anywhere and if I wanted to write some documentation for beginners, the best place for it was WordPress Lessons.

Eventually we decided that I would write something about Gravatars for beginners.  I had used Gravatars before, but never looked in the core code of WordPress to understand how they work.  The Codex document I wrote didn't cover everything about the topic--only enough to get administrators started using them and the basics of incorporating them into a a theme.  After some editing and suggestions from Lorelle and the people on the wp-docs team (everyone one on the list is part of the "team", which is nice), my Codex document went live and I had finally contributed something to WordPress.

After contributing to the codex, albeit in a limited way, I found that I enjoyed writing documentation aimed at both users and developers.  To my surprise, I had a lot of fun writing for the codex (I particularly enjoyed reading the code in the WordPress core).  I hope to contribute more to the Codex and start contributing in other ways as well.