<?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>Vogsphere</title>
	<atom:link href="http://vogsphere.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://vogsphere.org</link>
	<description>code is vogon poetry</description>
	<lastBuildDate>Thu, 17 Sep 2009 04:47:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Redirecting WordPress Subscribers</title>
		<link>http://vogsphere.org/redirecting-wordpress-subscribers/</link>
		<comments>http://vogsphere.org/redirecting-wordpress-subscribers/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 18:44:14 +0000</pubDate>
		<dc:creator>nathany</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[redirect_to]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://vogsphere.dev/redirecting-wordpress-subscribers/</guid>
		<description><![CDATA[Note: This article was originally posted at nathany.com

the problem

When subscribers log into WordPress, they are sent to the Dashboard where they can modify their profile. Chances are, this isn&#8217;t exactly what you had in mind.

To have subscribers sent to the home page, you might tack a query string onto your login links:

?redirect_to=http://mysite.com


Problem is, you won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Note: This article was originally posted at nathany.com</p>

<h3>the problem</h3>

<p>When subscribers log into WordPress, they are sent to the Dashboard where they can modify their profile. Chances are, this isn&#8217;t exactly what you had in mind.</p>

<p>To have subscribers sent to the home page, you might tack a query string onto your login links:</p>

<pre><code>?redirect_to=http://mysite.com
</code></pre>

<p>Problem is, you won&#8217;t catch them all. What if they register and then login, or click the login button on the registration page? Those are part of wp-admin in the core of WordPress.</p>

<p>That led me to changing the default <code>redirect_to</code> in wp-login.php. It works, it&#8217;s in one place, but changing core code makes upgrading a hassle.</p>

<h3>the solution</h3>

<p>This morning I was pleased to find that a <code>login_redirect</code> filter was <a href="http://trac.wordpress.org/ticket/7002">added</a> in the just released <a href="http://wordpress.org/development/2008/09/wordpress-262/">WordPress 2.6.2</a>, providing a much cleaner solution.</p>

<p>Here is the code to add to your themes&#8217; <code>functions.php</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// redirect subscribers to the home page (WP 2.6.2)</span>
<span style="color: #000000; font-weight: bold;">function</span> change_login_redirect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirect_to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request_redirect_to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_a</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'WP_User'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">has_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_posts'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'siteurl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$redirect_to</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// add filter with default priority (10), filter takes (3) parameters</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login_redirect'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'change_login_redirect'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>We check the capabilities for <code>edit_posts</code>, if not present, we force the redirect to the home page. The other approach would be to look into the <code>$user-&gt;roles</code> array for &#8217;subscriber&#8217;, but capabilities are more exact, say, if you add another subscriber-like role using <a href="http://www.im-web-gefunden.de/wordpress-plugins/role-manager/">Role Manager</a>.</p>

<p>Sometimes <code>$user</code> will be a <code>WP_Error</code> object, so the code handles that case by ensuring it actually is a <code>WP_User</code>.</p>

<p>And that&#8217;s all it takes. Happy WordPressing.</p>
]]></content:encoded>
			<wfw:commentRss>http://vogsphere.org/redirecting-wordpress-subscribers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
