Opened 15 years ago
Closed 14 years ago
#11424 closed defect (bug) (worksforme)
Loops can develop in the post_parent hierarchy
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.9 |
Component: | General | Keywords: | close |
Focuses: | Cc: |
Description
It is possible to use wp_insert_post() to create a loop in the post_parent hierarchy.
E.g.
ID = 1, post_parent = 3 ID = 2, post_parent = 1 ID = 3, post_parent = 2
The admin UI does not present this opportunity, but loops can happen elsewhere (e.g. imports, xmlrpc, etc.).
wp_insert_post() only protects against loops with node length 1 or 2 (a post's post_parent is set to its own ID, or a two posts are parents of one another). Longer loops are not caught.
Attached uses a while loop to find and break any hierarchy loop.
Attachments (1)
Change History (9)
#3
@
15 years ago
The underlying datastrcutrure offer loops. I do not think that this is a bug but a feature.
#4
@
15 years ago
Patch file is broken.
In wp_insert_post() there are done some validation checks on post_ID and post_parent. Setting the post's parent to the post itself (Post can't be its own parent) and the parent post post's parent (grandparent) to the the post itself (Check for circular dependency).
Both checks are only half-way implemented because they only work in case that a post is updated and not for creation.
So technically you can create posts will loose their parent on the next update (parent set to 0 on update).
Looks like a concept is missing on post_parent. On a new blog you can create A Post that will have the parent to it's own if you know the next post_ID which is not that hard to guess.
This patch only catches loops that would be created by the call to wp_insert_post(). Loops that are already present are not caught (and could cause wp_insert_post() to enter an infinite loop of its own with this patch).