Archive for the ‘Plugins’ category

WordPress SB Mail Attachment Widget Update (V1.1)

January 31st, 2012

A minor update today to improve the delivery efficiency of the emails with attachments. If you have no idea what this plugin is then check out my original post on it a few weeks ago here.

Some users were reporting issues with the email coming through as ignoring the HTTP headers and including all of them within the email itself. A big mess indeed. Now it uses the wp_mail command so it can be hooked into by other plugins. Also because of this function usage it means that I don’t need to write the headers manually.. WordPress does all that for you. It should now be a lot more compatible with the various mail clients.

Download it here: SB Mail Attachment Widget (2.7 kB)

SB Mail Attachment Widget

December 5th, 2011

Ever wanted to use a simple contact form for your site where people can attach a file? Well I did for a recent project of mine. We wanted people to be able to apply for jobs whilst keeping the site very simple. Each post linked to a job and the consultant responsible for the job was set as the post author. Using a plugin like Contact Form 7 or Gravity Forms we thought we would be able to make up a form that people could fill in and, depending on the author of the post/page it’s on, send the email to one of many recipients.

Simple right using one of those bulky and, sometimes, advanced plugins? No…

I decided to write a plugin for it. The fields we wanted were clear, who are you, how can we get in touch with you and can you attach your CV? Well I wrote just that. This plugin adds a widget which allows you to configure the form and the email which gets sent. Most importantly it allows you to either set a fixed recipient address for the email or allow it to be set by the post author when the form is submitted. Emails sent with an attachment and it does work very well indeed (or did for us).

Note from the screenshot that you can include in the intro paragraph the name of the person who is to be informed if you so wish (admin2 in our case).

I am happy to make amends to this plugin for anyone if they will use it. I dare say I shall use it again in the future. I hope someone finds it useful if only for something to base their own plugin on.

Download it here: SB Mail Attachment Widget (2.7 kB)

SB Tell a Friend Widget

November 30th, 2011

I was looking for a widget to allow people to tell their friends about a site for a client of mine and realised that any I found in the WordPress repository were forcing you to use a third party service to do such a simple job. I wrote this plugin to do just that. It creates a widget for you to use on your site which is very flexible and requires no signups or payments to anything.

It was written for a recruitment company so the screenshot shows it in the job vacancy context. The title, intro paragraph (optional) and labels for the boxes are all configurable via the widget as is the content of the email sent to the recommended person.

Currently there are no stats logged for usage of this plugin but it’s something I am going to be looking at in due course. It would be nice, for instance, to record the details of each recommendation sent either in our own system or in Google Analytics.

Download it here: SB Tell a Friend (2.03 kB)

Getting the WordPress Excerpt outside of The Loop

November 16th, 2011

I have been working my way around this one for a few months now, never bothering to think about the best solution. There is not, in fact, a WordPress simple function to get the excerpt outside of the WordPress loop. Why would you want to do that you ask…

Example:

I have a plugin I have written to create a basic shopping cart and shop front. It makes use of a simple shortcode on a Page to generate the shop which is based on a custom post type called Products. The Loop is used on the main page itself to generate the WordPress Page and subsequently process the shortcode. I loop through the products using a query_posts statement to bung the data into an array (for caching and manipulating so using a child Loop isn’t possible here) and then loop over it again later on. I want to show the Excerpt (which may or may not exist) on the shop front and the full description for my individual product pages.

So I initially thought of doing something like the following:

<?php
$product = get_page($product_id);
echo $product->post_excerpt;
?>

What this approach does wrong is returns nothing at all when the user hasn’t filled in an Excerpt for the product they entered. WordPress normally takes a selection of text from the main content, strips out any HTML and shortcodes and shows that instead.

Next option is this:

<?php
echo get_the_excerpt();
?>

What this does is prints the excerpt for the page which the shop front it hosted on (the parent page) because, as far as The Loop is concerned, the context of the page isn’t a shop front, it’s just a normal Page.

So why does this not work?

<?php
echo get_the_excerpt($product_id);
?>

Well some bright spark on a blog out in the ether thought it did however, regardless of what the argument for the function was initially, it no longer works as has been depracated (the argument that is).

So what’s the solution… well sadly it’s a custom function of your own. Luckily for you I have backtraced the code and writted my own little version of the above and it works a treat…

<?php
        function get_the_excerpt($id=false) {
            global $post;

            $old_post = $post;
            if ($id != $post->ID) {
                $post = get_page($id);
            }

            if (!$excerpt = trim($post->post_excerpt)) {
                $excerpt = $post->post_content;
                $excerpt = strip_shortcodes( $excerpt );
                $excerpt = apply_filters('the_content', $excerpt);
                $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
                $excerpt = strip_tags($excerpt);
                $excerpt_length = apply_filters('excerpt_length', 55);
                $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');

                $words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
                if ( count($words) > $excerpt_length ) {
                    array_pop($words);
                    $excerpt = implode(' ', $words);
                    $excerpt = $excerpt . $excerpt_more;
                } else {
                    $excerpt = implode(' ', $words);
                }
            }

            $post = $old_post;

            return $excerpt;
        }
?>

I have put mine in a class I used for my plugins these days as a helper function however just rename it (to avoid a naming conflict with it’s namesake) and call it from your plugin or theme as you would normally.

hope this helps someone out. Please let me know if anyone knows a better or simpler way. This works for me but I really wish there wasn’t such a monumental oversight by the WordPress guys on this one (other than creating sub loops which just feels wrong and inflexible to me)

Simple custom post type features for WordPress

July 15th, 2011

I have been using custom post types in WordPress for a long time now…. In fact each new theme or plugin I write I tend to integrate a custom post type and some supplementary meta boxes here and there. If you have no idea what i’m talking about then this article probably isn’t for you… however read on and I shall explain briefly.

Custom post types are wonderful for parts of sites that don’t generally fit into the standard Post or Page model. For instance WP Ecommerce (the most popular WP shopping cart) has just started using custom post types for storing their products… you will get the idea, products being a custom post type. If I say that they are a way of storing things in WordPress that can, if needed, provide a way of administering these objects as if they were a page like any other.

Adding them yourself requires some code and adding the fields that will appear on the page will require some more. This isn’t what I want to go over right now as there is an easier way. To get an idea of what I mean, see the following screenshots…

Note the bottom three, they are custom post types

This admin interface is generated for you with 0 effort.

“Products” is generated by WP Ecommerce and my theme added “FAQs” and “Photography”. The second screenshot shows the admin interface, similar to the post/page editor, which is generated and the meta boxes which can be added very easily indeed to make it appear that way. The way that these can be added without writing any code would be to use one of the ‘More’ plugins…. These are More Fields, More Types and More Taxonomies… all freely available WordPress plugins although I tend not to use them these days (I write them into my themes instead). Take a look though.

This article was really to outline what you do with the data within these types in the real world. Of course storing the data is easy, using it requires some imagination really. The post type items are stored in the wp_posts table and the fields you add as meta data are stored in wp_usermeta. You can easily retrieve the information using standard WordPress functions.

The following function can be used to get all of the photography items and store them in an Array of Objects for looping and output any way you see fit…

function get_custom_post_type_items($custom_post_type) {
	$args = array(
	'post_type' => $custom_post_type,
	'post_status' => 'publish',
	'posts_per_page' =>-1,
	'orderby' => 'post_date',
	'order' => 'DESC'
	);

	$posts = new WP_Query($args);
	$return = array();

	if ($posts->have_posts()) {
		while ($posts->have_posts()) {
			$posts->the_post();

			$post_id = get_the_ID();

			$sub_post = new stdClass();
			$sub_post->post_id = $post_id;
			$sub_post->title = get_the_title();
			$sub_post->permalink = get_permalink($post_id);
			$sub_post->content = wpautop(get_the_content());
			$sub_post->meta_data = get_post_meta($post_id, 'meta_data_name, true);

			$return[] = $sub_post;
		}
	}

	wp_reset_query();

	return $return;
}

You can use this function in your functions.php file in your theme to be called by a page template or a shortcode if you add one to return the items you have added as custom post types. I have added a single meta data item called meta_data in each row which gets a custom field from the custom post type item called meta_data_name. In my Photography example I would just have more lines like this to get the various items from my custom meta box

$sub_post->png_image = get_post_meta($post_id, 'png_image_url, true);

Another good example use of this function would be for a featured items slider that you often see at the top of websites. One or more pages might have a portfolio item slider or a rotating banner or something. In that case you would call my function from your header.php file then loop through it outputting the appropriate HTML per line before using something like a jQuery call to construct the slider.

When you understand the applications for custom post types you might be finding yourself using them in more and more creative ways. I wrote a custom meta box a while back to link custom post type items to each other across different types. This was to allow staff member types to be linked to team and office types and so on. Then using this association you can output something like a dynamic organisational chart using a shortcode or a custom page template without having to hard code a thing.

This is a thinker, I imagine, for some people. Get in touch with me if you want any help putting these custom post types in place and utilising them on your site.

Zen Cart Welcome Email Editor Update

July 12th, 2011

Just a quick one today. I have recently updated my Welcome email editor for Zencart. Not much of a change but a helpful user said that coupon codes weren’t working. They now do along with a few more hooks and options. Comments and suggestions welcome! Enjoy!

Original post here: http://www.sean-barton.co.uk/2008/07/zen-cart-welcome-email-editor/

Here’s the download link: Welcome Email Editor for ZenCart (5.29 kB)

SB Uploader gets an upgrade

June 27th, 2011

It’s been a while since I have posted anything, simply because I have been too busy with work and family etc… However, this is a good one for you. I have just spent the last couple of days on and off extending the SB Uploader plugin. For those of you that don’t know what it does it’s a meta box that sits in the post/page interface within WordPress and allows you to upload images and attach them to your content effortlessly and without being bombarded with options such as those that WordPress gives by default.

This new update adds some really useful features to the plugin. They are as follows:

  • Multiple instances of an uploader meaning you can have more than one image per page
  • Shortcodes added so you can effortlessly use your images within your content without coding
  • Configurable names (custom field names) for uploads so you aren’t stuck with post_image (see screenshot in gallery below)
  • Not only posts and pages, it now works with categories, tags and other taxonomies as well
  • Widgets added for both post and taxonomy images. Backup text/HTML added or optionally hides widget if no image uploaded

Grab a copy now from the WordPress extend directory. It’s free remember so worth a go. Please do let me know if you would like help using it or if you can think of any way of bettering it. I always enjoy a good challenge!

Download it here http://wordpress.org/extend/plugins/sb-uploader