Web Site Design Blog

Blog Category: Programming
January 18, 2015

I am using the Amazon Feeds API to automate listing items on Amazon for clients. My clients run a variety of shopping carts and CMS’s ranging from osCommerce to custom frameworks so a simple plugin doesn’t suit my needs. As is usually the case I need to be able to understand and customize my own per each individual client.

Unfortunately the documentation is a little sparse and fragmented for such a large and unforgiving specification. I will document some of the initial challenges I have run into as Google doesn’t seem to be able to provide quick answers.

Errors in the Feeds API PHP Client Library

There is a couple of ‘bugs’ in the Amazon Feeds API Section Client Library – PHP – Version 2009-01-01

Fatal error: Call to undefined method MarketplaceWebService_Model_GetFeedSubmissionResultResponse::_toXMLFragment() in /MarketplaceWebService/Model/GetFeedSubmissionResultResponse.php on line 189

The MarketplaceWebService_Model_GetFeedSubmissionResultResponse and SubmitFeedResponse call the _toXML() method. The method in the parent abstract class (MarketplaceWebService_Model) is named toXML().
Change line to:
$xml .= $this->toXMLFragment();

The next error is:

Catchable fatal error: Object of class DateTime could not be converted to string in /MarketplaceWebService/Model.php on line 140

The private method escapeXML of Model.php tries to run str_replace on a DateTime object. I resolved this issue by adding
if(is_object($str))
return;

to the top of the function.

Fork on Github

January 14, 2015

Add Google’s latest simple checkbox reCAPTCHA to WordPress default login page. This plugin will help secure your wordpress administration area against brute force hacking attacks using the latest, simple and elegant ‘No Captcha’ reCaptcha checkbox from Google.

* PHP 5.3 or greater required
Which you probably should be running by now anyways.

1. Download Plugin.

2. Install Plugin.

3. Get reCaptcha API Keys from Google.

4. Enter Keys in WP Admin -> Settings -> reCaptcha

You will need to check the Google reCaptcha box next time you log in.

Available on WordPress.org

Fork on Github

June 4, 2012

I recently added the Facebook comments and Addthis plugins to my site. One of the issues that occurred was a duplicate ‘Like’ button when the comments plugin loaded. After a quick look at the comments plugin code, I saw that the Facebook javascript SDK was being loaded in the footer.

add_action('wp_footer', 'fbmlsetup', 100);

My first instinct was to move this to the ‘wp_head’ hook, then I realized that wouldn’t be good because it would place the <div> and script inside the <head> element of the page. My experience told me this code is supposed to live right after the <body> tag. Apparently there is no such hook built into WordPress, but to create one in your theme is simple and painless.

In your theme’s functions.php add the following function named ‘after_body’:

function after_body(){
	do_action('after_body');
}

In your theme’s header.php call the ‘after_body’ function right after the <body> tag:

<body>
<?php after_body(); ?>

Now just a little hack to the plugin code, I commented out the ‘wp_footer’ hook and replaced it with the ‘after_body’ hook.

// moving this to head to avoid conflict with addThis buttons ... 
// add_action('wp_footer', 'fbmlsetup', 100);
add_action('after_body', 'fbmlsetup', 100);

This resolved the issue and helped me understand how simple it is to create a custom action hook in WordPress.