@@ 5848-5874 (lines=27) @@ | ||
5845 | * @param int $post_ID ID of the post we're checking. |
|
5846 | * @return int The new post_parent for the post, 0 otherwise. |
|
5847 | */ |
|
5848 | function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { |
|
5849 | // Nothing fancy here - bail. |
|
5850 | if ( !$post_parent ) |
|
5851 | return 0; |
|
5852 | ||
5853 | // New post can't cause a loop. |
|
5854 | if ( empty( $post_ID ) ) |
|
5855 | return $post_parent; |
|
5856 | ||
5857 | // Can't be its own parent. |
|
5858 | if ( $post_parent == $post_ID ) |
|
5859 | return 0; |
|
5860 | ||
5861 | // Now look for larger loops. |
|
5862 | if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) |
|
5863 | return $post_parent; // No loop |
|
5864 | ||
5865 | // Setting $post_parent to the given value causes a loop. |
|
5866 | if ( isset( $loop[$post_ID] ) ) |
|
5867 | return 0; |
|
5868 | ||
5869 | // There's a loop, but it doesn't contain $post_ID. Break the loop. |
|
5870 | foreach ( array_keys( $loop ) as $loop_member ) |
|
5871 | wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); |
|
5872 | ||
5873 | return $post_parent; |
|
5874 | } |
|
5875 | ||
5876 | /** |
|
5877 | * Set a post thumbnail. |
@@ 4423-4445 (lines=23) @@ | ||
4420 | * |
|
4421 | * @return int The new parent for the term. |
|
4422 | */ |
|
4423 | function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) { |
|
4424 | // Nothing fancy here - bail |
|
4425 | if ( !$parent ) |
|
4426 | return 0; |
|
4427 | ||
4428 | // Can't be its own parent. |
|
4429 | if ( $parent == $term_id ) |
|
4430 | return 0; |
|
4431 | ||
4432 | // Now look for larger loops. |
|
4433 | if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) |
|
4434 | return $parent; // No loop |
|
4435 | ||
4436 | // Setting $parent to the given value causes a loop. |
|
4437 | if ( isset( $loop[$term_id] ) ) |
|
4438 | return 0; |
|
4439 | ||
4440 | // There's a loop, but it doesn't contain $term_id. Break the loop. |
|
4441 | foreach ( array_keys( $loop ) as $loop_member ) |
|
4442 | wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); |
|
4443 | ||
4444 | return $parent; |
|
4445 | } |
|
4446 |