WordPress REST API returns error when updating quoted JSON data

My particular situation involved updating a user via REST API with a custom registered user meta.  The meta updates correctly the first time, and any time there is a change. However an error is thrown if the user update includes the unchanged user meta (i.e. I’m updating the user’s first name, but my solution includes all fields with each update). The user meta value was a quoted JSON object, but this also applies to other serialized values. This also occurs with custom meta for other types besides users, like posts or comments.

The server returns a 500 HTTP status, with the following response:

{“code”:”rest_meta_database_error”,”message”:”Could not update meta value in database.”,”data”:{“key”:”my_custom_meta_key”,”status”:500}}

Credit for identifying this bug goes to Corey Salzano. Corey’s solution is to first pull the data, and if there’s no change, omit it in the update request. I didn’t want to add another request to the server, so I came up with a server-side solution. It is provided below with no guarantees!

Note that you will have to change the hook update_user_metadata  and $meta_type  and $serialized_meta_keys  for your particular situation.

reCAPTCHA Scrolling Issue on iOS

The problem occurs when an iOS user succeeds in verifying a Google reCaptcha (with or without the additional challenges); the window scrolls down way past the CAPTCHA, which can be very confusing for users. It was brought to my attention because some users at a site I manage were confounded when they were scrolled to a login form below a registration form…they thought it was some vicious loop! ?

This issue is documented at Google Groups, GitHub, and stackoverflow. The latter link is where most of the code below is sourced from, so credit to Jacob Cruz.

This was all within the context of a Gravity Forms form, using their native CAPTCHA field. I placed the code shown below in an HTML field after the CAPTCHA field.

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 “wan_status.sh”, 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: wan_refresh.sh

$ ./wan_refresh.sh

wan_refresh.sh sources wan_status.sh which sources login.sh

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 “login.sh”, 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.

WordPress.org 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 Babelscribe.com

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.