Edit File by line
/home/barbar84/www/wp-inclu...
File: taxonomy.php
'get' => 'all',
[1000] Fix | Delete
'number' => 1,
[1001] Fix | Delete
'taxonomy' => $taxonomy,
[1002] Fix | Delete
'update_term_meta_cache' => false,
[1003] Fix | Delete
'orderby' => 'none',
[1004] Fix | Delete
'suppress_filter' => true,
[1005] Fix | Delete
);
[1006] Fix | Delete
[1007] Fix | Delete
switch ( $field ) {
[1008] Fix | Delete
case 'slug':
[1009] Fix | Delete
$args['slug'] = $value;
[1010] Fix | Delete
break;
[1011] Fix | Delete
case 'name':
[1012] Fix | Delete
$args['name'] = $value;
[1013] Fix | Delete
break;
[1014] Fix | Delete
case 'term_taxonomy_id':
[1015] Fix | Delete
$args['term_taxonomy_id'] = $value;
[1016] Fix | Delete
unset( $args['taxonomy'] );
[1017] Fix | Delete
break;
[1018] Fix | Delete
default:
[1019] Fix | Delete
return false;
[1020] Fix | Delete
}
[1021] Fix | Delete
[1022] Fix | Delete
$terms = get_terms( $args );
[1023] Fix | Delete
if ( is_wp_error( $terms ) || empty( $terms ) ) {
[1024] Fix | Delete
return false;
[1025] Fix | Delete
}
[1026] Fix | Delete
[1027] Fix | Delete
$term = array_shift( $terms );
[1028] Fix | Delete
[1029] Fix | Delete
// In the case of 'term_taxonomy_id', override the provided `$taxonomy` with whatever we find in the DB.
[1030] Fix | Delete
if ( 'term_taxonomy_id' === $field ) {
[1031] Fix | Delete
$taxonomy = $term->taxonomy;
[1032] Fix | Delete
}
[1033] Fix | Delete
[1034] Fix | Delete
return get_term( $term, $taxonomy, $output, $filter );
[1035] Fix | Delete
}
[1036] Fix | Delete
[1037] Fix | Delete
/**
[1038] Fix | Delete
* Merge all term children into a single array of their IDs.
[1039] Fix | Delete
*
[1040] Fix | Delete
* This recursive function will merge all of the children of $term into the same
[1041] Fix | Delete
* array of term IDs. Only useful for taxonomies which are hierarchical.
[1042] Fix | Delete
*
[1043] Fix | Delete
* Will return an empty array if $term does not exist in $taxonomy.
[1044] Fix | Delete
*
[1045] Fix | Delete
* @since 2.3.0
[1046] Fix | Delete
*
[1047] Fix | Delete
* @param int $term_id ID of Term to get children.
[1048] Fix | Delete
* @param string $taxonomy Taxonomy Name.
[1049] Fix | Delete
* @return array|WP_Error List of Term IDs. WP_Error returned if `$taxonomy` does not exist.
[1050] Fix | Delete
*/
[1051] Fix | Delete
function get_term_children( $term_id, $taxonomy ) {
[1052] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[1053] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[1054] Fix | Delete
}
[1055] Fix | Delete
[1056] Fix | Delete
$term_id = (int) $term_id;
[1057] Fix | Delete
[1058] Fix | Delete
$terms = _get_term_hierarchy( $taxonomy );
[1059] Fix | Delete
[1060] Fix | Delete
if ( ! isset( $terms[ $term_id ] ) ) {
[1061] Fix | Delete
return array();
[1062] Fix | Delete
}
[1063] Fix | Delete
[1064] Fix | Delete
$children = $terms[ $term_id ];
[1065] Fix | Delete
[1066] Fix | Delete
foreach ( (array) $terms[ $term_id ] as $child ) {
[1067] Fix | Delete
if ( $term_id === $child ) {
[1068] Fix | Delete
continue;
[1069] Fix | Delete
}
[1070] Fix | Delete
[1071] Fix | Delete
if ( isset( $terms[ $child ] ) ) {
[1072] Fix | Delete
$children = array_merge( $children, get_term_children( $child, $taxonomy ) );
[1073] Fix | Delete
}
[1074] Fix | Delete
}
[1075] Fix | Delete
[1076] Fix | Delete
return $children;
[1077] Fix | Delete
}
[1078] Fix | Delete
[1079] Fix | Delete
/**
[1080] Fix | Delete
* Get sanitized Term field.
[1081] Fix | Delete
*
[1082] Fix | Delete
* The function is for contextual reasons and for simplicity of usage.
[1083] Fix | Delete
*
[1084] Fix | Delete
* @since 2.3.0
[1085] Fix | Delete
* @since 4.4.0 The `$taxonomy` parameter was made optional. `$term` can also now accept a WP_Term object.
[1086] Fix | Delete
*
[1087] Fix | Delete
* @see sanitize_term_field()
[1088] Fix | Delete
*
[1089] Fix | Delete
* @param string $field Term field to fetch.
[1090] Fix | Delete
* @param int|WP_Term $term Term ID or object.
[1091] Fix | Delete
* @param string $taxonomy Optional. Taxonomy Name. Default empty.
[1092] Fix | Delete
* @param string $context Optional. How to sanitize term fields. Look at sanitize_term_field() for available options.
[1093] Fix | Delete
* Default 'display'.
[1094] Fix | Delete
* @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term.
[1095] Fix | Delete
*/
[1096] Fix | Delete
function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
[1097] Fix | Delete
$term = get_term( $term, $taxonomy );
[1098] Fix | Delete
if ( is_wp_error( $term ) ) {
[1099] Fix | Delete
return $term;
[1100] Fix | Delete
}
[1101] Fix | Delete
[1102] Fix | Delete
if ( ! is_object( $term ) ) {
[1103] Fix | Delete
return '';
[1104] Fix | Delete
}
[1105] Fix | Delete
[1106] Fix | Delete
if ( ! isset( $term->$field ) ) {
[1107] Fix | Delete
return '';
[1108] Fix | Delete
}
[1109] Fix | Delete
[1110] Fix | Delete
return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
[1111] Fix | Delete
}
[1112] Fix | Delete
[1113] Fix | Delete
/**
[1114] Fix | Delete
* Sanitizes Term for editing.
[1115] Fix | Delete
*
[1116] Fix | Delete
* Return value is sanitize_term() and usage is for sanitizing the term for
[1117] Fix | Delete
* editing. Function is for contextual and simplicity.
[1118] Fix | Delete
*
[1119] Fix | Delete
* @since 2.3.0
[1120] Fix | Delete
*
[1121] Fix | Delete
* @param int|object $id Term ID or object.
[1122] Fix | Delete
* @param string $taxonomy Taxonomy name.
[1123] Fix | Delete
* @return string|int|null|WP_Error Will return empty string if $term is not an object.
[1124] Fix | Delete
*/
[1125] Fix | Delete
function get_term_to_edit( $id, $taxonomy ) {
[1126] Fix | Delete
$term = get_term( $id, $taxonomy );
[1127] Fix | Delete
[1128] Fix | Delete
if ( is_wp_error( $term ) ) {
[1129] Fix | Delete
return $term;
[1130] Fix | Delete
}
[1131] Fix | Delete
[1132] Fix | Delete
if ( ! is_object( $term ) ) {
[1133] Fix | Delete
return '';
[1134] Fix | Delete
}
[1135] Fix | Delete
[1136] Fix | Delete
return sanitize_term( $term, $taxonomy, 'edit' );
[1137] Fix | Delete
}
[1138] Fix | Delete
[1139] Fix | Delete
/**
[1140] Fix | Delete
* Retrieves the terms in a given taxonomy or list of taxonomies.
[1141] Fix | Delete
*
[1142] Fix | Delete
* You can fully inject any customizations to the query before it is sent, as
[1143] Fix | Delete
* well as control the output with a filter.
[1144] Fix | Delete
*
[1145] Fix | Delete
* The return type varies depending on the value passed to `$args['fields']`. See
[1146] Fix | Delete
* WP_Term_Query::get_terms() for details. In all cases, a `WP_Error` object will
[1147] Fix | Delete
* be returned if an invalid taxonomy is requested.
[1148] Fix | Delete
*
[1149] Fix | Delete
* The {@see 'get_terms'} filter will be called when the cache has the term and will
[1150] Fix | Delete
* pass the found term along with the array of $taxonomies and array of $args.
[1151] Fix | Delete
* This filter is also called before the array of terms is passed and will pass
[1152] Fix | Delete
* the array of terms, along with the $taxonomies and $args.
[1153] Fix | Delete
*
[1154] Fix | Delete
* The {@see 'list_terms_exclusions'} filter passes the compiled exclusions along with
[1155] Fix | Delete
* the $args.
[1156] Fix | Delete
*
[1157] Fix | Delete
* The {@see 'get_terms_orderby'} filter passes the `ORDER BY` clause for the query
[1158] Fix | Delete
* along with the $args array.
[1159] Fix | Delete
*
[1160] Fix | Delete
* Prior to 4.5.0, the first parameter of `get_terms()` was a taxonomy or list of taxonomies:
[1161] Fix | Delete
*
[1162] Fix | Delete
* $terms = get_terms( 'post_tag', array(
[1163] Fix | Delete
* 'hide_empty' => false,
[1164] Fix | Delete
* ) );
[1165] Fix | Delete
*
[1166] Fix | Delete
* Since 4.5.0, taxonomies should be passed via the 'taxonomy' argument in the `$args` array:
[1167] Fix | Delete
*
[1168] Fix | Delete
* $terms = get_terms( array(
[1169] Fix | Delete
* 'taxonomy' => 'post_tag',
[1170] Fix | Delete
* 'hide_empty' => false,
[1171] Fix | Delete
* ) );
[1172] Fix | Delete
*
[1173] Fix | Delete
* @since 2.3.0
[1174] Fix | Delete
* @since 4.2.0 Introduced 'name' and 'childless' parameters.
[1175] Fix | Delete
* @since 4.4.0 Introduced the ability to pass 'term_id' as an alias of 'id' for the `orderby` parameter.
[1176] Fix | Delete
* Introduced the 'meta_query' and 'update_term_meta_cache' parameters. Converted to return
[1177] Fix | Delete
* a list of WP_Term objects.
[1178] Fix | Delete
* @since 4.5.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
[1179] Fix | Delete
* Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata.
[1180] Fix | Delete
* @since 4.8.0 Introduced 'suppress_filter' parameter.
[1181] Fix | Delete
*
[1182] Fix | Delete
* @internal The `$deprecated` parameter is parsed for backward compatibility only.
[1183] Fix | Delete
*
[1184] Fix | Delete
* @param array|string $args Optional. Array or string of arguments. See WP_Term_Query::__construct()
[1185] Fix | Delete
* for information on accepted arguments. Default empty array.
[1186] Fix | Delete
* @param array|string $deprecated Optional. Argument array, when using the legacy function parameter format.
[1187] Fix | Delete
* If present, this parameter will be interpreted as `$args`, and the first
[1188] Fix | Delete
* function parameter will be parsed as a taxonomy or array of taxonomies.
[1189] Fix | Delete
* Default empty.
[1190] Fix | Delete
* @return WP_Term[]|int[]|string[]|string|WP_Error Array of terms, a count thereof as a numeric string,
[1191] Fix | Delete
* or WP_Error if any of the taxonomies do not exist.
[1192] Fix | Delete
* See the function description for more information.
[1193] Fix | Delete
*/
[1194] Fix | Delete
function get_terms( $args = array(), $deprecated = '' ) {
[1195] Fix | Delete
$term_query = new WP_Term_Query();
[1196] Fix | Delete
[1197] Fix | Delete
$defaults = array(
[1198] Fix | Delete
'suppress_filter' => false,
[1199] Fix | Delete
);
[1200] Fix | Delete
[1201] Fix | Delete
/*
[1202] Fix | Delete
* Legacy argument format ($taxonomy, $args) takes precedence.
[1203] Fix | Delete
*
[1204] Fix | Delete
* We detect legacy argument format by checking if
[1205] Fix | Delete
* (a) a second non-empty parameter is passed, or
[1206] Fix | Delete
* (b) the first parameter shares no keys with the default array (ie, it's a list of taxonomies)
[1207] Fix | Delete
*/
[1208] Fix | Delete
$_args = wp_parse_args( $args );
[1209] Fix | Delete
$key_intersect = array_intersect_key( $term_query->query_var_defaults, (array) $_args );
[1210] Fix | Delete
$do_legacy_args = $deprecated || empty( $key_intersect );
[1211] Fix | Delete
[1212] Fix | Delete
if ( $do_legacy_args ) {
[1213] Fix | Delete
$taxonomies = (array) $args;
[1214] Fix | Delete
$args = wp_parse_args( $deprecated, $defaults );
[1215] Fix | Delete
$args['taxonomy'] = $taxonomies;
[1216] Fix | Delete
} else {
[1217] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[1218] Fix | Delete
if ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) {
[1219] Fix | Delete
$args['taxonomy'] = (array) $args['taxonomy'];
[1220] Fix | Delete
}
[1221] Fix | Delete
}
[1222] Fix | Delete
[1223] Fix | Delete
if ( ! empty( $args['taxonomy'] ) ) {
[1224] Fix | Delete
foreach ( $args['taxonomy'] as $taxonomy ) {
[1225] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[1226] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[1227] Fix | Delete
}
[1228] Fix | Delete
}
[1229] Fix | Delete
}
[1230] Fix | Delete
[1231] Fix | Delete
// Don't pass suppress_filter to WP_Term_Query.
[1232] Fix | Delete
$suppress_filter = $args['suppress_filter'];
[1233] Fix | Delete
unset( $args['suppress_filter'] );
[1234] Fix | Delete
[1235] Fix | Delete
$terms = $term_query->query( $args );
[1236] Fix | Delete
[1237] Fix | Delete
// Count queries are not filtered, for legacy reasons.
[1238] Fix | Delete
if ( ! is_array( $terms ) ) {
[1239] Fix | Delete
return $terms;
[1240] Fix | Delete
}
[1241] Fix | Delete
[1242] Fix | Delete
if ( $suppress_filter ) {
[1243] Fix | Delete
return $terms;
[1244] Fix | Delete
}
[1245] Fix | Delete
[1246] Fix | Delete
/**
[1247] Fix | Delete
* Filters the found terms.
[1248] Fix | Delete
*
[1249] Fix | Delete
* @since 2.3.0
[1250] Fix | Delete
* @since 4.6.0 Added the `$term_query` parameter.
[1251] Fix | Delete
*
[1252] Fix | Delete
* @param array $terms Array of found terms.
[1253] Fix | Delete
* @param array $taxonomies An array of taxonomies.
[1254] Fix | Delete
* @param array $args An array of get_terms() arguments.
[1255] Fix | Delete
* @param WP_Term_Query $term_query The WP_Term_Query object.
[1256] Fix | Delete
*/
[1257] Fix | Delete
return apply_filters( 'get_terms', $terms, $term_query->query_vars['taxonomy'], $term_query->query_vars, $term_query );
[1258] Fix | Delete
}
[1259] Fix | Delete
[1260] Fix | Delete
/**
[1261] Fix | Delete
* Adds metadata to a term.
[1262] Fix | Delete
*
[1263] Fix | Delete
* @since 4.4.0
[1264] Fix | Delete
*
[1265] Fix | Delete
* @param int $term_id Term ID.
[1266] Fix | Delete
* @param string $meta_key Metadata name.
[1267] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[1268] Fix | Delete
* @param bool $unique Optional. Whether the same key should not be added.
[1269] Fix | Delete
* Default false.
[1270] Fix | Delete
* @return int|false|WP_Error Meta ID on success, false on failure.
[1271] Fix | Delete
* WP_Error when term_id is ambiguous between taxonomies.
[1272] Fix | Delete
*/
[1273] Fix | Delete
function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
[1274] Fix | Delete
if ( wp_term_is_shared( $term_id ) ) {
[1275] Fix | Delete
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
[1276] Fix | Delete
}
[1277] Fix | Delete
[1278] Fix | Delete
return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
[1279] Fix | Delete
}
[1280] Fix | Delete
[1281] Fix | Delete
/**
[1282] Fix | Delete
* Removes metadata matching criteria from a term.
[1283] Fix | Delete
*
[1284] Fix | Delete
* @since 4.4.0
[1285] Fix | Delete
*
[1286] Fix | Delete
* @param int $term_id Term ID.
[1287] Fix | Delete
* @param string $meta_key Metadata name.
[1288] Fix | Delete
* @param mixed $meta_value Optional. Metadata value. If provided,
[1289] Fix | Delete
* rows will only be removed that match the value.
[1290] Fix | Delete
* Must be serializable if non-scalar. Default empty.
[1291] Fix | Delete
* @return bool True on success, false on failure.
[1292] Fix | Delete
*/
[1293] Fix | Delete
function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
[1294] Fix | Delete
return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
[1295] Fix | Delete
}
[1296] Fix | Delete
[1297] Fix | Delete
/**
[1298] Fix | Delete
* Retrieves metadata for a term.
[1299] Fix | Delete
*
[1300] Fix | Delete
* @since 4.4.0
[1301] Fix | Delete
*
[1302] Fix | Delete
* @param int $term_id Term ID.
[1303] Fix | Delete
* @param string $key Optional. The meta key to retrieve. By default,
[1304] Fix | Delete
* returns data for all keys. Default empty.
[1305] Fix | Delete
* @param bool $single Optional. Whether to return a single value.
[1306] Fix | Delete
* This parameter has no effect if $key is not specified.
[1307] Fix | Delete
* Default false.
[1308] Fix | Delete
* @return mixed An array if $single is false. The value of the meta field
[1309] Fix | Delete
* if $single is true. False for an invalid $term_id.
[1310] Fix | Delete
*/
[1311] Fix | Delete
function get_term_meta( $term_id, $key = '', $single = false ) {
[1312] Fix | Delete
return get_metadata( 'term', $term_id, $key, $single );
[1313] Fix | Delete
}
[1314] Fix | Delete
[1315] Fix | Delete
/**
[1316] Fix | Delete
* Updates term metadata.
[1317] Fix | Delete
*
[1318] Fix | Delete
* Use the `$prev_value` parameter to differentiate between meta fields with the same key and term ID.
[1319] Fix | Delete
*
[1320] Fix | Delete
* If the meta field for the term does not exist, it will be added.
[1321] Fix | Delete
*
[1322] Fix | Delete
* @since 4.4.0
[1323] Fix | Delete
*
[1324] Fix | Delete
* @param int $term_id Term ID.
[1325] Fix | Delete
* @param string $meta_key Metadata key.
[1326] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[1327] Fix | Delete
* @param mixed $prev_value Optional. Previous value to check before updating.
[1328] Fix | Delete
* If specified, only update existing metadata entries with
[1329] Fix | Delete
* this value. Otherwise, update all entries. Default empty.
[1330] Fix | Delete
* @return int|bool|WP_Error Meta ID if the key didn't exist. true on successful update,
[1331] Fix | Delete
* false on failure or if the value passed to the function
[1332] Fix | Delete
* is the same as the one that is already in the database.
[1333] Fix | Delete
* WP_Error when term_id is ambiguous between taxonomies.
[1334] Fix | Delete
*/
[1335] Fix | Delete
function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
[1336] Fix | Delete
if ( wp_term_is_shared( $term_id ) ) {
[1337] Fix | Delete
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
[1338] Fix | Delete
}
[1339] Fix | Delete
[1340] Fix | Delete
return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
[1341] Fix | Delete
}
[1342] Fix | Delete
[1343] Fix | Delete
/**
[1344] Fix | Delete
* Updates metadata cache for list of term IDs.
[1345] Fix | Delete
*
[1346] Fix | Delete
* Performs SQL query to retrieve all metadata for the terms matching `$term_ids` and stores them in the cache.
[1347] Fix | Delete
* Subsequent calls to `get_term_meta()` will not need to query the database.
[1348] Fix | Delete
*
[1349] Fix | Delete
* @since 4.4.0
[1350] Fix | Delete
*
[1351] Fix | Delete
* @param array $term_ids List of term IDs.
[1352] Fix | Delete
* @return array|false An array of metadata on success, false if there is nothing to update.
[1353] Fix | Delete
*/
[1354] Fix | Delete
function update_termmeta_cache( $term_ids ) {
[1355] Fix | Delete
return update_meta_cache( 'term', $term_ids );
[1356] Fix | Delete
}
[1357] Fix | Delete
[1358] Fix | Delete
/**
[1359] Fix | Delete
* Get all meta data, including meta IDs, for the given term ID.
[1360] Fix | Delete
*
[1361] Fix | Delete
* @since 4.9.0
[1362] Fix | Delete
*
[1363] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1364] Fix | Delete
*
[1365] Fix | Delete
* @param int $term_id Term ID.
[1366] Fix | Delete
* @return array|false Array with meta data, or false when the meta table is not installed.
[1367] Fix | Delete
*/
[1368] Fix | Delete
function has_term_meta( $term_id ) {
[1369] Fix | Delete
$check = wp_check_term_meta_support_prefilter( null );
[1370] Fix | Delete
if ( null !== $check ) {
[1371] Fix | Delete
return $check;
[1372] Fix | Delete
}
[1373] Fix | Delete
[1374] Fix | Delete
global $wpdb;
[1375] Fix | Delete
[1376] Fix | Delete
return $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, term_id FROM $wpdb->termmeta WHERE term_id = %d ORDER BY meta_key,meta_id", $term_id ), ARRAY_A );
[1377] Fix | Delete
}
[1378] Fix | Delete
[1379] Fix | Delete
/**
[1380] Fix | Delete
* Registers a meta key for terms.
[1381] Fix | Delete
*
[1382] Fix | Delete
* @since 4.9.8
[1383] Fix | Delete
*
[1384] Fix | Delete
* @param string $taxonomy Taxonomy to register a meta key for. Pass an empty string
[1385] Fix | Delete
* to register the meta key across all existing taxonomies.
[1386] Fix | Delete
* @param string $meta_key The meta key to register.
[1387] Fix | Delete
* @param array $args Data used to describe the meta key when registered. See
[1388] Fix | Delete
* {@see register_meta()} for a list of supported arguments.
[1389] Fix | Delete
* @return bool True if the meta key was successfully registered, false if not.
[1390] Fix | Delete
*/
[1391] Fix | Delete
function register_term_meta( $taxonomy, $meta_key, array $args ) {
[1392] Fix | Delete
$args['object_subtype'] = $taxonomy;
[1393] Fix | Delete
[1394] Fix | Delete
return register_meta( 'term', $meta_key, $args );
[1395] Fix | Delete
}
[1396] Fix | Delete
[1397] Fix | Delete
/**
[1398] Fix | Delete
* Unregisters a meta key for terms.
[1399] Fix | Delete
*
[1400] Fix | Delete
* @since 4.9.8
[1401] Fix | Delete
*
[1402] Fix | Delete
* @param string $taxonomy Taxonomy the meta key is currently registered for. Pass
[1403] Fix | Delete
* an empty string if the meta key is registered across all
[1404] Fix | Delete
* existing taxonomies.
[1405] Fix | Delete
* @param string $meta_key The meta key to unregister.
[1406] Fix | Delete
* @return bool True on success, false if the meta key was not previously registered.
[1407] Fix | Delete
*/
[1408] Fix | Delete
function unregister_term_meta( $taxonomy, $meta_key ) {
[1409] Fix | Delete
return unregister_meta_key( 'term', $meta_key, $taxonomy );
[1410] Fix | Delete
}
[1411] Fix | Delete
[1412] Fix | Delete
/**
[1413] Fix | Delete
* Determines whether a taxonomy term exists.
[1414] Fix | Delete
*
[1415] Fix | Delete
* Formerly is_term(), introduced in 2.3.0.
[1416] Fix | Delete
*
[1417] Fix | Delete
* For more information on this and similar theme functions, check out
[1418] Fix | Delete
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
[1419] Fix | Delete
* Conditional Tags} article in the Theme Developer Handbook.
[1420] Fix | Delete
*
[1421] Fix | Delete
* @since 3.0.0
[1422] Fix | Delete
*
[1423] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1424] Fix | Delete
*
[1425] Fix | Delete
* @param int|string $term The term to check. Accepts term ID, slug, or name.
[1426] Fix | Delete
* @param string $taxonomy Optional. The taxonomy name to use.
[1427] Fix | Delete
* @param int $parent Optional. ID of parent term under which to confine the exists search.
[1428] Fix | Delete
* @return mixed Returns null if the term does not exist.
[1429] Fix | Delete
* Returns the term ID if no taxonomy is specified and the term ID exists.
[1430] Fix | Delete
* Returns an array of the term ID and the term taxonomy ID if the taxonomy is specified and the pairing exists.
[1431] Fix | Delete
* Returns 0 if term ID 0 is passed to the function.
[1432] Fix | Delete
*/
[1433] Fix | Delete
function term_exists( $term, $taxonomy = '', $parent = null ) {
[1434] Fix | Delete
global $wpdb;
[1435] Fix | Delete
[1436] Fix | Delete
$select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
[1437] Fix | Delete
$tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";
[1438] Fix | Delete
[1439] Fix | Delete
if ( is_int( $term ) ) {
[1440] Fix | Delete
if ( 0 === $term ) {
[1441] Fix | Delete
return 0;
[1442] Fix | Delete
}
[1443] Fix | Delete
$where = 't.term_id = %d';
[1444] Fix | Delete
if ( ! empty( $taxonomy ) ) {
[1445] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
[1446] Fix | Delete
return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . ' AND tt.taxonomy = %s', $term, $taxonomy ), ARRAY_A );
[1447] Fix | Delete
} else {
[1448] Fix | Delete
return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) );
[1449] Fix | Delete
}
[1450] Fix | Delete
}
[1451] Fix | Delete
[1452] Fix | Delete
$term = trim( wp_unslash( $term ) );
[1453] Fix | Delete
$slug = sanitize_title( $term );
[1454] Fix | Delete
[1455] Fix | Delete
$where = 't.slug = %s';
[1456] Fix | Delete
$else_where = 't.name = %s';
[1457] Fix | Delete
$where_fields = array( $slug );
[1458] Fix | Delete
$else_where_fields = array( $term );
[1459] Fix | Delete
$orderby = 'ORDER BY t.term_id ASC';
[1460] Fix | Delete
$limit = 'LIMIT 1';
[1461] Fix | Delete
if ( ! empty( $taxonomy ) ) {
[1462] Fix | Delete
if ( is_numeric( $parent ) ) {
[1463] Fix | Delete
$parent = (int) $parent;
[1464] Fix | Delete
$where_fields[] = $parent;
[1465] Fix | Delete
$else_where_fields[] = $parent;
[1466] Fix | Delete
$where .= ' AND tt.parent = %d';
[1467] Fix | Delete
$else_where .= ' AND tt.parent = %d';
[1468] Fix | Delete
}
[1469] Fix | Delete
[1470] Fix | Delete
$where_fields[] = $taxonomy;
[1471] Fix | Delete
$else_where_fields[] = $taxonomy;
[1472] Fix | Delete
[1473] Fix | Delete
$result = $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields ), ARRAY_A );
[1474] Fix | Delete
if ( $result ) {
[1475] Fix | Delete
return $result;
[1476] Fix | Delete
}
[1477] Fix | Delete
[1478] Fix | Delete
return $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields ), ARRAY_A );
[1479] Fix | Delete
}
[1480] Fix | Delete
[1481] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
[1482] Fix | Delete
$result = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields ) );
[1483] Fix | Delete
if ( $result ) {
[1484] Fix | Delete
return $result;
[1485] Fix | Delete
}
[1486] Fix | Delete
[1487] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
[1488] Fix | Delete
return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields ) );
[1489] Fix | Delete
}
[1490] Fix | Delete
[1491] Fix | Delete
/**
[1492] Fix | Delete
* Check if a term is an ancestor of another term.
[1493] Fix | Delete
*
[1494] Fix | Delete
* You can use either an ID or the term object for both parameters.
[1495] Fix | Delete
*
[1496] Fix | Delete
* @since 3.4.0
[1497] Fix | Delete
*
[1498] Fix | Delete
* @param int|object $term1 ID or object to check if this is the parent term.
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function