google+ wordpress plugin – googleCards-WordPress

As promised in yesterdays post, I have turned my google+ profile scraper class into a wordpress plugin.

google+ for wordpress
the google+ cards widget

The plugin adds a widget to your wordpress install that will display your ‘googleCard’ in your blog’s sidebar.

Download
Github

Installation
1. Download googlecards.zip and unzip
2. Upload the unzipped googlecards folder to the `/wp-content/plugins/` directory
3. Activate the plugin through the ‘Plugins’ menu in WordPress
4. Go to the ‘Widgets’ menu in WordPress and add the widget to your sidebar.
5. Choose a title for the widget and input your google+ id. (You can find your google+ id by going to your profile, it is the 21 digit number e.g. plus.google.com/YOUR_ID_IS_HERE).

If you like this plugin, please give it a rating and review on the WordPress Plugin directory 🙂

How to show the widget in a template
If you don’t have a widgetized sidebar or you would just like to display the widget somewhere in your template, you can do so by adding the following php snippet to your template where you want the googleCard to appear :

01
02
03
04
05
06
07
08
09
10
11
<!–?php $instance = array( ‘title’ =–> ‘Follow me on Google+’, // your widget title
‘plus_id’ => ‘111270891764039363851’, // your google+ id
‘credit’ => 1
);
$args = array(‘before_title’ => ‘</pre>
<h3 class=”widget-title”>’, ‘after_title’ => ‘</h3>
<pre>
‘);
$gc = new GoogleCardsWidget();
$gc->widget($args,$instance);
?>
Note : You will need version 0.4.3 or later for this snippet to work, and it is only needed if you don’t want to use the standard widget.

Changelog
0.4.5
Fixes profile image and circle count fetching problems. (Google changed the layout of user profiles which broke the scraper in the plugin).

0.4.4
Added option to add rel=”author” to google plus profile links, and the option to open the links in a new window / tab.

0.4.3
Added contribution from Joe Vaughan for using the WordPress 3.0 widget API so widget can be used in multiple sidebars. Thanks Joe, chapeau. Also added the option to disable the developer credit if you’re a really mean sort of person and removed the example Google+ ID. (note to wordpress.org – I am not Larry Page. Unfortunately. This message sent from my $45million luxury yacht)

0.4.2
Forever alone – fix for bug when no one has the google+ account in a circle.

0.4.1
Test for safe_mode and open_basedir. Fixes curl_setopt() bug.

0.4
Added file_get_contents as a backup for curl and use the transients API if we cant use a cache file. Tell curl not to verify https. Some minor css stuff.

0.3.1
Some css fixes for people with big names and small sidebars.

0.3
Fix for lowercase names in wordpress plugin directory

0.2
Fixed some caching and css problems

0.1
Initial release

FAQ
If you get ‘Couldn’t get data from Google+’ when running the plugin, before asking for help please turn on PHP error reporting and see if your error matches something in the FAQ.

1. I get the error “Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in plugins/googlecards/googleCardClass.php on line 25“.
This is a problem with your PHP setup. You are almost certainly running PHP4. The plugin requires PHP5. WordPress requires PHP5 after version 3.2 too. Talk to your host about using PHP5.

2. I get the error “Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /*****/*****/public_html/blog/wp-content/plugins/googlecards/googleCardClass.php on line 181“.
You probably have something other than your Google+ id in the Google+ id box. Make sure you just put in the numbers from the url of your Google+ profile and nothing else.

3. I get the error “Warning: file_get_contents(http://plus.google.com/*******… [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden“.
This is a HTTP 403 error from Google+, it means they have banned your server’s IP from making requests to their servers. This usually isn’t anything to do with the plugin (it makes very few calls to Google’s servers) and it is more likely that you are on shared hosting, and someone else who shares your IP has been scraping Google.

4. I get the error “file_get_contents(http://plus.google.com/… [function.file-get-contents]: failed to open stream: Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?“.
Because Google+ is HTTPS, you need to get your host to enable openssl and configure it for PHP.

5. I get the error “Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/web1281/html/wordpress/wp-content/plugins/googlecards/googleCardClass.php on line 181“.
AND/OR I get the error “Warning: file_get_contents(http://plus.google.com/1082378… [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /var/www/web1281/html/wordpress/wp-content/plugins/googlecards/googleCardClass.php on line 181“.
The plugin requires either CURL or file_get_contents() to be enabled on your server.If your host gives you access to your php.ini then you can change the ‘allow_url_fopen’ setting to ’1′ which will fix your problem. Otherwise speak to your host and ask them to enable CURL or allow_url_fopen for you.

Updated 9/7/2011 : I’ve just uploaded a new version of the plugin to the wordpress directory (version 0.3.1). This hopefully fixes alot of the styling problems people with big names and small sidebars were having.
I’m also no-longer hosting the plugin here as you can get it from the official wordpress plugin directory now.
For people still having problems fetching data from google+, I hope to have that completely fixed in a later update but try using version 0.3.1 if you are using an earlier version.

Updated 11/7/2011 : I’ve just released a major update to the plugin, if you were having problems fetching google plus data please update your plugin to version 0.4 immediately. The new version no longer requires a file for caching (but will use it if it’s there) and adds a backup method for getting data from google+ that hopefully should fix most of the ‘Couldn’t get data from google+’ errors.
Update 2: Updated to 0.4.1 – I added a test to see if safe_mode is or open_basedir is set in php.ini – If they are google+ cards now avoids using curl to stop the Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /wp-content/plugins/googlecards/googleCardClass.php error.
Update 3 : Version 0.4.2 – codenamed forever alone fixes a bug where the google+ card would not show if no-one had you in a circle.

Updated 14/7/2011 : I’ve just released version 0.4.3 of the google+ cards plugin. This should probably be considered a major update as it uses the WordPress 3.0 widget functions instead of the legacy ones, thanks to Joe Vaughan for the github contribution. This version therefore allows you to use the googleCards widget in multiple widgetised sidebars on your blog.
I had to remove the default Google+ ID by WordPress.org’s request and I have also included an option for you to disable crediting me in the widget if you’re cruel and heartless 😉
One more thing! Because of the new way of hooking into wordpress widgets, when you upgrade to this version you will need to re-add the widget and put your Google+ id in again. Sorry, won’t happen again.

Updated 04/8/2011 : I’ve just pushed out version 0.4.5 of the googleCards plugin. This was a bit of a forced update as Google changed the structure of user profile pages on Google+, which broke the scraping function of the plugin. The new version should fix circle counts and user images not showing. You will need to either delete your cache file after updating or clear the wordpress transient cache. Otherwise wait a (default) maximum of 4 hours and it should start working again. Please don’t complain in the comments until you have either cleared the cache or waited 4 hours after updating, thanks!

Leave a Comment

Your email address will not be published. Required fields are marked *