- This topic has 12 replies, 3 voices, and was last updated 14 years, 4 months ago by Anonymous.
-
AuthorPosts
-
October 21, 2008 at 3:07 am #418martinjMember
Is there any way to include pages marked as "Private" in the menu?
I’ve got a page that I want accessible to users ONLY when they’re logged in to the site. I’ve marked it as "Private" and placed it in the right order, but it doesn’t appear in the menu (whether I’m logged in or not). I can access the page directly using the permalink only when logged in.
Thanks …
October 21, 2008 at 3:57 am #3991martinjMemberRelated to above … can you include PHP code in the Custom Code fields?
e.g. <?php if (is_user_logged_in()){ echo "<li>link to page url</li>" }; ?>
October 21, 2008 at 9:57 am #3992imported_RyanMemberI’ve never thought about that before.
If it isn’t appearing, then I guess the defauly wp_list_pages function in WordPress doesn’t allow that.
Do you know if any themes or widgets display the private pages? If they do, then I should be able to work out how they did and integrate it into the plugin.
If not, then you could setup a custom script which detects whether a user is logged in and displays a different menu accordingly. I normally suggest people sign up for our premium membership option so I can do it for them (https://geek.hellyer.kiwi/premium_support/) but it sounds like you know what you are doing anyway so that probably isn’t necessary.
You can’t use PHP in the custom code box. However if you are going to do something like that, then you probably have the skills to bypass the plugin completely anyway. So instead of inserting suckerfish() into your theme, just insert the wrapper tags for the unordered list like so:
[code:2apk1soe]<ul id="suckerfishnav">
*** insert menu here ***
</ul>[/code:2apk1soe]
Then add some scripts to display the menu contents. I don’t know if ‘is_user_logged_in’ is an actual WordPress function (I haven’t checked), but assuming it is, then the following would display a list of the regular WordPress pages, followed by a specific page specified by you:
[code:2apk1soe]<ul id="suckerfishnav">
<?php wp_list_pages(); ?>
<?php if (is_user_logged_in()){ echo "<li><a href="">link to page url</a></li>" }; ?>
</ul>
[/code:2apk1soe]Doing it this way will be a pinch quicker too as you don’t need to hit the database on each page loads since it’s hard coded into the theme. Having said that, the speed difference will be negligible. In fact in some crude tests I did a while back when someone complained the plugin was slowing their site down, I couldn’t see any difference whatsoever. But in theory there is a performance increase by doing it this way.
It’s nice to see someone coming up with new problems like this rather than the generic ‘I can’t get the plugin working with theme X’ ” title=”Smiley” />
I’m not sure this is a feature I’d include with the plugin though. It doesn’t seem like something too many people would have a use for. In fact I think you are the first to mention it. I assumed the private pages would automatically appear when you are logged in, but I guess not.
I use a similar system to what you are suggesting above on http://dunedinicehockey.hellyer.kiwi/, although the user permissions system on that site are powered by SMF, not WordPress.
October 22, 2008 at 5:42 pm #3993martinjMemberThanks for the feedback!
My preference is *not* to bypass your plugin as I really like the functionality that you’ve provided.
You have given me a couple of ideas though … first and foremost I need to look at what wp_list_pages() does in terms of "Private" pages … there may be some underlying WP options to handle them.
I’ll poke around a bit and post back if I’ve come up with anything exciting ” title=”Smiley” />
October 22, 2008 at 8:22 pm #3994martinjMemberTook a while to find, but it’s a problem in the WordPress core … not in the plugin. wp_list_pages *DOES NOT* list private pages (as of 2.6.2)
See http://trac.wordpress.org/ticket/6939
I’m going to apply the patch and see if it works with the plugin.
October 22, 2008 at 9:35 pm #3995imported_RyanMemberIf it’s included in WP 2.7 it may be easier to download one of the nightly builds instead.
October 22, 2008 at 9:51 pm #3996martinjMemberGood news!
With the patch applied private pages behave as expected with the plugin.
If you’re logged in and have the capability to view a private page, it shows up in the menu … otherwise the page is not visible in the menu.
The patch as specified in the post noted above changes in 2.6.2. For those interested, the change in in wp-includes/post.php in the function get_pages() .. line 2077 in the file.
[b:twiotfsw]Original:[/b:twiotfsw]
[code:twiotfsw]$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = ‘page’ AND post_status = ‘publish’) $where ";[/code:twiotfsw][b:twiotfsw]Modified:[/b:twiotfsw]
[code:twiotfsw]$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = ‘page’ AND " . get_private_posts_cap_sql(‘page’) . ") $where ";[/code:twiotfsw]I’m going to take a look at a nightly build from 2.7 and see if the fix is included.
October 23, 2008 at 5:32 am #3997martinjMemberBad news!
The fix isn’t in 2.7 as of 10/23/08.
I [u:e7p4lcy5]really[/u:e7p4lcy5] hate hacking the core ” title=”Sad” /> OTOH, the ‘hack’ is pretty trivial and it works like a champ, so looks like I’m going to keep this one.
Thanks for your help, Ryan!!
October 24, 2008 at 8:12 am #3998imported_RyanMemberThanks for the info. martinj.
It would probably be possible to create a plugin to patch that. It is too complicated for me, but I have a specialist programmer who could probably do it. It wouldn’t be cheap, but if you have money to burn feel free to contact me via the [iurl=https://geek.hellyer.kiwi/contact/]contact page[/iurl] for pricing information.
April 9, 2009 at 4:48 am #3999AnonymousMemberyou just saved me hours of stress.
thank God for forums.
bye
jonNovember 6, 2009 at 11:28 am #4000AnonymousMemberJust wanted to add my thanks to this post, as I to had this problem, im currently working with 2.8.5 and the issue still hasnt been fixed to my knowledge….!
Just to say if your wary of editing the core files due to upgrade issues in the future what i did was move the get_pages function into your own functions.php file, and rename e.g. get_pages_private() then add the change to the SQL call. Then even when you upate the core files the functionality will stay the same and the update wont break.
Anyway thanks again!
November 7, 2009 at 2:55 am #4001imported_RyanMemberThanks for the tip Peter, that’s really useful to know it can be done without hacking the core like that.
July 5, 2010 at 7:58 am #4002AnonymousMembermartinj,
your solution worked like a charm after trying multiple forums.
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.