I’m creating a platform with “X” categories and “X” roles with the same name to each category.
I would like to know how to change the user’s role after they have read all the posts in a category. When the role changes, the user will have access to the next category.
To make the categories private and to create the related groups of users I’m using the Role Scoper plugin.
This solution is very similar to what I mean: https://stackoverflow.com/questions/9181440/wordpress-change-user-role-conditionally
Thanks
Just to clarify:
You have, for example, the categories ‘foo’, ‘bar’ and ‘baz’. New users with the role ‘foo’ can only read posts in the category ‘foo’. After they have read all the posts in ‘foo’, their role will be changed to ‘bar’ so they can read the posts in category ‘bar’. And so on…
Everything starts with a good plan, so let’s make a plan.
Sounds easy, doesn’t it? I put it all together in one class because this saves some code and makes some things easier. Call this class with
$updated = new WPSE78727();
inside your single post template (single.php
), e.g. at the beginning of the template.If the user was updated,
$updated->updated
is set to the new role of the user, otherwise it is set to false.This code is untested and may be buggy. It should be considered a starting point and not as a complete solution.