WordPress.org

Ready to get started?Download WordPress

Forums

Create permissions for pages (9 posts)

  1. Morrigan
    Member
    Posted 7 years ago #

    How would I call a permission for a page or a category?
    Say I only want Admins, Authors and Editors to access a page/category but no contributors/subscribers or guests.

  2. Andrew Ozz
    WordPress Dev
    Posted 7 years ago #

    Password-protect the posts/pages (with the same password)?

  3. Morrigan
    Member
    Posted 7 years ago #

    See but that's not a good answer to me as password protecting, especially with the same password, is unsafe. Also, what if I change an Author/Editor to a Contributor or Subscriber because of issues, Then I have to go through the hassle of changing the password for every post/page and then update every member that needs that password with the new password and there is no simple way for me to provide that other then email them.

    Unfortunately that is not a good solution.

  4. Morrigan
    Member
    Posted 7 years ago #

    I think to describe this more clearly, I just need an If Then statement that I can add

    if (user_has_permission('publish_posts'));
    The Page
    else
    Sorry you can't access this

    I've tried it multiple times and each time it does nothing or it gives me SQL errors.
    As for the categories I'm either going to have to mod the admin and other code or something but I would need the same code that I'm using here to mod it I would assume.

  5. Andrew Ozz
    WordPress Dev
    Posted 7 years ago #

    I think you can use the "current_user_can()" function in your templates. Have a look here:
    http://wordpress.org/tags/current_user_can

  6. Morrigan
    Member
    Posted 7 years ago #

    That's what I needed.

    If anyone else needs this for pages on their site:

    <?php
    /*
    Template Name: Template Name
    */
    get_header();
    get_currentuserinfo();
    //Only Authors and higher can read this page.
       if (current_user_can('publish_posts')) { ?>
    
    	<div id="content" class="narrowcolumn">
    
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>
    
    <?php     }
    else
    {
    //Tell the people that don't have access to this page that they do not have access.
    ?>
    You don't have access to this page.
    <?php } ?>
    <?php get_footer(); ?>
  7. Morrigan
    Member
    Posted 7 years ago #

    I'm curious if anyone has found a way to lock categories from unregistered users? The above blocks users from pages but not categories, is there a way to filter them from categories?

    I think it has something to do with making an array for the categories that would be something like:
    if (logged_in)
    {
    $category=array(Category numbers);
    }
    else
    {
    $category=array(Category numbers);
    }

  8. paulak83
    Member
    Posted 6 years ago #

    thanks for the help locking pages, im gunna try it out.

    It would be really helpful if support for Category permission were added in future versions though.

    Im implementing WP as a tool for our organization to share news and ideas, and to draw public interest.

    It would be nice, and I think encourage greater participation by our staff, if it could additionally be used for discussion of company politics and more sensitive matters that we dont want the public to view.

    One idea would be to give the Author the option of setting (or possibly requesting) what groups are able to see their post.
    This way a lower lever user would have the ability to post something that could only be viewed by administrators, not his colleagues.
    ..Just a thought.

    Some sort of simple Category based permission would be great though.

    Send requests for the feature to WP!

  9. paulak83
    Member
    Posted 6 years ago #

    Hey Morrigan,
    Could you give a little more info on how to implement that code on a page? Im not much on programming or php. Does that need to be enclosed in some sort of html tag?
    thanks for the help

Topic Closed

This topic has been closed to new replies.

About this Topic