Opened 18 years ago
Closed 16 years ago
#2623 closed defect (bug) (invalid)
Need hook for admin category list
Reported by: | coppit | Owned by: | davidhouse |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.1 |
Component: | Administration | Keywords: | has-patch |
Focuses: | Cc: |
Description
My category access plugin restricts visibility of certain categories from specific users. Currently there is no hook to filter the category checkboxes used when writing a post. This means that users can write a post for a category that they're not supposed to be able to view. (!)
I'd like something like list_cats_exclusions for the get_nested_categories function in wp-admin/admin-functions.php. (Actually, it would be nice if all categories system-wide were fetched from one function that had a hook, so that I would only need to filter categories in one place.)
Attachments (2)
Change History (17)
#3
@
18 years ago
get_the_category()
works (pass the post ID, it should return an array of category objects) but that won't really help here... What we need (and I think I've seen this requested elsewhere) is a filter on the category list that is shown on the post screen.
#5
@
18 years ago
This seems to be a duplicate of #2466 - a patch that filtered all instances of categories has been available for some time there, but probably suffers from patch rot now due to the big changes made with categories over the last few weeks.
#6
@
18 years ago
Scratch that, #2466 is about filtering category names and isn't really related at all. Sorry.
#7
@
18 years ago
- Keywords bg|has-patch added
Here's a patch then. I decided to go against refactoring on accounts that it would involve changing most of the way the admin works at present.
#8
@
18 years ago
Oh, and the filter is run _before_ the call to usort()
so plugins don't have to worry about messing up the sort.
#9
@
17 years ago
- Keywords has-patch added; bg|has-patch removed
- Milestone set to 2.3
Patch refreshed
#11
in reply to:
↑ 10
@
17 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
- Type changed from enhancement to defect
Replying to rob1n:
(In [5379]) Apply get_nested_cats filter. Props davidhouse and Nazgul. fixes #2623
This hook is unusable with nested categories. get_nested_categories() is a recursive function that traverses the category tree depth-first. The hook will be called multiple times, first with the grandchildren, than the children and finally the parents.
Testcase:
Create a nested category tree. Add a hook to 'get_nested_categories':
function test_hook_get_nested_category($results) { print_r($results); return $results; }
and look at the output: it will contain lot's of empty arrays, then the grandchildren, then the children and finally the whole nested category tree.
Solution:
Drop
$result = apply_filters('get_nested_categories', $result);
from the function get_nested_categories()
and change the function dropdown_categories() to:
function dropdown_categories( $default = 0 ) { $result = get_nested_categories( $default ); $result = apply_filters('get_nested_categories', $result); write_nested_categories( $result ); }
#12
@
17 years ago
- Milestone changed from 2.3 to 2.3.2
Reopened on 2.3, moving to 2.3.2. Not sure if ticket is still valid.
is there an API func to get the categories a given post is in?