Make WordPress Core

Opened 18 years ago

Closed 16 years ago

#2623 closed defect (bug) (invalid)

Need hook for admin category list

Reported by: coppit's profile coppit Owned by: davidhouse's profile 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)

2623.diff (344 bytes) - added by davidhouse 18 years ago.
2623b.diff (351 bytes) - added by Nazgul 17 years ago.

Download all attachments as: .zip

Change History (17)

#1 @davidhouse
18 years ago

  • Owner changed from anonymous to davidhouse
  • Status changed from new to assigned

#2 @davidhouse
18 years ago

is there an API func to get the categories a given post is in?

#3 @markjaquith
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.

#4 @davidhouse
18 years ago

Yeah, I know, I'm halfway through writing a patch and just needed to know this.

#5 @majelbstoat
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 @majelbstoat
18 years ago

Scratch that, #2466 is about filtering category names and isn't really related at all. Sorry.

#7 @davidhouse
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 @davidhouse
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.

@davidhouse
18 years ago

@Nazgul
17 years ago

#9 @Nazgul
17 years ago

  • Keywords has-patch added; bg|has-patch removed
  • Milestone set to 2.3

Patch refreshed

#10 follow-up: @rob1n
17 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [5379]) Apply get_nested_cats filter. Props davidhouse and Nazgul. fixes #2623

#11 in reply to: ↑ 10 @BenDeRydt
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 @darkdragon
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.

#13 @lloydbudd
17 years ago

  • Milestone changed from 2.3.2 to 2.5

#14 @pishmishy
17 years ago

  • Milestone changed from 2.5 to 2.6

Bumping milestone for feature freeze. Can this be closed?

#15 @azaozz
16 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

The API has changed long ago and similar filter now exists.

Note: See TracTickets for help on using tickets.