Archive for the ‘PHP’ category

How to integrate Mandrill into your PHP site

May 18th, 2013

You might have heard of Mailchimp… who hasn’t these days! Well the same guys have released a rather nice little system called Mandrill (or did earlier this year at least). It is a transactional SMTP relax service with a rather nice little API for those who care.

For those that don’t give a monkeys (get it.. monkeys?!) I have a barebones little bit of PHP code for you to use which will effect the sending of your emails. Most sites using PHP have a central ‘mail’ command. There will be a function in a file or include somewhere which will handle the sending of mail using this sort of syntax:

mail($to, $subject, $body);

Quite simple.. it’s how PHP sends emails normally. The following code is to replace that mail command. Don’t forget to enter your API key!

$to = 'test@test.com';
$content = '<p>this is the emails html <a href="www.google.co.uk">content</a></p>';
$subject = 'this is the subject';
$from = 'test@mandrill.com';

$uri = 'https://mandrillapp.com/api/1.0/messages/send.json';
$api_key = 'YOUR KEY HERE';
$content_text = strip_tags($content);

$postString = '{
"key": "' . $api_key . '",
"message": {
 "html": "' . $content . '",
 "text": "' . $content_text . '",
 "subject": "' . $subject . '",
 "from_email": "' . $from . '",
 "from_name": "' . $from . '",
 "to": [
 {
 "email": "' . $to . '",
 "name": "' . $to . '"
 }
 ],
 "track_opens": true,
 "track_clicks": true,
 "auto_text": true,
 "url_strip_qs": true,
 "preserve_recipients": true
},
"async": false
}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);

You can also echo the $result variable to debug this code.. it will return a string of JSON with either a success message or an error. Rather useful I think!

SB Content Widget – WordPress plugin

April 29th, 2013

Another quick one from me today. I have written a widget for WordPress that simply allows you to output the content of a specific page (or the current one). Sometimes your design needs you to show page content in an area otherwise designed for different things, this allows you to do that. The widget has optional title with [post_title] shortcode hook and a Page ID option which, when left blank, will use the current page. I refer to Pages but this can be used for posts or custom post type items too.

Grab it here

SB Content Widget (923 bytes)

SB Add WooCommerce Tabs – WordPress Plugin

March 30th, 2013

You have been asking for this so I wrote it for you. This plugin is a very simply way of adding a WYSIWYG controlled tab to your WooCommerce products. It does the legwork for you and all you need to do it edit 1 line in the plugin file to set the tab name and to determine how many tabs you want. I have even provided examples for you in the code.

I might eventually add a little admin system to this but for now you get the following:

$sb_awt_tabs = array(
    'New Tab 1'=>50
    , 'New Tab 2'=>60
    // , 'New Tab 3'=>50
    // , 'New Tab 4'=>50
);

You wil note two tabs are uncommented and two are commented. Simply change the part at the start for the name and the second part is the priority. Very simply put the higher the number the further right in your tab list it will be. If you need more than 4 tabs then simply duplicate a line as normal.

Once you activate the plugin you will notice a new Tiny MCE editor at the bottom of each edit products page. Simply fill it in if you want the tab to show or leave it blank to hide the tab. Nice and easy!

I should add that if you include any shortcodes in the tab editor then they will be read also.. ie a YouTube video or something.

Download

SB Add WooCommerce Tabs (1.26 kB)

Note

This plugin only works with WooCommerce Version 2 or newer. I have already written another post last year to show you how to add new tabs to older versions.

SB Mini Features WordPress plugin

March 26th, 2013

I was inspired by the wonderful work of the WooThemes team when I saw and subsequently used the various features on the custom home pages that come with their theme work. I noticed that often a theme will create a number of custom post types in order to allow the admin to create a number of objects to be used in a specific point within a theme.

There is a common system called the Mini Feature. This is really a generic name for a small item with thumbnail and intro text to promote a feature or service of the site. We all know that home pages look boring if they match the rest of the site but often if you are trying to dream up a theme or make something yourself inspiration might be hard to come by. These little features break up a page using a shortcode to generate the output for a pre styled grid type view of the items in the post type.

Adding the plugin and activating it will add a new post type and taxonomy for you. When you use the shortcode ‘[sb_mini_feature]‘ it will show the last 6 in 3 column view from all features. I have, however, added support for a number of different argument to the shortcode as follows:

  • limit (default 6)
  • cols (default 3)
  • heading_type (default h2)
  • orderby (default menu_order)
  • cat (default none)

The last is worth talking about. It accepts the slug of an item of the new taxonomy that the plugin creates so you can create a mini feature list for different areas of your site if you wish.

The mini features are, by default, linked to their own item pages which will show the content you enter into the editor part of the feature. However, you might not want this and so I have allowed for a custom link to be used and also for the link to be disabled entirely. It should give enough flexibility for most situations.

The excerpt of the mini feature is shown verbatim if it exists. I have intentionally pulled this directly from the post object so that the excerpt_more filter is not used. This means no read more tag. I can make this optional if anyone feels they want a continue reading link.

Download

SB Mini Features (599.77 kB)

Screenshots

The plugin comes complete with a pre-styled 24 column responsive grid (in my experience 12 is never enough for complex layouts) with unique classnames to avoid conflict but you should be able to override these styles using your theme CSS. Examples of the output of the plugin in various forms are as follows:

 

SB Spider Framework

March 26th, 2013

Screen Shot 2013-03-26 at 22.10.17Ever wanted to work on a live site or a dev site without version control? I know a bit silly but what 90% of the developing population do. This script will spider your site files and report back any file paths which have been modified in a certain time frame. It means that if you make changes to a site you don’t need to keep a list of files you are editing. Simply run this script when you have finished your work and it will give you a list of changed files.

The script accepts a querystring parameter of time_frame which is in YYYY-MM-DD+HH:MM format. If not used then it will default to 24 hours before the time the page was loaded. I have used this for a few sites since writing it and find it invaluable. It is also particularly useful for monitoring what others are doing on your site if multiple developers are working on something or if you are hacked for instance and want to know which files have been changed in recent hours for instance.

Download

You can get the file below. Any changes you would like me to add please do say. It could easily be used to self refresh via CRON and then log to a file perhaps so as to maintain an audit trail for a server log.

SB Spider Framework (1.38 kB)

Note

Note that caching plugins and systems constantly refresh their files so make sure to exclude caching directories using one of the arrays at the top of the code before the result will make much useful sense.

How to remove the WooCommerce 2.0+ Reviews tab

March 7th, 2013

woothemes-ninja3On the 6th of March (I think) the lovely guys at WooThemes graced us with a lovely new version of their fantastic WooCommerce plugin. They changed a lot of things, most of which I have yet to absorb. A couple of notable things though caught my eye. You may or may not be aware that I have written a few tutorials concerning the WooCommerce tab system. Adding new ones and, of course, removing the reviews tab. Since 2.0 the product tab API has been updated and is now somewhat slightly more elegant. » Read more: How to remove the WooCommerce 2.0+ Reviews tab

WooCommerce VoguePay, CashEnvoy and Eyowo plugins now written

February 10th, 2013

gatewaysSome background perhaps.. Nigeria, as a nation, has a huge amount of stigma around it after various different online scams and a general feel of corruption about it. In fact I am sorry to say that the people of Nigeria have it incredibly hard on the internet and to make money is especially difficult because the big reputable payment processors like PayPal are not available to them. This is rather frustrating because over the last few weeks I have met and worked with (even outsourced work to) various Nigerian people and I have not got a bad thing to say about any of them. It’s sad, in my opinion, that the lack of PayPal hinders international business the way it does.

Anyway, soap box aside, I have to say that, despite this hinderance, I have taken on and completed 5 or 6 different projects and am happy to tell you about three of them right now.

Ever since I wrote the WooCommerce Interswitch WebPay plugin a couple of months ago I have had a stream of communications with various Nigerian business people who are interested in having a variety of different gateways integrated for them. I am pleased to announce that I have now completed work on the following three plugins

  • WooCommerce VoguePay plugin
  • WooCommerce CashEnvoy plugin
  • WooCommerce Eyowo plugin

That’s the good news. The bad news is that they were written on commission and the source is not mine to distribute unlike with the Interswitch WebPay module. However, in the name of vanity, I am very pleased with my work on all of these plugins and am hoping that my name being attached to them will give the work a certain level of credibility. I will release the URLs where more information can be gathered about these modules when I receive work back from my clients.

If anyone has an interest in these or any other payment gateway integrations for WordPress or any platform then please do get in touch with me and I will gladly work with/for you to find the integration that is right for you.

SB WooCommerce Facebook Comments Plugin

February 5th, 2013

woocommerce_logoThis was requested by a commenter on a previous post on a similar subject. I have written in the past extensively about removing the WooCommerce reviews tab. It was suggested that Facebook comments might be an interesting addition and so I have written a very small plugin to add one.

The plugin simply removes the existing WooCommerce Reviews Tab and creates a new one called Reviews showing the Facebook comments system instead. Because the plugin is basic I have provided a few simple options in the code itself. You can configure the title of the tab, the width of the comment area and the number of comments to show.

Simply edit the PHP variables as follows:

$sb_fc_tab_title = 'Reviews';
$sb_fc_width = '600'; 
$sb_fc_comments = '50';

This is a tab called ‘Reviews’,  a width of 600 pixels and to show 50 comments. Edit to suit.

UPDATE: Updated my code for WooCommerce 2.0+.  Use the following link:

SB WooCommerce Facebook Comments for WooCommerce 2.0+ (693 bytes)

For PRE-WooCommerce 2.0 installations:

SB WooCommerce Facebook Comments (696 bytes)

Any comments or feedback by all means let me know