A WP user with the role “Author” can post articles. On the blog in question I have the requirement, that these users’ articles have to be live immediately but not publicly visible (i.e., for anonymous visitors or Subscribers). We use WP 3.0.5.
We already have a plugin running, that allows to hide categories from anonymous and Subscribers. So the most straight-forward method I came up with so far is: New blog posts by Authors should be automatically put in a category. Then I hide that category from anonymous users.
Does anyone know:
a) how to automatically put an article by “Author” users in a certain category, or
b) how the requirement “live but not public” could be achieved more elegantly for those posts?
(Plugin suggestions are welcome, too.)
What you probably want to do is write function to do this in your theme’s
functions.php
file, and then useadd_action
to trigger that function when a post is saved.For example:
Hope that makes sense, and gives you a hint as to how to do this â I’m afraid I haven’t been able to test it.
The following code will change posts made by an author to private automatically.
it filters the status on the post save, looks to see who the author is from the post variables, fetches their first role and sees if it’s author, if it is, then it returns ‘private’, otherwise it returns the natural status. No need to use categories to do it when you can do it directly here.