Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Conversation

@kjbenk
Copy link
Contributor

@kjbenk kjbenk commented Mar 16, 2016

Fixes this issue #2368

}

if ( isset( $request['parent'] ) ) {
if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think prepare_item_for_database() should ever return a WP_Error. You can silently ignore the parent param if it's not set in the schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would silently ignoring the parent parma be setting it to -1 instead of throwing an error, or not setting it at all within the $prepared_term object?

Also, if I remove the returned WP_Error objects then should I remove these checks as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would silently ignoring the parent parma be setting it to -1 instead of throwing an error, or not setting it at all within the $prepared_term object?

Probably setting it to 0, as that's the closest representation to a WP Term object

Also, if I remove the returned WP_Error objects then should I remove these checks as well?

Yes.

* FIXED: The prepare_item_for_database function will now only return a
valid WP_Term object
@kjbenk
Copy link
Contributor Author

kjbenk commented Mar 17, 2016

@danielbachhuber let if me if that new commit 5bc8309 is good for a merge.

if ( isset( $request['term_group'] ) ) {
$prepared_term->term_group = (int) $request['term_group'];
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support setting term_taxonomy_id through the REST API. term_taxonomy_id and term_id are the same in our eyes, and term_id is always exposed as id.

@danielbachhuber
Copy link
Member

@kjbenk Better. Left comments on a few more things needing to be changed.

* FIXED: Removed all term attributes that are either readonly or
irrelevant within the `prepare_item_for_database` function
* FIXED: Changes the `rest_pre_insert_` filter to account for all
taxonomies not just the generic `term`, so it is now
`rest_pre_insert_{$this->taxonomy}`
@kjbenk
Copy link
Contributor Author

kjbenk commented Mar 17, 2016

@danielbachhuber thanks for the feedback, I am learning a lot :) The next commit has passed so you are free to review it.

@danielbachhuber danielbachhuber added this to the 2.0 Beta 13 milestone Mar 17, 2016
@danielbachhuber
Copy link
Member

🚢 🚢 🚢

danielbachhuber added a commit that referenced this pull request Mar 17, 2016
@danielbachhuber danielbachhuber merged commit b230a8d into WP-API:develop Mar 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants