コード例 #1
0
 function mnt_delete_term($deprecated_taxonomy, $args, $term_id, $unused_tt_id = '', $taxonomy = '')
 {
     global $wpdb;
     if (!$term_id) {
         return;
     }
     if (!$taxonomy) {
         $taxonomy = $deprecated_taxonomy;
     }
     // could defer role/cache maint to speed potential bulk deletion, but script may be interrupted before admin_footer
     $this->item_deletion_aftermath(TERM_SCOPE_RS, $taxonomy, $term_id);
     delete_option("{$taxonomy}_children_rs");
     scoper_term_cache_flush();
     scoper_flush_roles_cache(TERM_SCOPE_RS, '', '', $taxonomy);
     scoper_flush_cache_flag_once("rs_{$taxonomy}");
 }
コード例 #2
0
function scoper_mnt_save_term($deprecated_taxonomy, $args, $term_id, $unused_tt_id = '', $taxonomy = '')
{
    if (!$taxonomy) {
        $taxonomy = $deprecated_taxonomy;
    }
    static $saved_terms;
    if (!isset($saved_terms)) {
        $saved_terms = array();
    }
    // so this filter doesn't get called by hook AND internally
    if (isset($saved_terms[$taxonomy][$term_id])) {
        return;
    }
    global $scoper;
    // parent settings can affect the auto-assignment of propagating roles/restrictions
    $set_parent = 0;
    if ($col_parent = $scoper->taxonomies->member_property($taxonomy, 'source', 'cols', 'parent')) {
        $tx_src_name = $scoper->taxonomies->member_property($taxonomy, 'source', 'name');
        $set_parent = (int) $scoper->data_sources->get_from_http_post('parent', $tx_src_name);
    }
    if (empty($term_id)) {
        $term_id = (int) $scoper->data_sources->get_from_http_post('id', $tx_src_name);
    }
    $saved_terms[$taxonomy][$term_id] = 1;
    // Determine whether this object is new (first time this RS filter has run for it, though the object may already be inserted into db)
    $last_parent = 0;
    $last_parents = get_option("scoper_last_{$taxonomy}_parents");
    if (!is_array($last_parents)) {
        $last_parents = array();
    }
    if (!isset($last_parents[$term_id])) {
        $is_new_term = true;
        $last_parents = array();
    } else {
        $is_new_term = false;
    }
    if (isset($last_parents[$term_id])) {
        $last_parent = $last_parents[$term_id];
    }
    if ($set_parent != $last_parent && ($set_parent || $last_parent)) {
        $last_parents[$term_id] = $set_parent;
        update_option("scoper_last_{$taxonomy}_parents", $last_parents);
    }
    $roles_customized = false;
    if (!$is_new_term) {
        if ($custom_role_objects = get_option("scoper_custom_{$taxonomy}")) {
            $roles_customized = isset($custom_role_objects[$term_id]);
        }
    }
    // Inherit parent roles / restrictions, but only for new terms,
    // or if a new parent is set and no roles have been manually assigned to this term
    if ($is_new_term || !$roles_customized && $set_parent != $last_parent) {
        // apply default roles for new term
        if ($is_new_term) {
            scoper_inherit_parent_roles($term_id, TERM_SCOPE_RS, $taxonomy, 0);
        } else {
            $args = array('inherited_only' => true, 'clear_propagated' => true);
            ScoperAdminLib::clear_restrictions(TERM_SCOPE_RS, $taxonomy, $term_id, $args);
            ScoperAdminLib::clear_roles(TERM_SCOPE_RS, $taxonomy, $term_id, $args);
        }
        // apply propagating roles,restrictions from specific parent
        if ($set_parent) {
            scoper_inherit_parent_roles($term_id, TERM_SCOPE_RS, $taxonomy, $set_parent);
            scoper_inherit_parent_restrictions($term_id, TERM_SCOPE_RS, $taxonomy, $set_parent);
        }
    }
    // endif new parent selection (or new object)
    scoper_term_cache_flush();
    scoper_flush_roles_cache(TERM_SCOPE_RS, '', '', $taxonomy);
    delete_option("{$taxonomy}_children");
    delete_option("{$taxonomy}_children_rs");
    delete_option("{$taxonomy}_ancestors_rs");
}