
如何在不同操作系统上安装phpMyAdmin
wp_check_term_hierarchy_for_loops ( $parent, $term_id, $taxonomy )
wp_check_term_hierarchy_for_loops: 这是一个检查术语层次结构中的循环的函数。它可以用来防止无限循环,当术语被组织成一个层次结构时,可能会出现无限循环。
检查术语层次结构的给定子集是否有层次结构循环。
防止循环的形成,并打破那些它发现的循环。
附在{@see ‘wp_update_term_parent’}过滤器上。
function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) { // Nothing fancy here - bail. if ( ! $parent ) { return 0; } // Can't be its own parent. if ( $parent === $term_id ) { return 0; } // Now look for larger loops. $loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ); if ( ! $loop ) { return $parent; // No loop. } // Setting $parent to the given value causes a loop. if ( isset( $loop[ $term_id ] ) ) { return 0; } // There's a loop, but it doesn't contain $term_id. Break the loop. foreach ( array_keys( $loop ) as $loop_member ) { wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); } return $parent; }