Filemaker and MySQL Floats in Relationship

I’ve been connecting a Filemaker Pro solution with a WordPress website for a client. In a matching relationship to a Gravity Forms table (rg_lead_detail) I was matching a local field with the Gravity Forms column “field_number” which is defined as a float. I noticed that the relationship was only matching whole integers, not numbers with decimals like “1.3”.

Researching this problem led me to this article about MySQL float columns not being precisely recorded:

If you store the number 1.3 in a float column of your database table, MySQL actually stores the number 1.2999999523162842.

My quick solution was to create two calculation fields, one high and one low based on the local field. The high calculation added 0.05 to the field, and the low field subtracted 0.05. This assumes the field only goes to tenths.

Edit Relationship

It works for this application, but I don’t see it working for solutions needing precision and accuracy to multiple decimal places.

TP-Link TL-R470T+ WAN Refresh Script

This is part 3 of 3… See the first post here.

In the first post of this series, I posted a script to login to the router’s web management page. The second post detailed the script that checks the status of each WAN connection.  The script below will refresh the WAN connections as needed.

This script depends on the second script “”, they should be placed in the same directory. This is the script to call to initiate a full check/refresh cycle.

At a prompt or via cron, you run this script:

$ ./ sources which sources

This script assumes two WAN connections. If you have more or less, you’ll have to make the appropriate changes. We use Google’s public DNS servers for the ping tests. This script alternates between the two, which is essential for this to work.

TP-Link TL-R470T+ WAN Status Script

This is part 2 of 3… See the first post here.

In the first post of this series, I posted a script to login to the router’s web management page. This post checks the status of each WAN connection.

This script depends on the first script “”, they should be placed in the same directory. This script assumes two WAN connections. If you have more or less, you’ll have to make the appropriate changes.

The script depends on some ugly RegEx matching to find the status of each WAN connection… I’m making due with what I have! No better interfaces are provided by TP-Link.

This is part 2 of 3… See the next post here.

WordPress 3.7.1 Update Causing Errors

upgrade_wordpressUpgrading to WordPress 3.7.1 broke a lot of backend (admin, wp-admin) pages. I got 404 Missing and sometimes 500 Internal Server Errors for themes.php, and options.php. No quick fixes were working…

Upgrading PHP from 5.3 to 5.4 solved all issues. states that the minimum PHP version required is version 5.2.4 or greater. I was using 5.2.11 and upgraded to 5.3.15. Good luck!

Compare Symlink and Target Modified Dates (script)

Here’s a short script that will check a specific directory for symbolic links and then:

  1. check the modification date of symlinks’ respective targets
  2. if the modification date of a symlink is older than the modification date of it’s target, the symlink is “touched” updating it’s modification date

That’s it. I created this to help make a file syncing service operate slightly differently than designed. Default behavior for this sync service was to follow symlinks, uploading the target (which is the desired behavior.) However it would only monitor the symlink for modification changes, not the target. This script bridges that gap. It also gives the added benefit of controlling how often syncs may occur, as you can set cron (or whatever) to run this script at an interval of your choosing.

This script works on Mac OS X 10.8 and has only been tested on such. It should work on other versions of OSX and is likely to work on various linux flavors (though I have noticed flags and behavior for the command “stat” differ between OS X and linux.)

Modify the above directory path, escaping any spaces, and leave the asterisk (*) on the end.

TP-Link TL-R470T+ Automated Login Script

TP-LINK TL-R470T+The TP-Link TL-R470T+ Load Balance Broadband Router performs mostly as desired and advertised. This is one of the very few load balancing routers under $150, coming in at about $55. As you might expect at that price point, it’s not perfect. One major limiting factor for my application is the limit of 16 (16?!) load balance policy rules. The only major flaw I’ve encountered in my use of this hardware is it’s “Online Detection” service.

The Problem: Online Detection
Determining if each WAN connection is online is an important feature of the router. Without this there would be no reliability. My connections are not the most reliable, hence the need for this router and two ISPs. I was often getting false positives and false negatives in online detection. Both false negatives and false positives are fairly disastrous for my network. I noticed that keeping the servers set to “manual” I would only receive false negatives (connection DOWN.) When I manually updated the settings for Online Detection, I could force the router to correctly refresh the status as long as the server addresses changed. I started using Google’s Public DNS hosts for ping and name resolution (in Online Detection settings) as I couldn’t trust the “Auto” setting. This was partially due to one WAN connection being a private subnet (double NAT).

Online Detection settings page

The Solution: Automatically Update the Settings Every 5 Minutes
It’s crazy I know, but it’s been working for many months now. Requests for help from tech support and community forums received no serious answers. I crafted a couple Bash shell scripts on a local Linux (Ubuntu) machine to run every 5 minutes, automating the change in settings for Online Detection’s servers. This way a WAN connection is incorrectly marked online or offline for no longer than 5 minutes. The single disadvantage I’ve experienced from this method is normal access of the admin web page. The router only allows access to the admin pages from one IP at a time. This means you have to load and make changes between those automated accesses every 5 minutes. The interval can be changed at your discretion of course.

The script below is one part of this solution, it authenticates with the router’s web interface. The following scripts use the cookie generated by this script to access the Online Detection page. I kept the scripts separate for functionality.


This is part 1 of 3… See the next post here.

Change Media Attachment Post in WordPress

When you upload an image or other media to a WordPress site via the “Add Media” button on a post (or page or custom type) edit page, that media is linked to that page. You can still insert that media on another post, or in a gallery on another post, but it is “forever” attached to the original post. I say “forever” because WordPress stock gives you no options for reattaching it (or detaching it.) This may be desired for many situations often involving 3rd party plugins. Your options are re-upload the media to the new post, alter the MySQL database directly or find a plugin that adds this functionality. Below is quick code that adds a link on the Media page for each Media Item.

Credit for this code goes to Andy Potanin via the WordPress forums here. Add it to your theme’s function.php file at the end. I just tested it with WordPress 3.5.1…


WP E-Commerce Using Incorrect Timezone

I noticed incorrect dates in the sales log, as well as incorrect expiration calculations for coupons… Not great things. WP E-Commerce appears to ignore the WordPress settings and use the server settings via PHP.

Quick fix solution, credit goes to

Set the server timezone by adding this to the header file of your theme:

<?php date_default_timezone_set ('Pacific/Auckland' ); ?>

Time zones are detailed here:

I just added it to the top of the theme’s function.php, seems more appropriate than any header template. Obviously you must adjust the argument for your timezone.

This instantly fixed and updated dates displayed everywhere in WP E-Commerce.

Creating a WP e-Commerce plugin: Settings Page API (fix)

Recently I’ve been developing a WordPress plugin to extend WP e-Commerce, a free storefront plugin. I used to use osCommerce, a robust PHP solution for shopping carts and heavily customized it. I was looking at this implementation of osCommerce (a great effort) as a WordPress plugin, but it was like reinventing the wheel–not worth it. WP e-Commerce is a native WordPress plugin, works well, has a huge user base and is (mostly) easy to extend.

The WP e-Commerce developers are kind enough to provide documentation for developers of plugins. Their page on “Settings Page API” describes the process of adding a tab to the WPEC settings page. While mostly straightforward there are two points that tripped me up:

  1. The  class WPSC_Settings_Tab_PLUGIN_SLUG extends WPSC_Settings_Tab needs to be inside the plugin tab function being described. This issue was mostly a result of my own dimness…
  2. This one seems to be a typo. The action hook tying in your plugin tab function as described is: However while using this action hook, my plugin settings tab was not accessible directly, only through an AJAX call after the settings page was already loaded. Also, I was using the optional  public function callback_submit_options()  to handle the form submission myself, and this was non-functional! Using the following hook fixed all this and resulted in a settings tab that functioned identically to the default tabs:

add_action( 'wpsc_register_settings_tabs', 'my_plugin_settings_tabs');  

It’s this the main query?

The main query in a WordPress site is the query based on the URL being accessed. When you access this post’s single page, the URL indicates the main query is the text you are reading right now. The “Recent Posts” widget on the sidebar is generated from a query, but not the main query.

There are a few methods to test for the “main query”. As of WordPress 3.3, there is a new way:


Examples: Using pre_get_posts hook | Using posts_where hook

There’s the old way (which is the basis for the above method):

In situations where I wanted to alter the content of a post (in the loop) if it was the main query, the above methods didn’t work reliably. I attempted to hook into the pre_get_posts action and set a global variable, which I would then test in the content filter function. I reasoned that the variable would be set to true before the loop, and then set to false if another query was called after that. The results however were always false.

My solution was to set a global variable with the post ID in a wp_head action, then test that against the post ID while in the loop (every time the_content filter is called.) Code below…

Now it’s quite possible this is not the most direct, efficient or reliable method. I welcome your comments if you have suggestions or concerns.