-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#57897: REST attachments controller: Handle terms on creation #5238
Conversation
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
$request->set_param( 'categories', array( $category['term_id'] ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$attachment = $response->get_data(); | ||
$this->assertSame( array( $category['term_id'] ), wp_list_pluck( wp_get_post_terms( $attachment['id'], 'category' ), 'term_id' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->assertSame( array( $category['term_id'] ), wp_list_pluck( wp_get_post_terms( $attachment['id'], 'category' ), 'term_id' ) ); | |
$term = wp_get_post_terms( $attachment['id'], 'category' ); | |
$this->assertSame( $category['term_id'], $term[0]->term_id ); |
Simplified version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 4c7bbca
Thank you, @iamdharmesh, for the unit tests. They appear to be solid to me. Let's wait for feedback from some of the maintainers before marking it for commit. |
Committed in https://core.trac.wordpress.org/changeset/57380 |
PR adds handle terms in the REST attachments controller to assign terms to the freshly created attachment.
Currently,
\WP_REST_Attachments_Controller::create_item()
does not callparent::create_item()
, thus it also doesn't call\WP_REST_Posts_Controller::handle_terms()
. That means it's impossible to assign terms to the freshly uploaded attachment. As suggested in the ticket description, PR addshandle_terms()
inWP_REST_Attachments_Controller
to fix this issue.Trac ticket: https://core.trac.wordpress.org/ticket/57897
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.