Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: taxonomy.php
[4000] Fix | Delete
return $term_list;
[4001] Fix | Delete
}
[4002] Fix | Delete
[4003] Fix | Delete
/**
[4004] Fix | Delete
* Adds count of children to parent count.
[4005] Fix | Delete
*
[4006] Fix | Delete
* Recalculates term counts by including items from child terms. Assumes all
[4007] Fix | Delete
* relevant children are already in the $terms argument.
[4008] Fix | Delete
*
[4009] Fix | Delete
* @access private
[4010] Fix | Delete
* @since 2.3.0
[4011] Fix | Delete
*
[4012] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4013] Fix | Delete
*
[4014] Fix | Delete
* @param object[]|WP_Term[] $terms List of term objects (passed by reference).
[4015] Fix | Delete
* @param string $taxonomy Term context.
[4016] Fix | Delete
*/
[4017] Fix | Delete
function _pad_term_counts( &$terms, $taxonomy ) {
[4018] Fix | Delete
global $wpdb;
[4019] Fix | Delete
[4020] Fix | Delete
// This function only works for hierarchical taxonomies like post categories.
[4021] Fix | Delete
if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
[4022] Fix | Delete
return;
[4023] Fix | Delete
}
[4024] Fix | Delete
[4025] Fix | Delete
$term_hier = _get_term_hierarchy( $taxonomy );
[4026] Fix | Delete
[4027] Fix | Delete
if ( empty( $term_hier ) ) {
[4028] Fix | Delete
return;
[4029] Fix | Delete
}
[4030] Fix | Delete
[4031] Fix | Delete
$term_items = array();
[4032] Fix | Delete
$terms_by_id = array();
[4033] Fix | Delete
$term_ids = array();
[4034] Fix | Delete
[4035] Fix | Delete
foreach ( (array) $terms as $key => $term ) {
[4036] Fix | Delete
$terms_by_id[ $term->term_id ] = & $terms[ $key ];
[4037] Fix | Delete
$term_ids[ $term->term_taxonomy_id ] = $term->term_id;
[4038] Fix | Delete
}
[4039] Fix | Delete
[4040] Fix | Delete
// Get the object and term IDs and stick them in a lookup table.
[4041] Fix | Delete
$tax_obj = get_taxonomy( $taxonomy );
[4042] Fix | Delete
$object_types = esc_sql( $tax_obj->object_type );
[4043] Fix | Delete
$results = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" );
[4044] Fix | Delete
[4045] Fix | Delete
foreach ( $results as $row ) {
[4046] Fix | Delete
$id = $term_ids[ $row->term_taxonomy_id ];
[4047] Fix | Delete
[4048] Fix | Delete
$term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1;
[4049] Fix | Delete
}
[4050] Fix | Delete
[4051] Fix | Delete
// Touch every ancestor's lookup row for each post in each term.
[4052] Fix | Delete
foreach ( $term_ids as $term_id ) {
[4053] Fix | Delete
$child = $term_id;
[4054] Fix | Delete
$ancestors = array();
[4055] Fix | Delete
while ( ! empty( $terms_by_id[ $child ] ) && $parent = $terms_by_id[ $child ]->parent ) {
[4056] Fix | Delete
$ancestors[] = $child;
[4057] Fix | Delete
[4058] Fix | Delete
if ( ! empty( $term_items[ $term_id ] ) ) {
[4059] Fix | Delete
foreach ( $term_items[ $term_id ] as $item_id => $touches ) {
[4060] Fix | Delete
$term_items[ $parent ][ $item_id ] = isset( $term_items[ $parent ][ $item_id ] ) ? ++$term_items[ $parent ][ $item_id ] : 1;
[4061] Fix | Delete
}
[4062] Fix | Delete
}
[4063] Fix | Delete
[4064] Fix | Delete
$child = $parent;
[4065] Fix | Delete
[4066] Fix | Delete
if ( in_array( $parent, $ancestors, true ) ) {
[4067] Fix | Delete
break;
[4068] Fix | Delete
}
[4069] Fix | Delete
}
[4070] Fix | Delete
}
[4071] Fix | Delete
[4072] Fix | Delete
// Transfer the touched cells.
[4073] Fix | Delete
foreach ( (array) $term_items as $id => $items ) {
[4074] Fix | Delete
if ( isset( $terms_by_id[ $id ] ) ) {
[4075] Fix | Delete
$terms_by_id[ $id ]->count = count( $items );
[4076] Fix | Delete
}
[4077] Fix | Delete
}
[4078] Fix | Delete
}
[4079] Fix | Delete
[4080] Fix | Delete
/**
[4081] Fix | Delete
* Adds any terms from the given IDs to the cache that do not already exist in cache.
[4082] Fix | Delete
*
[4083] Fix | Delete
* @since 4.6.0
[4084] Fix | Delete
* @since 6.1.0 This function is no longer marked as "private".
[4085] Fix | Delete
* @since 6.3.0 Use wp_lazyload_term_meta() for lazy-loading of term meta.
[4086] Fix | Delete
*
[4087] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4088] Fix | Delete
*
[4089] Fix | Delete
* @param array $term_ids Array of term IDs.
[4090] Fix | Delete
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
[4091] Fix | Delete
*/
[4092] Fix | Delete
function _prime_term_caches( $term_ids, $update_meta_cache = true ) {
[4093] Fix | Delete
global $wpdb;
[4094] Fix | Delete
[4095] Fix | Delete
$non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' );
[4096] Fix | Delete
if ( ! empty( $non_cached_ids ) ) {
[4097] Fix | Delete
$fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );
[4098] Fix | Delete
[4099] Fix | Delete
update_term_cache( $fresh_terms );
[4100] Fix | Delete
}
[4101] Fix | Delete
[4102] Fix | Delete
if ( $update_meta_cache ) {
[4103] Fix | Delete
wp_lazyload_term_meta( $term_ids );
[4104] Fix | Delete
}
[4105] Fix | Delete
}
[4106] Fix | Delete
[4107] Fix | Delete
//
[4108] Fix | Delete
// Default callbacks.
[4109] Fix | Delete
//
[4110] Fix | Delete
[4111] Fix | Delete
/**
[4112] Fix | Delete
* Updates term count based on object types of the current taxonomy.
[4113] Fix | Delete
*
[4114] Fix | Delete
* Private function for the default callback for post_tag and category
[4115] Fix | Delete
* taxonomies.
[4116] Fix | Delete
*
[4117] Fix | Delete
* @access private
[4118] Fix | Delete
* @since 2.3.0
[4119] Fix | Delete
*
[4120] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4121] Fix | Delete
*
[4122] Fix | Delete
* @param int[] $terms List of term taxonomy IDs.
[4123] Fix | Delete
* @param WP_Taxonomy $taxonomy Current taxonomy object of terms.
[4124] Fix | Delete
*/
[4125] Fix | Delete
function _update_post_term_count( $terms, $taxonomy ) {
[4126] Fix | Delete
global $wpdb;
[4127] Fix | Delete
[4128] Fix | Delete
$object_types = (array) $taxonomy->object_type;
[4129] Fix | Delete
[4130] Fix | Delete
foreach ( $object_types as &$object_type ) {
[4131] Fix | Delete
list( $object_type ) = explode( ':', $object_type );
[4132] Fix | Delete
}
[4133] Fix | Delete
[4134] Fix | Delete
$object_types = array_unique( $object_types );
[4135] Fix | Delete
[4136] Fix | Delete
$check_attachments = array_search( 'attachment', $object_types, true );
[4137] Fix | Delete
if ( false !== $check_attachments ) {
[4138] Fix | Delete
unset( $object_types[ $check_attachments ] );
[4139] Fix | Delete
$check_attachments = true;
[4140] Fix | Delete
}
[4141] Fix | Delete
[4142] Fix | Delete
if ( $object_types ) {
[4143] Fix | Delete
$object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) );
[4144] Fix | Delete
}
[4145] Fix | Delete
[4146] Fix | Delete
$post_statuses = array( 'publish' );
[4147] Fix | Delete
[4148] Fix | Delete
/**
[4149] Fix | Delete
* Filters the post statuses for updating the term count.
[4150] Fix | Delete
*
[4151] Fix | Delete
* @since 5.7.0
[4152] Fix | Delete
*
[4153] Fix | Delete
* @param string[] $post_statuses List of post statuses to include in the count. Default is 'publish'.
[4154] Fix | Delete
* @param WP_Taxonomy $taxonomy Current taxonomy object.
[4155] Fix | Delete
*/
[4156] Fix | Delete
$post_statuses = esc_sql( apply_filters( 'update_post_term_count_statuses', $post_statuses, $taxonomy ) );
[4157] Fix | Delete
[4158] Fix | Delete
foreach ( (array) $terms as $term ) {
[4159] Fix | Delete
$count = 0;
[4160] Fix | Delete
[4161] Fix | Delete
// Attachments can be 'inherit' status, we need to base count off the parent's status if so.
[4162] Fix | Delete
if ( $check_attachments ) {
[4163] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.QuotedDynamicPlaceholderGeneration
[4164] Fix | Delete
$count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status IN ('" . implode( "', '", $post_statuses ) . "') OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) IN ('" . implode( "', '", $post_statuses ) . "') ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) );
[4165] Fix | Delete
}
[4166] Fix | Delete
[4167] Fix | Delete
if ( $object_types ) {
[4168] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.QuotedDynamicPlaceholderGeneration
[4169] Fix | Delete
$count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status IN ('" . implode( "', '", $post_statuses ) . "') AND post_type IN ('" . implode( "', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) );
[4170] Fix | Delete
}
[4171] Fix | Delete
[4172] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[4173] Fix | Delete
do_action( 'edit_term_taxonomy', $term, $taxonomy->name );
[4174] Fix | Delete
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
[4175] Fix | Delete
[4176] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[4177] Fix | Delete
do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
[4178] Fix | Delete
}
[4179] Fix | Delete
}
[4180] Fix | Delete
[4181] Fix | Delete
/**
[4182] Fix | Delete
* Updates term count based on number of objects.
[4183] Fix | Delete
*
[4184] Fix | Delete
* Default callback for the 'link_category' taxonomy.
[4185] Fix | Delete
*
[4186] Fix | Delete
* @since 3.3.0
[4187] Fix | Delete
*
[4188] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4189] Fix | Delete
*
[4190] Fix | Delete
* @param int[] $terms List of term taxonomy IDs.
[4191] Fix | Delete
* @param WP_Taxonomy $taxonomy Current taxonomy object of terms.
[4192] Fix | Delete
*/
[4193] Fix | Delete
function _update_generic_term_count( $terms, $taxonomy ) {
[4194] Fix | Delete
global $wpdb;
[4195] Fix | Delete
[4196] Fix | Delete
foreach ( (array) $terms as $term ) {
[4197] Fix | Delete
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) );
[4198] Fix | Delete
[4199] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[4200] Fix | Delete
do_action( 'edit_term_taxonomy', $term, $taxonomy->name );
[4201] Fix | Delete
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
[4202] Fix | Delete
[4203] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[4204] Fix | Delete
do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
[4205] Fix | Delete
}
[4206] Fix | Delete
}
[4207] Fix | Delete
[4208] Fix | Delete
/**
[4209] Fix | Delete
* Creates a new term for a term_taxonomy item that currently shares its term
[4210] Fix | Delete
* with another term_taxonomy.
[4211] Fix | Delete
*
[4212] Fix | Delete
* @ignore
[4213] Fix | Delete
* @since 4.2.0
[4214] Fix | Delete
* @since 4.3.0 Introduced `$record` parameter. Also, `$term_id` and
[4215] Fix | Delete
* `$term_taxonomy_id` can now accept objects.
[4216] Fix | Delete
*
[4217] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4218] Fix | Delete
*
[4219] Fix | Delete
* @param int|object $term_id ID of the shared term, or the shared term object.
[4220] Fix | Delete
* @param int|object $term_taxonomy_id ID of the term_taxonomy item to receive a new term, or the term_taxonomy object
[4221] Fix | Delete
* (corresponding to a row from the term_taxonomy table).
[4222] Fix | Delete
* @param bool $record Whether to record data about the split term in the options table. The recording
[4223] Fix | Delete
* process has the potential to be resource-intensive, so during batch operations
[4224] Fix | Delete
* it can be beneficial to skip inline recording and do it just once, after the
[4225] Fix | Delete
* batch is processed. Only set this to `false` if you know what you are doing.
[4226] Fix | Delete
* Default: true.
[4227] Fix | Delete
* @return int|WP_Error When the current term does not need to be split (or cannot be split on the current
[4228] Fix | Delete
* database schema), `$term_id` is returned. When the term is successfully split, the
[4229] Fix | Delete
* new term_id is returned. A WP_Error is returned for miscellaneous errors.
[4230] Fix | Delete
*/
[4231] Fix | Delete
function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) {
[4232] Fix | Delete
global $wpdb;
[4233] Fix | Delete
[4234] Fix | Delete
if ( is_object( $term_id ) ) {
[4235] Fix | Delete
$shared_term = $term_id;
[4236] Fix | Delete
$term_id = (int) $shared_term->term_id;
[4237] Fix | Delete
}
[4238] Fix | Delete
[4239] Fix | Delete
if ( is_object( $term_taxonomy_id ) ) {
[4240] Fix | Delete
$term_taxonomy = $term_taxonomy_id;
[4241] Fix | Delete
$term_taxonomy_id = (int) $term_taxonomy->term_taxonomy_id;
[4242] Fix | Delete
}
[4243] Fix | Delete
[4244] Fix | Delete
// If there are no shared term_taxonomy rows, there's nothing to do here.
[4245] Fix | Delete
$shared_tt_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy tt WHERE tt.term_id = %d AND tt.term_taxonomy_id != %d", $term_id, $term_taxonomy_id ) );
[4246] Fix | Delete
[4247] Fix | Delete
if ( ! $shared_tt_count ) {
[4248] Fix | Delete
return $term_id;
[4249] Fix | Delete
}
[4250] Fix | Delete
[4251] Fix | Delete
/*
[4252] Fix | Delete
* Verify that the term_taxonomy_id passed to the function is actually associated with the term_id.
[4253] Fix | Delete
* If there's a mismatch, it may mean that the term is already split. Return the actual term_id from the db.
[4254] Fix | Delete
*/
[4255] 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 ) );
[4256] Fix | Delete
if ( $check_term_id !== $term_id ) {
[4257] Fix | Delete
return $check_term_id;
[4258] Fix | Delete
}
[4259] Fix | Delete
[4260] Fix | Delete
// Pull up data about the currently shared slug, which we'll use to populate the new one.
[4261] Fix | Delete
if ( empty( $shared_term ) ) {
[4262] Fix | Delete
$shared_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.* FROM $wpdb->terms t WHERE t.term_id = %d", $term_id ) );
[4263] Fix | Delete
}
[4264] Fix | Delete
[4265] Fix | Delete
$new_term_data = array(
[4266] Fix | Delete
'name' => $shared_term->name,
[4267] Fix | Delete
'slug' => $shared_term->slug,
[4268] Fix | Delete
'term_group' => $shared_term->term_group,
[4269] Fix | Delete
);
[4270] Fix | Delete
[4271] Fix | Delete
if ( false === $wpdb->insert( $wpdb->terms, $new_term_data ) ) {
[4272] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not split shared term.' ), $wpdb->last_error );
[4273] Fix | Delete
}
[4274] Fix | Delete
[4275] Fix | Delete
$new_term_id = (int) $wpdb->insert_id;
[4276] Fix | Delete
[4277] Fix | Delete
// Update the existing term_taxonomy to point to the newly created term.
[4278] Fix | Delete
$wpdb->update(
[4279] Fix | Delete
$wpdb->term_taxonomy,
[4280] Fix | Delete
array( 'term_id' => $new_term_id ),
[4281] Fix | Delete
array( 'term_taxonomy_id' => $term_taxonomy_id )
[4282] Fix | Delete
);
[4283] Fix | Delete
[4284] Fix | Delete
// Reassign child terms to the new parent.
[4285] Fix | Delete
if ( empty( $term_taxonomy ) ) {
[4286] Fix | Delete
$term_taxonomy = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
[4287] Fix | Delete
}
[4288] Fix | Delete
[4289] 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 ) );
[4290] Fix | Delete
if ( ! empty( $children_tt_ids ) ) {
[4291] Fix | Delete
foreach ( $children_tt_ids as $child_tt_id ) {
[4292] Fix | Delete
$wpdb->update(
[4293] Fix | Delete
$wpdb->term_taxonomy,
[4294] Fix | Delete
array( 'parent' => $new_term_id ),
[4295] Fix | Delete
array( 'term_taxonomy_id' => $child_tt_id )
[4296] Fix | Delete
);
[4297] Fix | Delete
clean_term_cache( (int) $child_tt_id, '', false );
[4298] Fix | Delete
}
[4299] Fix | Delete
} else {
[4300] Fix | Delete
// If the term has no children, we must force its taxonomy cache to be rebuilt separately.
[4301] Fix | Delete
clean_term_cache( $new_term_id, $term_taxonomy->taxonomy, false );
[4302] Fix | Delete
}
[4303] Fix | Delete
[4304] Fix | Delete
clean_term_cache( $term_id, $term_taxonomy->taxonomy, false );
[4305] Fix | Delete
[4306] Fix | Delete
/*
[4307] Fix | Delete
* Taxonomy cache clearing is delayed to avoid race conditions that may occur when
[4308] Fix | Delete
* regenerating the taxonomy's hierarchy tree.
[4309] Fix | Delete
*/
[4310] Fix | Delete
$taxonomies_to_clean = array( $term_taxonomy->taxonomy );
[4311] Fix | Delete
[4312] Fix | Delete
// Clean the cache for term taxonomies formerly shared with the current term.
[4313] Fix | Delete
$shared_term_taxonomies = $wpdb->get_col( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
[4314] Fix | Delete
$taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies );
[4315] Fix | Delete
[4316] Fix | Delete
foreach ( $taxonomies_to_clean as $taxonomy_to_clean ) {
[4317] Fix | Delete
clean_taxonomy_cache( $taxonomy_to_clean );
[4318] Fix | Delete
}
[4319] Fix | Delete
[4320] Fix | Delete
// Keep a record of term_ids that have been split, keyed by old term_id. See wp_get_split_term().
[4321] Fix | Delete
if ( $record ) {
[4322] Fix | Delete
$split_term_data = get_option( '_split_terms', array() );
[4323] Fix | Delete
if ( ! isset( $split_term_data[ $term_id ] ) ) {
[4324] Fix | Delete
$split_term_data[ $term_id ] = array();
[4325] Fix | Delete
}
[4326] Fix | Delete
[4327] Fix | Delete
$split_term_data[ $term_id ][ $term_taxonomy->taxonomy ] = $new_term_id;
[4328] Fix | Delete
update_option( '_split_terms', $split_term_data );
[4329] Fix | Delete
}
[4330] Fix | Delete
[4331] Fix | Delete
// If we've just split the final shared term, set the "finished" flag.
[4332] Fix | Delete
$shared_terms_exist = $wpdb->get_results(
[4333] Fix | Delete
"SELECT tt.term_id, t.*, count(*) as term_tt_count FROM {$wpdb->term_taxonomy} tt
[4334] Fix | Delete
LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
[4335] Fix | Delete
GROUP BY t.term_id
[4336] Fix | Delete
HAVING term_tt_count > 1
[4337] Fix | Delete
LIMIT 1"
[4338] Fix | Delete
);
[4339] Fix | Delete
if ( ! $shared_terms_exist ) {
[4340] Fix | Delete
update_option( 'finished_splitting_shared_terms', true );
[4341] Fix | Delete
}
[4342] Fix | Delete
[4343] Fix | Delete
/**
[4344] Fix | Delete
* Fires after a previously shared taxonomy term is split into two separate terms.
[4345] Fix | Delete
*
[4346] Fix | Delete
* @since 4.2.0
[4347] Fix | Delete
*
[4348] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4349] Fix | Delete
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
[4350] Fix | Delete
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
[4351] Fix | Delete
* @param string $taxonomy Taxonomy for the split term.
[4352] Fix | Delete
*/
[4353] Fix | Delete
do_action( 'split_shared_term', $term_id, $new_term_id, $term_taxonomy_id, $term_taxonomy->taxonomy );
[4354] Fix | Delete
[4355] Fix | Delete
return $new_term_id;
[4356] Fix | Delete
}
[4357] Fix | Delete
[4358] Fix | Delete
/**
[4359] Fix | Delete
* Splits a batch of shared taxonomy terms.
[4360] Fix | Delete
*
[4361] Fix | Delete
* @since 4.3.0
[4362] Fix | Delete
*
[4363] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4364] Fix | Delete
*/
[4365] Fix | Delete
function _wp_batch_split_terms() {
[4366] Fix | Delete
global $wpdb;
[4367] Fix | Delete
[4368] Fix | Delete
$lock_name = 'term_split.lock';
[4369] Fix | Delete
[4370] Fix | Delete
// Try to lock.
[4371] Fix | Delete
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'off') /* LOCK */", $lock_name, time() ) );
[4372] Fix | Delete
[4373] Fix | Delete
if ( ! $lock_result ) {
[4374] Fix | Delete
$lock_result = get_option( $lock_name );
[4375] Fix | Delete
[4376] Fix | Delete
// Bail if we were unable to create a lock, or if the existing lock is still valid.
[4377] Fix | Delete
if ( ! $lock_result || ( $lock_result > ( time() - HOUR_IN_SECONDS ) ) ) {
[4378] Fix | Delete
wp_schedule_single_event( time() + ( 5 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
[4379] Fix | Delete
return;
[4380] Fix | Delete
}
[4381] Fix | Delete
}
[4382] Fix | Delete
[4383] Fix | Delete
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
[4384] Fix | Delete
update_option( $lock_name, time() );
[4385] Fix | Delete
[4386] Fix | Delete
// Get a list of shared terms (those with more than one associated row in term_taxonomy).
[4387] Fix | Delete
$shared_terms = $wpdb->get_results(
[4388] Fix | Delete
"SELECT tt.term_id, t.*, count(*) as term_tt_count FROM {$wpdb->term_taxonomy} tt
[4389] Fix | Delete
LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
[4390] Fix | Delete
GROUP BY t.term_id
[4391] Fix | Delete
HAVING term_tt_count > 1
[4392] Fix | Delete
LIMIT 10"
[4393] Fix | Delete
);
[4394] Fix | Delete
[4395] Fix | Delete
// No more terms, we're done here.
[4396] Fix | Delete
if ( ! $shared_terms ) {
[4397] Fix | Delete
update_option( 'finished_splitting_shared_terms', true );
[4398] Fix | Delete
delete_option( $lock_name );
[4399] Fix | Delete
return;
[4400] Fix | Delete
}
[4401] Fix | Delete
[4402] Fix | Delete
// Shared terms found? We'll need to run this script again.
[4403] Fix | Delete
wp_schedule_single_event( time() + ( 2 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
[4404] Fix | Delete
[4405] Fix | Delete
// Rekey shared term array for faster lookups.
[4406] Fix | Delete
$_shared_terms = array();
[4407] Fix | Delete
foreach ( $shared_terms as $shared_term ) {
[4408] Fix | Delete
$term_id = (int) $shared_term->term_id;
[4409] Fix | Delete
$_shared_terms[ $term_id ] = $shared_term;
[4410] Fix | Delete
}
[4411] Fix | Delete
$shared_terms = $_shared_terms;
[4412] Fix | Delete
[4413] Fix | Delete
// Get term taxonomy data for all shared terms.
[4414] Fix | Delete
$shared_term_ids = implode( ',', array_keys( $shared_terms ) );
[4415] Fix | Delete
$shared_tts = $wpdb->get_results( "SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})" );
[4416] Fix | Delete
[4417] Fix | Delete
// Split term data recording is slow, so we do it just once, outside the loop.
[4418] Fix | Delete
$split_term_data = get_option( '_split_terms', array() );
[4419] Fix | Delete
$skipped_first_term = array();
[4420] Fix | Delete
$taxonomies = array();
[4421] Fix | Delete
foreach ( $shared_tts as $shared_tt ) {
[4422] Fix | Delete
$term_id = (int) $shared_tt->term_id;
[4423] Fix | Delete
[4424] Fix | Delete
// Don't split the first tt belonging to a given term_id.
[4425] Fix | Delete
if ( ! isset( $skipped_first_term[ $term_id ] ) ) {
[4426] Fix | Delete
$skipped_first_term[ $term_id ] = 1;
[4427] Fix | Delete
continue;
[4428] Fix | Delete
}
[4429] Fix | Delete
[4430] Fix | Delete
if ( ! isset( $split_term_data[ $term_id ] ) ) {
[4431] Fix | Delete
$split_term_data[ $term_id ] = array();
[4432] Fix | Delete
}
[4433] Fix | Delete
[4434] Fix | Delete
// Keep track of taxonomies whose hierarchies need flushing.
[4435] Fix | Delete
if ( ! isset( $taxonomies[ $shared_tt->taxonomy ] ) ) {
[4436] Fix | Delete
$taxonomies[ $shared_tt->taxonomy ] = 1;
[4437] Fix | Delete
}
[4438] Fix | Delete
[4439] Fix | Delete
// Split the term.
[4440] Fix | Delete
$split_term_data[ $term_id ][ $shared_tt->taxonomy ] = _split_shared_term( $shared_terms[ $term_id ], $shared_tt, false );
[4441] Fix | Delete
}
[4442] Fix | Delete
[4443] Fix | Delete
// Rebuild the cached hierarchy for each affected taxonomy.
[4444] Fix | Delete
foreach ( array_keys( $taxonomies ) as $tax ) {
[4445] Fix | Delete
delete_option( "{$tax}_children" );
[4446] Fix | Delete
_get_term_hierarchy( $tax );
[4447] Fix | Delete
}
[4448] Fix | Delete
[4449] Fix | Delete
update_option( '_split_terms', $split_term_data );
[4450] Fix | Delete
[4451] Fix | Delete
delete_option( $lock_name );
[4452] Fix | Delete
}
[4453] Fix | Delete
[4454] Fix | Delete
/**
[4455] Fix | Delete
* In order to avoid the _wp_batch_split_terms() job being accidentally removed,
[4456] Fix | Delete
* checks that it's still scheduled while we haven't finished splitting terms.
[4457] Fix | Delete
*
[4458] Fix | Delete
* @ignore
[4459] Fix | Delete
* @since 4.3.0
[4460] Fix | Delete
*/
[4461] Fix | Delete
function _wp_check_for_scheduled_split_terms() {
[4462] Fix | Delete
if ( ! get_option( 'finished_splitting_shared_terms' ) && ! wp_next_scheduled( 'wp_split_shared_term_batch' ) ) {
[4463] Fix | Delete
wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_split_shared_term_batch' );
[4464] Fix | Delete
}
[4465] Fix | Delete
}
[4466] Fix | Delete
[4467] Fix | Delete
/**
[4468] Fix | Delete
* Checks default categories when a term gets split to see if any of them need to be updated.
[4469] Fix | Delete
*
[4470] Fix | Delete
* @ignore
[4471] Fix | Delete
* @since 4.2.0
[4472] Fix | Delete
*
[4473] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4474] Fix | Delete
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
[4475] Fix | Delete
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
[4476] Fix | Delete
* @param string $taxonomy Taxonomy for the split term.
[4477] Fix | Delete
*/
[4478] Fix | Delete
function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
[4479] Fix | Delete
if ( 'category' !== $taxonomy ) {
[4480] Fix | Delete
return;
[4481] Fix | Delete
}
[4482] Fix | Delete
[4483] Fix | Delete
foreach ( array( 'default_category', 'default_link_category', 'default_email_category' ) as $option ) {
[4484] Fix | Delete
if ( (int) get_option( $option, -1 ) === $term_id ) {
[4485] Fix | Delete
update_option( $option, $new_term_id );
[4486] Fix | Delete
}
[4487] Fix | Delete
}
[4488] Fix | Delete
}
[4489] Fix | Delete
[4490] Fix | Delete
/**
[4491] Fix | Delete
* Checks menu items when a term gets split to see if any of them need to be updated.
[4492] Fix | Delete
*
[4493] Fix | Delete
* @ignore
[4494] Fix | Delete
* @since 4.2.0
[4495] Fix | Delete
*
[4496] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[4497] Fix | Delete
*
[4498] Fix | Delete
* @param int $term_id ID of the formerly shared term.
[4499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function