I had an idea - you add a new field in the $user_data and call it user_catid
So started editing this:
<?
/*
Plugin Name: Limit Categories
Plugin URI: http://www.asymptomatic.net/wp-hacks
Description: Limits the categories to which users of certain levels can make posts.
Version: 1.1
Author: Owen Winkler
Author URI: http://www.asymptomatic.net
*/
/*
Limit Categories - Limits the categories to which users of
certain levels can make posts.
This code is licensed under the MIT License.
http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2005 Owen Winkler
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to
do so, subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
$limit_minlevel = 2; // The minimum level you need to see ALL categories.
$limit_onlycats = array('Uncategorized', 'FFAF'); //The categories that you can see when you have a low user level
$limit_dosubcats = true; // Show subcategories for the limited categories
add_action('admin_head', array('catlimit', 'admin_head'));
class catlimit {
function admin_head($unused) {
global $userdata, $limit_minlevel;
get_currentuserinfo();
if($userdata->user_level < $limit_minlevel) {
if(preg_match('|/wp-admin/post.php|', $_SERVER['REQUEST_URI'])) {
ob_start(array('catlimit', 'ob_done'));
}
}
}
function ob_done($content) {
return preg_replace('|<fieldset id="categorydiv">.*?</fieldset>|sie', 'catlimit::return_catshell();', $content);
}
function return_catshell() {
$output = '<fieldset id="categorydiv"><legend><a href="http://wordpress.org/docs/reference/post/#category" title="' . __('Help on categories') . '">' . __('Categories') . '</a></legend><div>';
$categories = get_nested_categories();
$output .= catlimit::return_catlist($categories);
$output .= '</div></fieldset>';
return $output;
}
function return_catlist($categories, $use_children = false) {
global $limit_onlycats, $limit_dosubcats;
foreach($categories as $category) {
if($use_children || in_array($category['cat_name'], $limit_onlycats)) {
$output .= '<label for="category-' . $category['cat_ID'] . '" class="selectit"><input value="' . $category['cat_ID']
. '" type="checkbox" name="post_category[]" id="category-' . $category['cat_ID'] . '"'
. ($category['checked'] ? ' checked="checked"' : "") . '/> ' . wp_specialchars($category['cat_name']) . "</label>n";
if($limit_dosubcats && isset($category['children'])) {
$output .= "n<span class='cat-nest'>n";
$output .= catlimit::return_catlist($category['children'], true);
$output .= "</span>n";
}
}
}
return $output;
}
}
?>
to get this:
<?
/*
Plugin Name: Limit Categories
Plugin URI: http://www.asymptomatic.net/wp-hacks
Description: Limits the categories to which users of certain levels can make posts.
Version: 1.1
Author: Owen Winkler
Author URI: http://www.asymptomatic.net
*/
/*
Limit Categories - Limits the categories to which users of
certain levels can make posts.
This code is licensed under the MIT License.
http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2005 Owen Winkler
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to
do so, subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
$limit_minlevel = 5; // The minimum level you need to see ALL categories.
$limit_onlycats = echo'$userdata->user_catid'; //The categories that you can see when you have a low user level
$limit_dosubcats = true; // Show subcategories for the limited categories
add_action('admin_head', array('catlimit', 'admin_head'));
class catlimit {
function admin_head($unused) {
global $userdata, $limit_minlevel;
get_currentuserinfo();
if($userdata->user_catid ='0') {
if(preg_match('|/wp-admin/post.php|', $_SERVER['REQUEST_URI'])) {
ob_start(array('catlimit', 'ob_done'));
}
}
}
function ob_done($content) {
return preg_replace('|<fieldset id="categorydiv">.*?</fieldset>|sie', 'catlimit::return_catshell();', $content);
}
function return_catshell() {
$output = '<fieldset id="categorydiv"><legend><a href="http://wordpress.org/docs/reference/post/#category" title="' . __('Help on categories') . '">' . __('Categories') . '</a></legend><div>';
$categories = get_nested_categories();
$output .= catlimit::return_catlist($categories);
$output .= '</div></fieldset>';
return $output;
}
function return_catlist($categories, $use_children = false) {
global $limit_onlycats, $limit_dosubcats;
foreach($categories as $category) {
if($use_children || in_array($category['cat_name'], $limit_onlycats)) {
$output .= '<label for="category-' . $category['cat_ID'] . '" class="selectit"><input value="' . $category['cat_ID']
. '" type="checkbox" name="post_category[]" id="category-' . $category['cat_ID'] . '"'
. ($category['checked'] ? ' checked="checked"' : "") . '/> ' . wp_specialchars($category['cat_name']) . "</label>n";
if($limit_dosubcats && isset($category['children'])) {
$output .= "n<span class='cat-nest'>n";
$output .= catlimit::return_catlist($category['children'], true);
$output .= "</span>n";
}
}
}
return $output;
}
}
?>
But I don't know where to go from there as the rest is gibberish!
I hope you can understand from what I have changed what I want to accomplish and then edit the code for me :D
The only problem then is getting a way to add the new field into the profile so only admin can edit it :S
BTW These are the edit's I made:
$limit_minlevel = 5; // The minimum level you need to see ALL categories.
$limit_onlycats = echo'$userdata->user_catid'; //The categories that you can see when you have a low user level
$limit_dosubcats = true; // Show subcategories for the limited categories
add_action('admin_head', array('catlimit', 'admin_head'));
class catlimit {
function admin_head($unused) {
global $userdata, $limit_minlevel;
get_currentuserinfo();
if($userdata->user_catid ='0') {
Can be found in there. Where I said if($userdata->user_catid ='0') {
I basically wanted to say that
if {$userdata->user_catid="0"} //Admin will be 0
then {$post_ability="all"} //They can post everywhere
else {$userdata->user_catid=$post_ability}; ?> //Else they post in the category corresponding to their catid
Hope you can help and that this made sense.......
(Im a a php newbie at the moment :( )