mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-24 21:24:34 +00:00
Networks and Sites: Officially remove global terms.
Global terms was a feature from the WordPress MU days where multisite and single site installs used different code bases. In WordPress 3.0, WordPress MU was merged into one location and the UI [14854] and “on” switch [14880] for global terms were completely removed. Even before this merge, global terms was bug infested and unreliable. After [14854]/[14880], the feature was no longer maintained and became increasingly broken as taxonomies progressed without it (term splitting and term meta do not work at all). At this point, the feature has not worked in 12+ years and there’s no hope for saving it. This deprecates the remaining global terms related code and no-ops the functions. Global terms, you don’t have to go home, but you can’t stay here. Props scribu, wonderboymusic, SergeyBiryukov, nacin, pento, desrosj, johnjamesjacoby, johnbillion, dd32. Fixes #21734. git-svn-id: https://develop.svn.wordpress.org/trunk@54240 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -340,10 +340,19 @@ class wpdb {
|
||||
'signups',
|
||||
'site',
|
||||
'sitemeta',
|
||||
'sitecategories',
|
||||
'registration_log',
|
||||
);
|
||||
|
||||
/**
|
||||
* List of deprecated WordPress Multisite global tables.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @see wpdb::tables()
|
||||
* @var string[]
|
||||
*/
|
||||
public $old_ms_global_tables = array( 'sitecategories' );
|
||||
|
||||
/**
|
||||
* WordPress Comments table.
|
||||
*
|
||||
@@ -1123,11 +1132,13 @@ class wpdb {
|
||||
* - 'old' - returns tables which are deprecated.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 6.1.0 `old` now includes deprecated multisite global tables only on multisite.
|
||||
*
|
||||
* @uses wpdb::$tables
|
||||
* @uses wpdb::$old_tables
|
||||
* @uses wpdb::$global_tables
|
||||
* @uses wpdb::$ms_global_tables
|
||||
* @uses wpdb::$old_ms_global_tables
|
||||
*
|
||||
* @param string $scope Optional. Possible values include 'all', 'global', 'ms_global', 'blog',
|
||||
* or 'old' tables. Default 'all'.
|
||||
@@ -1159,6 +1170,9 @@ class wpdb {
|
||||
break;
|
||||
case 'old':
|
||||
$tables = $this->old_tables;
|
||||
if ( is_multisite() ) {
|
||||
$tables = array_merge( $tables, $this->old_ms_global_tables );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return array();
|
||||
|
||||
@@ -6219,41 +6219,6 @@ function get_main_network_id() {
|
||||
return (int) apply_filters( 'get_main_network_id', $main_network_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether global terms are enabled.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return bool True if multisite and global terms enabled.
|
||||
*/
|
||||
function global_terms_enabled() {
|
||||
if ( ! is_multisite() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static $global_terms = null;
|
||||
if ( is_null( $global_terms ) ) {
|
||||
|
||||
/**
|
||||
* Filters whether global terms are enabled.
|
||||
*
|
||||
* Returning a non-null value from the filter will effectively short-circuit the function
|
||||
* and return the value of the 'global_terms_enabled' site option instead.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param null $enabled Whether global terms are enabled.
|
||||
*/
|
||||
$filter = apply_filters( 'global_terms_enabled', null );
|
||||
if ( ! is_null( $filter ) ) {
|
||||
$global_terms = (bool) $filter;
|
||||
} else {
|
||||
$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
|
||||
}
|
||||
}
|
||||
return $global_terms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether site meta is enabled.
|
||||
*
|
||||
|
||||
@@ -75,7 +75,6 @@ add_action( 'template_redirect', 'maybe_redirect_404' );
|
||||
add_filter( 'allowed_redirect_hosts', 'redirect_this_site' );
|
||||
|
||||
// Administration.
|
||||
add_filter( 'term_id_filter', 'global_terms', 10, 2 );
|
||||
add_action( 'after_delete_post', '_update_posts_count_on_delete' );
|
||||
add_action( 'delete_post', '_update_blog_date_on_post_delete' );
|
||||
add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3 );
|
||||
|
||||
@@ -730,3 +730,34 @@ function update_user_status( $id, $pref, $value, $deprecated = null ) {
|
||||
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* Determines whether global terms are enabled.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 6.1.0 This function now always returns false.
|
||||
* @deprecated 6.1.0
|
||||
*
|
||||
* @return bool Always returns false.
|
||||
*/
|
||||
function global_terms_enabled() {
|
||||
_deprecated_function( __FUNCTION__, '6.1.0' );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 6.1.0 This function no longer does anything.
|
||||
* @deprecated 6.1.0
|
||||
*
|
||||
* @param int $term_id An ID for a term on the current blog.
|
||||
* @param string $deprecated Not used.
|
||||
* @return int An ID from the global terms table mapped from $term_id.
|
||||
*/
|
||||
function global_terms( $term_id, $deprecated = '' ) {
|
||||
_deprecated_function( __FUNCTION__, '6.1.0' );
|
||||
|
||||
return $term_id;
|
||||
}
|
||||
|
||||
@@ -2049,97 +2049,6 @@ function wpmu_log_new_registrations( $blog_id, $user_id ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @see term_id_filter
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @param int $term_id An ID for a term on the current blog.
|
||||
* @param string $deprecated Not used.
|
||||
* @return int An ID from the global terms table mapped from $term_id.
|
||||
*/
|
||||
function global_terms( $term_id, $deprecated = '' ) {
|
||||
global $wpdb;
|
||||
static $global_terms_recurse = null;
|
||||
|
||||
if ( ! global_terms_enabled() ) {
|
||||
return $term_id;
|
||||
}
|
||||
|
||||
// Prevent a race condition.
|
||||
$recurse_start = false;
|
||||
if ( null === $global_terms_recurse ) {
|
||||
$recurse_start = true;
|
||||
$global_terms_recurse = 1;
|
||||
} elseif ( 10 < $global_terms_recurse++ ) {
|
||||
return $term_id;
|
||||
}
|
||||
|
||||
$term_id = (int) $term_id;
|
||||
$c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) );
|
||||
|
||||
$global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) );
|
||||
if ( null == $global_id ) {
|
||||
$used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) );
|
||||
if ( null == $used_global_id ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->sitecategories,
|
||||
array(
|
||||
'cat_ID' => $term_id,
|
||||
'cat_name' => $c->name,
|
||||
'category_nicename' => $c->slug,
|
||||
)
|
||||
);
|
||||
$global_id = $wpdb->insert_id;
|
||||
if ( empty( $global_id ) ) {
|
||||
return $term_id;
|
||||
}
|
||||
} else {
|
||||
$max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" );
|
||||
$max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" );
|
||||
$new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 );
|
||||
$wpdb->insert(
|
||||
$wpdb->sitecategories,
|
||||
array(
|
||||
'cat_ID' => $new_global_id,
|
||||
'cat_name' => $c->name,
|
||||
'category_nicename' => $c->slug,
|
||||
)
|
||||
);
|
||||
$global_id = $wpdb->insert_id;
|
||||
}
|
||||
} elseif ( $global_id != $term_id ) {
|
||||
$local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) );
|
||||
if ( null != $local_id ) {
|
||||
global_terms( $local_id );
|
||||
if ( 10 < $global_terms_recurse ) {
|
||||
$global_id = $term_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $global_id != $term_id ) {
|
||||
if ( get_option( 'default_category' ) == $term_id ) {
|
||||
update_option( 'default_category', $global_id );
|
||||
}
|
||||
|
||||
$wpdb->update( $wpdb->terms, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) );
|
||||
$wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) );
|
||||
$wpdb->update( $wpdb->term_taxonomy, array( 'parent' => $global_id ), array( 'parent' => $term_id ) );
|
||||
|
||||
clean_term_cache( $term_id );
|
||||
}
|
||||
if ( $recurse_start ) {
|
||||
$global_terms_recurse = null;
|
||||
}
|
||||
|
||||
return $global_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the current site's domain is listed in the allowed redirect host list.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user