Code Duplication    Length = 23-27 lines in 2 locations

src/wp-includes/post.php 1 location

@@ 5975-6001 (lines=27) @@
5972
 * @param int $post_ID     ID of the post we're checking.
5973
 * @return int The new post_parent for the post, 0 otherwise.
5974
 */
5975
function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) {
5976
	// Nothing fancy here - bail.
5977
	if ( !$post_parent )
5978
		return 0;
5979
5980
	// New post can't cause a loop.
5981
	if ( empty( $post_ID ) )
5982
		return $post_parent;
5983
5984
	// Can't be its own parent.
5985
	if ( $post_parent == $post_ID )
5986
		return 0;
5987
5988
	// Now look for larger loops.
5989
	if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) )
5990
		return $post_parent; // No loop
5991
5992
	// Setting $post_parent to the given value causes a loop.
5993
	if ( isset( $loop[$post_ID] ) )
5994
		return 0;
5995
5996
	// There's a loop, but it doesn't contain $post_ID. Break the loop.
5997
	foreach ( array_keys( $loop ) as $loop_member )
5998
		wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) );
5999
6000
	return $post_parent;
6001
}
6002
6003
/**
6004
 * Set a post thumbnail.

src/wp-includes/taxonomy.php 1 location

@@ 4214-4236 (lines=23) @@
4211
 *
4212
 * @return int The new parent for the term.
4213
 */
4214
function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) {
4215
	// Nothing fancy here - bail
4216
	if ( !$parent )
4217
		return 0;
4218
4219
	// Can't be its own parent.
4220
	if ( $parent == $term_id )
4221
		return 0;
4222
4223
	// Now look for larger loops.
4224
	if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) )
4225
		return $parent; // No loop
4226
4227
	// Setting $parent to the given value causes a loop.
4228
	if ( isset( $loop[$term_id] ) )
4229
		return 0;
4230
4231
	// There's a loop, but it doesn't contain $term_id. Break the loop.
4232
	foreach ( array_keys( $loop ) as $loop_member )
4233
		wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) );
4234
4235
	return $parent;
4236
}
4237