Edit File by line
/home/barbar84/www/wp-inclu...
File: taxonomy.php
[4000] Fix | Delete
if ( ! $shared_tt_count ) {
[4001] Fix | Delete
return $term_id;
[4002] Fix | Delete
}
[4003] Fix | Delete
[4004] Fix | Delete
/*
[4005] Fix | Delete
* Verify that the term_taxonomy_id passed to the function is actually associated with the term_id.
[4006] Fix | Delete
* If there's a mismatch, it may mean that the term is already split. Return the actual term_id from the db.
[4007] Fix | Delete
*/
[4008] Fix | Delete
$check_term_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
[4009] Fix | Delete
if ( $check_term_id !== $term_id ) {
[4010] Fix | Delete
return $check_term_id;
[4011] Fix | Delete
}
[4012] Fix | Delete
[4013] Fix | Delete
// Pull up data about the currently shared slug, which we'll use to populate the new one.
[4014] Fix | Delete
if ( empty( $shared_term ) ) {
[4015] Fix | Delete
$shared_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.* FROM $wpdb->terms t WHERE t.term_id = %d", $term_id ) );
[4016] Fix | Delete
}
[4017] Fix | Delete
[4018] Fix | Delete
$new_term_data = array(
[4019] Fix | Delete
'name' => $shared_term->name,
[4020] Fix | Delete
'slug' => $shared_term->slug,
[4021] Fix | Delete
'term_group' => $shared_term->term_group,
[4022] Fix | Delete
);
[4023] Fix | Delete
[4024] Fix | Delete
if ( false === $wpdb->insert( $wpdb->terms, $new_term_data ) ) {
[4025] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not split shared term.' ), $wpdb->last_error );
[4026] Fix | Delete
}
[4027] Fix | Delete
[4028] Fix | Delete
$new_term_id = (int) $wpdb->insert_id;
[4029] Fix | Delete
[4030] Fix | Delete
// Update the existing term_taxonomy to point to the newly created term.
[4031] Fix | Delete
$wpdb->update(
[4032] Fix | Delete
$wpdb->term_taxonomy,
[4033] Fix | Delete
array( 'term_id' => $new_term_id ),
[4034] Fix | Delete
array( 'term_taxonomy_id' => $term_taxonomy_id )
[4035] Fix | Delete
);
[4036] Fix | Delete
[4037] Fix | Delete
// Reassign child terms to the new parent.
[4038] Fix | Delete
if ( empty( $term_taxonomy ) ) {
[4039] Fix | Delete
$term_taxonomy = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
[4040] Fix | Delete
}
[4041] Fix | Delete
[4042] Fix | Delete
$children_tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = %s", $term_id, $term_taxonomy->taxonomy ) );
[4043] Fix | Delete
if ( ! empty( $children_tt_ids ) ) {
[4044] Fix | Delete
foreach ( $children_tt_ids as $child_tt_id ) {
[4045] Fix | Delete
$wpdb->update(
[4046] Fix | Delete
$wpdb->term_taxonomy,
[4047] Fix | Delete
array( 'parent' => $new_term_id ),
[4048] Fix | Delete
array( 'term_taxonomy_id' => $child_tt_id )
[4049] Fix | Delete
);
[4050] Fix | Delete
clean_term_cache( (int) $child_tt_id, '', false );
[4051] Fix | Delete
}
[4052] Fix | Delete
} else {
[4053] Fix | Delete
// If the term has no children, we must force its taxonomy cache to be rebuilt separately.
[4054] Fix | Delete
clean_term_cache( $new_term_id, $term_taxonomy->taxonomy, false );
[4055] Fix | Delete
}
[4056] Fix | Delete
[4057] Fix | Delete
clean_term_cache( $term_id, $term_taxonomy->taxonomy, false );
[4058] Fix | Delete
[4059] Fix | Delete
/*
[4060] Fix | Delete
* Taxonomy cache clearing is delayed to avoid race conditions that may occur when
[4061] Fix | Delete
* regenerating the taxonomy's hierarchy tree.
[4062] Fix | Delete
*/
[4063] Fix | Delete
$taxonomies_to_clean = array( $term_taxonomy->taxonomy );
[4064] Fix | Delete
[4065] Fix | Delete
// Clean the cache for term taxonomies formerly shared with the current term.
[4066] Fix | Delete
$shared_term_taxonomies = $wpdb->get_col( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
[4067] Fix | Delete
$taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies );
[4068] Fix | Delete
[4069] Fix | Delete
foreach ( $taxonomies_to_clean as $taxonomy_to_clean ) {
[4070] Fix | Delete
clean_taxonomy_cache( $taxonomy_to_clean );
[4071] Fix | Delete
}
[4072] Fix | Delete
[4073] Fix | Delete
// Keep a record of term_ids that have been split, keyed by old term_id. See wp_get_split_term().
[4074] Fix | Delete
if ( $record ) {
[4075] Fix | Delete
$split_term_data = get_option( '_split_terms', array() );
[4076] Fix | Delete
if ( ! isset( $split_term_data[ $term_id ] ) ) {
[4077] Fix | Delete
$split_term_data[ $term_id ] = array();
[4078] Fix | Delete
}
[4079] Fix | Delete
[4080] Fix | Delete
$split_term_data[ $term_id ][ $term_taxonomy->taxonomy ] = $new_term_id;
[4081] Fix | Delete
update_option( '_split_terms', $split_term_data );
[4082] Fix | Delete
}
[4083] Fix | Delete
[4084] Fix | Delete
// If we've just split the final shared term, set the "finished" flag.
[4085] Fix | Delete
$shared_terms_exist = $wpdb->get_results(
[4086] Fix | Delete
"SELECT tt.term_id, t.*, count(*) as term_tt_count FROM {$wpdb->term_taxonomy} tt
[4087] Fix | Delete
LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
[4088] Fix | Delete
GROUP BY t.term_id
[4089] Fix | Delete
HAVING term_tt_count > 1
[4090] Fix | Delete
LIMIT 1"
[4091] Fix | Delete
);
[4092] Fix | Delete
if ( ! $shared_terms_exist ) {
[4093] Fix | Delete
update_option( 'finished_splitting_shared_terms', true );
[4094] Fix | Delete
}
[4095] Fix | Delete
[4096] Fix | Delete
/**
[4097] Fix | Delete
* Fires after a previously shared taxonomy term is split into two separate terms.
[4098] Fix | Delete
*
[4099] Fix | Delete
* @since 4.2.0
[4100] Fix | Delete
*
[4101] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4102] Fix | Delete
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
[4103] Fix | Delete
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
[4104] Fix | Delete
* @param string $taxonomy Taxonomy for the split term.
[4105] Fix | Delete
*/
[4106] Fix | Delete
do_action( 'split_shared_term', $term_id, $new_term_id, $term_taxonomy_id, $term_taxonomy->taxonomy );
[4107] Fix | Delete
[4108] Fix | Delete
return $new_term_id;
[4109] Fix | Delete
}
[4110] Fix | Delete
[4111] Fix | Delete
/**
[4112] Fix | Delete
* Splits a batch of shared taxonomy terms.
[4113] Fix | Delete
*
[4114] Fix | Delete
* @since 4.3.0
[4115] Fix | Delete
*
[4116] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4117] Fix | Delete
*/
[4118] Fix | Delete
function _wp_batch_split_terms() {
[4119] Fix | Delete
global $wpdb;
[4120] Fix | Delete
[4121] Fix | Delete
$lock_name = 'term_split.lock';
[4122] Fix | Delete
[4123] Fix | Delete
// Try to lock.
[4124] Fix | Delete
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) );
[4125] Fix | Delete
[4126] Fix | Delete
if ( ! $lock_result ) {
[4127] Fix | Delete
$lock_result = get_option( $lock_name );
[4128] Fix | Delete
[4129] Fix | Delete
// Bail if we were unable to create a lock, or if the existing lock is still valid.
[4130] Fix | Delete
if ( ! $lock_result || ( $lock_result > ( time() - HOUR_IN_SECONDS ) ) ) {
[4131] Fix | Delete
wp_schedule_single_event( time() + ( 5 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
[4132] Fix | Delete
return;
[4133] Fix | Delete
}
[4134] Fix | Delete
}
[4135] Fix | Delete
[4136] Fix | Delete
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
[4137] Fix | Delete
update_option( $lock_name, time() );
[4138] Fix | Delete
[4139] Fix | Delete
// Get a list of shared terms (those with more than one associated row in term_taxonomy).
[4140] Fix | Delete
$shared_terms = $wpdb->get_results(
[4141] Fix | Delete
"SELECT tt.term_id, t.*, count(*) as term_tt_count FROM {$wpdb->term_taxonomy} tt
[4142] Fix | Delete
LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
[4143] Fix | Delete
GROUP BY t.term_id
[4144] Fix | Delete
HAVING term_tt_count > 1
[4145] Fix | Delete
LIMIT 10"
[4146] Fix | Delete
);
[4147] Fix | Delete
[4148] Fix | Delete
// No more terms, we're done here.
[4149] Fix | Delete
if ( ! $shared_terms ) {
[4150] Fix | Delete
update_option( 'finished_splitting_shared_terms', true );
[4151] Fix | Delete
delete_option( $lock_name );
[4152] Fix | Delete
return;
[4153] Fix | Delete
}
[4154] Fix | Delete
[4155] Fix | Delete
// Shared terms found? We'll need to run this script again.
[4156] Fix | Delete
wp_schedule_single_event( time() + ( 2 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
[4157] Fix | Delete
[4158] Fix | Delete
// Rekey shared term array for faster lookups.
[4159] Fix | Delete
$_shared_terms = array();
[4160] Fix | Delete
foreach ( $shared_terms as $shared_term ) {
[4161] Fix | Delete
$term_id = (int) $shared_term->term_id;
[4162] Fix | Delete
$_shared_terms[ $term_id ] = $shared_term;
[4163] Fix | Delete
}
[4164] Fix | Delete
$shared_terms = $_shared_terms;
[4165] Fix | Delete
[4166] Fix | Delete
// Get term taxonomy data for all shared terms.
[4167] Fix | Delete
$shared_term_ids = implode( ',', array_keys( $shared_terms ) );
[4168] Fix | Delete
$shared_tts = $wpdb->get_results( "SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})" );
[4169] Fix | Delete
[4170] Fix | Delete
// Split term data recording is slow, so we do it just once, outside the loop.
[4171] Fix | Delete
$split_term_data = get_option( '_split_terms', array() );
[4172] Fix | Delete
$skipped_first_term = array();
[4173] Fix | Delete
$taxonomies = array();
[4174] Fix | Delete
foreach ( $shared_tts as $shared_tt ) {
[4175] Fix | Delete
$term_id = (int) $shared_tt->term_id;
[4176] Fix | Delete
[4177] Fix | Delete
// Don't split the first tt belonging to a given term_id.
[4178] Fix | Delete
if ( ! isset( $skipped_first_term[ $term_id ] ) ) {
[4179] Fix | Delete
$skipped_first_term[ $term_id ] = 1;
[4180] Fix | Delete
continue;
[4181] Fix | Delete
}
[4182] Fix | Delete
[4183] Fix | Delete
if ( ! isset( $split_term_data[ $term_id ] ) ) {
[4184] Fix | Delete
$split_term_data[ $term_id ] = array();
[4185] Fix | Delete
}
[4186] Fix | Delete
[4187] Fix | Delete
// Keep track of taxonomies whose hierarchies need flushing.
[4188] Fix | Delete
if ( ! isset( $taxonomies[ $shared_tt->taxonomy ] ) ) {
[4189] Fix | Delete
$taxonomies[ $shared_tt->taxonomy ] = 1;
[4190] Fix | Delete
}
[4191] Fix | Delete
[4192] Fix | Delete
// Split the term.
[4193] Fix | Delete
$split_term_data[ $term_id ][ $shared_tt->taxonomy ] = _split_shared_term( $shared_terms[ $term_id ], $shared_tt, false );
[4194] Fix | Delete
}
[4195] Fix | Delete
[4196] Fix | Delete
// Rebuild the cached hierarchy for each affected taxonomy.
[4197] Fix | Delete
foreach ( array_keys( $taxonomies ) as $tax ) {
[4198] Fix | Delete
delete_option( "{$tax}_children" );
[4199] Fix | Delete
_get_term_hierarchy( $tax );
[4200] Fix | Delete
}
[4201] Fix | Delete
[4202] Fix | Delete
update_option( '_split_terms', $split_term_data );
[4203] Fix | Delete
[4204] Fix | Delete
delete_option( $lock_name );
[4205] Fix | Delete
}
[4206] Fix | Delete
[4207] Fix | Delete
/**
[4208] Fix | Delete
* In order to avoid the _wp_batch_split_terms() job being accidentally removed,
[4209] Fix | Delete
* check that it's still scheduled while we haven't finished splitting terms.
[4210] Fix | Delete
*
[4211] Fix | Delete
* @ignore
[4212] Fix | Delete
* @since 4.3.0
[4213] Fix | Delete
*/
[4214] Fix | Delete
function _wp_check_for_scheduled_split_terms() {
[4215] Fix | Delete
if ( ! get_option( 'finished_splitting_shared_terms' ) && ! wp_next_scheduled( 'wp_split_shared_term_batch' ) ) {
[4216] Fix | Delete
wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_split_shared_term_batch' );
[4217] Fix | Delete
}
[4218] Fix | Delete
}
[4219] Fix | Delete
[4220] Fix | Delete
/**
[4221] Fix | Delete
* Check default categories when a term gets split to see if any of them need to be updated.
[4222] Fix | Delete
*
[4223] Fix | Delete
* @ignore
[4224] Fix | Delete
* @since 4.2.0
[4225] Fix | Delete
*
[4226] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4227] Fix | Delete
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
[4228] Fix | Delete
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
[4229] Fix | Delete
* @param string $taxonomy Taxonomy for the split term.
[4230] Fix | Delete
*/
[4231] Fix | Delete
function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
[4232] Fix | Delete
if ( 'category' !== $taxonomy ) {
[4233] Fix | Delete
return;
[4234] Fix | Delete
}
[4235] Fix | Delete
[4236] Fix | Delete
foreach ( array( 'default_category', 'default_link_category', 'default_email_category' ) as $option ) {
[4237] Fix | Delete
if ( (int) get_option( $option, -1 ) === $term_id ) {
[4238] Fix | Delete
update_option( $option, $new_term_id );
[4239] Fix | Delete
}
[4240] Fix | Delete
}
[4241] Fix | Delete
}
[4242] Fix | Delete
[4243] Fix | Delete
/**
[4244] Fix | Delete
* Check menu items when a term gets split to see if any of them need to be updated.
[4245] Fix | Delete
*
[4246] Fix | Delete
* @ignore
[4247] Fix | Delete
* @since 4.2.0
[4248] Fix | Delete
*
[4249] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4250] Fix | Delete
*
[4251] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4252] Fix | Delete
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
[4253] Fix | Delete
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
[4254] Fix | Delete
* @param string $taxonomy Taxonomy for the split term.
[4255] Fix | Delete
*/
[4256] Fix | Delete
function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
[4257] Fix | Delete
global $wpdb;
[4258] Fix | Delete
$post_ids = $wpdb->get_col(
[4259] Fix | Delete
$wpdb->prepare(
[4260] Fix | Delete
"SELECT m1.post_id
[4261] Fix | Delete
FROM {$wpdb->postmeta} AS m1
[4262] Fix | Delete
INNER JOIN {$wpdb->postmeta} AS m2 ON ( m2.post_id = m1.post_id )
[4263] Fix | Delete
INNER JOIN {$wpdb->postmeta} AS m3 ON ( m3.post_id = m1.post_id )
[4264] Fix | Delete
WHERE ( m1.meta_key = '_menu_item_type' AND m1.meta_value = 'taxonomy' )
[4265] Fix | Delete
AND ( m2.meta_key = '_menu_item_object' AND m2.meta_value = %s )
[4266] Fix | Delete
AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )",
[4267] Fix | Delete
$taxonomy,
[4268] Fix | Delete
$term_id
[4269] Fix | Delete
)
[4270] Fix | Delete
);
[4271] Fix | Delete
[4272] Fix | Delete
if ( $post_ids ) {
[4273] Fix | Delete
foreach ( $post_ids as $post_id ) {
[4274] Fix | Delete
update_post_meta( $post_id, '_menu_item_object_id', $new_term_id, $term_id );
[4275] Fix | Delete
}
[4276] Fix | Delete
}
[4277] Fix | Delete
}
[4278] Fix | Delete
[4279] Fix | Delete
/**
[4280] Fix | Delete
* If the term being split is a nav_menu, change associations.
[4281] Fix | Delete
*
[4282] Fix | Delete
* @ignore
[4283] Fix | Delete
* @since 4.3.0
[4284] Fix | Delete
*
[4285] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4286] Fix | Delete
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
[4287] Fix | Delete
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
[4288] Fix | Delete
* @param string $taxonomy Taxonomy for the split term.
[4289] Fix | Delete
*/
[4290] Fix | Delete
function _wp_check_split_nav_menu_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
[4291] Fix | Delete
if ( 'nav_menu' !== $taxonomy ) {
[4292] Fix | Delete
return;
[4293] Fix | Delete
}
[4294] Fix | Delete
[4295] Fix | Delete
// Update menu locations.
[4296] Fix | Delete
$locations = get_nav_menu_locations();
[4297] Fix | Delete
foreach ( $locations as $location => $menu_id ) {
[4298] Fix | Delete
if ( $term_id === $menu_id ) {
[4299] Fix | Delete
$locations[ $location ] = $new_term_id;
[4300] Fix | Delete
}
[4301] Fix | Delete
}
[4302] Fix | Delete
set_theme_mod( 'nav_menu_locations', $locations );
[4303] Fix | Delete
}
[4304] Fix | Delete
[4305] Fix | Delete
/**
[4306] Fix | Delete
* Get data about terms that previously shared a single term_id, but have since been split.
[4307] Fix | Delete
*
[4308] Fix | Delete
* @since 4.2.0
[4309] Fix | Delete
*
[4310] Fix | Delete
* @param int $old_term_id Term ID. This is the old, pre-split term ID.
[4311] Fix | Delete
* @return array Array of new term IDs, keyed by taxonomy.
[4312] Fix | Delete
*/
[4313] Fix | Delete
function wp_get_split_terms( $old_term_id ) {
[4314] Fix | Delete
$split_terms = get_option( '_split_terms', array() );
[4315] Fix | Delete
[4316] Fix | Delete
$terms = array();
[4317] Fix | Delete
if ( isset( $split_terms[ $old_term_id ] ) ) {
[4318] Fix | Delete
$terms = $split_terms[ $old_term_id ];
[4319] Fix | Delete
}
[4320] Fix | Delete
[4321] Fix | Delete
return $terms;
[4322] Fix | Delete
}
[4323] Fix | Delete
[4324] Fix | Delete
/**
[4325] Fix | Delete
* Get the new term ID corresponding to a previously split term.
[4326] Fix | Delete
*
[4327] Fix | Delete
* @since 4.2.0
[4328] Fix | Delete
*
[4329] Fix | Delete
* @param int $old_term_id Term ID. This is the old, pre-split term ID.
[4330] Fix | Delete
* @param string $taxonomy Taxonomy that the term belongs to.
[4331] Fix | Delete
* @return int|false If a previously split term is found corresponding to the old term_id and taxonomy,
[4332] Fix | Delete
* the new term_id will be returned. If no previously split term is found matching
[4333] Fix | Delete
* the parameters, returns false.
[4334] Fix | Delete
*/
[4335] Fix | Delete
function wp_get_split_term( $old_term_id, $taxonomy ) {
[4336] Fix | Delete
$split_terms = wp_get_split_terms( $old_term_id );
[4337] Fix | Delete
[4338] Fix | Delete
$term_id = false;
[4339] Fix | Delete
if ( isset( $split_terms[ $taxonomy ] ) ) {
[4340] Fix | Delete
$term_id = (int) $split_terms[ $taxonomy ];
[4341] Fix | Delete
}
[4342] Fix | Delete
[4343] Fix | Delete
return $term_id;
[4344] Fix | Delete
}
[4345] Fix | Delete
[4346] Fix | Delete
/**
[4347] Fix | Delete
* Determine whether a term is shared between multiple taxonomies.
[4348] Fix | Delete
*
[4349] Fix | Delete
* Shared taxonomy terms began to be split in 4.3, but failed cron tasks or
[4350] Fix | Delete
* other delays in upgrade routines may cause shared terms to remain.
[4351] Fix | Delete
*
[4352] Fix | Delete
* @since 4.4.0
[4353] Fix | Delete
*
[4354] Fix | Delete
* @param int $term_id Term ID.
[4355] Fix | Delete
* @return bool Returns false if a term is not shared between multiple taxonomies or
[4356] Fix | Delete
* if splitting shared taxonomy terms is finished.
[4357] Fix | Delete
*/
[4358] Fix | Delete
function wp_term_is_shared( $term_id ) {
[4359] Fix | Delete
global $wpdb;
[4360] Fix | Delete
[4361] Fix | Delete
if ( get_option( 'finished_splitting_shared_terms' ) ) {
[4362] Fix | Delete
return false;
[4363] Fix | Delete
}
[4364] Fix | Delete
[4365] Fix | Delete
$tt_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
[4366] Fix | Delete
[4367] Fix | Delete
return $tt_count > 1;
[4368] Fix | Delete
}
[4369] Fix | Delete
[4370] Fix | Delete
/**
[4371] Fix | Delete
* Generate a permalink for a taxonomy term archive.
[4372] Fix | Delete
*
[4373] Fix | Delete
* @since 2.5.0
[4374] Fix | Delete
*
[4375] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[4376] Fix | Delete
*
[4377] Fix | Delete
* @param WP_Term|int|string $term The term object, ID, or slug whose link will be retrieved.
[4378] Fix | Delete
* @param string $taxonomy Optional. Taxonomy. Default empty.
[4379] Fix | Delete
* @return string|WP_Error URL of the taxonomy term archive on success, WP_Error if term does not exist.
[4380] Fix | Delete
*/
[4381] Fix | Delete
function get_term_link( $term, $taxonomy = '' ) {
[4382] Fix | Delete
global $wp_rewrite;
[4383] Fix | Delete
[4384] Fix | Delete
if ( ! is_object( $term ) ) {
[4385] Fix | Delete
if ( is_int( $term ) ) {
[4386] Fix | Delete
$term = get_term( $term, $taxonomy );
[4387] Fix | Delete
} else {
[4388] Fix | Delete
$term = get_term_by( 'slug', $term, $taxonomy );
[4389] Fix | Delete
}
[4390] Fix | Delete
}
[4391] Fix | Delete
[4392] Fix | Delete
if ( ! is_object( $term ) ) {
[4393] Fix | Delete
$term = new WP_Error( 'invalid_term', __( 'Empty Term.' ) );
[4394] Fix | Delete
}
[4395] Fix | Delete
[4396] Fix | Delete
if ( is_wp_error( $term ) ) {
[4397] Fix | Delete
return $term;
[4398] Fix | Delete
}
[4399] Fix | Delete
[4400] Fix | Delete
$taxonomy = $term->taxonomy;
[4401] Fix | Delete
[4402] Fix | Delete
$termlink = $wp_rewrite->get_extra_permastruct( $taxonomy );
[4403] Fix | Delete
[4404] Fix | Delete
/**
[4405] Fix | Delete
* Filters the permalink structure for a terms before token replacement occurs.
[4406] Fix | Delete
*
[4407] Fix | Delete
* @since 4.9.0
[4408] Fix | Delete
*
[4409] Fix | Delete
* @param string $termlink The permalink structure for the term's taxonomy.
[4410] Fix | Delete
* @param WP_Term $term The term object.
[4411] Fix | Delete
*/
[4412] Fix | Delete
$termlink = apply_filters( 'pre_term_link', $termlink, $term );
[4413] Fix | Delete
[4414] Fix | Delete
$slug = $term->slug;
[4415] Fix | Delete
$t = get_taxonomy( $taxonomy );
[4416] Fix | Delete
[4417] Fix | Delete
if ( empty( $termlink ) ) {
[4418] Fix | Delete
if ( 'category' === $taxonomy ) {
[4419] Fix | Delete
$termlink = '?cat=' . $term->term_id;
[4420] Fix | Delete
} elseif ( $t->query_var ) {
[4421] Fix | Delete
$termlink = "?$t->query_var=$slug";
[4422] Fix | Delete
} else {
[4423] Fix | Delete
$termlink = "?taxonomy=$taxonomy&term=$slug";
[4424] Fix | Delete
}
[4425] Fix | Delete
$termlink = home_url( $termlink );
[4426] Fix | Delete
} else {
[4427] Fix | Delete
if ( $t->rewrite['hierarchical'] ) {
[4428] Fix | Delete
$hierarchical_slugs = array();
[4429] Fix | Delete
$ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' );
[4430] Fix | Delete
foreach ( (array) $ancestors as $ancestor ) {
[4431] Fix | Delete
$ancestor_term = get_term( $ancestor, $taxonomy );
[4432] Fix | Delete
$hierarchical_slugs[] = $ancestor_term->slug;
[4433] Fix | Delete
}
[4434] Fix | Delete
$hierarchical_slugs = array_reverse( $hierarchical_slugs );
[4435] Fix | Delete
$hierarchical_slugs[] = $slug;
[4436] Fix | Delete
$termlink = str_replace( "%$taxonomy%", implode( '/', $hierarchical_slugs ), $termlink );
[4437] Fix | Delete
} else {
[4438] Fix | Delete
$termlink = str_replace( "%$taxonomy%", $slug, $termlink );
[4439] Fix | Delete
}
[4440] Fix | Delete
$termlink = home_url( user_trailingslashit( $termlink, 'category' ) );
[4441] Fix | Delete
}
[4442] Fix | Delete
[4443] Fix | Delete
// Back compat filters.
[4444] Fix | Delete
if ( 'post_tag' === $taxonomy ) {
[4445] Fix | Delete
[4446] Fix | Delete
/**
[4447] Fix | Delete
* Filters the tag link.
[4448] Fix | Delete
*
[4449] Fix | Delete
* @since 2.3.0
[4450] Fix | Delete
* @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
[4451] Fix | Delete
* @since 5.4.1 Restored (un-deprecated).
[4452] Fix | Delete
*
[4453] Fix | Delete
* @param string $termlink Tag link URL.
[4454] Fix | Delete
* @param int $term_id Term ID.
[4455] Fix | Delete
*/
[4456] Fix | Delete
$termlink = apply_filters( 'tag_link', $termlink, $term->term_id );
[4457] Fix | Delete
} elseif ( 'category' === $taxonomy ) {
[4458] Fix | Delete
[4459] Fix | Delete
/**
[4460] Fix | Delete
* Filters the category link.
[4461] Fix | Delete
*
[4462] Fix | Delete
* @since 1.5.0
[4463] Fix | Delete
* @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
[4464] Fix | Delete
* @since 5.4.1 Restored (un-deprecated).
[4465] Fix | Delete
*
[4466] Fix | Delete
* @param string $termlink Category link URL.
[4467] Fix | Delete
* @param int $term_id Term ID.
[4468] Fix | Delete
*/
[4469] Fix | Delete
$termlink = apply_filters( 'category_link', $termlink, $term->term_id );
[4470] Fix | Delete
}
[4471] Fix | Delete
[4472] Fix | Delete
/**
[4473] Fix | Delete
* Filters the term link.
[4474] Fix | Delete
*
[4475] Fix | Delete
* @since 2.5.0
[4476] Fix | Delete
*
[4477] Fix | Delete
* @param string $termlink Term link URL.
[4478] Fix | Delete
* @param WP_Term $term Term object.
[4479] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[4480] Fix | Delete
*/
[4481] Fix | Delete
return apply_filters( 'term_link', $termlink, $term, $taxonomy );
[4482] Fix | Delete
}
[4483] Fix | Delete
[4484] Fix | Delete
/**
[4485] Fix | Delete
* Display the taxonomies of a post with available options.
[4486] Fix | Delete
*
[4487] Fix | Delete
* This function can be used within the loop to display the taxonomies for a
[4488] Fix | Delete
* post without specifying the Post ID. You can also use it outside the Loop to
[4489] Fix | Delete
* display the taxonomies for a specific post.
[4490] Fix | Delete
*
[4491] Fix | Delete
* @since 2.5.0
[4492] Fix | Delete
*
[4493] Fix | Delete
* @param array $args {
[4494] Fix | Delete
* Arguments about which post to use and how to format the output. Shares all of the arguments
[4495] Fix | Delete
* supported by get_the_taxonomies(), in addition to the following.
[4496] Fix | Delete
*
[4497] Fix | Delete
* @type int|WP_Post $post Post ID or object to get taxonomies of. Default current post.
[4498] Fix | Delete
* @type string $before Displays before the taxonomies. Default empty string.
[4499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function