|
@@ 1121-1139 (lines=19) @@
|
| 1118 |
|
* @return int|WP_Error|bool Meta ID on success. WP_Error when term_id is ambiguous between taxonomies. |
| 1119 |
|
* False on failure. |
| 1120 |
|
*/ |
| 1121 |
|
function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { |
| 1122 |
|
// Bail if term meta table is not installed. |
| 1123 |
|
if ( get_option( 'db_version' ) < 34370 ) { |
| 1124 |
|
return false; |
| 1125 |
|
} |
| 1126 |
|
|
| 1127 |
|
if ( wp_term_is_shared( $term_id ) ) { |
| 1128 |
|
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id ); |
| 1129 |
|
} |
| 1130 |
|
|
| 1131 |
|
$added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); |
| 1132 |
|
|
| 1133 |
|
// Bust term query cache. |
| 1134 |
|
if ( $added ) { |
| 1135 |
|
wp_cache_set( 'last_changed', microtime(), 'terms' ); |
| 1136 |
|
} |
| 1137 |
|
|
| 1138 |
|
return $added; |
| 1139 |
|
} |
| 1140 |
|
|
| 1141 |
|
/** |
| 1142 |
|
* Removes metadata matching criteria from a term. |
|
@@ 1203-1221 (lines=19) @@
|
| 1200 |
|
* @return int|WP_Error|bool Meta ID if the key didn't previously exist. True on successful update. |
| 1201 |
|
* WP_Error when term_id is ambiguous between taxonomies. False on failure. |
| 1202 |
|
*/ |
| 1203 |
|
function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { |
| 1204 |
|
// Bail if term meta table is not installed. |
| 1205 |
|
if ( get_option( 'db_version' ) < 34370 ) { |
| 1206 |
|
return false; |
| 1207 |
|
} |
| 1208 |
|
|
| 1209 |
|
if ( wp_term_is_shared( $term_id ) ) { |
| 1210 |
|
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id ); |
| 1211 |
|
} |
| 1212 |
|
|
| 1213 |
|
$updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); |
| 1214 |
|
|
| 1215 |
|
// Bust term query cache. |
| 1216 |
|
if ( $updated ) { |
| 1217 |
|
wp_cache_set( 'last_changed', microtime(), 'terms' ); |
| 1218 |
|
} |
| 1219 |
|
|
| 1220 |
|
return $updated; |
| 1221 |
|
} |
| 1222 |
|
|
| 1223 |
|
/** |
| 1224 |
|
* Updates metadata cache for list of term IDs. |