Edit File by line
/home/barbar84/www/wp-inclu...
File: taxonomy.php
*/
[2000] Fix | Delete
do_action( 'deleted_term_taxonomy', $tt_id );
[2001] Fix | Delete
[2002] Fix | Delete
// Delete the term if no taxonomies use it.
[2003] Fix | Delete
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term ) ) ) {
[2004] Fix | Delete
$wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) );
[2005] Fix | Delete
}
[2006] Fix | Delete
[2007] Fix | Delete
clean_term_cache( $term, $taxonomy );
[2008] Fix | Delete
[2009] Fix | Delete
/**
[2010] Fix | Delete
* Fires after a term is deleted from the database and the cache is cleaned.
[2011] Fix | Delete
*
[2012] Fix | Delete
* The {@see 'delete_$taxonomy'} hook is also available for targeting a specific
[2013] Fix | Delete
* taxonomy.
[2014] Fix | Delete
*
[2015] Fix | Delete
* @since 2.5.0
[2016] Fix | Delete
* @since 4.5.0 Introduced the `$object_ids` argument.
[2017] Fix | Delete
*
[2018] Fix | Delete
* @param int $term Term ID.
[2019] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2020] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2021] Fix | Delete
* @param WP_Term $deleted_term Copy of the already-deleted term.
[2022] Fix | Delete
* @param array $object_ids List of term object IDs.
[2023] Fix | Delete
*/
[2024] Fix | Delete
do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term, $object_ids );
[2025] Fix | Delete
[2026] Fix | Delete
/**
[2027] Fix | Delete
* Fires after a term in a specific taxonomy is deleted.
[2028] Fix | Delete
*
[2029] Fix | Delete
* The dynamic portion of the hook name, `$taxonomy`, refers to the specific
[2030] Fix | Delete
* taxonomy the term belonged to.
[2031] Fix | Delete
*
[2032] Fix | Delete
* @since 2.3.0
[2033] Fix | Delete
* @since 4.5.0 Introduced the `$object_ids` argument.
[2034] Fix | Delete
*
[2035] Fix | Delete
* @param int $term Term ID.
[2036] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2037] Fix | Delete
* @param WP_Term $deleted_term Copy of the already-deleted term.
[2038] Fix | Delete
* @param array $object_ids List of term object IDs.
[2039] Fix | Delete
*/
[2040] Fix | Delete
do_action( "delete_{$taxonomy}", $term, $tt_id, $deleted_term, $object_ids );
[2041] Fix | Delete
[2042] Fix | Delete
return true;
[2043] Fix | Delete
}
[2044] Fix | Delete
[2045] Fix | Delete
/**
[2046] Fix | Delete
* Deletes one existing category.
[2047] Fix | Delete
*
[2048] Fix | Delete
* @since 2.0.0
[2049] Fix | Delete
*
[2050] Fix | Delete
* @param int $cat_ID Category term ID.
[2051] Fix | Delete
* @return bool|int|WP_Error Returns true if completes delete action; false if term doesn't exist;
[2052] Fix | Delete
* Zero on attempted deletion of default Category; WP_Error object is also a possibility.
[2053] Fix | Delete
*/
[2054] Fix | Delete
function wp_delete_category( $cat_ID ) {
[2055] Fix | Delete
return wp_delete_term( $cat_ID, 'category' );
[2056] Fix | Delete
}
[2057] Fix | Delete
[2058] Fix | Delete
/**
[2059] Fix | Delete
* Retrieves the terms associated with the given object(s), in the supplied taxonomies.
[2060] Fix | Delete
*
[2061] Fix | Delete
* @since 2.3.0
[2062] Fix | Delete
* @since 4.2.0 Added support for 'taxonomy', 'parent', and 'term_taxonomy_id' values of `$orderby`.
[2063] Fix | Delete
* Introduced `$parent` argument.
[2064] Fix | Delete
* @since 4.4.0 Introduced `$meta_query` and `$update_term_meta_cache` arguments. When `$fields` is 'all' or
[2065] Fix | Delete
* 'all_with_object_id', an array of `WP_Term` objects will be returned.
[2066] Fix | Delete
* @since 4.7.0 Refactored to use WP_Term_Query, and to support any WP_Term_Query arguments.
[2067] Fix | Delete
*
[2068] Fix | Delete
* @param int|int[] $object_ids The ID(s) of the object(s) to retrieve.
[2069] Fix | Delete
* @param string|string[] $taxonomies The taxonomy names to retrieve terms from.
[2070] Fix | Delete
* @param array|string $args See WP_Term_Query::__construct() for supported arguments.
[2071] Fix | Delete
* @return WP_Term[]|WP_Error Array of terms or empty array if no terms found.
[2072] Fix | Delete
* WP_Error if any of the taxonomies don't exist.
[2073] Fix | Delete
*/
[2074] Fix | Delete
function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) {
[2075] Fix | Delete
if ( empty( $object_ids ) || empty( $taxonomies ) ) {
[2076] Fix | Delete
return array();
[2077] Fix | Delete
}
[2078] Fix | Delete
[2079] Fix | Delete
if ( ! is_array( $taxonomies ) ) {
[2080] Fix | Delete
$taxonomies = array( $taxonomies );
[2081] Fix | Delete
}
[2082] Fix | Delete
[2083] Fix | Delete
foreach ( $taxonomies as $taxonomy ) {
[2084] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[2085] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[2086] Fix | Delete
}
[2087] Fix | Delete
}
[2088] Fix | Delete
[2089] Fix | Delete
if ( ! is_array( $object_ids ) ) {
[2090] Fix | Delete
$object_ids = array( $object_ids );
[2091] Fix | Delete
}
[2092] Fix | Delete
$object_ids = array_map( 'intval', $object_ids );
[2093] Fix | Delete
[2094] Fix | Delete
$args = wp_parse_args( $args );
[2095] Fix | Delete
[2096] Fix | Delete
/**
[2097] Fix | Delete
* Filters arguments for retrieving object terms.
[2098] Fix | Delete
*
[2099] Fix | Delete
* @since 4.9.0
[2100] Fix | Delete
*
[2101] Fix | Delete
* @param array $args An array of arguments for retrieving terms for the given object(s).
[2102] Fix | Delete
* See {@see wp_get_object_terms()} for details.
[2103] Fix | Delete
* @param int[] $object_ids Array of object IDs.
[2104] Fix | Delete
* @param string[] $taxonomies Array of taxonomy names to retrieve terms from.
[2105] Fix | Delete
*/
[2106] Fix | Delete
$args = apply_filters( 'wp_get_object_terms_args', $args, $object_ids, $taxonomies );
[2107] Fix | Delete
[2108] Fix | Delete
/*
[2109] Fix | Delete
* When one or more queried taxonomies is registered with an 'args' array,
[2110] Fix | Delete
* those params override the `$args` passed to this function.
[2111] Fix | Delete
*/
[2112] Fix | Delete
$terms = array();
[2113] Fix | Delete
if ( count( $taxonomies ) > 1 ) {
[2114] Fix | Delete
foreach ( $taxonomies as $index => $taxonomy ) {
[2115] Fix | Delete
$t = get_taxonomy( $taxonomy );
[2116] Fix | Delete
if ( isset( $t->args ) && is_array( $t->args ) && array_merge( $args, $t->args ) != $args ) {
[2117] Fix | Delete
unset( $taxonomies[ $index ] );
[2118] Fix | Delete
$terms = array_merge( $terms, wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ) );
[2119] Fix | Delete
}
[2120] Fix | Delete
}
[2121] Fix | Delete
} else {
[2122] Fix | Delete
$t = get_taxonomy( $taxonomies[0] );
[2123] Fix | Delete
if ( isset( $t->args ) && is_array( $t->args ) ) {
[2124] Fix | Delete
$args = array_merge( $args, $t->args );
[2125] Fix | Delete
}
[2126] Fix | Delete
}
[2127] Fix | Delete
[2128] Fix | Delete
$args['taxonomy'] = $taxonomies;
[2129] Fix | Delete
$args['object_ids'] = $object_ids;
[2130] Fix | Delete
[2131] Fix | Delete
// Taxonomies registered without an 'args' param are handled here.
[2132] Fix | Delete
if ( ! empty( $taxonomies ) ) {
[2133] Fix | Delete
$terms_from_remaining_taxonomies = get_terms( $args );
[2134] Fix | Delete
[2135] Fix | Delete
// Array keys should be preserved for values of $fields that use term_id for keys.
[2136] Fix | Delete
if ( ! empty( $args['fields'] ) && 0 === strpos( $args['fields'], 'id=>' ) ) {
[2137] Fix | Delete
$terms = $terms + $terms_from_remaining_taxonomies;
[2138] Fix | Delete
} else {
[2139] Fix | Delete
$terms = array_merge( $terms, $terms_from_remaining_taxonomies );
[2140] Fix | Delete
}
[2141] Fix | Delete
}
[2142] Fix | Delete
[2143] Fix | Delete
/**
[2144] Fix | Delete
* Filters the terms for a given object or objects.
[2145] Fix | Delete
*
[2146] Fix | Delete
* @since 4.2.0
[2147] Fix | Delete
*
[2148] Fix | Delete
* @param WP_Term[] $terms Array of terms for the given object or objects.
[2149] Fix | Delete
* @param int[] $object_ids Array of object IDs for which terms were retrieved.
[2150] Fix | Delete
* @param string[] $taxonomies Array of taxonomy names from which terms were retrieved.
[2151] Fix | Delete
* @param array $args Array of arguments for retrieving terms for the given
[2152] Fix | Delete
* object(s). See wp_get_object_terms() for details.
[2153] Fix | Delete
*/
[2154] Fix | Delete
$terms = apply_filters( 'get_object_terms', $terms, $object_ids, $taxonomies, $args );
[2155] Fix | Delete
[2156] Fix | Delete
$object_ids = implode( ',', $object_ids );
[2157] Fix | Delete
$taxonomies = "'" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "'";
[2158] Fix | Delete
[2159] Fix | Delete
/**
[2160] Fix | Delete
* Filters the terms for a given object or objects.
[2161] Fix | Delete
*
[2162] Fix | Delete
* The `$taxonomies` parameter passed to this filter is formatted as a SQL fragment. The
[2163] Fix | Delete
* {@see 'get_object_terms'} filter is recommended as an alternative.
[2164] Fix | Delete
*
[2165] Fix | Delete
* @since 2.8.0
[2166] Fix | Delete
*
[2167] Fix | Delete
* @param WP_Term[] $terms Array of terms for the given object or objects.
[2168] Fix | Delete
* @param string $object_ids Comma separated list of object IDs for which terms were retrieved.
[2169] Fix | Delete
* @param string $taxonomies SQL fragment of taxonomy names from which terms were retrieved.
[2170] Fix | Delete
* @param array $args Array of arguments for retrieving terms for the given
[2171] Fix | Delete
* object(s). See wp_get_object_terms() for details.
[2172] Fix | Delete
*/
[2173] Fix | Delete
return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
[2174] Fix | Delete
}
[2175] Fix | Delete
[2176] Fix | Delete
/**
[2177] Fix | Delete
* Add a new term to the database.
[2178] Fix | Delete
*
[2179] Fix | Delete
* A non-existent term is inserted in the following sequence:
[2180] Fix | Delete
* 1. The term is added to the term table, then related to the taxonomy.
[2181] Fix | Delete
* 2. If everything is correct, several actions are fired.
[2182] Fix | Delete
* 3. The 'term_id_filter' is evaluated.
[2183] Fix | Delete
* 4. The term cache is cleaned.
[2184] Fix | Delete
* 5. Several more actions are fired.
[2185] Fix | Delete
* 6. An array is returned containing the `term_id` and `term_taxonomy_id`.
[2186] Fix | Delete
*
[2187] Fix | Delete
* If the 'slug' argument is not empty, then it is checked to see if the term
[2188] Fix | Delete
* is invalid. If it is not a valid, existing term, it is added and the term_id
[2189] Fix | Delete
* is given.
[2190] Fix | Delete
*
[2191] Fix | Delete
* If the taxonomy is hierarchical, and the 'parent' argument is not empty,
[2192] Fix | Delete
* the term is inserted and the term_id will be given.
[2193] Fix | Delete
*
[2194] Fix | Delete
* Error handling:
[2195] Fix | Delete
* If `$taxonomy` does not exist or `$term` is empty,
[2196] Fix | Delete
* a WP_Error object will be returned.
[2197] Fix | Delete
*
[2198] Fix | Delete
* If the term already exists on the same hierarchical level,
[2199] Fix | Delete
* or the term slug and name are not unique, a WP_Error object will be returned.
[2200] Fix | Delete
*
[2201] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2202] Fix | Delete
*
[2203] Fix | Delete
* @since 2.3.0
[2204] Fix | Delete
*
[2205] Fix | Delete
* @param string $term The term name to add.
[2206] Fix | Delete
* @param string $taxonomy The taxonomy to which to add the term.
[2207] Fix | Delete
* @param array|string $args {
[2208] Fix | Delete
* Optional. Array or query string of arguments for inserting a term.
[2209] Fix | Delete
*
[2210] Fix | Delete
* @type string $alias_of Slug of the term to make this term an alias of.
[2211] Fix | Delete
* Default empty string. Accepts a term slug.
[2212] Fix | Delete
* @type string $description The term description. Default empty string.
[2213] Fix | Delete
* @type int $parent The id of the parent term. Default 0.
[2214] Fix | Delete
* @type string $slug The term slug to use. Default empty string.
[2215] Fix | Delete
* }
[2216] Fix | Delete
* @return array|WP_Error {
[2217] Fix | Delete
* An array of the new term data, WP_Error otherwise.
[2218] Fix | Delete
*
[2219] Fix | Delete
* @type int $term_id The new term ID.
[2220] Fix | Delete
* @type int|string $term_taxonomy_id The new term taxonomy ID. Can be a numeric string.
[2221] Fix | Delete
* }
[2222] Fix | Delete
*/
[2223] Fix | Delete
function wp_insert_term( $term, $taxonomy, $args = array() ) {
[2224] Fix | Delete
global $wpdb;
[2225] Fix | Delete
[2226] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[2227] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[2228] Fix | Delete
}
[2229] Fix | Delete
[2230] Fix | Delete
/**
[2231] Fix | Delete
* Filters a term before it is sanitized and inserted into the database.
[2232] Fix | Delete
*
[2233] Fix | Delete
* @since 3.0.0
[2234] Fix | Delete
*
[2235] Fix | Delete
* @param string|WP_Error $term The term name to add, or a WP_Error object if there's an error.
[2236] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2237] Fix | Delete
*/
[2238] Fix | Delete
$term = apply_filters( 'pre_insert_term', $term, $taxonomy );
[2239] Fix | Delete
[2240] Fix | Delete
if ( is_wp_error( $term ) ) {
[2241] Fix | Delete
return $term;
[2242] Fix | Delete
}
[2243] Fix | Delete
[2244] Fix | Delete
if ( is_int( $term ) && 0 === $term ) {
[2245] Fix | Delete
return new WP_Error( 'invalid_term_id', __( 'Invalid term ID.' ) );
[2246] Fix | Delete
}
[2247] Fix | Delete
[2248] Fix | Delete
if ( '' === trim( $term ) ) {
[2249] Fix | Delete
return new WP_Error( 'empty_term_name', __( 'A name is required for this term.' ) );
[2250] Fix | Delete
}
[2251] Fix | Delete
[2252] Fix | Delete
$defaults = array(
[2253] Fix | Delete
'alias_of' => '',
[2254] Fix | Delete
'description' => '',
[2255] Fix | Delete
'parent' => 0,
[2256] Fix | Delete
'slug' => '',
[2257] Fix | Delete
);
[2258] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[2259] Fix | Delete
[2260] Fix | Delete
if ( (int) $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) {
[2261] Fix | Delete
return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) );
[2262] Fix | Delete
}
[2263] Fix | Delete
[2264] Fix | Delete
$args['name'] = $term;
[2265] Fix | Delete
$args['taxonomy'] = $taxonomy;
[2266] Fix | Delete
[2267] Fix | Delete
// Coerce null description to strings, to avoid database errors.
[2268] Fix | Delete
$args['description'] = (string) $args['description'];
[2269] Fix | Delete
[2270] Fix | Delete
$args = sanitize_term( $args, $taxonomy, 'db' );
[2271] Fix | Delete
[2272] Fix | Delete
// expected_slashed ($name)
[2273] Fix | Delete
$name = wp_unslash( $args['name'] );
[2274] Fix | Delete
$description = wp_unslash( $args['description'] );
[2275] Fix | Delete
$parent = (int) $args['parent'];
[2276] Fix | Delete
[2277] Fix | Delete
$slug_provided = ! empty( $args['slug'] );
[2278] Fix | Delete
if ( ! $slug_provided ) {
[2279] Fix | Delete
$slug = sanitize_title( $name );
[2280] Fix | Delete
} else {
[2281] Fix | Delete
$slug = $args['slug'];
[2282] Fix | Delete
}
[2283] Fix | Delete
[2284] Fix | Delete
$term_group = 0;
[2285] Fix | Delete
if ( $args['alias_of'] ) {
[2286] Fix | Delete
$alias = get_term_by( 'slug', $args['alias_of'], $taxonomy );
[2287] Fix | Delete
if ( ! empty( $alias->term_group ) ) {
[2288] Fix | Delete
// The alias we want is already in a group, so let's use that one.
[2289] Fix | Delete
$term_group = $alias->term_group;
[2290] Fix | Delete
} elseif ( ! empty( $alias->term_id ) ) {
[2291] Fix | Delete
/*
[2292] Fix | Delete
* The alias is not in a group, so we create a new one
[2293] Fix | Delete
* and add the alias to it.
[2294] Fix | Delete
*/
[2295] Fix | Delete
$term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1;
[2296] Fix | Delete
[2297] Fix | Delete
wp_update_term(
[2298] Fix | Delete
$alias->term_id,
[2299] Fix | Delete
$taxonomy,
[2300] Fix | Delete
array(
[2301] Fix | Delete
'term_group' => $term_group,
[2302] Fix | Delete
)
[2303] Fix | Delete
);
[2304] Fix | Delete
}
[2305] Fix | Delete
}
[2306] Fix | Delete
[2307] Fix | Delete
/*
[2308] Fix | Delete
* Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy,
[2309] Fix | Delete
* unless a unique slug has been explicitly provided.
[2310] Fix | Delete
*/
[2311] Fix | Delete
$name_matches = get_terms(
[2312] Fix | Delete
array(
[2313] Fix | Delete
'taxonomy' => $taxonomy,
[2314] Fix | Delete
'name' => $name,
[2315] Fix | Delete
'hide_empty' => false,
[2316] Fix | Delete
'parent' => $args['parent'],
[2317] Fix | Delete
'update_term_meta_cache' => false,
[2318] Fix | Delete
)
[2319] Fix | Delete
);
[2320] Fix | Delete
[2321] Fix | Delete
/*
[2322] Fix | Delete
* The `name` match in `get_terms()` doesn't differentiate accented characters,
[2323] Fix | Delete
* so we do a stricter comparison here.
[2324] Fix | Delete
*/
[2325] Fix | Delete
$name_match = null;
[2326] Fix | Delete
if ( $name_matches ) {
[2327] Fix | Delete
foreach ( $name_matches as $_match ) {
[2328] Fix | Delete
if ( strtolower( $name ) === strtolower( $_match->name ) ) {
[2329] Fix | Delete
$name_match = $_match;
[2330] Fix | Delete
break;
[2331] Fix | Delete
}
[2332] Fix | Delete
}
[2333] Fix | Delete
}
[2334] Fix | Delete
[2335] Fix | Delete
if ( $name_match ) {
[2336] Fix | Delete
$slug_match = get_term_by( 'slug', $slug, $taxonomy );
[2337] Fix | Delete
if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) {
[2338] Fix | Delete
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
[2339] Fix | Delete
$siblings = get_terms(
[2340] Fix | Delete
array(
[2341] Fix | Delete
'taxonomy' => $taxonomy,
[2342] Fix | Delete
'get' => 'all',
[2343] Fix | Delete
'parent' => $parent,
[2344] Fix | Delete
'update_term_meta_cache' => false,
[2345] Fix | Delete
)
[2346] Fix | Delete
);
[2347] Fix | Delete
[2348] Fix | Delete
$existing_term = null;
[2349] Fix | Delete
$sibling_names = wp_list_pluck( $siblings, 'name' );
[2350] Fix | Delete
$sibling_slugs = wp_list_pluck( $siblings, 'slug' );
[2351] Fix | Delete
[2352] Fix | Delete
if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, $sibling_names, true ) ) {
[2353] Fix | Delete
$existing_term = $name_match;
[2354] Fix | Delete
} elseif ( $slug_match && in_array( $slug, $sibling_slugs, true ) ) {
[2355] Fix | Delete
$existing_term = $slug_match;
[2356] Fix | Delete
}
[2357] Fix | Delete
[2358] Fix | Delete
if ( $existing_term ) {
[2359] Fix | Delete
return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $existing_term->term_id );
[2360] Fix | Delete
}
[2361] Fix | Delete
} else {
[2362] Fix | Delete
return new WP_Error( 'term_exists', __( 'A term with the name provided already exists in this taxonomy.' ), $name_match->term_id );
[2363] Fix | Delete
}
[2364] Fix | Delete
}
[2365] Fix | Delete
}
[2366] Fix | Delete
[2367] Fix | Delete
$slug = wp_unique_term_slug( $slug, (object) $args );
[2368] Fix | Delete
[2369] Fix | Delete
$data = compact( 'name', 'slug', 'term_group' );
[2370] Fix | Delete
[2371] Fix | Delete
/**
[2372] Fix | Delete
* Filters term data before it is inserted into the database.
[2373] Fix | Delete
*
[2374] Fix | Delete
* @since 4.7.0
[2375] Fix | Delete
*
[2376] Fix | Delete
* @param array $data Term data to be inserted.
[2377] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2378] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2379] Fix | Delete
*/
[2380] Fix | Delete
$data = apply_filters( 'wp_insert_term_data', $data, $taxonomy, $args );
[2381] Fix | Delete
[2382] Fix | Delete
if ( false === $wpdb->insert( $wpdb->terms, $data ) ) {
[2383] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert term into the database.' ), $wpdb->last_error );
[2384] Fix | Delete
}
[2385] Fix | Delete
[2386] Fix | Delete
$term_id = (int) $wpdb->insert_id;
[2387] Fix | Delete
[2388] Fix | Delete
// Seems unreachable. However, is used in the case that a term name is provided, which sanitizes to an empty string.
[2389] Fix | Delete
if ( empty( $slug ) ) {
[2390] Fix | Delete
$slug = sanitize_title( $slug, $term_id );
[2391] Fix | Delete
[2392] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[2393] Fix | Delete
do_action( 'edit_terms', $term_id, $taxonomy );
[2394] Fix | Delete
$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
[2395] Fix | Delete
[2396] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[2397] Fix | Delete
do_action( 'edited_terms', $term_id, $taxonomy );
[2398] Fix | Delete
}
[2399] Fix | Delete
[2400] Fix | Delete
$tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) );
[2401] Fix | Delete
[2402] Fix | Delete
if ( ! empty( $tt_id ) ) {
[2403] Fix | Delete
return array(
[2404] Fix | Delete
'term_id' => $term_id,
[2405] Fix | Delete
'term_taxonomy_id' => $tt_id,
[2406] Fix | Delete
);
[2407] Fix | Delete
}
[2408] Fix | Delete
[2409] Fix | Delete
if ( false === $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ) + array( 'count' => 0 ) ) ) {
[2410] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert term taxonomy into the database.' ), $wpdb->last_error );
[2411] Fix | Delete
}
[2412] Fix | Delete
[2413] Fix | Delete
$tt_id = (int) $wpdb->insert_id;
[2414] Fix | Delete
[2415] Fix | Delete
/*
[2416] Fix | Delete
* Sanity check: if we just created a term with the same parent + taxonomy + slug but a higher term_id than
[2417] Fix | Delete
* an existing term, then we have unwittingly created a duplicate term. Delete the dupe, and use the term_id
[2418] Fix | Delete
* and term_taxonomy_id of the older term instead. Then return out of the function so that the "create" hooks
[2419] Fix | Delete
* are not fired.
[2420] Fix | Delete
*/
[2421] Fix | Delete
$duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) );
[2422] Fix | Delete
[2423] Fix | Delete
/**
[2424] Fix | Delete
* Filters the duplicate term check that takes place during term creation.
[2425] Fix | Delete
*
[2426] Fix | Delete
* Term parent+taxonomy+slug combinations are meant to be unique, and wp_insert_term()
[2427] Fix | Delete
* performs a last-minute confirmation of this uniqueness before allowing a new term
[2428] Fix | Delete
* to be created. Plugins with different uniqueness requirements may use this filter
[2429] Fix | Delete
* to bypass or modify the duplicate-term check.
[2430] Fix | Delete
*
[2431] Fix | Delete
* @since 5.1.0
[2432] Fix | Delete
*
[2433] Fix | Delete
* @param object $duplicate_term Duplicate term row from terms table, if found.
[2434] Fix | Delete
* @param string $term Term being inserted.
[2435] Fix | Delete
* @param string $taxonomy Taxonomy name.
[2436] Fix | Delete
* @param array $args Term arguments passed to the function.
[2437] Fix | Delete
* @param int $tt_id term_taxonomy_id for the newly created term.
[2438] Fix | Delete
*/
[2439] Fix | Delete
$duplicate_term = apply_filters( 'wp_insert_term_duplicate_term_check', $duplicate_term, $term, $taxonomy, $args, $tt_id );
[2440] Fix | Delete
[2441] Fix | Delete
if ( $duplicate_term ) {
[2442] Fix | Delete
$wpdb->delete( $wpdb->terms, array( 'term_id' => $term_id ) );
[2443] Fix | Delete
$wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) );
[2444] Fix | Delete
[2445] Fix | Delete
$term_id = (int) $duplicate_term->term_id;
[2446] Fix | Delete
$tt_id = (int) $duplicate_term->term_taxonomy_id;
[2447] Fix | Delete
[2448] Fix | Delete
clean_term_cache( $term_id, $taxonomy );
[2449] Fix | Delete
return array(
[2450] Fix | Delete
'term_id' => $term_id,
[2451] Fix | Delete
'term_taxonomy_id' => $tt_id,
[2452] Fix | Delete
);
[2453] Fix | Delete
}
[2454] Fix | Delete
[2455] Fix | Delete
/**
[2456] Fix | Delete
* Fires immediately after a new term is created, before the term cache is cleaned.
[2457] Fix | Delete
*
[2458] Fix | Delete
* The {@see 'create_$taxonomy'} hook is also available for targeting a specific
[2459] Fix | Delete
* taxonomy.
[2460] Fix | Delete
*
[2461] Fix | Delete
* @since 2.3.0
[2462] Fix | Delete
*
[2463] Fix | Delete
* @param int $term_id Term ID.
[2464] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2465] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2466] Fix | Delete
*/
[2467] Fix | Delete
do_action( 'create_term', $term_id, $tt_id, $taxonomy );
[2468] Fix | Delete
[2469] Fix | Delete
/**
[2470] Fix | Delete
* Fires after a new term is created for a specific taxonomy.
[2471] Fix | Delete
*
[2472] Fix | Delete
* The dynamic portion of the hook name, `$taxonomy`, refers
[2473] Fix | Delete
* to the slug of the taxonomy the term was created for.
[2474] Fix | Delete
*
[2475] Fix | Delete
* @since 2.3.0
[2476] Fix | Delete
*
[2477] Fix | Delete
* @param int $term_id Term ID.
[2478] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2479] Fix | Delete
*/
[2480] Fix | Delete
do_action( "create_{$taxonomy}", $term_id, $tt_id );
[2481] Fix | Delete
[2482] Fix | Delete
/**
[2483] Fix | Delete
* Filters the term ID after a new term is created.
[2484] Fix | Delete
*
[2485] Fix | Delete
* @since 2.3.0
[2486] Fix | Delete
*
[2487] Fix | Delete
* @param int $term_id Term ID.
[2488] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2489] Fix | Delete
*/
[2490] Fix | Delete
$term_id = apply_filters( 'term_id_filter', $term_id, $tt_id );
[2491] Fix | Delete
[2492] Fix | Delete
clean_term_cache( $term_id, $taxonomy );
[2493] Fix | Delete
[2494] Fix | Delete
/**
[2495] Fix | Delete
* Fires after a new term is created, and after the term cache has been cleaned.
[2496] Fix | Delete
*
[2497] Fix | Delete
* The {@see 'created_$taxonomy'} hook is also available for targeting a specific
[2498] Fix | Delete
* taxonomy.
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function