<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:series="http://unfoldingneurons.com/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Wptuts+</title> <link>http://wp.tutsplus.com</link> <description>WordPress Tutorials</description> <lastBuildDate>Sat, 18 May 2013 15:30:35 +0000</lastBuildDate> <language /> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Wptuts" /><feedburner:info uri="wptuts" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>Wptuts</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Take Your Skills to the Next Level, Build Your Own Plugins</title><link>http://feedproxy.google.com/~r/Wptuts/~3/iXBVq3u8XV8/</link> <comments>http://wp.tutsplus.com/articles/news/take-your-skills-to-the-next-level-build-your-own-plugins/#comments</comments> <pubDate>Sat, 18 May 2013 15:30:35 +0000</pubDate> <dc:creator>Joel Bankhead</dc:creator> <category><![CDATA[News]]></category> <category><![CDATA[development]]></category> <category><![CDATA[Plugins]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31705</guid> <description>&lt;p&gt;&lt;strong&gt;There are only a few Early Bird tickets left for our fantastic new workshop led by Instructor Tom McFarlin: &lt;a
href="http://enva.to/106v8eX"&gt;Introduction to WordPress Plugin Development&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Are you an aspiring WordPress developer? Are you ready to take the next step and start building your own custom plugins for WordPress? Our newest Tuts+ Live Workshop is the perfect way to get started!&lt;/p&gt;&lt;p&gt;Tom is going to teach you how to write a WordPress plugin that connects to the &lt;a
href="http://is.gd"&gt;is.gd&lt;/a&gt; API in order to implement an alternative URL shortner to the built-in wp.me shortner.&lt;/p&gt;&lt;p&gt;The goal of the plugin is to demonstrate:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;How to write an object-oriented based plugin.&lt;/li&gt;&lt;li&gt;How to interface with a third-party API.&lt;/li&gt;&lt;li&gt;How to introduce a custom meta box.&lt;/li&gt;&lt;li&gt;How to perform input validation and sanitization.&lt;/li&gt;&lt;p&gt;&lt;strong&gt;Early Bird tickets are half-price at only $49&lt;/strong&gt;, but places are strictly limited so act fast to make sure you don’t miss out!&lt;br
/&gt; &lt;span
id="more-31705"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Introduction to WordPress Plugin Development&lt;/h2&gt;&lt;p&gt;Our newest Tuts+ Live Workshop, Introduction to WordPress Plugin Development, teaches you everything that you need to know to start developing WordPress plugins; from setting up a local development environment, all the way through to building a WordPress plugin that&amp;#8217;s ready for release into the WordPress Plugin Repository.&lt;/p&gt;&lt;p&gt;It&amp;#8217;s led by Instructor Tom McFarlin, a self-employed WordPress developer who divides his time between running his own WordPress development shop, building plugins for WordPress, blogging every day about software development in the context of WordPress, and working for 8BIT (the team responsible for Standard Theme and WP Daily).&lt;/p&gt;&lt;p&gt;Each weekly workshop will last one hour, running over a five week period. You&amp;#8217;ll have the opportunity to follow along with Tom, ask questions live during the workshop, and complete a weekly homework assignment. Not able to make it to the live recording? No problem! All of the workshop recordings will be made available online the day after the live workshop.&lt;/p&gt;&lt;p&gt;&lt;a
href="http://enva.to/106v8eX"&gt;Learn more about Introduction to WordPress Plugin Development&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;iframe
width="640" height="360" src="http://www.youtube.com/embed/QErsaJMdmCc?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Grab an Early Bird Ticket Now!&lt;/h2&gt;&lt;p&gt;We’re offering a &lt;strong&gt;special Early Bird price of $49&lt;/strong&gt;, but these tickets are limited. Once the Early Bird tickets have disappeared, the workshop will be $99.&lt;/p&gt;&lt;p&gt;If you’re interested in future workshops then definitely &lt;a
href="http://eepurl.com/qnEP5"&gt;join the Tuts+ Live Workshops mailing list&lt;/a&gt; to stay posted on upcoming workshops and get notified as soon as they’re available, the Early Bird tickets for our previous workshops have all sold out, so it’s worth getting ahead of the game!&lt;/p&gt;&lt;p&gt;We’re really excited about new workshop, &lt;a
href="http://enva.to/106v8eX"&gt;Introduction to WordPress Plugin Development&lt;/a&gt;, but places are strictly limited so act fast to make sure you don’t miss out!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/iXBVq3u8XV8" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/articles/news/take-your-skills-to-the-next-level-build-your-own-plugins/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://wp.tutsplus.com/articles/news/take-your-skills-to-the-next-level-build-your-own-plugins/</feedburner:origLink></item> <item><title>Design Patterns in WordPress: The Simple Factory Pattern</title><link>http://feedproxy.google.com/~r/Wptuts/~3/5pBVx7cN4do/</link> <comments>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-the-simple-factory-pattern/#comments</comments> <pubDate>Fri, 17 May 2013 13:34:36 +0000</pubDate> <dc:creator>Tom McFarlin</dc:creator> <category><![CDATA[Creative Coding]]></category> <category><![CDATA[design patterns]]></category> <category><![CDATA[plugin development]]></category> <category><![CDATA[Theme Development]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31652</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 3 of 3 in the series &lt;a
href="http://wp.tutsplus.com/series/design-patterns-in-wordpress/" class="series-1118" title="Design Patterns in WordPress"&gt;Design Patterns in WordPress&lt;/a&gt;&lt;/div&gt;&lt;p&gt;In this series, we&amp;#8217;re taking a look at design patterns and how we can leverage them to our advantage when building products on top of WordPress.&lt;/p&gt;&lt;p&gt;The nice thing about design patterns is that they aren&amp;#8217;t explicitly limited to themes or plugins &amp;#8211; they are handy in a variety of different scenarios. It&amp;#8217;s simply a matter of being able to identify which patterns are applicable to certain scenarios.&lt;span
id="more-31652"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;In the last post, we reviewed the Singleton Pattern. In this article, we&amp;#8217;re going to take a look at the Simple Factory Pattern which is especially useful when you have a number of different classes each of which has a unique purpose and solves a specific problem.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#8217;ll take a look at another pattern &amp;#8211; the Simple Factory Pattern &amp;#8211; which is useful when you have a number of classes each of which has a unique purpose and that can be selected based on certain criteria.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;The Factory Method Pattern&lt;/h2&gt;&lt;p&gt;The Simple Factory Pattern is actually derived from a pattern known as the Factory Method Pattern which is a slightly more complicated version of the pattern that we&amp;#8217;re going to be reviewing.&lt;/p&gt;&lt;p&gt;According to &lt;a
title="The Factory Method Pattern" href="http://en.wikipedia.org/wiki/Factory_method_pattern" target="_blank"&gt;Wikipedia&lt;/a&gt;, the Factory Method pattern is defined as follows:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The factory method pattern is an object-oriented creational design pattern to implement the concept of factories and deals with the problem of creating objects (products) without specifying the exact class of object that will be created&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Sounds a bit complicated, doesn&amp;#8217;t it?&lt;/p&gt;&lt;p&gt;The truth is, it&amp;#8217;s actually a really powerful design pattern but it would take a much longer article to discuss it, and it&amp;#8217;s a bit out of scope for the purpose of this series.&lt;/p&gt;&lt;p&gt;So, as mentioned, we&amp;#8217;re going to take a look at a version of the pattern that&amp;#8217;s paired down a little bit and &lt;em&gt;should&lt;/em&gt; be more generally applicable to less complicated projects.&lt;/p&gt;&lt;p&gt;Before we do that, let&amp;#8217;s come up with a definition of the Simple Factory Pattern:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The Simple Factory pattern returns a specific set of data or a specific class based on its input.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Ah the risk of making a pun, simple, right?&lt;/p&gt;&lt;h3&gt;A Note About the Simple Factory Pattern&lt;/h3&gt;&lt;p&gt;The truth is, many software engineers refer to the Simple Factory more as an idiom than a full-blown pattern; others consider this a pattern.&lt;/p&gt;&lt;p&gt;For what it&amp;#8217;s worth, I see it as a very simple pattern. It has a specific use case that can be easily identified when to use it during the course of development which we&amp;#8217;ll review later in this article.&lt;/p&gt;&lt;p&gt;Regardless, I bring this up so that if you see this used as an idiom (or a pattern) used throughout various articles on the Internet, or even in conversation, you&amp;#8217;ll know that the developers in question are referring to the same programming strategy &amp;#8211; just in a different way.&lt;/p&gt;&lt;h3&gt;So Why Does This Matter in WordPress?&lt;/h3&gt;&lt;p&gt;Just as design patterns in non-WordPress specific projects, such as larger applications, the design patterns provide a tried and true way to solve a common problem.&lt;/p&gt;&lt;p&gt;It helps to abstract our code a bit, keep our project easily maintainable, easily readable, and can actually help us to keep our code lean. This may result in us actually having more &lt;em&gt;files&lt;/em&gt; in our project, but each file should have fewer lines of code.&lt;/p&gt;&lt;p&gt;This means that each file should have a specific purpose that should be clear, not only to us, but future developers as well.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;What It Looks Like&lt;/h2&gt;&lt;p&gt;Now, before we dive into the diagrams, talking about classes, and the strategies required to implement the actual pattern, I want to mention that we&amp;#8217;re going to be taking a simple approach to this.&lt;/p&gt;&lt;p&gt;The thing is, the readership of this blog spans a wide array of experiences &amp;#8211; we have some people who are learning to write code; others who are seasoned veterans.&lt;/p&gt;&lt;p&gt;In order to appeal to the majority of the readership, we need to strike a balance. So for those of you who have been involved with software engineering for years, this may seem overly simplistic; however, don&amp;#8217;t skim it &amp;#8211; perhaps you&amp;#8217;ll pick up something new.&lt;/p&gt;&lt;p&gt;For those of you who are beginners or even intermediate programmers, pay close attention to what we&amp;#8217;re discussing as it can provide dividends in future (or even existing) work.&lt;/p&gt;&lt;h3&gt;The Purpose of the Simple Factory&lt;/h3&gt;&lt;p&gt;So imagine this scenario: You&amp;#8217;re working on a function that takes in a set of input &amp;#8211; usually some type of unique string or integer &amp;#8211; and you have this long &lt;code&gt;if/else&lt;/code&gt; statement or perhaps you have this large &lt;code&gt;switch/case&lt;/code&gt; statement that continues to grow as your project grows.&lt;/p&gt;&lt;p&gt;The problem is that the conditionals become a pain to manage. In fact case conditionals, or the case blocks, may actually end up doing as much work as a certain function should do.&lt;/p&gt;&lt;p&gt;This is where the Simple Factory comes into play. What we can do is abstract the details happening in each of the conditionals into their own class thus making it much easier to maintain and keeping the code much leaner.&lt;/p&gt;&lt;p&gt;And &lt;em&gt;that&lt;/em&gt; is the Simple Factory Pattern.&lt;/p&gt;&lt;h3&gt;A Look at the Pattern&lt;/h3&gt; &lt;figure
class="tutorial_image"&gt;&lt;img
class="aligncenter  wp-image-31657" alt="The Simple Factory Pattern" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/05/2013-05-10-14.58.37.png" width="737" height="553" /&gt;&lt;/figure&gt;&lt;p&gt;So here are the key features of the Simple Factory Pattern:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Notice that the Plugin class has a private reference to the Factory class&lt;/li&gt;&lt;li&gt;The Factory class encapsulates all of the logic to return an object of the type User&lt;/li&gt;&lt;li&gt;The User class is a base class for three other classes: Admin, Volunteer, Reader, and the idea is that each of these types are subclasses of users with unique functionality of their own&lt;/li&gt;&lt;li&gt;The Plugin will receive a certain type of input that it will pass to the Factory&lt;/li&gt;&lt;li&gt;The Factory will examine the input and then, based on its value, will return one of the three user types&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Nothing &lt;em&gt;too&lt;/em&gt; complicated, right? Honestly, I think that the diagram is a bit more complicated than the principles at play. It really provides a lot of flexibility &lt;em&gt;especially&lt;/em&gt; whenever you&amp;#8217;re looking to introduce another User type like an Editor or something similar.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This is &lt;em&gt;not&lt;/em&gt; to be confused with WordPress&amp;#8217; built-in user types. This is simply an example to show what the pattern would look like.&lt;/p&gt;&lt;h3&gt;A Working Example&lt;/h3&gt;&lt;p&gt;Now that we&amp;#8217;ve taken a look at the diagram for the pattern, let&amp;#8217;s take a look at the source code in action. Below, we&amp;#8217;ll look at the source code for each class and then I&amp;#8217;ll provide a download to a fully documented demo after the discussion.&lt;/p&gt;&lt;h4&gt;The Plugin&lt;/h4&gt;&lt;p&gt;First, let&amp;#8217;s look at the plugin class. Remember, this is nothing more than a prototype of what the pattern looks like. It&amp;#8217;s not the same thing as a fully developed WordPress plugin.&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php

include_once( 'simple-factory.php' );

class Plugin {

	private $factory;

	public function __construct() {
		$this-&amp;gt;factory = new Simple_Factory();
	}

	public function get_user( $permission ) {
		return $this-&amp;gt;factory-&amp;gt;get_user( $permission );
	}

}

?&amp;gt;
&lt;/pre&gt;&lt;p&gt;Notice that the plugin is relatively simple:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;It includes the &lt;strong&gt;simple-factory.php&lt;/strong&gt; script in the header of the file&lt;/li&gt;&lt;li&gt;It then defines a constructor in which it sets the &lt;code&gt;$factory&lt;/code&gt; property to an instance of the &lt;code&gt;Simple_Factory&lt;/code&gt;&lt;/li&gt;&lt;li&gt;The only method available in the plugin is &lt;code&gt;get_user&lt;/code&gt; which returns a user based on a type&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We&amp;#8217;ll see how this comes into play after we&amp;#8217;ve examined all of the other classes.&lt;/p&gt;&lt;h4&gt;The User&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;User&lt;/code&gt; is an abstract base class that provides a basic constructor and an abstract function that must be implemented by all other subclasses.&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php

abstract class User {

	private $role;

	public function __construct( $role ) {
		$this-&amp;gt;role = $role;
	}

	abstract public function get_role();

}

?&amp;gt;
&lt;/pre&gt;&lt;p&gt;Note that this class is intended to be subclassed by a variety of other classes, each of which we&amp;#8217;ll look at in detail momentarily.&lt;/p&gt;&lt;h4&gt;The Administrator, The Reader, and The Volunteer&lt;/h4&gt;&lt;p&gt;The following four classes are all separate files each of which subclass the &lt;code&gt;User&lt;/code&gt; base class. I&amp;#8217;ve opted to include them all here together because there&amp;#8217;s so little deviation from their actual implementation that it should be easy enough to follow.&lt;/p&gt;&lt;h5&gt;The Administrator&lt;/h5&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php

class Admin extends User {

	public function __construct() {
		$this-&amp;gt;role = &amp;quot;Administrator&amp;quot;;
	}

	public function get_role() {
		return $this-&amp;gt;role;
	}

}

?&amp;gt;
&lt;/pre&gt;&lt;h5&gt;The Reader&lt;/h5&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php

class Reader extends User {

	public function __construct() {
		$this-&amp;gt;role = &amp;quot;Reader&amp;quot;;
	}

	public function get_role() {
		return $this-&amp;gt;role;
	}

}

?&amp;gt;
&lt;/pre&gt;&lt;h5&gt;The Volunteer&lt;/h5&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php

class Volunteer extends User {

	public function __construct() {
		$this-&amp;gt;role = &amp;quot;Volunteer&amp;quot;;
	}

	public function get_role() {
		return $this-&amp;gt;role;
	}

}

?&amp;gt;
&lt;/pre&gt;&lt;p&gt;As usual, leave me questions in the comments; otherwise, review the code then be sure to read up on &lt;em&gt;The Simple Factory&lt;/em&gt; which is the next section &amp;#8211; it ties all of this together.&lt;/p&gt;&lt;p&gt;Also, remember that all of this code will be shared at the end of the article along with code comments that describe exactly what&amp;#8217;s happening.&lt;/p&gt;&lt;h4&gt;The Simple Factory&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;Simple_Factory&lt;/code&gt; class is really the crux of the entire pattern. Here is where all the decisions are made and the appropriate objects are returned.&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php

include_once( 'users/user.php' );
include_once( 'users/admin.php' );
include_once( 'users/volunteer.php' );
include_once( 'users/reader.php' );

class Simple_Factory {

	public function get_user( $permission ) {

		switch( strtolower( $permission ) ) {

			case 'read-write':
				$user = new Admin();
				break;

			case 'help':
				$user = new Volunteer();
				break;

			case 'read':
				$user = new Reader();
				break;

			default:
				$user = null;
				break;

		}

		return $user;

	}

}

?&amp;gt;
&lt;/pre&gt;&lt;p&gt;Note that the &lt;code&gt;Simple_Factory&lt;/code&gt; includes the base user class and its subclasses and then works to return the appropriate type of user based on the incoming set of permissions.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;The Advantages of the Simple Factory Pattern&lt;/h2&gt;&lt;p&gt;Though it should be a bit obvious by this point in the article, the Simple Factory Pattern provides a number of advantages especially if you&amp;#8217;re used to working with large conditionals.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;It provides an elegant way to abstract your code so there&amp;#8217;s less visual clutter&lt;/li&gt;&lt;li&gt;It allows you to introduce specialized, focused classes with a single purpose (which is great if you follow the &lt;a
title="SOLID Principles" href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)" target="_blank"&gt;SOLID&lt;/a&gt; principles)&lt;/li&gt;&lt;li&gt;It makes the code more maintainable as there&amp;#8217;s a single place where classes are instantiated, and each class serves a single purpose&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Overall, this is one of my favorite patterns simply for the matter of code organization and specialization that it can bring to the table.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Finally, you can checkout the entire source code &amp;#8211; complete with documentation and installation instructions &amp;#8211; on GitHub using &lt;a
title="Simple Factory Example" href="https://github.com/tommcfarlin/simple-factory-example" target="_blank"&gt;this link&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;At this point, we&amp;#8217;ve taken a look at three patterns:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;The Observer Pattern&lt;/li&gt;&lt;li&gt;The Singleton Pattern&lt;/li&gt;&lt;li&gt;The Simple Factory Pattern&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This series could go one for a while; however, I think that we&amp;#8217;ve covered enough ground at least to get many of us started with implementing patterns into our work.&lt;/p&gt;&lt;p&gt;So in the last article in the series, we&amp;#8217;ll recap what we&amp;#8217;ve learned and I&amp;#8217;ll also recommend some other patterns, their purpose, and some further points of research that should continue to aid you in continuing to learn about design patterns and their advantages not only in WordPress development, but general software development, as well.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/5pBVx7cN4do" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-the-simple-factory-pattern/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <series:name><![CDATA[Design Patterns in WordPress]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-the-simple-factory-pattern/</feedburner:origLink></item> <item><title>Quick Tip: After the Content – Share This</title><link>http://feedproxy.google.com/~r/Wptuts/~3/8PB_Rupv_bs/</link> <comments>http://wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-share-this/#comments</comments> <pubDate>Thu, 16 May 2013 12:47:51 +0000</pubDate> <dc:creator>Barış Ünver</dc:creator> <category><![CDATA[Tips]]></category> <category><![CDATA[content]]></category> <category><![CDATA[social media]]></category> <category><![CDATA[social plugins]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=30790</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 7 of 7 in the series &lt;a
href="http://wp.tutsplus.com/series/after-the-content/" class="series-1085" title="After the Content"&gt;After the Content&lt;/a&gt;&lt;/div&gt;&lt;p&gt;If we&amp;#8217;re saying that content is &amp;#8220;king&amp;#8221;, social media might as well be the &amp;#8220;queen&amp;#8221;. We can safely claim that social media is the most efficient way to spread the content around the web, in our time.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#8217;re going to cover how and why we should include a &amp;#8220;Share This&amp;#8221; section with our content.&lt;span
id="more-30790"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;&amp;#8220;Share This&amp;#8221; for Instant (And Free) Content Promotion&lt;/h2&gt;&lt;p&gt;In the golden era of social media, it would be silly not to encourage people to share your content on social networks like Facebook, Twitter, Pinterest, or Google+.&lt;/p&gt;&lt;p&gt;Yes, we live in a social world and it&amp;#8217;s not just something we do among our friends. I wrote this quick tip in Turkey, my editor published it in Australia and while a German reader gave it a five-star rating, an Iranian reader shared this quick tip on Twitter and a Korean friend of his retweeted his tweet. Just ten years ago, this wasn&amp;#8217;t possible at all.&lt;/p&gt;&lt;p&gt;Think of this example and think about your own blog. It doesn&amp;#8217;t have to be an international magnificance but you can reach a serious amount of people with the power of social media. With WordPress, it&amp;#8217;s ridiculously easy to go viral &amp;#8211; as long as you create quality content and allow your visitors to share that quality.&lt;/p&gt;&lt;h3&gt;Plugins to Offer a &amp;#8220;Share This&amp;#8221; Section&lt;/h3&gt;&lt;p&gt;As you can imagine, creating a &amp;#8220;Share This&amp;#8221; section manually is relatively easy. You could just get the &amp;#8220;widget codes&amp;#8221; of the social networks you like and replace the URLs with &lt;code&gt;&amp;lt;?php the_permalink(); ?&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;?php the_title(); ?&amp;gt;&lt;/code&gt; inside the widget code, if necessary.&lt;/p&gt;&lt;p&gt;Then it&amp;#8217;s all HTML:&lt;/p&gt;&lt;pre class="brush: xml; title: ; notranslate"&gt;
&amp;lt;div class=&amp;quot;share-this&amp;quot;&amp;gt;
	&amp;lt;div class=&amp;quot;twitter&amp;quot;&amp;gt;&amp;lt;!-- The widget code --&amp;gt;&amp;lt;/div&amp;gt;
	&amp;lt;div class=&amp;quot;facebook&amp;quot;&amp;gt;&amp;lt;!-- The widget code --&amp;gt;&amp;lt;/div&amp;gt;
	&amp;lt;div class=&amp;quot;google-plus&amp;quot;&amp;gt;&amp;lt;!-- The widget code --&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;p&gt;But there&amp;#8217;s an even easier way to create this section: with plugins. These plugins will most probably suffice for your blog and will fit your theme like a glove:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;&lt;a
href="http://wordpress.org/extend/plugins/jetpack/"&gt;Jetpack by WordPress.com&lt;/a&gt;&lt;/strong&gt; &amp;#8211; WordPress&amp;#8217; own &amp;#8220;feature pack&amp;#8221; comes with a variety of little plugins, including a sharing section which provides an elegant bar at the bottom of your posts, right after the post content. If you&amp;#8217;re already using Jetpack (like me), this is probably the best solution for you.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a
href="http://wordpress.org/extend/plugins/digg-digg/"&gt;Digg Digg&lt;/a&gt;&lt;/strong&gt; &amp;#8211; Digg Digg might be considered as a &amp;#8220;more comprehensive solution&amp;#8221; for sharing, in comparison to Jetpack&amp;#8217;s share buttons. It allows you to put the buttons before or after the content, or even as a floating bar along with the content. It also lets you choose big or small buttons to fit better with your design. If you like to take control with many, many options, this plugin is right for you.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;a
href="http://wordpress.org/extend/plugins/addthis/"&gt;Share Buttons by AddThis&lt;/a&gt;&lt;/strong&gt; &amp;#8211; It looks like yet another plugin that gives you share buttons. However, along with a membership on AddThis.com, this plugin shows you in-depth analytics of how your content is shared. If you&amp;#8217;re interested in your content&amp;#8217;s sharing statistics, this is the plugin you should use.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are, of course, &lt;a
href="http://wordpress.org/extend/plugins/search.php?q=share"&gt;many more share plugins&lt;/a&gt; out there and you may find some of them even better than the big guys above. My personal choice is Jetpack, but that&amp;#8217;s because I use many other features of the plugin along with the share buttons.&lt;/p&gt;&lt;p&gt;I recommend experiencing as many choices as possible (including the one with just HTML) and decide which one is the best based on your findings.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As I said before, we&amp;#8217;re communicating in a &lt;em&gt;social&lt;/em&gt; web now. If you want people to reach you, you have to provide share buttons for your content, &amp;#8220;the king&amp;#8221;.&lt;/p&gt;&lt;p&gt;Do you think there are better plugins (or non-plugin solutions) about social sharing sections worth mentioning? Post your comments below &amp;#8211; it&amp;#8217;s always important for you to share your thoughts with us!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/8PB_Rupv_bs" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-share-this/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[After the Content]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-share-this/</feedburner:origLink></item> <item><title>Design Patterns in WordPress: The Singleton Pattern</title><link>http://feedproxy.google.com/~r/Wptuts/~3/LiE2W9rPjEo/</link> <comments>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-the-singleton-pattern/#comments</comments> <pubDate>Tue, 14 May 2013 13:45:00 +0000</pubDate> <dc:creator>Tom McFarlin</dc:creator> <category><![CDATA[Creative Coding]]></category> <category><![CDATA[design patterns]]></category> <category><![CDATA[plugin development]]></category> <category><![CDATA[Theme Development]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31621</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 2 of 3 in the series &lt;a
href="http://wp.tutsplus.com/series/design-patterns-in-wordpress/" class="series-1118" title="Design Patterns in WordPress"&gt;Design Patterns in WordPress&lt;/a&gt;&lt;/div&gt;&lt;p&gt;Throughout this series, we&amp;#8217;re taking a look at the significance of design patterns and the roles that they play in WordPress development.&lt;/p&gt;&lt;p&gt;In the first post in the series, we took a high-level survey and even reviewed the Observer Pattern to see how it&amp;#8217;s possible to register various functions or objects with certain events that occur within the lifecycle of an application.&lt;/p&gt;&lt;p&gt;In this post, where&amp;#8217;s going to take a look at the Singleton Pattern.&lt;span
id="more-31621"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Specifically, we&amp;#8217;re going to take a look at the definition of the pattern and how it works, we&amp;#8217;re going to review a diagram of what the architecture of the pattern looks like, we&amp;#8217;ll cover some sample code for the pattern, and then we&amp;#8217;ll discuss the advantages of the pattern as it relates to WordPress development.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;The Singleton Pattern&lt;/h2&gt;&lt;p&gt;&lt;a
title="Singleton Pattern" href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank"&gt;Wikipedia&lt;/a&gt; defines the Singleton Pattern as follows:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Perhaps a simpler way of explaining the pattern is this: The Singleton Pattern ensures that a class can only have one instance and it provides a single way to retrieve an instance of itself.&lt;/p&gt;&lt;h3&gt;So Why Does This Matter in WordPress?&lt;/h3&gt;&lt;p&gt;As far as theme development is concerned, I personally don&amp;#8217;t see much of a use for it unless you&amp;#8217;re bundling some type of helper class or library with your theme; however, if you&amp;#8217;re building plugins, then this can be exceptionally useful.&lt;/p&gt;&lt;p&gt;As of now, there are really only a handful of ways to instantiate plugins (excluding widgets &amp;#8211; that&amp;#8217;s another topic) within WordPress:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You can instantiate the plugin at the bottom of your plugin file, but this can lead to an orphaned object&lt;/li&gt;&lt;li&gt;You can stick the plugin in the PHP &lt;code&gt;$GLOBALS&lt;/code&gt; collection, but this can be dangerous as you could trash something that already exists or it&amp;#8217;s making the collection needlessly larger&lt;/li&gt;&lt;li&gt;If you instantiate it with, say, each page load then the data isn&amp;#8217;t being persisted unless you serialize and hammer the database each time the plugin is instantiated&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;None of the above are particularly &lt;em&gt;good&lt;/em&gt; strategies (although you could make a case that they all work).&lt;/p&gt;&lt;p&gt;However, we care more than just getting something to work, right? We want it to work and we want an elegant solution to the problem. This is where design patterns &amp;#8211; more specifically, the Singleton Pattern &amp;#8211; come into play.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;What It Looks Like&lt;/h2&gt;&lt;p&gt;First, let&amp;#8217;s take a look at a diagram of the Singleton Pattern. Check out the diagram below, then we&amp;#8217;ll talk about the specifics after the image:&lt;/p&gt; &lt;figure
class="tutorial_image"&gt;&lt;img
class="aligncenter  wp-image-31622" alt="The Singleton Pattern" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/05/2013-05-08-08.26.26.png" width="737" height="553" /&gt;&lt;/figure&gt;&lt;p&gt;So here are the key features of the Singleton Pattern:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;There is a private, static instance variable defined in the attributes that is used to maintain a reference to the class&lt;/li&gt;&lt;li&gt;The constructor has been marked as private&lt;/li&gt;&lt;li&gt;There is a public static function named &lt;code&gt;get_instance&lt;/code&gt; which is used to return an instance of the class&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Nothing &lt;em&gt;too&lt;/em&gt; complicated, but I think reviewing the code for the Singleton Pattern goes a long way in making it a bit clearer, so let&amp;#8217;s do that now:&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
class Foo {

	/*--------------------------------------------*
	 * Attributes
	 *--------------------------------------------*/

	/** Refers to a single instance of this class. */
	private static $instance = null;

	/*--------------------------------------------*
	 * Constructor
	 *--------------------------------------------*/

	/**
	 * Creates or returns an instance of this class.
	 *
	 * @return	Foo	A single instance of this class.
	 */
	public static function get_instance() {

		if ( null == self::$instance ) {
			self::$instance = new self;
		}

		return self::$instance;

	} // end get_instance;

	/**
	 * Initializes the plugin by setting localization, filters, and administration functions.
	 */
	private function __construct() {

	} // end constructor

	/*--------------------------------------------*
	 * Functions
	 *--------------------------------------------*/

} // end class

Foo::get_instance();
&lt;/pre&gt;&lt;p&gt;Obviously, there&amp;#8217;s been &lt;em&gt;a lot&lt;/em&gt; of code left out of the above class, but the pattern&amp;#8217;s principles remain.&lt;/p&gt;&lt;p&gt;Notice that we have a private, static instance variable that&amp;#8217;s used to refer to this class. Specifically, it&amp;#8217;s set in the &lt;code&gt;get_instance&lt;/code&gt; function whereas the constructor has been marked as private.&lt;/p&gt;&lt;p&gt;Typically, when instantiating classes, the constructor is the function that is called whenever we initialize classes; however, in this case, the constructor is marked as private.&lt;/p&gt;&lt;p&gt;So what gives?&lt;/p&gt;&lt;p&gt;Notice that we have a public &lt;code&gt;get_instance&lt;/code&gt; function just above the constructor. This function literally checks to see if the static instance variable is &lt;code&gt;null&lt;/code&gt; and, if so, creates a new instance of the class (which it can do since it&amp;#8217;s within the context of the class); otherwise, it returns the current instance.&lt;/p&gt;&lt;p&gt;This is how no more than a single instance of a class is created.&lt;/p&gt;&lt;p&gt;Finally, note that we instantiate the class &lt;em&gt;not&lt;/em&gt; with the standard &lt;code&gt;new&lt;/code&gt; keyword, but by calling &lt;code&gt;get_instance&lt;/code&gt;. Not only that, but we also get future references to the class by using the same method.&lt;/p&gt;&lt;p&gt;So, for example, let&amp;#8217;s say that you&amp;#8217;re working in another template and you need to call a function &amp;#8211; say &lt;code&gt;bar()&lt;/code&gt; &amp;#8211; that exists in your plugin. In that case, you&amp;#8217;d do something like this:&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
$foo = Foo::get_instance();
$foo-&amp;gt;bar();
&lt;/pre&gt;&lt;p&gt;Pretty neat, isn&amp;#8217;t it?&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;The Advantages of the Singleton Pattern&lt;/h2&gt;&lt;p&gt;Despite the fact that we&amp;#8217;ve covered the Singleton Pattern from an architectural and a practical standpoint, we haven&amp;#8217;t actually talked about the advantages of the pattern.&lt;/p&gt;&lt;p&gt;Generally speaking:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The Singleton Pattern prevents other objects or clients from duplicating instances of the class. This makes sure that there&amp;#8217;s only one copy of the data maintained at any given time. All access to the object is done so by the single instance.&lt;/li&gt;&lt;li&gt;We have a wide array of flexibility when it comes to implementation because we can actually impact the instantiation process (though this is a bit out of scope for this particular post).&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Perhaps the largest drawback from using the pattern is lack of clarity that the plugin actually uses the pattern. If someone tries to instantiate the class, instantiation will fail because there&amp;#8217;s no public constructor.&lt;/p&gt;&lt;p&gt;As such, documentation is key.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Whether you&amp;#8217;ve seen them before or this is your first foray into design patterns, the Singleton Pattern is arguably the simplest design pattern there is. It&amp;#8217;s easy to implement, and it provides a significant source of functionality when implemented correctly especially as it relates to web applications.&lt;/p&gt;&lt;p&gt;In the next post, we&amp;#8217;ll take a look at another pattern &amp;#8211; the Simple Factory Pattern &amp;#8211; which is useful when you have a number of classes each of which has a unique purpose and that will be needed based on certain input criteria.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/LiE2W9rPjEo" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-the-singleton-pattern/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <series:name><![CDATA[Design Patterns in WordPress]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-the-singleton-pattern/</feedburner:origLink></item> <item><title>Design Patterns in WordPress: An Introduction</title><link>http://feedproxy.google.com/~r/Wptuts/~3/9OSVpqV7FhY/</link> <comments>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-an-introduction/#comments</comments> <pubDate>Fri, 10 May 2013 12:23:48 +0000</pubDate> <dc:creator>Tom McFarlin</dc:creator> <category><![CDATA[Creative Coding]]></category> <category><![CDATA[design patterns]]></category> <category><![CDATA[plugin development]]></category> <category><![CDATA[Theme Development]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31604</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 1 of 3 in the series &lt;a
href="http://wp.tutsplus.com/series/design-patterns-in-wordpress/" class="series-1118" title="Design Patterns in WordPress"&gt;Design Patterns in WordPress&lt;/a&gt;&lt;/div&gt;&lt;p&gt;For those who have an extensive background in software engineering, design patterns should be familiar territory; however, there&amp;#8217;s an entire group of developers &amp;#8211; especially in the web development community &amp;#8211; who aren&amp;#8217;t necessarily familiar with design patterns (even though they&amp;#8217;ve likely used them!).&lt;/p&gt;&lt;p&gt;In this series, we&amp;#8217;re going to take a look at design patterns, specifically in the context of WordPress, how they&amp;#8217;re useful, and some practical examples that we can use in our themes and plugins.&lt;span
id="more-31604"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The ultimate goal of the series is to provide a solid definition of what design patterns are, why they&amp;#8217;re useful, how they&amp;#8217;re used in WordPress core, and then review two popular examples that we can easily employ in our own work.&lt;/p&gt;&lt;p&gt;Before we get to taking a look at some practical examples, let&amp;#8217;s define design patterns, and look at an example of how they are used in WordPress core.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Design Patterns Defined&lt;/h2&gt;&lt;p&gt;For those of you who have never heard of or who have never used design patterns, it&amp;#8217;s important to understand what they are before we actually begin using them in our work.&lt;/p&gt;&lt;p&gt;Wikipedia provides &lt;a
title="Design Patterns" href="http://en.wikipedia.org/wiki/Design_patterns" target="_blank"&gt;the following definition&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A design pattern in architecture and computer science is a formal way of documenting a solution to a design problem in a particular field of expertise. An organized collection of design patterns that relate to a particular field is called a pattern language.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Perhaps a more simplified definition would be:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A pattern is a design that can be applied to a problem in a specific situation.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If that&amp;#8217;s &lt;em&gt;still&lt;/em&gt; not clear, think of it this way:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Whenever you&amp;#8217;re building a piece of software, you&amp;#8217;re likely to recognize that you&amp;#8217;re solving a problem that you&amp;#8217;ve already solved before. As such, you &lt;em&gt;know&lt;/em&gt; how to solve it.&lt;/li&gt;&lt;li&gt;Naturally, the solution to the problem will be a slightly more generalized form that&amp;#8217;s applicable to how you&amp;#8217;ve previously applied it.&lt;/li&gt;&lt;li&gt;This generalized form of the solution can be considered the design pattern.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The general implementation and architecture will look exactly the same; however, the specifics of the implementation will naturally vary from project-to-project, but that&amp;#8217;s simply the nature of the beast.&lt;/p&gt;&lt;p&gt;In the upcoming sections and upcoming articles, we&amp;#8217;ll be taking a look at this in a bit more detail.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Design Patterns in WordPress&lt;/h2&gt;&lt;p&gt;If you&amp;#8217;ve done any type of WordPress development involving the hook system &amp;#8211; that is, you&amp;#8217;ve written entire plugins, themes, or even a simple function and taken advantage of the &lt;code&gt;add_action&lt;/code&gt; or &lt;code&gt;add_filter&lt;/code&gt; functions &amp;#8211; then you&amp;#8217;ve used design patterns.&lt;/p&gt;&lt;p&gt;WordPress uses what&amp;#8217;s called an event-driven design pattern. There are several variations of event-driven design patterns one of which we&amp;#8217;ll review momentarily, but the gist of the patterns are all the same:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Part of the pattern implements what&amp;#8217;s known as a publisher&lt;/li&gt;&lt;li&gt;Part of the pattern implements what&amp;#8217;s known as a subscriber&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Generally speaking, the publisher broadcasts a message that &lt;em&gt;something has happened&lt;/em&gt; to all objects that are subscribed to that particular publisher.&lt;/p&gt;&lt;p&gt;Another way of looking at this is that, in software, whenever something happens we say that an event is raised. Perhaps the most common place we see this in web development is in JavaScript with things such as the mouse being clicked, a key on the keyboard being pressed, or something similar.&lt;/p&gt;&lt;p&gt;We then write functions that handle those functions, and these functions are appropriately referred to as event handlers because they are responsible for handling the case when an event happens.&lt;/p&gt;&lt;p&gt;Not terribly complicated, right? Honestly, sometimes I think the terminology can be more confusing than the actual implementation.&lt;/p&gt;&lt;p&gt;So anyway, in the context of WordPress &amp;#8211; or any web application, for that matter &amp;#8211; events aren&amp;#8217;t limited to key presses or mouse clicks. Instead, it can happen during various parts of the page load lifecycle, when data is written to the database, when data is read to the database, and so on.&lt;/p&gt;&lt;p&gt;Ultimately, you can implement the pattern however you like so that you can provide hooks into which developers can register functions to fire as soon the event occurs.&lt;/p&gt;&lt;p&gt;This brings us full circle back to WordPress&amp;#8217; architecture: Hooks are placed throughout the code such that we&amp;#8217;re able to register a function to fire whenever &lt;em&gt;something occurs&lt;/em&gt; (that is, whenever an event happens).&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;A Look at an Event-Driven Architecture: The Observer Pattern&lt;/h2&gt;&lt;p&gt;There are a number of event-driven design patterns, one of which is known as the Observer Pattern. This particular pattern is also known as the Publisher-Subscriber Pattern or, more concisely, Pub-Sub.&lt;/p&gt;&lt;p&gt;In the simplest implementation of this pattern, there is a single publisher that is responsible for broadcasting messages to one or many subscribers. The subscribers are responsible for registering themselves with the publisher, and then the publisher is responsible for sending a message or taking action on all of the subscribers.&lt;/p&gt;&lt;p&gt;A high-level diagram would look something like this:&lt;/p&gt; &lt;figure
class="tutorial_image"&gt;&lt;img
class="aligncenter size-full wp-image-31605" alt="WordPress Design Patterns" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/05/2013-05-06-10.18.05.png" width="610" height="458" /&gt;&lt;/figure&gt;&lt;p&gt;From a code perspective, the Publisher needs three things:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;A way to maintain a list of the subscribers&lt;/li&gt;&lt;li&gt;A way for the subscribers to register themselves&lt;/li&gt;&lt;li&gt;A way to broadcast a message to all of the subscribers&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Similarly, the Subscriber needs to be able to do two things:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Register itself with the Publisher&lt;/li&gt;&lt;li&gt;Optionally take action when the Publisher sends a message to it&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;There are a number of ways in which this can be implemented, but for all intents and purposes and to keep the example relatively simple, let&amp;#8217;s say that the Subscribers will register themselves with the Publisher with the Observer&amp;#8217;s &lt;code&gt;register&lt;/code&gt; method and the function accepts a reference to the Subscriber and each Subscriber has an &lt;code&gt;update&lt;/code&gt; method that the Publisher calls when broadcasting the message.&lt;/p&gt;&lt;h3&gt;Publisher Code&lt;/h3&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
class MyPublisher {

	/** The list of subscribers that are registered with this publisher */
	private $subscribers;

	/**
	 * Responsible for initializing the class and setting up the list of subscribers.
	 */
	public function __construct() {
		$this-&amp;gt;subscribers = array();
	} // end constructor

	/**
	 * Adds the incoming subject to the list of registered subscribers
	 *
	 * @param  array  $subject  The subject to add to the list of subscribers
	 */
	public function register( $subject ) {
		array_push( $this-&amp;gt;subscribers, $subject );
	} // end register_subscriber

	/**
	 * Notifies all of the subscribers that something has happened by calling their `update`
	 * method.
	 */
	public function notify_subscribers() {

		for ( $i = 0; $l &amp;lt; count( $this-&amp;gt;subscribers ); $i++ ) {

			$current_subscriber = $this-&amp;gt;subscribers[ $i ];
			$current_subscriber-&amp;gt;update();

		} // end for

	} // end notify_subscribers

} // end class
&lt;/pre&gt;&lt;p&gt;The code above is about as simple as we can make it:&lt;/p&gt;&lt;p&gt;For those who are more experienced with object-oriented techniques, then you&amp;#8217;ll likely see the need for creating a class interface for the Publisher, but that&amp;#8217;s outside the scope of this particular tutorial.&lt;/p&gt;&lt;p&gt;Remember, the purpose is to simply provide an example of what a simple observer may look like.&lt;/p&gt;&lt;h3&gt;Subscribe Code&lt;/h3&gt;&lt;p&gt;Creating a Publisher is really only half of the implementation. Remember, we have to have something that actually, you know, &lt;em&gt;subscribes&lt;/em&gt; to the Publisher to take action whenever something happens.&lt;/p&gt;&lt;p&gt;This is where the aptly named Subscriber comes into play.&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
class MySubscriber {

	/** The publisher to which this class registers */
	private $publisher;

	/**
	 * Responsible for initializing the class and setting up a reference to the publisher
	 */
	public function __construct() {

		$this-&amp;gt;publisher = new MyPublisher();
		$this-&amp;gt;publisher-&amp;gt;register( $this );

	} // end constructor

	/**
	 * This is the method that the Publisher calls when it it broadcasts its message.
	 */
	public function update() {

		/** Implementation is based purely on however you'd like. */

	} // end update

} // end class
&lt;/pre&gt;&lt;p&gt;In short, this is it. Notice above that this implementation of the &lt;code&gt;update&lt;/code&gt; function isn&amp;#8217;t actually defined. That&amp;#8217;s because it gives us the ability to provide unique behavior to this specific instance.&lt;/p&gt;&lt;p&gt;But remember, there&amp;#8217;s a lot of code in WordPress core that is not object-oriented. Instead, it&amp;#8217;s procedural. As such, the implementation of a pattern like this varies a little bit.&lt;/p&gt;&lt;p&gt;For example, an analogy in WordPress would be something like this:&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
function my_custom_subscriber( $content ) {

	$content = 'This is my custom content.' . $content;
	return $content;

} // end my_custom_subscriber
add_action( 'the_content', 'my_custom_subscriber' );
&lt;/pre&gt;&lt;p&gt;Notice that the syntax is a bit different, but we&amp;#8217;re essentially doing a very similar thing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;We have a subscribe function &amp;#8211; &lt;code&gt;my_custom_subscriber&lt;/code&gt; &amp;#8211; and it&amp;#8217;s registered with the &lt;code&gt;the_content&lt;/code&gt; event&lt;/li&gt;&lt;li&gt;When the &lt;code&gt;the_content&lt;/code&gt; function fires, our custom function will fire.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Nothing too complicated, I hope.&lt;/p&gt;&lt;p&gt;One of the goals in this series is not only to provide a few examples of design patterns and how to implement them, but they are already in place in existing systems.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;The Patterns We&amp;#8217;ll Examine&lt;/h2&gt;&lt;p&gt;In addition to the event-driven pattern that we&amp;#8217;ve examined above, we&amp;#8217;re also going to take a look at two patterns that are common, practical, and highly useful in our day-to-day work.&lt;/p&gt;&lt;p&gt;Specifically, we&amp;#8217;re going to take a look at the following patterns:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;Singleton Pattern&lt;/strong&gt;. In object-oriented design, the Single Pattern ensures that only a single instance of a class is created. This is useful so that we don&amp;#8217;t accidentally create multiple instances maintaining their own sets of data ultimately giving conflicting results during a project&amp;#8217;s lifecycle.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Simple Factory Pattern&lt;/strong&gt;. If you have a collection of classes each of which are designed to handle a specific type of data (as opposed to have one large class do it), then the Simple Factory Pattern is useful for taking a look at the incoming data and then returning an instance of the proper class for processing the data.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Obviously, talking about software only goes so far without talking about diagrams and/or code so we&amp;#8217;ll be taking a look at both of those in the upcoming set of articles.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As you can see, the concept of design patterns isn&amp;#8217;t anything terribly complicated and there&amp;#8217;s a lot to be gained by using them in our work. Perhaps the greatest challenge that developers face is using design patterns for the sake of using design patterns.&lt;/p&gt;&lt;p&gt;Instead, it&amp;#8217;s important to recognize that there are certain situations in which design patterns are applicable. That is to say that there are certain problems for which design patterns are the perfect solution. Experience is arguably the best teacher for knowing when to use a design pattern and when not to use it.&lt;/p&gt;&lt;p&gt;In the following articles, hopefully we&amp;#8217;ll be able to cover enough territory to provide two solid examples of design patterns, when they&amp;#8217;re applicable, how to use them, and how they can help us in our future work.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/9OSVpqV7FhY" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-an-introduction/feed/</wfw:commentRss> <slash:comments>11</slash:comments> <series:name><![CDATA[Design Patterns in WordPress]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-an-introduction/</feedburner:origLink></item> <item><title>Introduction to WordPress Plugin Development: Early Bird Tickets Now Available!</title><link>http://feedproxy.google.com/~r/Wptuts/~3/0WCVt3lqe_Y/</link> <comments>http://wp.tutsplus.com/articles/news/tuts-live-workshops-introduction-to-developing-wordpress-plugins/#comments</comments> <pubDate>Thu, 09 May 2013 13:05:08 +0000</pubDate> <dc:creator>Joel Bankhead</dc:creator> <category><![CDATA[News]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31626</guid> <description>&lt;p&gt;&lt;strong&gt;Today, we are excited to announce a fantastic new workshop led by Instructor Tom McFarlin: &lt;a
href="http://enva.to/WsETYw"&gt;Introduction to WordPress Plugin Development&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Are you an aspiring WordPress developer? Are you ready to take the next step and start building your own custom plugins for WordPress? Our newest Tuts+ Live Workshop is the perfect way to get started!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Early Bird tickets are half-price at only $49&lt;/strong&gt;, but places are strictly limited so act fast to make sure you don’t miss out!&lt;br
/&gt; &lt;span
id="more-31626"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Introduction to WordPress Plugin Development&lt;/h2&gt;&lt;p&gt;Our newest Tuts+ Live Workshop, Introduction to WordPress Plugin Development, teaches you everything that you need to know to start developing WordPress plugins; from setting up a local development environment, all the way through to building a WordPress plugin that&amp;#8217;s ready for release into the WordPress Plugin Repository.&lt;/p&gt;&lt;p&gt;It&amp;#8217;s led by Instructor Tom McFarlin, a self-employed WordPress developer who divides his time between running his own WordPress development shop, building plugins for WordPress, blogging every day about software development in the context of WordPress, and working for 8BIT (the team responsible for Standard Theme and WP Daily).&lt;/p&gt;&lt;p&gt;Each weekly workshop will last one hour, running over a five week period. You&amp;#8217;ll have the opportunity to follow along with Tom, ask questions live during the workshop, and complete a weekly homework assignment. Not able to make it to the live recording? No problem! All of the workshop recordings will be made available online the day after the live workshop.&lt;/p&gt;&lt;p&gt;&lt;a
href="http://enva.to/WsETYw"&gt;Learn more about Introduction to WordPress Plugin Development&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;iframe
width="640" height="360" src="http://www.youtube.com/embed/QErsaJMdmCc?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Grab an Early Bird Ticket Now!&lt;/h2&gt;&lt;p&gt;We’re offering a &lt;strong&gt;special Early Bird price of $49&lt;/strong&gt;, but these tickets are limited. Once the Early Bird tickets have disappeared, the workshop will be $99.&lt;/p&gt;&lt;p&gt;If you’re interested in future workshops then definitely &lt;a
href="http://eepurl.com/qnEP5"&gt;join the Tuts+ Live Workshops mailing list&lt;/a&gt; to stay posted on upcoming workshops and get notified as soon as they’re available, the Early Bird tickets for our previous workshops have all sold out, so it’s worth getting ahead of the game!&lt;/p&gt;&lt;p&gt;We’re really excited about new workshop, &lt;a
href="http://enva.to/WsETYw"&gt;Introduction to WordPress Plugin Development&lt;/a&gt;, but places are strictly limited so act fast to make sure you don’t miss out!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/0WCVt3lqe_Y" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/articles/news/tuts-live-workshops-introduction-to-developing-wordpress-plugins/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://wp.tutsplus.com/articles/news/tuts-live-workshops-introduction-to-developing-wordpress-plugins/</feedburner:origLink></item> <item><title>Tuts+ Premium Cash Back Offer: 3 Days to Go</title><link>http://feedproxy.google.com/~r/Wptuts/~3/d9Lu7eBvZqk/</link> <comments>http://wp.tutsplus.com/articles/news/try-tuts-premium-get-cash-back/#comments</comments> <pubDate>Wed, 08 May 2013 14:00:30 +0000</pubDate> <dc:creator>Joel Bankhead</dc:creator> <category><![CDATA[News]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31612</guid> <description>&lt;p&gt;&lt;strong&gt;This offer ends soon! Act now and don’t miss out on cash back when trying a monthly Tuts+ Premium subscription.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;At $19 a month, Tuts+ Premium is fantastic value. But it&amp;#8217;s even better when we hand your first $19 right back to you!&lt;/p&gt;&lt;p&gt;For a limited time we&amp;#8217;re offering $19 cash back to new Tuts+ Premium monthly subscribers when signing up via PayPal. If you’ve been thinking about checking out our extensive library of courses, tutorials, eBooks and guides there’s never been a better time to join up and dive in.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;This offer ends at noon on the 20th of May AEST, so act fast.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a
href="https://tutsplus.com/paypal-cash-back-offer/?utm_source=wptutsend&amp;#038;utm_medium=post&amp;#038;utm_campaign=paypal_cashback&amp;#038;wt.mc_id=paypal"&gt;Become a Tuts+ Premium Member and take your creative &amp;#038; technical skills to a new level.&lt;/a&gt;&lt;br
/&gt; &lt;span
id="more-31612"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt; What can you learn on Tuts+ Premium? Glad you asked! Currently, more than 15,000 members are sharpening their skills in a wide range of areas including web design, web development, Photoshop, vectors, video effects, and many more.&lt;/p&gt;&lt;p&gt;With Tuts+ Premium you learn from expert instructors in every field, such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Designer Justin Maller (Nike, Verizon, DC Shoe Co.)&lt;/li&gt;&lt;li&gt;Illustrator Russell Tate (McDonald&amp;#8217;s, Coca-Cola)&lt;/li&gt;&lt;li&gt;Developer Burak Guzel (Software Engineer at Facebook)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Join now and get instant access to your very own library of courses, tutorials, and eBooks, available whenever you need them. Become part of a community of over 15,000 members and start getting better at the skills you care about. Our dedicated team adds new content weekly, so there&amp;#8217;s always something fresh to sink your teeth into.&lt;/p&gt;&lt;p&gt;&lt;a
href="https://tutsplus.com/paypal-cash-back-offer/?utm_source=wptutsend&amp;#038;utm_medium=post&amp;#038;utm_campaign=paypal_cashback&amp;#038;wt.mc_id=paypal"&gt;Join Tuts+ Premium&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/d9Lu7eBvZqk" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/articles/news/try-tuts-premium-get-cash-back/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://wp.tutsplus.com/articles/news/try-tuts-premium-get-cash-back/</feedburner:origLink></item> <item><title>Quick Tip: After the Content – More From This Category</title><link>http://feedproxy.google.com/~r/Wptuts/~3/ARIEWv5glFM/</link> <comments>http://wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-more-from-this-category/#comments</comments> <pubDate>Tue, 07 May 2013 14:01:34 +0000</pubDate> <dc:creator>Barış Ünver</dc:creator> <category><![CDATA[Tips]]></category> <category><![CDATA[content]]></category> <category><![CDATA[posts from category]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=30696</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 6 of 7 in the series &lt;a
href="http://wp.tutsplus.com/series/after-the-content/" class="series-1085" title="After the Content"&gt;After the Content&lt;/a&gt;&lt;/div&gt;&lt;p&gt;Do you have a solid construction of categories on your blog? If so, you might not need a &amp;#8220;Related Posts&amp;#8221; section at all &amp;#8211; you can just display latest posts from the same category.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#8217;re going to go through the &amp;#8220;More From This Category&amp;#8221; section, an alternative to &amp;#8220;Related Posts&amp;#8221; (&lt;a
href="wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-related-posts/"&gt;which we covered earlier&lt;/a&gt;).&lt;span
id="more-30696"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Show You Have More to Say&lt;/h2&gt;&lt;p&gt;If you keep your posts organized well with categories, you might find it useful to have a list of posts from the post&amp;#8217;s category.&lt;/p&gt;&lt;p&gt;&amp;#8220;Related Posts&amp;#8221; is not always the answer: If you have a website where the posts are &lt;em&gt;separated&lt;/em&gt; with categories, a &amp;#8220;Related Posts&amp;#8221; section might &amp;#8220;break&amp;#8221; this separation.&lt;/p&gt;&lt;p&gt;For example, if you have a blog about different occupational groups, you can&amp;#8217;t show news about the textile sector as &amp;#8220;Related News&amp;#8221; under a post about informatics. A number of latest posts from the same category would be more relevant, right?&lt;/p&gt;&lt;h3&gt;Creating a &amp;#8220;More From This Category&amp;#8221; List&lt;/h3&gt;&lt;p&gt;As you may have guessed, listing latest posts from a post&amp;#8217;s category will be much easier than displaying related posts based on a post&amp;#8217;s tags. We just need to get the category of the post and list a number of posts from that category, excluding the post that the visitors have just read. The arguments that we can pass in the &lt;code&gt;get_posts()&lt;/code&gt; function has everything we need.&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
&amp;lt;?php
// &amp;quot;More from This Category&amp;quot; list by Barış Ünver @ Wptuts+
function wptuts_more_from_cat( $title = &amp;quot;More From This Category:&amp;quot; ) {
    global $post;
    // We should get the first category of the post
    $categories = get_the_category( $post-&amp;gt;ID );
    $first_cat = $categories[0]-&amp;gt;cat_ID;
    // Let's start the $output by displaying the title and opening the &amp;lt;ul&amp;gt;
    $output = '&amp;lt;div id=&amp;quot;more-from-cat&amp;quot;&amp;gt;&amp;lt;h3&amp;gt;' . $title . '&amp;lt;/h3&amp;gt;';
    // The arguments of the post list!
    $args = array(
        // It should be in the first category of our post:
        'category__in' =&amp;gt; array( $first_cat ),
        // Our post should NOT be in the list:
        'post__not_in' =&amp;gt; array( $post-&amp;gt;ID ),
        // ...And it should fetch 5 posts - you can change this number if you like:
        'posts_per_page' =&amp;gt; 5
    );
    // The get_posts() function
    $posts = get_posts( $args );
    if( $posts ) {
		$output .= '&amp;lt;ul&amp;gt;';
		// Let's start the loop!
		foreach( $posts as $post ) {
			setup_postdata( $post );
			$post_title = get_the_title();
			$permalink = get_permalink();
			$output .= '&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;' . $permalink . '&amp;quot; title=&amp;quot;' . esc_attr( $post_title ) . '&amp;quot;&amp;gt;' . $post_title . '&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';
		}
		$output .= '&amp;lt;/ul&amp;gt;';
	} else {
		// If there are no posts, we should return something, too!
		$output .= '&amp;lt;p&amp;gt;Sorry, this category has just one post and you just read it!&amp;lt;/p&amp;gt;';
	}
    // Let's close the &amp;lt;div&amp;gt; and return the $output:
    $output .= '&amp;lt;/div&amp;gt;';
    return $output;
}
?&amp;gt;
&lt;/pre&gt;&lt;p&gt;Done! You can include this function inside your &lt;strong&gt;functions.php&lt;/strong&gt; file (or save it as a separate plugin) and echo it (as &lt;code&gt;&amp;lt;?php echo wptuts_more_from_cat( 'More From This Category:' ); ?&amp;gt;&lt;/code&gt;) anywhere you want inside your &lt;strong&gt;single.php&lt;/strong&gt; file.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Yes, content may be &amp;#8220;king&amp;#8221; but a lonely king is a weak king, and people might not respect that &amp;#8220;king&amp;#8221;.&lt;/p&gt;&lt;p&gt;Do you think there are more page elements that can help &amp;#8220;the king&amp;#8221;? Post your comments below &amp;#8211; it&amp;#8217;s always important for you to share your thoughts with us!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/ARIEWv5glFM" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-more-from-this-category/feed/</wfw:commentRss> <slash:comments>7</slash:comments> <series:name><![CDATA[After the Content]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/articles/tips-articles/quick-tip-after-the-content-more-from-this-category/</feedburner:origLink></item> <item><title>A Walkthrough for Jetpack’s “Post by Email” Feature</title><link>http://feedproxy.google.com/~r/Wptuts/~3/WURiTYuWW14/</link> <comments>http://wp.tutsplus.com/tutorials/plugins/a-walkthrough-for-jetpacks-post-by-email-feature/#comments</comments> <pubDate>Mon, 06 May 2013 13:15:34 +0000</pubDate> <dc:creator>Barış Ünver</dc:creator> <category><![CDATA[Plugins]]></category> <category><![CDATA[jetpack]]></category> <category><![CDATA[post by email]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31120</guid> <description>&lt;p&gt;WordPress has a sufficient, mostly responsive, back-end and great applications for mobile devices, but there might come a day when you&amp;#8217;ll just want to send an email to post an entry to your website.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#8217;re going to go through this handy little feature of &lt;a
title="JetPack" href="http://wordpress.org/extend/plugins/jetpack/" target="_blank"&gt;Jetpack&lt;/a&gt;: Post by Email.&lt;span
id="more-31120"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;WordPress has a &lt;a
href="http://codex.wordpress.org/Post_to_your_blog_using_email"&gt;Post via Email&lt;/a&gt; functionality in its core, but it&amp;#8217;s far from being handy or user friendly.&lt;/p&gt;&lt;p&gt;As the Codex says, you have to:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Create a dedicated e-mail account to be used solely for posting to your blog&lt;/li&gt;&lt;li&gt;Configure WordPress to access that account via POP3&lt;/li&gt;&lt;li&gt;Configure WordPress to publish messages from that e-mail account&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;And even if you do, you&amp;#8217;re stuck with plain text posts &lt;em&gt;and&lt;/em&gt; you can&amp;#8217;t post any email attachments!&lt;/p&gt;&lt;p&gt;Plus, you have to at least set up a function in your theme (or as a separate plugin) for WordPress to recognize your email as a post. Oh, did I mention that you can only select one category to post and you can&amp;#8217;t set any tags or any other kind of taxonomy?&lt;/p&gt;&lt;p&gt;Luckily, this problematic approach can be replaced with Jetpack, another creation from Automattic. &lt;a
href="http://jetpack.me/support/post-by-email/"&gt;The Post by Email module&lt;/a&gt; solves all the problems above &lt;em&gt;and&lt;/em&gt; allows you to do lots more. In short, you can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use HTML in your email&lt;/li&gt;&lt;li&gt;Include attachments (and include the attached images as a slideshow or an inline gallery)&lt;/li&gt;&lt;li&gt;Set a title (and a slug) different than your email title&lt;/li&gt;&lt;li&gt;Set categories and tags&lt;/li&gt;&lt;li&gt;Turn on or off comments for the post&lt;/li&gt;&lt;li&gt;Set an excerpt&lt;/li&gt;&lt;li&gt;Change the status of the post&lt;/li&gt;&lt;li&gt;Set a password for the post&lt;/li&gt;&lt;li&gt;Set a time for the post to be published&lt;/li&gt;&lt;li&gt;Add &lt;code&gt;&amp;lt;--more--&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;--nextpage--&amp;gt;&lt;/code&gt; tags inside the post&lt;/li&gt;&lt;li&gt;&lt;em&gt;End&lt;/em&gt; your post anywhere inside your email&lt;/li&gt;&lt;li&gt;Include a PollDaddy poll&lt;/li&gt;&lt;li&gt;Turn off geotagging&lt;/li&gt;&lt;li&gt;Set Publicize options, another module of Jetpack&lt;/li&gt;&lt;/ul&gt;&lt;hr
/&gt;&lt;h2&gt;Warming Up&lt;/h2&gt;&lt;p&gt;You need to do a bunch of things with Jetpack, too:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a
href="http://wordpress.org/extend/plugins/jetpack/"&gt;Install the plugin&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Connect your website with your WordPress.com account&lt;/li&gt;&lt;li&gt;Check if the &amp;#8220;Post by Email&amp;#8221; module is enabled&lt;/li&gt;&lt;li&gt;Go to Users » Your Profile and click on &amp;#8220;Enable Post by Email&amp;#8221;&lt;/li&gt;&lt;li&gt;Get the special email address and add it to your address book&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Notice that you don&amp;#8217;t even have to use your keyboard while taking these steps &amp;#8211; except, maybe, entering your WordPress.com credentials. After doing these in order, you&amp;#8217;re ready to send your first post via email!&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Available Shortcodes&lt;/h2&gt;&lt;p&gt;Now that you&amp;#8217;re all set on your WordPress admin panel, you can now log in to your email account &amp;#8211; the one you&amp;#8217;re registered with WordPress.com. With your first post (and all others, naturally), you can use the following shortcodes anywhere inside your email:&lt;/p&gt;&lt;h3&gt;Title: &lt;code&gt;[title Hello World!]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; The specified title.&lt;/p&gt;&lt;p&gt;If you want to send an email with a different title than the title of the post, you can use this shortcode to set a title for the post. If this shortcode is used, Jetpack will disregard the title of the email.&lt;/p&gt;&lt;h3&gt;Slug: &lt;code&gt;[slug oh-hai]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; The specified slug.&lt;/p&gt;&lt;p&gt;The usual &amp;#8220;slug&amp;#8221;, the words on the address bar. You can use this shortcode to use shorter URLS like &lt;code&gt;myblog.com/hawaii-trip/&lt;/code&gt; and avoid huge ones like &lt;code&gt;myblog.com/a-trip-to-hawaii-what-i-expected-to-see-and-what-i-saw/&lt;/code&gt;.&lt;/p&gt;&lt;h3&gt;Categories: &lt;code&gt;[category News, Personal]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; Comma separated category names or IDs.&lt;/p&gt;&lt;p&gt;You can set any category you want with this shortcode. Just use names or IDs as parameters and you&amp;#8217;re good to go! It even gets the right category when you don&amp;#8217;t use the full name, like &amp;#8220;Anno&amp;#8221; instead of &amp;#8220;Announcements&amp;#8221;.&lt;/p&gt;&lt;h3&gt;Tags: &lt;code&gt;[tags lorem, ipsum, dolor]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; Comma separated tag names.&lt;/p&gt;&lt;p&gt;Like categories, you can use tag names&lt;/p&gt; &lt;strong&gt;P.S.&lt;/strong&gt; As far as I can see, it doesn&amp;#8217;t support custom taxonomies, which is a bummer. It would be great if a [tax] shortcode is introduced and used like this: &lt;code&gt;[tax custom-taxonomy]lorem, ipsum, dolor[/tax]&lt;/code&gt; (where the default parameter is &amp;#8220;tag&amp;#8221;). Let&amp;#8217;s hope the module will support this in the future :).&lt;h3&gt;Comments: &lt;code&gt;[comments off]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; &amp;#8220;on&amp;#8221; or &amp;#8220;off&amp;#8221;.&lt;/p&gt;&lt;p&gt;No need to explain this one: You can turn on or off comments on your post with this shortcode.&lt;/p&gt;&lt;h3&gt;Post Status: &lt;code&gt;[status private]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; &amp;#8220;publish&amp;#8221; (default), &amp;#8220;private&amp;#8221;, &amp;#8220;pending&amp;#8221; or &amp;#8220;draft&amp;#8221;.&lt;/p&gt;&lt;p&gt;Again, this is self-explanatory: You can set the four parameters to set the status of your post.&lt;/p&gt;&lt;h3&gt;Post Password: &lt;code&gt;[password CorrectHorseBatteryStaple]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; The specified password.&lt;/p&gt;&lt;p&gt;You can protect your post with a password with this shortcode.&lt;/p&gt; &lt;strong&gt;P.S.&lt;/strong&gt; I got the password from &lt;a
href="http://xkcd.com/936/"&gt;an XKCD comic&lt;/a&gt;.&lt;h3&gt;Publish Date/Time: &lt;code&gt;[delay +2 days]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; a date/time description like &amp;#8220;+1 week 2 days 3 hours&amp;#8221; or &amp;#8220;next Saturday&amp;#8221; or &amp;#8220;25 November 2013&amp;#8243;.&lt;/p&gt;&lt;p&gt;Using the &lt;a
href="http://php.net/strtotime"&gt;strtotime&lt;/a&gt; format, you can set the date and time of your post. If you set the parameter to &amp;#8220;+2 hours&amp;#8221;, your post will be published 2 hours after you send the email.&lt;/p&gt;&lt;h3&gt;Excerpt: &lt;code&gt;[excerpt]...[/excerpt]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;If you&amp;#8217;re using the &amp;#8220;excerpts&amp;#8221; of WordPress posts on your website, you can set an excerpt between &lt;code&gt;[excerpt]&lt;/code&gt; and &lt;code&gt;[/excerpt]&lt;/code&gt; tags.&lt;/p&gt;&lt;h3&gt;Geotagging: &lt;code&gt;[geotag off]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; &amp;#8220;on&amp;#8221; or &amp;#8220;off&amp;#8221;.&lt;/p&gt;&lt;p&gt;If your phone (or email client) is using your GPS information inside the emails, &lt;a
href="http://en.support.wordpress.com/geotagging/"&gt;geotagging&lt;/a&gt; will be enabled by default. If you don&amp;#8217;t want to share that information on your posts, you should disable it by using this shortcode with the parameter &amp;#8220;off&amp;#8221;.&lt;/p&gt;&lt;h3&gt;Publicize: &lt;code&gt;[publicize facebook twitter]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; Space separated list of services (like Facebook and Twitter) or &amp;#8220;off&amp;#8221;.&lt;/p&gt;&lt;p&gt;Jetpack has another useful module called &lt;a
href="http://jetpack.me/support/publicize/"&gt;Publicize&lt;/a&gt;, letting you share your post automatically on social networks when it&amp;#8217;s published. If you want to do the same with email, you can use this shortcode to Publicize your post.&lt;/p&gt;&lt;h3&gt;Separating Content: &lt;code&gt;[more]&lt;/code&gt; and &lt;code&gt;[nextpage]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;These two are also self-explanatory: If you ever need to use the &lt;code&gt;&amp;lt;--more--&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;--nextpage--&amp;gt;&lt;/code&gt; tags inside your post, you can use these shortcodes.&lt;/p&gt;&lt;h3&gt;Attachments: &lt;code&gt;[slideshow]&lt;/code&gt; and &lt;code&gt;[noslider]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;By default, Jetpack will include your image attachments in the post. If you attach just one image, it will be displayed inline and if you attach more, all of them will form a gallery.&lt;/p&gt;&lt;p&gt;If you don&amp;#8217;t like this behavior, you can use [nogallery] to display all images inline or use [slideshow] to replace the gallery with a slideshow.&lt;/p&gt;&lt;h3&gt;PollDaddy Polls: &lt;code&gt;[poll]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt; &amp;#8220;type&amp;#8221; (single, multi or a number), &amp;#8220;style&amp;#8221; (manga or medium), &amp;#8220;other&amp;#8221; (yes or no).&lt;/p&gt;&lt;p&gt;If you have a PollDaddy account, you can use this shortcode to include a poll inside your post. Here&amp;#8217;s an example on how to use it:&lt;/p&gt;&lt;pre class="brush: plain; title: ; notranslate"&gt;
[poll type=&amp;quot;3&amp;quot; style=&amp;quot;medium&amp;quot; other=&amp;quot;yes&amp;quot;]
What are your favorite Tuts+ blogs? (select three)
* Wptuts+
* Nettuts+
* Webdesigntuts+
* Psdtuts+
* Phototuts+
[/poll]
&lt;/pre&gt;&lt;h3&gt;The End: &lt;code&gt;[end]&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;There could be email signatures you can&amp;#8217;t remove (company policy, hmpfh) or your smartphone could add lines like &amp;#8220;sent from myPhone&amp;#8221; (&lt;em&gt;that company&lt;/em&gt;&amp;#8216;s policy, hmpfh) and you wouldn&amp;#8217;t want these signatures to be included in your post.&lt;/p&gt;&lt;p&gt;Jetpack automatically cuts out the text after a &lt;a
href="http://en.wikipedia.org/wiki/Signature_block"&gt;signature block&lt;/a&gt; or an &lt;code&gt;&amp;lt;hr /&amp;gt;&lt;/code&gt; tag, but you can use [end] alternatively to end the post right where you use it.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Wrapping Up&lt;/h2&gt;&lt;p&gt;I always thought that the core &amp;#8220;post via email&amp;#8221; feature of WordPress was too much limiting, kind of redundant and absolutely hard to use. Now that we went through everything Jetpack&amp;#8217;s &amp;#8220;Post by Email&amp;#8221; module can do, I&amp;#8217;m glad that there&amp;#8217;s an alternative to it, also developed by Automattic.&lt;/p&gt;&lt;p&gt;What do you think about this feature &amp;#8211; do you plan to use it? Share your comments below and don&amp;#8217;t forget to share the post!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/WURiTYuWW14" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/plugins/a-walkthrough-for-jetpacks-post-by-email-feature/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://wp.tutsplus.com/tutorials/plugins/a-walkthrough-for-jetpacks-post-by-email-feature/</feedburner:origLink></item> <item><title>Guide to Creating Your Own WordPress Editor Buttons</title><link>http://feedproxy.google.com/~r/Wptuts/~3/smdREbjvZMo/</link> <comments>http://wp.tutsplus.com/tutorials/theme-development/guide-to-creating-your-own-wordpress-editor-buttons/#comments</comments> <pubDate>Tue, 30 Apr 2013 14:20:14 +0000</pubDate> <dc:creator>Lee Pham</dc:creator> <category><![CDATA[Theme Development]]></category> <category><![CDATA[text editor]]></category> <category><![CDATA[TinyMCE]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=30182</guid> <description>&lt;p&gt;Most likely you know that WordPress is bundled with the HTML WYSIWYG editor, &lt;a
href="http://codex.wordpress.org/TinyMCE"&gt;TinyMCE&lt;/a&gt;. The variety of features, and the ability to be extended though plugins, make it the most used WYSIWYG editor in the world. WordPress doesn&amp;#8217;t make use of all its features, however. WordPress customizes it and only keeps parts which are really helpful to users, avoiding messing up the user interface. That also means some features, buttons for example, have been hidden from users. You can totally &lt;a
href="http://codex.wordpress.org/TinyMCE_Custom_Buttons#Enabling_hidden_MCE_buttons"&gt;enable the hidden MCE buttons&lt;/a&gt;. Typically they are &lt;strong&gt;stylesheet&lt;/strong&gt;, &lt;strong&gt;sub&lt;/strong&gt;, &lt;strong&gt;sup&lt;/strong&gt; buttons. If even the hidden ones still don&amp;#8217;t satisfy your needs, then you have to create a TinyMCE plugin to do add your own. In this tutorial, I will walk you through the basics of adding your WordPress Editor buttons by creating a TinyMCE plugin.&lt;span
id="more-30182"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Before We Start&lt;/h2&gt;&lt;p&gt;As mentioned earlier, we will create a new TinyMCE plugin whose task is to add the new buttons we want. So which buttons are we going to add? We will try to add two simple buttons: &lt;strong&gt;Dropcap&lt;/strong&gt; and &lt;strong&gt;Recent Posts&lt;/strong&gt;, in which the former gives you the ability to convert a selected letter to a drop cap letter, and the latter will display recent posts. The code generates these buttons shown below.&lt;/p&gt;&lt;p&gt;Let&amp;#8217;s create a new folder named &lt;strong&gt;wptuts-editor-buttons&lt;/strong&gt; (of course, you can change it to something else if you want) in your theme directory (I&amp;#8217;m using TwentyTwelve). Continue to create two new files, &lt;strong&gt;wptuts.php&lt;/strong&gt; that invokes customized PHP, and the other named &lt;strong&gt;wptuts-plugin.js&lt;/strong&gt; where the JavaScript code snippets will be located. Finally, open your theme&amp;#8217;s &lt;strong&gt;functions.php&lt;/strong&gt; file and include the newly created &lt;strong&gt;wptuts.php&lt;/strong&gt; file in it. Note, remember to define its path exactly:&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
require( 'wptuts-editor-buttons/wptuts.php' );
&lt;/pre&gt;&lt;p&gt;Then we need to prepare some code for those two buttons:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Dropcap&lt;/strong&gt; &amp;#8211; The ideal way of making a letter into drop caps is to simply wrap the user&amp;#8217;s selected letter within a pre-defined HTML span class which styles that letter to look like drop caps. The CSS code of the class shown below, just appends it to your theme&amp;#8217;s &lt;strong&gt;style.css&lt;/strong&gt; file:&lt;pre class="brush: css; title: ; notranslate"&gt;
		/* Add this code in style.css */
		.dropcap {
			float: left;
			font-size: 80px;
			padding-right: 7px;
			line-height: 72px;
		}
		&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Recent Posts&lt;/strong&gt; &amp;#8211; We will make a &lt;a
href="http://codex.wordpress.org/Shortcode_API"&gt;shortcode&lt;/a&gt; that will add a list of recent posts into the page, open the &lt;strong&gt;wptuts.php&lt;/strong&gt; file and add the following code:&lt;pre class="brush: php; title: ; notranslate"&gt;
		add_shortcode( 'recent-posts', 'wptuts_recent_posts' );
		function wptuts_recent_posts( $atts ) {
			extract( shortcode_atts( array(
				'numbers' =&amp;gt; '5',
			), $atts ) );
			$rposts = new WP_Query( array( 'posts_per_page' =&amp;gt; $numbers, 'orderby' =&amp;gt; 'date' ) );
			if ( $rposts-&amp;gt;have_posts() ) {
				$html = '&amp;lt;h3&amp;gt;Recent Posts&amp;lt;/h3&amp;gt;&amp;lt;ul class=&amp;quot;recent-posts&amp;quot;&amp;gt;';
				while( $rposts-&amp;gt;have_posts() ) {
					$rposts-&amp;gt;the_post();
					$html .= sprintf(
						'&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;%s&amp;quot; title=&amp;quot;%s&amp;quot;&amp;gt;%s&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;',
						get_permalink($rposts-&amp;gt;post-&amp;gt;ID),
						get_the_title(),
						get_the_title()
					);
				}
				$html .= '&amp;lt;/ul&amp;gt;';
			}
			wp_reset_query();
			return $html;
		}
		&lt;/pre&gt;&lt;p&gt; We assume that when users click the &lt;strong&gt;Recent Posts&lt;/strong&gt; button, the browser will popup a dialog asking them for the number of posts they want to show. After having that number, the editor will fill it as an argument into the above shortcode. For example, if we want to show seven recent posts, the shortcode is generated as follows:&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
		[recent-posts numbers=&amp;quot;7&amp;quot;/]
		&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr
/&gt;&lt;h2&gt;Registering a New TinyMCE Plugin&lt;/h2&gt;&lt;p&gt;Assuming we already had the new plugin, then we need to register it with WordPress to integrate it into the TinyMCE editor. The code is shown below:&lt;/p&gt;&lt;pre class="brush: php; title: ; notranslate"&gt;
add_action( 'init', 'wptuts_buttons' );
function wptuts_buttons() {
	add_filter( &amp;quot;mce_external_plugins&amp;quot;, &amp;quot;wptuts_add_buttons&amp;quot; );
	add_filter( 'mce_buttons', 'wptuts_register_buttons' );
}
function wptuts_add_buttons( $plugin_array ) {
	$plugin_array['wptuts'] = get_template_directory_uri() . '/wptuts-editor-buttons/wptuts-plugin.js';
	return $plugin_array;
}
function wptuts_register_buttons( $buttons ) {
	array_push( $buttons, 'dropcap', 'showrecent' ); // dropcap', 'recentposts
	return $buttons;
}
&lt;/pre&gt;&lt;p&gt;The important filter hook &lt;code&gt;mce_external_plugins&lt;/code&gt; is used to hook the new plugin to TinyMCE. We need to pass a plugin ID (&lt;code&gt;wptuts&lt;/code&gt;) and the absolute URL pointing to our &lt;strong&gt;wptuts-plugin.js&lt;/strong&gt; file. The &lt;code&gt;mce_buttons&lt;/code&gt; hook is used to tell the TinyMCE editor which buttons in our plugin we want to show. The &lt;strong&gt;dropcap&lt;/strong&gt; and &lt;strong&gt;showrecent&lt;/strong&gt; are the ID values of these buttons that we plan to create. Keep in mind these values, they will be used later.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Setting Up TinyMCE Plugin&lt;/h2&gt;&lt;p&gt;In general, I think the best way to extend or develop something on a platform is to consult the documentation for that platform. TinyMCE has its own &lt;a
href="http://www.tinymce.com/wiki.php"&gt;wiki&lt;/a&gt; that you might find useful. By following an example of &lt;a
href="http://www.tinymce.com/wiki.php/Creating_a_plugin"&gt;how to create a TinyMCE plugin&lt;/a&gt;, we have the following initialisation code:&lt;/p&gt;&lt;pre class="brush: jscript; title: ; notranslate"&gt;
(function() {
	tinymce.create('tinymce.plugins.Wptuts', {
		/**
		 * Initializes the plugin, this will be executed after the plugin has been created.
		 * This call is done before the editor instance has finished it's initialization so use the onInit event
		 * of the editor instance to intercept that event.
		 *
		 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
		 * @param {string} url Absolute URL to where the plugin is located.
		 */
		init : function(ed, url) {

		},

		/**
		 * Creates control instances based in the incomming name. This method is normally not
		 * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
		 * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
		 * method can be used to create those.
		 *
		 * @param {String} n Name of the control to create.
		 * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
		 * @return {tinymce.ui.Control} New control instance or null if no control was created.
		 */
		createControl : function(n, cm) {
			return null;
		},

		/**
		 * Returns information about the plugin as a name/value array.
		 * The current keys are longname, author, authorurl, infourl and version.
		 *
		 * @return {Object} Name/value array containing information about the plugin.
		 */
		getInfo : function() {
			return {
				longname : 'Wptuts Buttons',
				author : 'Lee',
				authorurl : 'http://wp.tutsplus.com/author/leepham',
				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example',
				version : &amp;quot;0.1&amp;quot;
			};
		}
	});

	// Register plugin
	tinymce.PluginManager.add( 'wptuts', tinymce.plugins.Wptuts );
})();
&lt;/pre&gt;&lt;p&gt;Remember to add this code into the &lt;strong&gt;wptuts-plugin.js&lt;/strong&gt; file. We&amp;#8217;ve left the code comments for you to easily understand what&amp;#8217;s going on. The above code just does two main tasks:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;First, defining a new TinyMCE plugin in a safe way by calling TinyMCE&amp;#8217;s &lt;code&gt;create&lt;/code&gt; method. Our plugin&amp;#8217;s behavior will be defined in the &lt;code&gt;init&lt;/code&gt; and &lt;code&gt;createControl&lt;/code&gt; functions. You can see that the plugin&amp;#8217;s information is declared in the &lt;code&gt;getInfo&lt;/code&gt; function too. Our plugin will have the name &lt;code&gt;Wptuts&lt;/code&gt; and the ID &lt;code&gt;wptuts&lt;/code&gt; as you can see.&lt;/li&gt;&lt;li&gt;Last, simply add our new plugin into the TinyMCE Plugin Manager.&lt;/li&gt;&lt;/ol&gt;&lt;hr
/&gt;&lt;h2&gt;Creating Buttons&lt;/h2&gt;&lt;p&gt;In the &lt;code&gt;init&lt;/code&gt; function, we start to create our buttons. The code seen as follows:&lt;/p&gt;&lt;pre class="brush: jscript; title: ; notranslate"&gt;
(function() {
	tinymce.create('tinymce.plugins.Wptuts', {
		init : function(ed, url) {
			ed.addButton('dropcap', {
				title : 'DropCap',
				cmd : 'dropcap',
				image : url + '/dropcap.jpg'
			});

			ed.addButton('showrecent', {
				title : 'Add recent posts shortcode',
				cmd : 'showrecent',
				image : url + '/recent.jpg'
			});
		},
		// ... Hidden code
	});
	// Register plugin
	tinymce.PluginManager.add( 'wptuts', tinymce.plugins.Wptuts );
})();
&lt;/pre&gt;&lt;p&gt;By using the &lt;code&gt;addButton&lt;/code&gt; method of the &lt;code&gt;ed&lt;/code&gt; object, we tell the current editor that we want to create all these buttons. This method accepts two arguments:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The first one is the button&amp;#8217;s ID. In the previous section, we mentioned it. It must be the same as the one we defined before. Otherwise, it will not work properly.&lt;/li&gt;&lt;li&gt;The second one is the object containing the button&amp;#8217;s information, such as:&lt;ul&gt;&lt;li&gt;The button&amp;#8217;s title&lt;/li&gt;&lt;li&gt;The most important: the task that the button will do. Take a look at the &lt;code&gt;cmd&lt;/code&gt; property, it has the value of &lt;strong&gt;showrecent&lt;/strong&gt;. That is the command&amp;#8217;s ID which is executed every time it is called, we will go into detail shortly&lt;/li&gt;&lt;li&gt;The image of the button. Note that the URL parameter holds the absolute directory&amp;#8217;s URL in which our plugin is located, this makes it easier to reference the image that you want. So you need to place your image into the plugin&amp;#8217;s folder and ensure its name to is set precisely to the &lt;code&gt;image&lt;/code&gt;&amp;#8216;s value.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now, check the WordPress editor and we will see our buttons showing up. However, they do nothing right now.&lt;/p&gt; &lt;figure
class="tutorial_image"&gt; &lt;a
href="http://wp.tutsplus.com/?attachment_id=31244" rel="attachment wp-att-31244"&gt;&lt;img
src="http://cdn.tutsplus.com/wp.tutsplus.com/authors/leepham/Guide-To-Creating-Your-Own-WPs-Editor-Buttons-1.png" alt="Guide-To-Creating-Your-Own-WPs-Editor-Buttons-1" width="287" height="119" class="alignnone size-full wp-image-31244" /&gt;&lt;/a&gt;&lt;br
/&gt; &lt;figcaption&gt;Our buttons showed up.&lt;/figcaption&gt; &lt;/figure&gt;&lt;hr
/&gt;&lt;h2&gt;Adding Buttons&amp;#8217; Commands&lt;/h2&gt;&lt;p&gt;We&amp;#8217;ve defined the name of the commands our buttons will execute, but have not yet defined what they will actually run. In this step, we will set up the things our buttons will do. Inside the &lt;code&gt;init&lt;/code&gt; function, continue to add this code as shown:&lt;/p&gt;&lt;pre class="brush: jscript; title: ; notranslate"&gt;
(function() {
	tinymce.create('tinymce.plugins.Wptuts', {
		init : function(ed, url) {
			ed.addButton('dropcap', {
				title : 'DropCap',
				cmd : 'dropcap',
				image : url + '/dropcap.jpg'
			});

			ed.addButton('showrecent', {
				title : 'Add recent posts shortcode',
				cmd : 'showrecent',
				image : url + '/recent.jpg'
			});

			ed.addCommand('dropcap', function() {
				var selected_text = ed.selection.getContent();
				var return_text = '';
				return_text = '&amp;lt;span class=&amp;quot;dropcap&amp;quot;&amp;gt;' + selected_text + '&amp;lt;/span&amp;gt;';
				ed.execCommand('mceInsertContent', 0, return_text);
			});

			ed.addCommand('showrecent', function() {
				var number = prompt(&amp;quot;How many posts you want to show ? &amp;quot;),
					shortcode;
				if (number !== null) {
					number = parseInt(number);
					if (number &amp;gt; 0 &amp;amp;&amp;amp; number &amp;lt;= 20) {
						shortcode = '[recent-post number=&amp;quot;' + number + '&amp;quot;/]';
						ed.execCommand('mceInsertContent', 0, shortcode);
					}
					else {
						alert(&amp;quot;The number value is invalid. It should be from 0 to 20.&amp;quot;);
					}
				}
			});
		},
		// ... Hidden code
	});
	// Register plugin
	tinymce.PluginManager.add( 'wptuts', tinymce.plugins.Wptuts );
})();
&lt;/pre&gt;&lt;p&gt;Now, the &lt;code&gt;ed.addCommand&lt;/code&gt; method will help us to add a new command. You need to pass the command&amp;#8217;s ID and the callback function that will be executed if it was called by the &lt;code&gt;ed.execCommand&lt;/code&gt; method. Note that &lt;strong&gt;ed&lt;/strong&gt; represents the &lt;code&gt;tinyMCE.activeEditor&lt;/code&gt; object. Let&amp;#8217;s take a look at the callback functions:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;In the &lt;code&gt;dropcap&lt;/code&gt; command, the desire we want is when a user selects a letter and clicks the &lt;strong&gt;DropCap&lt;/strong&gt; button, the letter will then be transformed to drop cap form. So how do we get that letter? Well, the &lt;code&gt;ed.selection.getContent&lt;/code&gt; method will do that for us. Next, once we&amp;#8217;ve gotten that letter we just wrap it within a &lt;code&gt;span&lt;/code&gt; element. Remember to set this element&amp;#8217;s class value to &lt;strong&gt;dropcap&lt;/strong&gt; that we&amp;#8217;ve defined before, right? Finally, we have the complete text that needs to be inserted back into the editor. TinyMCE has a default command with the name &lt;code&gt;mceInsertContent&lt;/code&gt; which is used to insert specific content into the editor, how to use it is shown above. The content will be passed as the third argument of the &lt;code&gt;mceInsertContent&lt;/code&gt; method.&lt;/li&gt;&lt;li&gt;A similar thing happens in the &lt;strong&gt;showrecent&lt;/strong&gt; command as in the &lt;strong&gt;dropcap&lt;/strong&gt; command, excepting we don&amp;#8217;t need to get the user&amp;#8217;s selected content. We just simply display a dialog asking the user how many posts they want to show up, then insert that number value in an appropriate shortcode syntax.&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Registering Custom CSS for Buttons (Optionally)&lt;/h3&gt;&lt;p&gt;Instead of adding pure text when the buttons insert contents into the visual editor, we can make it much more visual by registering custom CSS for our buttons. It depends on which type of content data, and you can choose an appropriate style. For example, our &lt;strong&gt;Dropcap&lt;/strong&gt;&amp;#8216;s style can have the same as the one showing on the front-end. So you can take its CSS code in the very top of this post, then place it into the &lt;strong&gt;editor-style.css&lt;/strong&gt; file (for default, see &lt;a
href="http://codex.wordpress.org/Function_Reference/add_editor_style"&gt;&lt;code&gt;add_editor_style&lt;/code&gt;&lt;/a&gt; for detais).&lt;/p&gt;&lt;p&gt;For shortcodes, they might not have an HTML element themselves. How should we style them? Well, this situation is much more complex to achieve the result, it&amp;#8217;s not impossible though (you can see some default WordPress button such as &amp;#8216;Add media&amp;#8217;). However, it can still be a tricky, by wrapping that shortcode in a HTML element and then styling that element just like above. It&amp;#8217;s quite simple, not completely perfect though. In this post, we won&amp;#8217;t focus on that complex processing.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Results&lt;/h2&gt;&lt;p&gt;Finally, the results we get are shown as following:&lt;/p&gt; &lt;figure
class="tutorial_image"&gt; &lt;a
href="http://wp.tutsplus.com/?attachment_id=31247" rel="attachment wp-att-31247"&gt;&lt;img
src="http://cdn.tutsplus.com/wp.tutsplus.com/authors/leepham/Guide-To-Creating-Your-Own-WPs-Editor-Buttons-2.png" alt="Test-the-Dropcap-button." width="211" height="203" class="alignnone size-full wp-image-31247" /&gt;&lt;/a&gt;&lt;br
/&gt; &lt;figcaption&gt;Test the Dropcap button.&lt;/figcaption&gt; &lt;/figure&gt;&lt;p&gt;Then, on the front-end:&lt;/p&gt; &lt;figure
class="tutorial_image"&gt; &lt;a
href="http://wp.tutsplus.com/?attachment_id=31248" rel="attachment wp-att-31248"&gt;&lt;img
src="http://cdn.tutsplus.com/wp.tutsplus.com/authors/leepham/Guide-To-Creating-Your-Own-WPs-Editor-Buttons-3.png" alt="Dropcap-letter-in-front-end." width="445" height="205" class="alignnone size-full wp-image-31248" /&gt;&lt;/a&gt;&lt;br
/&gt; &lt;figcaption&gt;Dropcap letter in front-end.&lt;/figcaption&gt; &lt;/figure&gt;&lt;p&gt;And the Recent Posts button works well too:&lt;/p&gt; &lt;figure
class="tutorial_image"&gt; &lt;a
href="http://wp.tutsplus.com/?attachment_id=31249" rel="attachment wp-att-31249"&gt;&lt;img
src="http://cdn.tutsplus.com/wp.tutsplus.com/authors/leepham/Guide-To-Creating-Your-Own-WPs-Editor-Buttons-4.png" alt="Recent-Posts-button-worked." width="569" height="295" class="alignnone size-full wp-image-31249" /&gt;&lt;/a&gt;&lt;br
/&gt; &lt;figcaption&gt;Recent Posts button worked.&lt;/figcaption&gt; &lt;/figure&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Okay, we covered a practice which is quite simple and easy to follow. You might notice that the Recent Posts button allows you to adjust a setting (the number of posts that will show). You certainly know that we used the default JavaScript, &lt;code&gt;prompt&lt;/code&gt;, to achieve that. What if you want a more complex popup, which has many settings rather than only one? Well, in another post we will discuss this and try another approach.&lt;/p&gt;&lt;p&gt;Any feedback about this post will be appreciated. Thanks for reading, and see you later.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Reference&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a
href="http://codex.wordpress.org/TinyMCE_Custom_Buttons"&gt;&lt;code&gt;TinyMCE_Custom_Buttons&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href="http://www.tinymce.com/wiki.php/Creating_a_plugin"&gt;Creating A TinyMCE Plugin&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/smdREbjvZMo" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/theme-development/guide-to-creating-your-own-wordpress-editor-buttons/feed/</wfw:commentRss> <slash:comments>9</slash:comments> <feedburner:origLink>http://wp.tutsplus.com/tutorials/theme-development/guide-to-creating-your-own-wordpress-editor-buttons/</feedburner:origLink></item> </channel> </rss><!-- Dynamic Page Served (once) in 0.858 seconds -->
