<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Konstantin Kovshenin &#187; tips</title>
	<atom:link href="http://kovshenin.com/tag/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://kovshenin.com</link>
	<description>WordPress, Automattic and Open Source</description>
	<lastBuildDate>Mon, 21 May 2012 15:59:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Quick tip: Hide the Home Item on Your Front Page in WordPress</title>
		<link>http://kovshenin.com/2012/quick-tip-hide-the-home-item-on-your-front-page-in-wordpress/</link>
		<comments>http://kovshenin.com/2012/quick-tip-hide-the-home-item-on-your-front-page-in-wordpress/#comments</comments>
		<pubDate>Fri, 11 May 2012 07:00:41 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5662</guid>
		<description><![CDATA[The title says it all &#8212; this one-liner CSS will hide the home item from your navigation menu, when you&#8217;re on the home page: body.home .current-menu-item { display: none; } If you&#8217;re not yet using wp_nav_menu to build your navigation menus, then, uhm, wake up! Also, the snippet relies on the body_class usage in your [...]]]></description>
			<content:encoded><![CDATA[<p>The title says it all &#8212; this one-liner CSS will hide the home item from your navigation menu, when you&#8217;re on the home page:</p>
<pre>body.home .current-menu-item { display: none; }
</pre>
<p>If you&#8217;re not yet using <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu</a> to build your navigation menus, then, uhm, wake up! Also, the snippet relies on the <a href="http://codex.wordpress.org/Function_Reference/body_class">body_class</a> usage in your theme, and if your theme doesn&#8217;t use one, uhm, <a href="http://codex.wordpress.org/Theme_Review#Required_Hooks_and_Navigation">wake up</a>! :)</p>
<p>I also want to avoid the discussion about how the primary navigation should be consistent through each and every page on the website, if at all possible :)</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/quick-tip-hide-the-home-item-on-your-front-page-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Never Set Defaults in the Database</title>
		<link>http://kovshenin.com/2012/never-set-defaults-in-the-database/</link>
		<comments>http://kovshenin.com/2012/never-set-defaults-in-the-database/#comments</comments>
		<pubDate>Fri, 04 May 2012 14:57:37 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5636</guid>
		<description><![CDATA[Speaking of defaults, NEVER SET DEFAULTS IN THE DATABASE. Not ever. The theme options you store in the DB should always, always, *always* be something the user has selected. If the user selects the default, then that’s fine to set in the DB. but you don’t set it in the DB just because it’s not [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Speaking of defaults, NEVER SET DEFAULTS IN THE DATABASE. Not ever. The theme options you store in the DB should always, always, *always* be something the user has selected. If the user selects the default, then that’s fine to set in the DB. but you don’t set it in the DB just because it’s not set at all. get_theme_mod has a second option for the default value. So does get_option for that matter. Use this.</p>
<p><cite>Otto Wood, WordPress Core Developer on <a href="http://wpcandy.com/thinks/custom-admin-screens-are-the-worst#comment-127921">Custom Admin Screens</a></cite>
</p></blockquote>
<p>Thanks, Otto, for clearing that up :)</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/never-set-defaults-in-the-database/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Default Custom Background for WordPress 3.4</title>
		<link>http://kovshenin.com/2012/default-custom-background-for-wordpress-3-4/</link>
		<comments>http://kovshenin.com/2012/default-custom-background-for-wordpress-3-4/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 08:59:01 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5509</guid>
		<description><![CDATA[Custom backgrounds are handled through add_theme_support since WordPress 3.4, and although you can add your custom callback to wp_head, you don&#8217;t need you. You can simply pass a default-image to add_theme_support for your custom background: add_theme_support( 'custom-background', array( 'default-image' =&#62; get_template_directory_uri() . '/images/default-background.png', ) ); The default custom background image will be used when one [...]]]></description>
			<content:encoded><![CDATA[<p>Custom backgrounds are handled through <a href="http://codex.wordpress.org/Function_Reference/add_theme_support">add_theme_support</a> since WordPress 3.4, and although you can add your custom callback to <code>wp_head</code>, you don&#8217;t need you. You can simply pass a <code>default-image</code> to <code>add_theme_support</code> for your custom background:</p>
<pre>add_theme_support( 'custom-background', array(
	'default-image' =&gt; get_template_directory_uri() . '/images/default-background.png',
) );</pre>
<p>The default custom background image will be used when one is not set, or the user hits the &#8220;Restore Original Image&#8221; button in the custom background options. However, the old method should still be compatible with WordPress 3.4, unless you&#8217;re doing something wrong :)</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/default-custom-background-for-wordpress-3-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Disable Jetpack Subscriptions Notifications</title>
		<link>http://kovshenin.com/2012/how-to-disable-jetpack-subscriptions-notifications/</link>
		<comments>http://kovshenin.com/2012/how-to-disable-jetpack-subscriptions-notifications/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 13:23:37 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[jetpack]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5307</guid>
		<description><![CDATA[It&#8217;s more difficult to keep this in mind, than it is to actually execute it. Sometimes we (content creators) want to publish content to see how it feeds to our Twitter or Facebook accounts, or to see how it turns up in the RSS feed, so what we usually do is publish a &#8220;test&#8221; post [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s more difficult to keep this in mind, than it is to actually execute it. Sometimes we (content creators) want to publish content to see how it feeds to our Twitter or Facebook accounts, or to see how it turns up in the RSS feed, so what we usually do is publish a &#8220;test&#8221; post and delete it afterwards (together with the tweet and Facebook post.)</p>
<p>However, sent e-mails cannot be deleted, once they&#8217;re out there, there&#8217;s no turning back. It&#8217;s not the best user experience to receive a &#8220;testing my twitter plugin&#8221; e-mail, right? <a href="http://jetpack.me/">Jetpack</a> is one of the best ways to deliver e-mail notifications, about your new posts, to your subscribers. I <a href="http://kovshenin.com/2012/using-jetpack-for-e-mail-subscriptions-in-wordpress/">wrote</a> about it before and actually <a href="http://kovshenin.com/subscribe/">use it</a> myself.</p>
<p>The best way to prevent all of this is of course to use dummy accounts or staging servers. The second best way to test your posts publishing out, is to wait for actual content (and if things didn&#8217;t work, try again next time), but sometimes we want to just try it out in our live environment, and if you do that, don&#8217;t forget to disable Jetpack subscriptions, which can be done in two easy steps. In the Jetpack configuration page under Subscriptions, hit <strong>Learn More</strong> and you&#8217;ll see a <strong>Deactivate</strong> button.</p>
<p><a href="http://kovshenin.com/files/2012/03/disable-jetpack-subscriptions.png"><img class="alignnone size-large wp-image-5308" title="Disable Jetpack Subscriptions" src="http://kovshenin.com/files/2012/03/disable-jetpack-subscriptions-680x197.png" alt="Disable Jetpack Subscriptions" width="580" height="168" /></a></p>
<p>Don&#8217;t worry, you will not loose all your subscribers, they&#8217;ll start receiving notification e-mails, when you <strong>Activate</strong> the subscriptions module again on that very same page, and yeah, don&#8217;t forget to activate it back when you&#8217;re done &#8220;testing things out.&#8221;</p>
<p>That&#8217;s about it! How do you handle test posts you don&#8217;t want your subscribers to see? Can you easily deactivate the e-mails with other plugins and services such as Feedburner? Share your thoughts and comments and thank you for <a href="http://kovshenin.com/subscribe/">subscribing</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/how-to-disable-jetpack-subscriptions-notifications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Changing the Default Theme in WordPress Multisite</title>
		<link>http://kovshenin.com/2012/changing-the-default-theme-in-wordpress-multisite/</link>
		<comments>http://kovshenin.com/2012/changing-the-default-theme-in-wordpress-multisite/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 14:42:59 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[multisite]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5283</guid>
		<description><![CDATA[Tip: if you want to change the default theme in a #WordPress Multisite network, use: define( &#8216;WP_DEFAULT_THEME&#8217;, &#8216;themename&#8217; ); &#8212; Konstantin Kovshenin (@kovshenin) March 16, 2012 It&#8217;s important for a network (WordPress Multisite) to have a valid default theme for newly created sites. The current version sets this to twentyeleven in default-constants.php. If your default [...]]]></description>
			<content:encoded><![CDATA[<blockquote class="twitter-tweet" width="550"><p>Tip: if you want to change the default theme in a <a href="https://twitter.com/search/%2523WordPress">#WordPress</a> Multisite network, use: define( &#8216;WP_DEFAULT_THEME&#8217;, &#8216;themename&#8217; );</p>
<p>&mdash; Konstantin Kovshenin (@kovshenin) <a href="https://twitter.com/kovshenin/status/180544972313985024" data-datetime="2012-03-16T06:44:10+00:00">March 16, 2012</a></p></blockquote>
<p><script src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>It&#8217;s important for a network (WordPress Multisite) to have a valid default theme for newly created sites. The current version sets this to <strong>twentyeleven</strong> in <a href="http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/default-constants.php#L297">default-constants.php</a>. If your default theme isn&#8217;t installed or disabled network-wide, you might face some errors when creating new sites in the network. You can define <code>WP_DEFAULT_THEME</code> in your wp-config.php file.</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/changing-the-default-theme-in-wordpress-multisite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: esc_url versus esc_url_raw</title>
		<link>http://kovshenin.com/2012/esc_url-vs-esc_url_raw/</link>
		<comments>http://kovshenin.com/2012/esc_url-vs-esc_url_raw/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 18:33:19 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5224</guid>
		<description><![CDATA[Tip: don&#8217;t use esc_url() with wp_remote_get() and other HTTP functions. Use esc_url_raw() instead. #wordpress &#8212; Konstantin Kovshenin (@kovshenin) March 13, 2012 This tweet gained some good attention on Twitter, so I thought it would be good to explain why. Then I found a support forums thread where Mark Jaquith pretty much explains it all: esc_url() [...]]]></description>
			<content:encoded><![CDATA[<blockquote class="twitter-tweet" width="550"><p>Tip: don&#8217;t use esc_url() with wp_remote_get() and other HTTP functions. Use esc_url_raw() instead. <a href="https://twitter.com/search/%2523wordpress">#wordpress</a></p>
<p>&mdash; Konstantin Kovshenin (@kovshenin) <a href="https://twitter.com/kovshenin/status/179599647130652672" data-datetime="2012-03-13T16:07:47+00:00">March 13, 2012</a></p></blockquote>
<p><script src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>This tweet gained some good attention on Twitter, so I thought it would be good to explain why. Then I found a support forums <a href="http://wordpress.org/support/topic/clean_url-vs-sanitize_url-vs-esc_url-vs-esc_url_raw?replies=2">thread</a> where Mark Jaquith pretty much explains it all:</p>
<blockquote><p><code>esc_url()</code> is for something like <code>&lt;a href="SANITIZE_THIS"&gt;text&lt;/a&gt;</code></p></blockquote>
<p>So if you&#8217;re going to use the URL in your HTML output, like a href attribute for a link, or a src attribute for an image element, you should use <strong>esc_url()</strong>.</p>
<blockquote><p><code>esc_url_raw()</code> is for other cases where you want a clean URL, but you don&#8217;t want HTML entities to be encoded. So any non-HTML usage (DB, redirect) would use this.</p></blockquote>
<p>The <strong>esc_url_raw()</strong> function will do pretty much the same as esc_url, but it will not decode entities, meaning it will not replace <code>&amp;</code> with <code>&amp;#038</code> and so on. As Mark pointed out, it&#8217;s safe to use esc_url_raw in database queries, redirects and HTTP functions, such as <code>wp_remote_get</code>.</p>
<p>Oh, there&#8217;s now a codex entry for <a href="http://codex.wordpress.org/Function_Reference/esc_url_raw">esc_url_raw</a> too!</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/esc_url-vs-esc_url_raw/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Daniel Bachhuber: The Zen of WordPress Development</title>
		<link>http://kovshenin.com/2012/daniel-bachhuber-the-zen-of-wordpress-development/</link>
		<comments>http://kovshenin.com/2012/daniel-bachhuber-the-zen-of-wordpress-development/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 09:48:49 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[videos]]></category>
		<category><![CDATA[wordcamp]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5188</guid>
		<description><![CDATA[Daniel Bachhuber of Automattic&#8217;s WordPress.com VIP team, gave this awesome talk at WordCamp Phoenix 2012 earlier this year. He walked through some things developers are overlooking when working with WordPress, and some great tips and tricks to speed up your development workflow. One thing I learned from that talk is that I should stop using [...]]]></description>
			<content:encoded><![CDATA[<p><embed src="http://v.wordpress.com/nWoZmCPz" type="application/x-shockwave-flash" width="580" height="326" allowscriptaccess="always" allowfullscreen="true" wmode="transparent"></embed></p>
<p><a href="https://twitter.com/#!/danielbachhuber">Daniel Bachhuber</a> of Automattic&#8217;s WordPress.com VIP team, gave this awesome talk at WordCamp Phoenix 2012 earlier this year. He walked through some things developers are overlooking when working with WordPress, and some great tips and tricks to speed up your development workflow.</p>
<p>One thing I learned from that talk is that I should stop using Textmate&#8217;s &#8220;search in project&#8221; and use <strong>ack</strong> instead, which is faster, available in the command line environment (no need for GUI), and has a bunch of options for output customization. By the way, here&#8217;s how you install <strong>ack on OS X</strong>:</p>
<ul>
<li>Download and install <a href="http://www.macports.org/install.php">MacPorts</a> if you haven&#8217;t already.</li>
<li>Open your Terminal and type <code>sudo port install p5-app-ack</code></li>
</ul>
<p>You can find the notes and slides to the presentation on <a href="http://danielbachhuber.com/2012/02/25/wcphx-five-tenets-to-mastering-wordpress-development/">Daniel&#8217;s blog</a>, and by the way, it was originally called &#8220;Five tenets to mastering WordPress development&#8221; :) </p>
<p>Hope you enjoy the video and feel free to share your thoughts in the comments section below.</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/daniel-bachhuber-the-zen-of-wordpress-development/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Native Image Sizing &#8220;On the Fly&#8221; with WordPress</title>
		<link>http://kovshenin.com/2012/native-image-sizing-on-the-fly-with-wordpress/</link>
		<comments>http://kovshenin.com/2012/native-image-sizing-on-the-fly-with-wordpress/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 07:06:49 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[shortcodes]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5181</guid>
		<description><![CDATA[I tweeted it out not too long ago, and it seems to have gotten people&#8217;s attention. So why do WordPress theme developers still use TimThumb? One of the valid reasons seems to be dynamic image sizing. Of course if you&#8217;re using TimThumb for post thumbnails in your theme, your life saver is the add_image_size function &#8212; [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://kovshenin.com/2012/timthumb-in-wordpress-themes/">tweeted</a> it out not too long ago, and it seems to have gotten people&#8217;s attention. So why do WordPress theme developers still use TimThumb? One of the valid reasons seems to be dynamic image sizing. Of course if you&#8217;re using TimThumb for post thumbnails in your theme, your life saver is the <a href="http://codex.wordpress.org/Function_Reference/add_image_size">add_image_size</a> function &#8212; you don&#8217;t need &#8220;dynamic resizing&#8221; since all your thumbnails are of equal sizes throughout your theme.</p>
<p>However, the valid reason I seem to have bumped in, is the fact that sometimes you would want to use a specific size for an image, but only once, for one post or page. The add_image_size function here will add a lot of overhead, crunching <span style="color: #333333;"><strong>all the uploaded images</strong> into the size you want to use only once. Like a shortcode that can resize and crop an image from your media library to whatever dimensions you tell it to:</span></p>
<pre>[image src="http://example.org/wp-content/uploads/2012/03/image.png" width="150" height="150"]</pre>
<p>Right, a shortcode (argh!) to dynamically resize an image. Fair enough, a lot of premium themes seem to have something similar, but mostly use TimThumb because it&#8217;s so simple. However, I&#8217;ve created <a href="https://gist.github.com/1984363">an image shortcode</a> function that resizes and crops images from the media library on the fly using the <a href="http://codex.wordpress.org/Function_Reference/image_make_intermediate_size">image_make_intermediate_size</a> function available as early as WordPress 2.5!</p>
<p>It saves the resized image on disk, and returns the absolute URL to that image. Of course you&#8217;d want to add things like captions, alt tags and so on, but the basic idea is there. Why is this better than TimThumb?</p>
<ul>
<li><span style="line-height: 21px;">It stores the image files on disk and uses absolute URLs to those images, meaning you won&#8217;t have problems hosting your thumbnails on a CDN.</span></li>
<li><span style="line-height: 21px;">It uses functions native to WordPress and works with the WordPress media library, so extra files are deleted when an attachment is deleted &#8212; no more junk in your cache/folder.</span></li>
<li><span style="line-height: 21px;">It doesn&#8217;t have a zero-day vulnerability :)</span></li>
</ul>
<p>There are drawbacks too, like the fact that it&#8217;s a shortcode! Although I&#8217;m pretty sure we can use the same technique and hook it directly to the content, bypassing the shortcodes madness. Oh, and it doesn&#8217;t support remote files too, only the ones in your media library, but that&#8217;s a good thing, as we have all figured out by now.</p>
<p>Feel free to fork <a href="https://gist.github.com/1984363">the Gist on Github</a> and experiment with the code, I&#8217;m sure you can think of how to make it better, easier to use and faster. Thoughts and comments welcome, and thank you for stopping by!</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/native-image-sizing-on-the-fly-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Dear WordPress Theme Developers, Stop Using TimThumb</title>
		<link>http://kovshenin.com/2012/timthumb-in-wordpress-themes/</link>
		<comments>http://kovshenin.com/2012/timthumb-in-wordpress-themes/#comments</comments>
		<pubDate>Sat, 03 Mar 2012 19:19:46 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=5175</guid>
		<description><![CDATA[Dear theme developers, WordPress has a billion functions to work with images, look at image-edit.php and stop using TimThumb! #tech &#8212; Konstantin Kovshenin (@kovshenin) March 3, 2012 Just a reminder, since this weekend I had to help out with yet another TimThumb-powered WordPress theme, broken by a &#8220;security patch&#8221; at the web hosting provider. This [...]]]></description>
			<content:encoded><![CDATA[<blockquote class="twitter-tweet" width="550"><p>Dear theme developers, WordPress has a billion functions to work with images, look at image-edit.php and stop using TimThumb! <a href="https://twitter.com/search/%2523tech">#tech</a></p>
<p>&mdash; Konstantin Kovshenin (@kovshenin) <a href="https://twitter.com/kovshenin/status/175993539040260097" data-datetime="2012-03-03T17:18:24+00:00">March 3, 2012</a></p></blockquote>
<p><script src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>Just a reminder, since this weekend I had to help out with yet another TimThumb-powered WordPress theme, broken by a &#8220;security patch&#8221; at the web hosting provider. This time it was Acquisto by Press75. The problems of Acquisto are not limited to thumbnails.</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/timthumb-in-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Jetpack for E-mail Subscriptions in WordPress</title>
		<link>http://kovshenin.com/2012/using-jetpack-for-e-mail-subscriptions-in-wordpress/</link>
		<comments>http://kovshenin.com/2012/using-jetpack-for-e-mail-subscriptions-in-wordpress/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 14:49:59 +0000</pubDate>
		<dc:creator>Konstantin Kovshenin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[jetpack]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kovshenin.com/?p=3815</guid>
		<description><![CDATA[You can find a bunch of &#8220;subscribe to posts&#8221; plugins in the WordPress.org directory but from my personal experience, it&#8217;s very difficult to find something as good and reliable as Jetpack. The major difference is behind the scenes &#8212; when most post subscription plugins will use the wp_mail function to distribute your new post (using sendmail from [...]]]></description>
			<content:encoded><![CDATA[<p>You can find a bunch of &#8220;subscribe to posts&#8221; plugins in the <a href="http://wordpress.org/extend/plugins/">WordPress.org directory</a> but from my personal experience, it&#8217;s very difficult to find something as good and reliable as <a href="http://jetpack.me/">Jetpack</a>.</p>
<p><img class="alignnone size-large wp-image-3817" src="http://kovshenin.com/files/2012/02/jetpack-subscriptions-680x189.png" alt="Jetpack E-mail Subscriptions for WordPress" width="580" height="161" /></p>
<p>The major difference is behind the scenes &#8212; when most post subscription plugins will use the <a href="http://codex.wordpress.org/Function_Reference/wp_mail">wp_mail</a> function to distribute your new post (using sendmail from your server or an SMTP account,) Jetpack will simply send your new post to the WordPress.com server, which will take care of the distribution for you.</p>
<p><span id="more-3815"></span></p>
<p>Why does that matter? I can name several reasons:</p>
<ul>
<li><span style="line-height: 21px">The WordPress.com mail servers can handle far more load than your shared hosting server, VPS or dedicated server, so e-mails will (most likely) be delivered on time and to everyone.</span></li>
<li><span style="line-height: 21px">People enjoy reading posts from one place. RSS feeds is a good option, but so is the <a href="http://wordpress.com/read/">WordPress.com Read</a> module.</span></li>
<li><span style="line-height: 21px">People can manage their WordPress.com and Jetpack-powered subscriptions in one place, choose between immediate e-mails, daily digests and IM notifications, as well as choose between HTML and plain text e-mails.</span></li>
<li><span style="line-height: 21px">You can use Stats in Jetpack to track your blog followers.</span></li>
</ul>
<p>However, there are drawbacks too, the major one of which, is that you don&#8217;t have control over the actual markup in the e-mail that&#8217;s being sent, so no advertising, changing colors and so on. But, we can live without that, right? :)</p>
<h2>The Subscription Form</h2>
<p>The easiest way to enable e-mail subscriptions, is to use the sidebar widget that Jetpack comes with. You can find a great tutorial on the <a href="http://wordpress.com/read/">Jetpack website</a>, however, today I&#8217;d like to show you how to totally customize that part by using your own form, handler and calls to the Jetpack API.</p>
<p>Note that to get this working, you will need public WordPress site with Jetpack enabled and linked to your WordPress.com account. So let&#8217;s begin with a simple form, somewhere in your theme template files:</p>
<pre>&lt;form method="POST"&gt;
    &lt;input type="hidden" name="my-form-action" value="subscribe" /&gt;
    &lt;input name="my-email" value="" placeholder="Enter your e-mail" /&gt;
    &lt;input type="submit" /&gt;
&lt;/form&gt;</pre>
<p><img class="alignnone size-full wp-image-3818" src="http://kovshenin.com/files/2012/02/subscribe-form-1.png" alt="Jetpack Subscription Form" width="677" height="228" /></p>
<p>That&#8217;s easy enough to understand, right? A hidden field that would tell us when the form is submitted, an input field for the e-mail address and a submit button. A <a href="http://codex.wordpress.org/Function_Reference/wp_nonce_field">nonce field</a> would be very useful too, but let&#8217;s try and keep it simple.</p>
<h2>The Subscription Form Handler</h2>
<p>Next, you will need something that will handle the form submission, somewhere in your theme&#8217;s functions.php file or preferably a plugin file (<a href="http://kovshenin.com/2012/plugins-vs-without-a-plugin/">here&#8217;s why</a>.)</p>
<pre>add_action( 'init', 'process_my_subscription_form' );
function process_my_subscription_form() {
    if ( isset( $_POST['my-form-action'] ) &amp;&amp; $_POST['my-form-action'] == 'subscribe' ) {
        $email = $_POST['my-email'];
        $subscribe = Jetpack_Subscriptions::subscribe( $email, 0, false );
        // check subscription status (to be continued)
    }
}</pre>
<p>This is quite simple to follow along too, we&#8217;re checking whether the form was submitted and then using the <code>subscribe</code> method of the <code>Jetpack_Subscriptions</code> class, which takes three arguments &#8212; e-mail address, a post ID (if you were subscribing to comments) and a boolean value for async versus sync calls. You shouldn&#8217;t worry about these for now.</p>
<p>This form handler, together with the above form, will already allow users to input their e-mail addresses and hit the submit button. They&#8217;ll get a notification to their e-mail address to confirm their subscription, and if they do, they&#8217;ll start receiving new posts from your website. Hurray! But wait&#8230;</p>
<h2>Subscription Status Feedback</h2>
<p>The problem, however, is that we haven&#8217;t provided any feedback about their subscription: was it successful, or are they already subscribed, or maybe they entered an invalid e-mail address. For this purpose, we should look at what the Jetpack subscribe method returned, and check for success or errors.</p>
<p>We don&#8217;t have to reinvent the weel here, but rather use the same code that is used in Jetpack&#8217;s e-mail subscriptions widget, right after calling the subscribe method:</p>
<pre>// check subscription status
if ( is_wp_error( $subscribe ) ) {
    $error = $subscribe-&gt;get_error_code();
} else {
    $error = false;
    foreach ( $subscribe as $response ) {
        if ( is_wp_error( $response ) ) {
            $error = $response-&gt;get_error_code();
            break;
        }
    }
}

if ( $error ) {
    switch( $error ) {
        case 'invalid_email':
            $redirect = add_query_arg( 'subscribe', 'invalid_email' );
            break;
        case 'active': case 'pending':
            $redirect = add_query_arg( 'subscribe', 'already' );
            break;
        default:
            $redirect = add_query_arg( 'subscribe', 'error' );
            break;
    }
} else {
    $redirect = add_query_arg( 'subscribe', 'success' );
}

wp_safe_redirect( $redirect );</pre>
<p>Although quite long, the code above is very easy to understand. We&#8217;re checking the <code>$subscribe</code> variable (returned from Jetpack) for whether it&#8217;s an error or an array of errors. If it&#8217;s an error, we read the error code, and change the <code>subscribe</code> query argument accordingly, with <code>add_query_arg</code>. This will add, for example, <code>?subscribe=invalid_email</code>, to our current URL.</p>
<p>If there was no error, we use <code>success</code> for that very same query argument. Finally, we redirect to our newly constructed URL. It&#8217;s much easier to understand when you&#8217;ll see this in action.</p>
<p><img class="alignnone size-full wp-image-3819" src="http://kovshenin.com/files/2012/02/subscribe-success.png" alt="E-mail subscription Success" width="500" height="70" /></p>
<p>At this point, you can test again by trying to subscribe, and you&#8217;ll see that the page is being redirected with the <code>subscribe</code> query argument added each time, showing the status of the subscription. Go ahead and enter an invalid e-mail address.</p>
<h2>The Subscription Form (again)</h2>
<p>Let&#8217;s return to our theme template where we rendered our subscription form and tweak it a little bit, based on our subscription status:</p>
<pre>&lt;?php $status = isset( $_REQUEST['subscribe'] ) ? $_REQUEST['subscribe'] : false; ?&gt;
&lt;?php if ( $status == 'invalid_email' ) : ?&gt;
    &lt;p&gt;You have entered an invalid e-mail, please try again!&lt;/p&gt;
&lt;?php elseif ( $status == 'success' ) : ?&gt;
    &lt;p&gt;Thank you for subscribing! Please check your e-mail to confirm.&lt;/p&gt;
&lt;?php else : ?&gt;
    &lt;form method="POST"&gt;
        &lt;input type="hidden" name="my-form-action" value="subscribe" /&gt;
        &lt;input name="my-email" value="" placeholder="Enter your e-mail" /&gt;
        &lt;input type="submit" /&gt;
    &lt;/form&gt;
&lt;?php endif; ?&gt;</pre>
<p>The first line will read the status into a variable, and then a check for the status with the relevant messages. I haven&#8217;t included all statuses for brevity, but you should have a couple more <code>elseif</code> blocks for &#8220;already&#8221; and &#8220;error&#8221;. Voila!</p>
<p><img class="alignnone size-large wp-image-3820" src="http://kovshenin.com/files/2012/02/thank-you-for-subscribing-680x211.png" alt="Thank you for subscribing" width="580" height="179" /></p>
<p><strong>What&#8217;s next?</strong> Well it&#8217;s up to you: you can customize the form however you like, you can redirect your visitors to a &#8220;thank you for subscribing&#8221; page (in the form handler,) or you can even send them an e-mail thanking them for their subscription :)</p>
<p>That&#8217;s about it! What&#8217;s your favorite way to handle e-mail subscriptions on your blog? What about newsletters, have you tried Jetpack to send out newsletters, or have you got a different preferred way? Share your thoughts and thanks for stopping by!</p>
]]></content:encoded>
			<wfw:commentRss>http://kovshenin.com/2012/using-jetpack-for-e-mail-subscriptions-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

