當前位置: 首頁>>代碼示例>>PHP>>正文


PHP wp_find_hierarchy_loop函數代碼示例

本文整理匯總了PHP中wp_find_hierarchy_loop函數的典型用法代碼示例。如果您正苦於以下問題:PHP wp_find_hierarchy_loop函數的具體用法?PHP wp_find_hierarchy_loop怎麽用?PHP wp_find_hierarchy_loop使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了wp_find_hierarchy_loop函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: wp_check_post_hierarchy_for_loops

/**
 * Checks the given subset of the post hierarchy for hierarchy loops.
 * Prevents loops from forming and breaks those that it finds.
 *
 * Attached to the wp_insert_post_parent filter.
 *
 * @since 3.1.0
 * @uses wp_find_hierarchy_loop()
 *
 * @param int $post_parent ID of the parent for the post we're checking.
 * @parem int $post_ID ID of the post we're checking.
 *
 * @return int The new post_parent for the post.
 */
function wp_check_post_hierarchy_for_loops($post_parent, $post_ID)
{
    // Nothing fancy here - bail
    if (!$post_parent) {
        return 0;
    }
    // New post can't cause a loop
    if (empty($post_ID)) {
        return $post_parent;
    }
    // Can't be its own parent
    if ($post_parent == $post_ID) {
        return 0;
    }
    // Now look for larger loops
    if (!($loop = wp_find_hierarchy_loop('wp_get_post_parent_id', $post_ID, $post_parent))) {
        return $post_parent;
    }
    // No loop
    // Setting $post_parent to the given value causes a loop
    if (isset($loop[$post_ID])) {
        return 0;
    }
    // There's a loop, but it doesn't contain $post_ID.  Break the loop.
    foreach (array_keys($loop) as $loop_member) {
        wp_update_post(array('ID' => $loop_member, 'post_parent' => 0));
    }
    return $post_parent;
}
開發者ID:BGCX261,項目名稱:zombie-craft-svn-to-git,代碼行數:43,代碼來源:post.php

示例2: wp_check_term_hierarchy_for_loops

/**
 * Checks the given subset of the term hierarchy for hierarchy loops.
 * Prevents loops from forming and breaks those that it finds.
 *
 * Attached to the {@see 'wp_update_term_parent'} filter.
 *
 * @since 3.1.0
 *
 * @param int    $parent   `term_id` of the parent for the term we're checking.
 * @param int    $term_id  The term we're checking.
 * @param string $taxonomy The taxonomy of the term we're checking.
 *
 * @return int The new parent for the term.
 */
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.
    if (!($loop = wp_find_hierarchy_loop('wp_get_term_taxonomy_parent_id', $term_id, $parent, array($taxonomy)))) {
        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;
}
開發者ID:n8maninger,項目名稱:WordPress,代碼行數:39,代碼來源:taxonomy-functions.php


注:本文中的wp_find_hierarchy_loop函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。