WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#42138 new enhancement

Pass post ID into assign_terms checks

Reported by: johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: 2nd-opinion has-patch
Focuses: Cc:

Description

When checking if a user can assign_terms it would be helpful to know which post ID it is that terms are potentially being assigned to.

This would allow plugins to conditionally prevent the assignment of terms to specific posts.

A few more thoughts about this idea:

  • The singular form (assign_term) already exists, and accepts a term ID, to check if a specific term ID is assignable
  • assign_terms may not always be used in the context of a single post ID
  • current_user_can() supports multiple $args, so an assign_term_to_post could, in theory, accept both the post ID and term ID at the same time, though nothing in core takes advantage of this yet. We should probably stick to independently checking each object, but I wanted to mention the idea to be thorough.

I'll post a first-pass patch at including the post ID imminently.

Attachments (1)

42138.diff (4.2 KB) - added by johnjamesjacoby 3 years ago.

Download all attachments as: .zip

Change History (3)

#1 in reply to: ↑ description ; follow-up: @johnbillion
3 years ago

  • Keywords has-patch added

Replying to johnjamesjacoby:

  • current_user_can() supports multiple $args, so an assign_term_to_post could, in theory, accept both the post ID and term ID at the same time, though nothing in core takes advantage of this yet.

Post meta checks make use of this. AFAIK it's the only place in core that does. https://core.trac.wordpress.org/browser/trunk/src/wp-includes/capabilities.php?rev=41322&marks=307#L304

#2 in reply to: ↑ 1 @johnjamesjacoby
3 years ago

Replying to johnbillion:

Post meta checks make use of this. AFAIK it's the only place in core that does. https://core.trac.wordpress.org/browser/trunk/src/wp-includes/capabilities.php?rev=41322&marks=307#L304

Oh yeah! Yay prior art!

Note: See TracTickets for help on using tickets.