<?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>Thu, 23 May 2013 23:16:54 +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>Using CSS Preprocessors With WordPress – LESS + CodeKit</title><link>http://feedproxy.google.com/~r/Wptuts/~3/htoTM8fj6cY/</link> <comments>http://wp.tutsplus.com/tutorials/theme-development/using-css-preprocessors-with-wordpress-less-codekit/#comments</comments> <pubDate>Thu, 23 May 2013 12:37:36 +0000</pubDate> <dc:creator>Jason Bradley</dc:creator> <category><![CDATA[Theme Development]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[LESS]]></category> <category><![CDATA[preprocessors]]></category> <category><![CDATA[Sass]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31524</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 2 of 2 in the series &lt;a
href="http://wp.tutsplus.com/series/using-preprocessors-with-wordpress/" class="series-1122" title="Using Preprocessors With WordPress"&gt;Using Preprocessors With WordPress&lt;/a&gt;&lt;/div&gt;&lt;p&gt;In the &lt;a
title="Using CSS Preprocessors With WordPress – What Are They?" href="http://wp.tutsplus.com/tutorials/theme-development/using-preprocessors-with-wordpress-what-are-they/"&gt;first part of this series&lt;/a&gt; I gave a quick overview of the popular CSS preprocessors LESS and SASS. I also shared a few of the frameworks in which they are used.&lt;/p&gt;&lt;p&gt;I plan on taking a deeper dive into LESS and talking about the parts of the language I use most often. I also plan on showing you how to get started using it with &lt;a
title="http://incident57.com/codekit/" href="http://incident57.com/codekit/"&gt;CodeKit&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Let&amp;#8217;s dig in!&lt;span
id="more-31524"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;What I Use and Why&lt;/h2&gt;&lt;p&gt;I personally use LESS for most WordPress projects. I spend a lot of time working with &lt;a
title="http://standardtheme.com" href="http://standardtheme.com"&gt;Standard&lt;/a&gt; and it uses &lt;a
title="http://twitter.github.io/bootstrap/" href="http://twitter.github.io/bootstrap/"&gt;Bootstrap&lt;/a&gt; as its framework of choice.&lt;/p&gt;&lt;p&gt;Since Bootstrap uses LESS for compiling its CSS, I have learned how to use its &lt;strong&gt;.less&lt;/strong&gt; files to make modifications. I know of other web designers and developers who prefer to use &lt;a
title="http://foundation.zurb.com/" href="http://foundation.zurb.com/"&gt;Foundation&lt;/a&gt;. Since Foundation uses SASS, they have learned to use that instead.&lt;/p&gt;&lt;p&gt;I am personally starting to work on another web project that uses SASS, and it has been relatively easy to pick things up due to my experience with LESS.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;A Look at LESS&lt;/h2&gt;&lt;h3&gt;Variables&lt;/h3&gt;&lt;p&gt;Variables are pretty self-explanatory. You can create a variable somewhere in your &lt;strong&gt;.less&lt;/strong&gt; file and then reference it in other places in that file, or other files. I tend to use it for colors, fonts, padding, and margins.&lt;/p&gt;&lt;p&gt;Here&amp;#8217;s an example:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
// Variables
@red: #ff0000;
@green: #00ff00;
@blue: #0000ff;

// Styling

// Links
a { color: @blue; }
a:visited { color: @blue; }
&lt;/pre&gt;&lt;p&gt;That will then compile to this:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
a { color: #0000ff; }
a:visited { color: #0000ff; }
&lt;/pre&gt;&lt;p&gt;If you wanted to change the color of both link stylings, then you just need to change the variable:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;@blue&lt;/pre&gt;&lt;p&gt;from&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;#0000ff&lt;/pre&gt;&lt;p&gt;to&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;#0000a4&lt;/pre&gt;&lt;p&gt;You change in one spot, recompile, and you have changed all instances of that variable throughout the file.&lt;/p&gt;&lt;p&gt;Another great way to use these variables as well would be to use more semantic naming like:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;@primaryColor&lt;/pre&gt;&lt;p&gt;and&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;@secondaryColor&lt;/pre&gt;&lt;p&gt;You can then use those variables throughout your code. When your designer comes up with those colors, you can just change them once, recompile, then you&amp;#8217;re done!&lt;/p&gt;&lt;h3&gt;Nesting&lt;/h3&gt;&lt;p&gt;Nesting is used just like you would nest logic in an &lt;code&gt;if/else&lt;/code&gt; block in your PHP or JavaScript: You set your higher level selector like &lt;code&gt;.post&lt;/code&gt;, then place the other selectors inside of it. It will eliminate the need to repeatedly type out &lt;code&gt;.post&lt;/code&gt; in front of your other selectors like so:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
// Post
.post {
	padding: 20px;
	.post-header {
		margin: 20px 0;
	}
}
&lt;/pre&gt;&lt;p&gt;That will then compile to this:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
.post { padding: 20px; }
.post .post-header { margin: 20px 0; }
&lt;/pre&gt;&lt;p&gt;You can also use &lt;code&gt;&amp;amp;&lt;/code&gt; to concatenate selectors as well. An example could be if you wanted to target specific widgets in your sidebar. Let&amp;#8217;s say you wanted to style the background color of Recent Posts and Recent Comments widgets differently. You can do the following in LESS:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
.widget {
	padding: 20px;
	&amp;amp;.widget_recent_entries {
		background-color: white;
	}
	&amp;amp;.widget_recent_comments {
		background-color: black;
	}
}
&lt;/pre&gt;&lt;p&gt;That would compile into this:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
.widget { padding: 20px; }
.widget.widget_recent_entries { background-color: white; }
.widget.widget_recent_comments { background-color: black; }
&lt;/pre&gt;&lt;p&gt;You can also use this for pseudo classes like &lt;code&gt;:hover&lt;/code&gt;, &lt;code&gt;:active&lt;/code&gt;, &lt;code&gt;:visited&lt;/code&gt;, &lt;code&gt;:before&lt;/code&gt;, and &lt;code&gt;:after&lt;/code&gt;.&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
// Links
a {
	color: blue;
	&amp;amp;:hover {
		color: red;
	}
	&amp;amp;:visited {
		color: red;
	}
}
&lt;/pre&gt;&lt;p&gt;That would compile to this:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
a { color: blue; }
a:hover { color: red; }
a:visited { color: red; }
&lt;/pre&gt;&lt;h3&gt;Mixins&lt;/h3&gt;&lt;p&gt;Mixins are basically a number of style attributes that you want to group together. A great example of this is for attributes that are different between browsers like border radius.&lt;/p&gt;&lt;p&gt;Instead of having to remember each one, you can call your mixin and it will provide each attribute for you. Here&amp;#8217;s an example:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
// Mixin
.border-radius {
	border-radius: 4px;
	-moz-border-radius: 4px;
	-webkit-border-radius: 4px;
}
// Widget
.widget {
	.border-radius;
}
&lt;/pre&gt;&lt;p&gt;That will compile to the following:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
.widget {
	border-radius: 4px;
	-moz-border-radius: 4px;
	-webkit-border-radius: 4px;
}
&lt;/pre&gt;&lt;p&gt;What if you wanted to use border radius multiple times in your &lt;strong&gt;.less&lt;/strong&gt; file but wanted different amounts for each? That&amp;#8217;s when you would use a &lt;a
title="http://lesscss.org" href="http://lesscss.org"&gt;Parametric Mixin&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;This simply means that you can reuse a mixin and pass it an argument to use. Here&amp;#8217;s an example:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
// Mixin
.border-radius (@radius: 4px) {
	border-radius: @radius;
	-moz-border-radius: @radius;
	-webkit-border-radius: @radius;
}

// Widget
.widget {
	.border-radius();
}

// Post
.post {
	.border-radius(8px);
}
&lt;/pre&gt;&lt;p&gt;That would compile to this:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
.widget {
	border-radius: 4px;
	-moz-border-radius: 4px;
	-webkit-border-radius: 4px;
}
.post {
	border-radius: 8px;
	-moz-border-radius: 8px;
	-webkit-border-radius: 8px;
}
&lt;/pre&gt;&lt;h3&gt;Putting It All Together&lt;/h3&gt;&lt;p&gt;Here&amp;#8217;s an example of using variables, nesting, and mixins all at the same time:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
// Variables
@widget-recent-posts-border-radius: 4px;
@widget-recent-posts-background-color: white;
@widget-recent-posts-link-color: @blue;

@widget-recent-comments-border-radius: 8px;
@widget-recent-comments-background-color: black;
@widget-recent-comments-link-color: @red;

// Colors
@blue: #0000ff;
@red: #ff0000;

// Mixins
.border-radius (@radius: 4px) {
	border-radius: @radius;
	-moz-border-radius: @radius;
	-webkit-border-radius: @radius;
}

// Widgets
.widget {
	&amp;amp;.widget_recent_entries {
		background-color: @widget-recent-posts-background-color;
		.border-radius(@widget-recent-posts-border-radius);
		ul li a {
			color: @widget-recent-posts-link-color;
		}
	&amp;amp;.widget_recent_comments {
		background-color: @widget-recent-comments-background-color;
		.border-radius(@widget-recent-comments-border-radius);
		ul li a {
			color: @widget-recent-comments-link-color;
		}
	}
}
&lt;/pre&gt;&lt;p&gt;Which would all compile into this:&lt;/p&gt;&lt;pre class="brush: css; title: ; notranslate"&gt;
.widget.wiget_recent_entries {
	background-color: white;
	border-radius: 4px;
	-moz-border-radius: 4px;
	-webkit-border-radius: 4px;
}
.widget.widget_recent_entries ul li a { color: #0000ff; }
.widget.wiget_recent_comments {
	background-color: black;
	border-radius: 8px;
	-moz-border-radius: 8px;
	-webkit-border-radius: 8px;
}
.widget.widget_recent_entries ul li a { color: #ff0000; }
&lt;/pre&gt;&lt;hr
/&gt;&lt;h2&gt;Using CodeKit&lt;/h2&gt;&lt;h3&gt;Importing a Project&lt;/h3&gt;&lt;p&gt;It&amp;#8217;s extremely easy to setup your CodeKit Project. You can simply drag and drop your folder into CodeKit, or you can click the plus button in the bottom left and then select a folder from the file browser.&lt;/p&gt;&lt;p&gt;Once you do that, CodeKit will automatically scan all the files in that folder and then group them into the following categories:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Styles&lt;/li&gt;&lt;li&gt;Scripts&lt;/li&gt;&lt;li&gt;Pages&lt;/li&gt;&lt;li&gt;Images&lt;/li&gt;&lt;/ul&gt; &lt;figure
class="tutorial_image"&gt;&lt;a
href="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/codekit-file-types.png"&gt;&lt;img
class="alignnone size-full wp-image-31528" alt="codekit-file-types" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/codekit-file-types.png" width="600" height="400" /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;h3&gt;Configuring the Project&lt;/h3&gt;&lt;p&gt;So you have now imported your project files. Next we are going to set the output path of your &lt;strong&gt;.less&lt;/strong&gt; files. I would suggest to have a &lt;strong&gt;css&lt;/strong&gt; folder and a &lt;strong&gt;less&lt;/strong&gt; folder inside of it. You will want to make sure to have all of your files in that &lt;strong&gt;less&lt;/strong&gt; folder to point to your &lt;strong&gt;style.less&lt;/strong&gt; file.&lt;/p&gt;&lt;p&gt;You will want to switch over to the Styles view. We will want to have the &lt;strong&gt;style.less&lt;/strong&gt; file be compiled into your theme&amp;#8217;s root folder as &lt;strong&gt;style.css&lt;/strong&gt;. To do this, you will want to right-click on the &lt;strong&gt;style.less&lt;/strong&gt; file, and select &amp;#8220;&lt;em&gt;Set output path…&lt;/em&gt;&amp;#8220;. This will bring up a File Browser.&lt;/p&gt; &lt;figure
class="tutorial_image"&gt;&lt;a
href="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/set-output-path.png"&gt;&lt;img
class="alignnone size-full wp-image-31526" alt="set-output-path" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/set-output-path.png" width="600" height="400" /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;p&gt;Next, you will want to click in the Output filename and extension text input. Once you do that it may auto populate &lt;strong&gt;style.css&lt;/strong&gt; for you. If it doesn&amp;#8217;t, then you will want to enter in &lt;strong&gt;style.css&lt;/strong&gt;. Lastly you will click on &lt;em&gt;Select&lt;/em&gt; to save.&lt;/p&gt;&lt;p&gt;We are almost there! Next we will need to select a compilation setting. You will see the compilation settings screen reveal itself when you click on a &lt;strong&gt;.less&lt;/strong&gt; file. We have three available output styles:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Regular&lt;/li&gt;&lt;li&gt;Minified&lt;/li&gt;&lt;li&gt;Compressed (YUI)&lt;/li&gt;&lt;/ul&gt; &lt;figure
class="tutorial_image"&gt;&lt;a
href="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/codekit-output-style.png"&gt;&lt;img
class="alignnone size-full wp-image-31527" alt="codekit-output-style" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/codekit-output-style.png" width="600" height="400" /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;p&gt;Select one of the above and click on &amp;#8220;&lt;em&gt;Compile&lt;/em&gt;&amp;#8220;. You should get a notification that your &lt;strong&gt;style.less&lt;/strong&gt; file has compiled.&lt;/p&gt;&lt;p&gt;If all of your syntax is correct, your compile will be successful. If there are any errors, it will flip you over to the &lt;em&gt;Log&lt;/em&gt; view and give you the line number and explanation of the error.&lt;/p&gt;&lt;p&gt;If everything compiles correctly, you should be able to open up your &lt;strong&gt;style.css&lt;/strong&gt; file and see the output. As you edit your &lt;strong&gt;.less&lt;/strong&gt; files and save them, CodeKit will automatically recompile your files.&lt;/p&gt;&lt;p&gt;Note: Make sure that you don&amp;#8217;t make any changes to the &lt;strong&gt;style.css&lt;/strong&gt; file, because as soon as you recompile your &lt;strong&gt;.less&lt;/strong&gt; files, your changes will be overridden.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;We have now gone through a deeper dive into LESS and broken down a few of the popular features. I have explained a few reasons why I personally choose to use LESS in my WordPress projects and how to use CodeKit to compile all of my files.&lt;/p&gt;&lt;p&gt;In the next post, I will go into greater detail around how to structure your &amp;#8216;&lt;strong&gt;.less&lt;/strong&gt;&amp;#8216; files and connect them all together.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Resources&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="http://lesscss.org " href="http://lesscss.org "&gt;LESS&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://twitter.github.io/bootstrap/ " href="http://twitter.github.io/bootstrap/ "&gt;Bootstrap&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://sass-lang.com/ " href="http://sass-lang.com/ "&gt;SASS&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://foundation.zurb.com/ " href="http://foundation.zurb.com/ "&gt;Foundation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://incident57.com/codekit/ " href="http://incident57.com/codekit/ "&gt;CodeKit&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/htoTM8fj6cY" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/theme-development/using-css-preprocessors-with-wordpress-less-codekit/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <series:name><![CDATA[Using Preprocessors With WordPress]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/tutorials/theme-development/using-css-preprocessors-with-wordpress-less-codekit/</feedburner:origLink></item> <item><title>Win a Ticket to Our New Tuts+ Live Workshop</title><link>http://feedproxy.google.com/~r/Wptuts/~3/2EAsPXRJofM/</link> <comments>http://wp.tutsplus.com/articles/news/31787giveaway/#comments</comments> <pubDate>Wed, 22 May 2013 14:45:17 +0000</pubDate> <dc:creator>Joel Bankhead</dc:creator> <category><![CDATA[News]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31787</guid> <description>&lt;p&gt;&lt;strong&gt;We have 5 tickets to give away for our newest Tuts+ Live Workshop, all you have to do is &lt;a
href="http://eepurl.com/qnEP5"&gt;subscribe to our newsletter&lt;/a&gt;. Be quick though, this giveaway ends on Monday!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;We have a superb new Workshop, &lt;a
href="http://workshops.tutsplus.com/plugin-development.html?utm_source=wptuts&amp;#038;utm_medium=giveawaypost&amp;#038;utm_campaign=pluginw"&gt;Introduction to WordPress Plugin Development&lt;/a&gt;, starting in a week. This is your chance to win a free ticket!&lt;/p&gt;&lt;p&gt;Simply &lt;a
href="http://eepurl.com/qnEP5"&gt;subscribe to the Tuts+ Live Workshops newsletter&lt;/a&gt; and we’ll pick the winners on Monday 27th. Read on to find out more about the Workshop and for more details about the giveaway!&lt;/p&gt;&lt;p&gt;&lt;span
id="more-31787"&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://workshops.tutsplus.com/plugin-development.html?utm_source=wptuts&amp;#038;utm_medium=giveawaypost&amp;#038;utm_campaign=pluginw"&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;Subscribe and Win a Ticket!&lt;/h2&gt;&lt;p&gt;We have 5 tickets to give away and will be choosing the winners from everyone who has subscribed to the Tuts+ Live Workshops newsletter, so no worries if you’ve already signed up. We’ll also reimburse any winners who have already paid for their ticket.&lt;/p&gt;&lt;p&gt;To enter simply &lt;a
href="http://eepurl.com/qnEP5"&gt;subscribe to the Tuts+ Live Workshops newsletter&lt;/a&gt; and stay informed on upcoming workshops!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/2EAsPXRJofM" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/articles/news/31787giveaway/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://wp.tutsplus.com/articles/news/31787giveaway/</feedburner:origLink></item> <item><title>Design Patterns in WordPress: We’re Just Getting Started</title><link>http://feedproxy.google.com/~r/Wptuts/~3/4mweN3gRWQQ/</link> <comments>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-were-just-getting-started/#comments</comments> <pubDate>Tue, 21 May 2013 12:26: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=31663</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 4 of 4 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;ve been taking a look at a few design patterns and how they are applicable to software development &amp;#8211; specifically WordPress development.&lt;/p&gt;&lt;p&gt;The thing about design patterns is that there is a &lt;em&gt;wide&lt;/em&gt; variety of them and it would be near impossible to do justice to each of the patterns in a series here on the blog. Nonetheless, hopefully taking a look at these three have helped kickstart your interest in using design patterns in your work.&lt;span
id="more-31663"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;To wrap up this series, I wanted to provide a list of other patterns, resources, and guides that you may find useful if you&amp;#8217;ve found this particular series useful in your development endeavors.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;A List of Design Patterns&lt;/h2&gt;&lt;p&gt;Here&amp;#8217;s the thing: The list of design patterns isn&amp;#8217;t fixed. There are some that have been established for quite some time.&lt;/p&gt;&lt;p&gt;The truth is, the patterns even have various permutations based on the environment in which they&amp;#8217;re implemented &amp;#8211; this is why I think it&amp;#8217;s so important to understand the core pattern so that you can adapt it to your needs, or so you can recognize it in the wild so that &amp;#8211; should the need arise &amp;#8211; you can continue to implement your work in a way that plays nicely with the existing implementation.&lt;/p&gt;&lt;p&gt;With that said, I can&amp;#8217;t possibly list out all of the design patterns here. I &lt;em&gt;can&lt;/em&gt; list out many of the popular patterns along with some links to their corresponding Wikipedia articles so you have a few to review.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="The Abstract Pattern" href="http://en.wikipedia.org/wiki/Abstract_factory_pattern" target="_blank"&gt;The Abstract Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Singleton Pattern" href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank"&gt;The Singleton Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Adapter Pattern" href="http://en.wikipedia.org/wiki/Adapter_pattern" target="_blank"&gt;The Adapter Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Composite Pattern" href="http://en.wikipedia.org/wiki/Composite_pattern" target="_blank"&gt;The Composite Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Decorator Pattern" href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank"&gt;The Decorator Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Flyweight Pattern" href="http://en.wikipedia.org/wiki/Flyweight_pattern" target="_blank"&gt;The Flyweight Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Chain of Responsibility Pattern" href="http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern" target="_blank"&gt;The Chain-of-Responsibility Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Null Object Pattern" href="http://en.wikipedia.org/wiki/Null_Object_pattern" target="_blank"&gt;The Null Object Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Visitor Pattern" href="http://en.wikipedia.org/wiki/Visitor_pattern" target="_blank"&gt;The Visitor Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="The Scheduler Pattern" href="http://en.wikipedia.org/wiki/Scheduler_pattern" target="_blank"&gt;The Scheduler Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;For a more comprehensive list, check out &lt;a
title="Object-Oriented Design Patterns" href="http://en.wikipedia.org/wiki/List_of_Object-oriented_design_patterns#Classification_and_list" target="_blank"&gt;this page&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For those that are listed above, I recommend at least reading through each of the articles. Many of the them will likely be applicable to your day-to-day work &lt;em&gt;especially&lt;/em&gt; if you&amp;#8217;re working on larger applications. Even if you&amp;#8217;re working on a smaller project, they&amp;#8217;re still applicable and beneficial.&lt;/p&gt;&lt;p&gt;After that, we&amp;#8217;ll take a look at two books that I highly recommend for developers to have on their desk at any given time.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Resources&lt;/h2&gt;&lt;p&gt;Whenever others ask me for resources on design patterns, there are really only two books that I recommend. Both of them are listed below along with links, a short description of each, why I recommend them, and the target audience for each of them.&lt;/p&gt;&lt;h3&gt;&lt;em&gt;Head First Design Patterns&lt;/em&gt;&lt;/h3&gt; &lt;figure
class="tutorial_image"&gt;&lt;img
class="aligncenter  wp-image-31670" alt="Head First Design Patterns" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/05/head-first-design-patterns.png" width="420" height="486" /&gt;&lt;/figure&gt;&lt;p&gt;&lt;em&gt;&lt;a
title="Head First Design Patterns" href="http://www.amazon.com/Head-First-Design-Patterns-ebook/dp/B00AA36RZY/ref=sr_1_1?ie=UTF8&amp;amp;qid=1368285420&amp;amp;sr=8-1&amp;amp;keywords=head+first+design+patterns" target="_blank"&gt;Head First Design Patterns&lt;/a&gt;&lt;/em&gt; is a relatively new book in comparison to a lot of the material that&amp;#8217;s available today. It uses a different teaching style than many classical books or text books in that it uses a lot of humor, lots of pictures, diagrams, humor, and so on.&lt;/p&gt;&lt;p&gt;Personally, I&amp;#8217;m a fan of its style but I know that some may reject it.&lt;/p&gt;&lt;p&gt;Nonetheless, the book covers the following patterns:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The Strategy Pattern&lt;/li&gt;&lt;li&gt;The Observer Pattern&lt;/li&gt;&lt;li&gt;The Decorator Pattern&lt;/li&gt;&lt;li&gt;The Simple Factory Pattern&lt;/li&gt;&lt;li&gt;The Factory Pattern&lt;/li&gt;&lt;li&gt;The Singleton Pattern&lt;/li&gt;&lt;li&gt;The Command Pattern&lt;/li&gt;&lt;li&gt;The Adapter Pattern&lt;/li&gt;&lt;li&gt;The Facade Pattern&lt;/li&gt;&lt;li&gt;The Template Method Pattern&lt;/li&gt;&lt;li&gt;The Iterator Pattern&lt;/li&gt;&lt;li&gt;The Composite Pattern&lt;/li&gt;&lt;li&gt;The State Pattern&lt;/li&gt;&lt;li&gt;The Proxy Pattern&lt;/li&gt;&lt;li&gt;The Compound Pattern&lt;/li&gt;&lt;li&gt;And a list of other common patterns that we&amp;#8217;ve listed in the first part of this article.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you&amp;#8217;re looking for a book to get started in design patterns, then this is the book with which I&amp;#8217;d start.&lt;/p&gt;&lt;h3&gt;&lt;em&gt;Design Patterns: Elements of Reusable Object-Oriented Software&lt;/em&gt;&lt;/h3&gt; &lt;figure
class="tutorial_image"&gt;&lt;img
class="aligncenter size-full wp-image-31671" alt="Gang of Four" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/05/gang-of-four.gif" width="420" height="523" /&gt;&lt;/figure&gt;&lt;p&gt;This book is also known as &lt;em&gt;&lt;a
title="Design Patterns: Elements of Reusable Object-Oriented Software" href="http://www.amazon.com/Design-Patterns-Elements-Object-Oriented-ebook/dp/B000SEIBB8/ref=sr_1_4?ie=UTF8&amp;amp;qid=1368286647&amp;amp;sr=8-4&amp;amp;keywords=gang+of+four" target="_blank"&gt;The Gang of Four Book&lt;/a&gt;&lt;/em&gt; because it was written by four accomplished software engineers. It&amp;#8217;s a more technical read than &lt;em&gt;Head First Design Patterns&lt;/em&gt;, but I still recommend it as the description of the patterns and the provided diagrams and implementations are easy to follow.&lt;/p&gt;&lt;p&gt;I will say that if you&amp;#8217;re just now venturing into the world of design patterns, I&amp;#8217;d start with &lt;em&gt;Head First&lt;/em&gt; and then read this book; otherwise, this one may seem a bit more dry or less interesting.&lt;/p&gt;&lt;p&gt;Nonetheless, here&amp;#8217;s the list of patterns the &lt;em&gt;Gang of Four&lt;/em&gt; provide in their book:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The Abstract Pattern&lt;/li&gt;&lt;li&gt;The Builder Pattern&lt;/li&gt;&lt;li&gt;The Factory Pattern&lt;/li&gt;&lt;li&gt;The Prototype Pattern&lt;/li&gt;&lt;li&gt;The Singleton Pattern&lt;/li&gt;&lt;li&gt;The Chain of Responsibility&lt;/li&gt;&lt;li&gt;The Command Pattern&lt;/li&gt;&lt;li&gt;The Interpreter Pattern&lt;/li&gt;&lt;li&gt;The Iterator Pattern&lt;/li&gt;&lt;li&gt;The Mediator Pattern&lt;/li&gt;&lt;li&gt;The Memento Pattern&lt;/li&gt;&lt;li&gt;The Observer Pattern&lt;/li&gt;&lt;li&gt;The State Pattern&lt;/li&gt;&lt;li&gt;The Strategy Pattern&lt;/li&gt;&lt;li&gt;The Template Method Pattern&lt;/li&gt;&lt;li&gt;The Adapter Pattern&lt;/li&gt;&lt;li&gt;The Bridge Pattern&lt;/li&gt;&lt;li&gt;The Composite Pattern&lt;/li&gt;&lt;li&gt;The Decorator Pattern&lt;/li&gt;&lt;li&gt;The Facade Pattern&lt;/li&gt;&lt;li&gt;The Flyweight Pattern&lt;/li&gt;&lt;li&gt;The Proxy Pattern&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition to covering the patterns, the book also uses case studies to show actual implementations of the pattern in real world examples which I think can be incredibly useful when referring to them in your work.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;One of the dangers for people who first discover design patterns is the propensity to try to apply them &lt;em&gt;everywhere&lt;/em&gt;, but don&amp;#8217;t do that: design patterns offer a lot of advantages in software development, but they have their place and things should not be forced into a pattern.&lt;/p&gt;&lt;p&gt;They should fit naturally.&lt;/p&gt;&lt;p&gt;In short, don&amp;#8217;t try to use patterns for the sake of using a pattern, use them when their design fits the problem that you&amp;#8217;re trying to solve.&lt;/p&gt;&lt;p&gt;With that said, we&amp;#8217;ve wrapped up the Design Patterns in WordPress series.&lt;/p&gt;&lt;p&gt;To summarize:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;We&amp;#8217;ve covered the Observer Pattern and how we can setup our code to fire events and to publish them to other objects that are interested.&lt;/li&gt;&lt;li&gt;We&amp;#8217;ve reviewed how to setup our plugins so that a single instance of the plugin is always accessible throughout the lifetime of the plugin, theme, or application&lt;/li&gt;&lt;li&gt;We also took a detailed look at the Simple Factory pattern that included a demo application, diagram, and sample code&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All in all, it feels as if we&amp;#8217;ve covered a lot of ground. The truth is, there&amp;#8217;s still much to review. If you&amp;#8217;ve found this particular series interesting, or want to take a deeper dive into the topics at hand, be sure to review the design patterns listed earlier in this article, or read the two books that are linked above.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/4mweN3gRWQQ" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/creative-coding/design-patterns-in-wordpress-were-just-getting-started/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-were-just-getting-started/</feedburner:origLink></item> <item><title>Using CSS Preprocessors With WordPress – What Are They?</title><link>http://feedproxy.google.com/~r/Wptuts/~3/LIeQNI_vY4E/</link> <comments>http://wp.tutsplus.com/tutorials/theme-development/using-preprocessors-with-wordpress-what-are-they/#comments</comments> <pubDate>Mon, 20 May 2013 14:32:45 +0000</pubDate> <dc:creator>Jason Bradley</dc:creator> <category><![CDATA[Theme Development]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[LESS]]></category> <category><![CDATA[preprocessors]]></category> <category><![CDATA[Sass]]></category> <guid isPermaLink="false">http://wp.tutsplus.com/?p=31512</guid> <description>&lt;div
class="seriesmeta"&gt;This entry is part 1 of 2 in the series &lt;a
href="http://wp.tutsplus.com/series/using-preprocessors-with-wordpress/" class="series-1122" title="Using Preprocessors With WordPress"&gt;Using Preprocessors With WordPress&lt;/a&gt;&lt;/div&gt;&lt;p&gt;I&amp;#8217;ve been working with WordPress for three years, but it wasn&amp;#8217;t until a year ago that I got serious about WordPress development. Specifically, I&amp;#8217;m passionate about child theming and spend much of my time working in theme development.&lt;/p&gt;&lt;p&gt;During the past couple of years, we&amp;#8217;ve seen the rise of CSS preprocessors &amp;#8211; mainly, tools that make writing stylesheets easier and make them more maintainable.&lt;/p&gt;&lt;p&gt;In this series, we&amp;#8217;re going to take a look at what preprocessors are, what popular ones are available, and how we can integrate them into our theme development.&lt;span
id="more-31512"&gt;&lt;/span&gt;&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Where We&amp;#8217;re Headed&lt;/h2&gt;&lt;p&gt;When it comes to user-interface development, it&amp;#8217;s not just about how to make things look great, but it&amp;#8217;s also about making things well-structured and as performant as possible, and I believe that this should be something that&amp;#8217;s pulled through in our WordPress projects, as well.&lt;/p&gt;&lt;p&gt;In this series, I plan on giving a little background on what preprocessors are and highlight some of the key players in the space. I will also talk about some of the more popular frameworks. I will then move on to more of a deep dive into LESS and explain why I prefer using it. Lastly I will cover how to use it with &lt;a
title="http://incident57.com/codekit/" href="http://incident57.com/codekit/"&gt;CodeKit&lt;/a&gt; to compile your CSS for your theme.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;About CSS Preprocessors&lt;/h2&gt;&lt;p&gt;As mentioned, there are a number of CSS preprocessors, the most commonly used being LESS and SASS. Both are syntactically similar and can dramatically increase the speed at which you can write your CSS.&lt;/p&gt;&lt;p&gt;There are a few differences like their compilers and extensions or frameworks with which they can be combined.&lt;/p&gt;&lt;h3&gt;LESS&lt;/h3&gt; &lt;figure
class="tutorial_image"&gt;&lt;a
href="http://lesscss.org" rel="attachment wp-att-31513"&gt;&lt;img
class="size-full wp-image-31513 alignright" title="LESS Logo" alt="less_logo" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/less_logo.png" width="199" height="81" /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;p&gt;&lt;a
title="http://lesscss.org" href="http://lesscss.org"&gt;LESS&lt;/a&gt; is a dynamic stylesheet language. You can write your CSS programmatically in a &lt;strong&gt;.less&lt;/strong&gt; file and compile your output into a &lt;strong&gt;.css&lt;/strong&gt; file. The compilation language for LESS is JavaScript. This a great because you can run the compiler on the server side or client side.&lt;/p&gt;&lt;p&gt;Some of the features of LESS include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="http://lesscss.org/#-variables" href="http://lesscss.org/#-variables"&gt;Variables&lt;/a&gt; &amp;#8211; Variables can be defined and are used throughout your file. Make a change in one place and see it updated wherever it&amp;#8217;s used.&lt;/li&gt;&lt;li&gt;&lt;a
title="http://lesscss.org/#-mixins" href="http://lesscss.org/#-mixins"&gt;Mixins&lt;/a&gt; &amp;#8211; Mixins include a bunch of properties from one ruleset into another ruleset. You can also use &lt;a
title="http://lesscss.org/#-parametric-mixins" href="http://lesscss.org/#-parametric-mixins"&gt;Parametric Mixins&lt;/a&gt; that accept arguments.&lt;/li&gt;&lt;li&gt;&lt;a
title="http://lesscss.org/#-nested-rules" href="http://lesscss.org/#-nested-rules"&gt;Nested Rules&lt;/a&gt; &amp;#8211; Nested Rules give you the ability to use nesting instead of, or in combination with cascading.&lt;/li&gt;&lt;li&gt;&lt;a
title="http://lesscss.org/#-namespaces" href="http://lesscss.org/#-namespaces"&gt;Namespaces&lt;/a&gt; &amp;#8211; Namespaces allow you to group your variables or mixins, for organizational purposes, or just to offer some encapsulation.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I will be going into more detail on the syntax for these in the next post in this series.&lt;/p&gt;&lt;p&gt;Two of the more popular front-end frameworks that use LESS are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="http://twitter.github.com/bootstrap/" href="http://twitter.github.com/bootstrap/"&gt;Bootstrap&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://framelessgrid.com/#downloads" href="http://framelessgrid.com/#downloads"&gt;Frameless&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;SASS&lt;/h3&gt; &lt;figure
class="tutorial_image"&gt;&lt;a
href="http://sass-lang.com/" rel="attachment wp-att-31514"&gt;&lt;img
class="size-full wp-image-31514 alignright" title="SASS Logo" alt="sass_logo" src="http://cdn.tutsplus.com/wp.tutsplus.com/uploads/2013/04/sass_logo.gif" width="217" height="238" /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;p&gt;&lt;a
title="http://sass-lang.com/" href="http://sass-lang.com/"&gt;SASS&lt;/a&gt; is an extension of CSS3. It has two syntaxes: &lt;code&gt;.scss&lt;/code&gt; and &lt;code&gt;.sass&lt;/code&gt;. &lt;code&gt;.SCSS&lt;/code&gt; is the most common syntax used but it also supports the older &lt;a
title="http://sass-lang.com/docs/yardoc/file.INDENTED_SYNTAX.html" href="http://sass-lang.com/docs/yardoc/file.INDENTED_SYNTAX.html"&gt;indented syntax&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Some of the features of SASS include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="http://sass-lang.com/#variables" href="http://sass-lang.com/#variables"&gt;Variables&lt;/a&gt; &amp;#8211; Variables can be defined and are used throughout your file. Make a change in one place and see it updated wherever it&amp;#8217;s used like LESS.&lt;/li&gt;&lt;li&gt;&lt;a
title="http://sass-lang.com/#mixins" href="http://sass-lang.com/#mixins"&gt;Mixins&lt;/a&gt; &amp;#8211; Mixins allow you to re-use whole chunks of CSS, properties or selectors like LESS&lt;/li&gt;&lt;li&gt;&lt;a
title="http://sass-lang.com/#nesting" href="http://sass-lang.com/#nesting"&gt;Nesting&lt;/a&gt; &amp;#8211; Avoid repetition by nesting selectors within one another like LESS&lt;/li&gt;&lt;li&gt;&lt;a
title="http://sass-lang.com/#extend" href="http://sass-lang.com/#extend"&gt;Selector Inheritance&lt;/a&gt; &amp;#8211; It can tell one selector to inherit all the styles of another without duplicating the CSS properties. Not available in LESS.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Here&amp;#8217;s a few frameworks that include SASS and SCSS:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="http://foundation.zurb.com/" href="http://foundation.zurb.com/"&gt;Foundation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://gravityframework.com/" href="http://gravityframework.com/"&gt;Gravity&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://framelessgrid.com/#downloads" href="http://framelessgrid.com/#downloads"&gt;Frameless&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr
/&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;CSS Preprocessors are definitely a growing trend in web design. They can dramatically speed up the time you spend on writing styles for your sites.&lt;/p&gt;&lt;p&gt;They can also help with structuring your CSS like you would functions in other languages like PHP or JavaScript. If you aren&amp;#8217;t already using CSS preprocessors in your web project, you should definitely consider it.&lt;/p&gt;&lt;p&gt;Now that we&amp;#8217;ve taken a look at two of the more popular preprocessors, I&amp;#8217;ll take a deeper dive into LESS and give some reasons why I personally choose to use it in the next post. I will also show you how to get started with using CodeKit with your WordPress projects.&lt;/p&gt;&lt;hr
/&gt;&lt;h2&gt;Resources&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a
title="http://lesscss.org" href="http://lesscss.org"&gt;LESS&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
title="http://sass-lang.com/" href="http://sass-lang.com/"&gt;SASS&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/Wptuts/~4/LIeQNI_vY4E" height="1" width="1"/&gt;</description> <wfw:commentRss>http://wp.tutsplus.com/tutorials/theme-development/using-preprocessors-with-wordpress-what-are-they/feed/</wfw:commentRss> <slash:comments>15</slash:comments> <series:name><![CDATA[Using Preprocessors With WordPress]]></series:name> <feedburner:origLink>http://wp.tutsplus.com/tutorials/theme-development/using-preprocessors-with-wordpress-what-are-they/</feedburner:origLink></item> <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>2</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 4 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>3</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>3</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 4 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 4 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>12</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>Learn WordPress Plugin Development with Tuts+ Live Workshops</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;We are excited to announce a fantastic new workshop led by Instructor Tom McFarlin: &lt;a
href="http://enva.to/Z7ZGBR"&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;Tickets are a great investment at $99, 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/Z7ZGBR"&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;Workshop Schedule&lt;/h2&gt;&lt;p&gt;The weekly workshops will be taking place at 12pm EDT (US), on the following days:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Thursday 30th May – Let&amp;#8217;s Set Up&lt;/li&gt;&lt;li&gt;Thursday 6th June &amp;#8211; Planning The Plugin&lt;/li&gt;&lt;li&gt;Thursday 13th June &amp;#8211; Building WP IS.GD &amp;#8211; Part 1&lt;/li&gt;&lt;li&gt;Thursday 20th June &amp;#8211; Building WP IS.GD, Part 2&lt;/li&gt;&lt;li&gt;Thursday 27th June &amp;#8211; Preparing The Plugin For Release&lt;/li&gt;&lt;/ul&gt;&lt;hr
/&gt;&lt;h2&gt;Sign Up to Our Newsletter&lt;/h2&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/Z7ZGBR"&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> </channel> </rss><!-- Dynamic Page Served (once) in 0.815 seconds -->
