Category Visibility Plugin – Fixed a bug
-
I discovered (and fixed) a show-stopper bug in Keith McDuffee’s otherwise excellent Category Visibility plugin (https://www.gudlyf.com/archives/2005/03/08/wordpress-plugin-category-visibility/).
——————
BUG DESCRIPTION: Creating a new category or subcategory leaves the catvis_user_level blank, resulting in no one being able to see the category or its posts.In lay language, Category Visibility includes on its Manage page a “user level” field for every category and subcategory. Only users at or above that user level (WP 1.5x user levels) can see the category or posts within it. Setting the field to 0 allows all everyone (including non-registered users) to see them. Leaving the field blank, however, means the cateogry and its contents are invisible to everyone of any user level (including the admin at level 10).
When creating a new category, Category Visibility defaults to leaving the category visibility user level field blank. Thus, for every new category, someone (with adequate permissions) has to go manually change that on the Category Visibility Manage page.
——————
RESOLUTION: Replace a line in the Category Visibility Plugin (category_visibility.php) code. (Don’t get squeamish! This is easy!)Open category_visibility.php in a text editor and locate line #106, which is this code:
$catvis_user_level = $catvis->user_level;
Now replace that entire line with this:
if ($catvis->user_level == ” ) $catvis_user_level = “0”; else $catvis_user_level = $catvis->user_level;
——————
WHAT’S IT DOING: (I SWEAR I am NOT a programmer!) As Keith wrote the original code, the field $catvis_user_level is being told to look up the value of field $catvis->user_level. When $catvis->user_level already has a value (meaning you went in and set a user level for that category), everything works fine; the value you set merely gets shown again as you set it. But, when you create new categories, $catvis->user_level starts out blank. Thus $catvis_user_level also becomes blank, making all newly created categories totally invisible at creation time.There’s error-checking built into Keith’s script such that, if user_level is blank, it should be set to 0 automatically. Unfortunately, that’s failing for some reason (at least it is on my four WP installs).
In the corrected code, $catvis_user_level also looks up the value of $catvis->user_level, using whatever value is there. BUT, if $catvis->user_level happens to be blank, then $catvis_user_level sets itself to (visible to user level) 0 (and above). The result is that newly created categories are visible to everyone by default instead of INvisible to everyone by default.
——————
VARIANT: If your needs differ–say, you want newly created categories to be visible only to users level 4 and above–just change $catvis_user_level = “0” to $catvis_user_level = “4” or whatever you need.ASIDE: I apologize to the PHP-literate for my verbosity above. I recognize that I could have simply posted the original and replacement code without explanation. However, many WP users don’t understand the typical “replace ‘this’ with ‘this'” help often found in this forum (I know I didn’t when I was first trying to figure out all of this PHP stuff). More to the point, I always like to give people the courtesy of explaining WHY to choose to do something rather than just HOW.
- The topic ‘Category Visibility Plugin – Fixed a bug’ is closed to new replies.