<?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>BlackHC's Adventures in the Dev World &#187; Private Pages</title>
	<atom:link href="http://blog.blackhc.net/tag/private-pages/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.blackhc.net</link>
	<description>Just another weblog</description>
	<lastBuildDate>Wed, 16 Nov 2011 23:12:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WordPress Hacking II</title>
		<link>http://blog.blackhc.net/2009/01/wordpress-hacking-ii/</link>
		<comments>http://blog.blackhc.net/2009/01/wordpress-hacking-ii/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 12:34:44 +0000</pubDate>
		<dc:creator>BlackHC</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Pages Widget]]></category>
		<category><![CDATA[Private Pages]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.blackhc.net/?p=236</guid>
		<description><![CDATA[<a href="http://blog.blackhc.net/2009/01/wordpress-hacking-ii/" title="WordPress Hacking II"></a>I have a few private pages that I use to store random stuff and ideas and private pages (for a reason I don't understand) don't show up in the pages widget. It turns out that WordPress's get_pages function always filters &#8230;<p class="read-more"><a href="http://blog.blackhc.net/2009/01/wordpress-hacking-ii/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://blog.blackhc.net/2009/01/wordpress-hacking-ii/" title="WordPress Hacking II"></a><p><img class="alignright size-full wp-image-239" title="privatepagesfix" src="http://blog.blackhc.net/wp-content/uploads/2009/01/privatepagesfix.jpg" alt="privatepagesfix" width="265" height="315" />I have a few private pages that I use to store random stuff and ideas and private pages (for a reason I don't understand) don't show up in the pages widget.</p>
<p>It turns out that WordPress's <strong>get_pages</strong> function always filters them out, while <strong>get_posts</strong> doesn't (it actually has some logic to figure out whether to show private pages or not).</p>
<p>I've decided to fix this. A real fix would probably be merging <strong>get_pages</strong> and <strong>get_posts</strong> because both seem to do pretty much the same except that get_posts is a tad bit more advanced, but I'm all for quick fixes at the moment, because I don't have much time and I don't want to end up considering myself a PHP developer <img src='http://blog.blackhc.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>To make <strong>get_pages</strong> return private pages, too, you have to open the file <strong>wp-includes/post.php</strong> and change the following lines near the bottom of the <strong>get_pages</strong> function:</p>
<pre>
<pre class="brush: php; title: ; notranslate">	$query = &quot;SELECT * FROM $wpdb-&gt;posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where &quot;;
	$query .= $author_query;
	$query .= &quot; ORDER BY &quot; . $sort_column . &quot; &quot; . $sort_order ;</pre>
</pre>
<p>to:</p>
<pre>
<pre class="brush: php; title: ; notranslate">	$private_pages_inclusion_where = &quot;&quot;;
	if ( is_user_logged_in() ) {
		$private_pages_inclusion_where  = current_user_can( &quot;read_private_pages&quot; ) ? &quot; OR post_status = 'private'&quot; : &quot; OR post_author = $user_ID AND post_status = 'private'&quot;;
	}

	$query = &quot;SELECT * FROM $wpdb-&gt;posts $join WHERE (post_type = 'page' AND (post_status = 'publish' $private_pages_inclusion_where)) $where &quot;;
	$query .= $author_query;
	$query .= &quot; ORDER BY &quot; . $sort_column . &quot; &quot; . $sort_order ;</pre>
</pre>
<p>If you also want to make it easier to distinguish private pages from normal ones, you can also change the following bits in <strong>wp-includes/classes.php</strong> in the method <strong>Walker_Page::start_el</strong>:</p>
<pre>
<pre class="brush: php; title: ; notranslate">$output .= $indent . '&lt;li class=&quot;' . $css_class . '&quot;&gt;&lt;a href=&quot;' . get_page_link($page-&gt;ID) .
	'&quot; title=&quot;' . attribute_escape(apply_filters('the_title', $page-&gt;post_title)) . '&quot;&gt;' .
	$link_before . apply_filters('the_title', $page-&gt;post_title) . $link_after . '&lt;/a&gt;';
</pre>
</pre>
<p>to:</p>
<pre>
<pre class="brush: php; title: ; notranslate">$output .= $indent . '&lt;li class=&quot;' . $css_class . '&quot;&gt;&lt;a href=&quot;' . get_page_link($page-&gt;ID) .
	'&quot; title=&quot;' . attribute_escape(apply_filters('the_title', $page-&gt;post_title)) . '&quot;&gt;' .
	$link_before . apply_filters('the_title', $page-&gt;post_title) . ($page-&gt;post_status == 'private' ? &quot; (Private)&quot; : &quot;&quot;) . $link_after . '&lt;/a&gt;';
</pre>
</pre>
<p>Cheers,<br />
Andreas</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blackhc.net/2009/01/wordpress-hacking-ii/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

