"Private" Pages in Menu?

Forums Forums Menus "Private" Pages in Menu?

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #418
    martinj
    Member

    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 …

    #3991
    martinj
    Member

    Related 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>" }; ?>

    #3992

    I’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’ <img decoding=” 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.

    #3993
    martinj
    Member

    Thanks 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 <img decoding=” title=”Smiley” />

    #3994
    martinj
    Member

    Took 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.

    #3995

    If it’s included in WP 2.7 it may be easier to download one of the nightly builds instead.

    #3996
    martinj
    Member

    Good 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.

    #3997
    martinj
    Member

    Bad news!

    The fix isn’t in 2.7 as of 10/23/08.

    I [u:e7p4lcy5]really[/u:e7p4lcy5] hate hacking the core <img decoding=” 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!!

    #3998

    Thanks 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.

    #3999
    Anonymous
    Member

    you just saved me hours of stress.
    thank God for forums.
    bye
    jon

    #4000
    Anonymous
    Member

    Just 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!

    #4001

    Thanks for the tip Peter, that’s really useful to know it can be done without hacking the core like that.

    #4002
    Anonymous
    Member

    martinj,

    your solution worked like a charm after trying multiple forums. 

    Thanks!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.