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.
Built from https://develop.svn.wordpress.org/trunk@54240


git-svn-id: http://core.svn.wordpress.org/trunk@53799 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2022-09-20 02:51:09 +00:00
parent 0cac41db2e
commit 7d87ce12c8
15 changed files with 83 additions and 215 deletions

View File

@ -148,7 +148,6 @@ if ( isset( $tag->name ) ) {
<td><input name="name" id="name" type="text" value="<?php echo $tag_name_value; ?>" size="40" aria-required="true" aria-describedby="name-description" />
<p class="description" id="name-description"><?php echo $tax->labels->name_field_description; ?></p></td>
</tr>
<?php if ( ! global_terms_enabled() ) { ?>
<tr class="form-field term-slug-wrap">
<th scope="row"><label for="slug"><?php _e( 'Slug' ); ?></label></th>
<?php
@ -170,7 +169,6 @@ if ( isset( $tag->name ) ) {
<td><input name="slug" id="slug" type="text" value="<?php echo esc_attr( $slug ); ?>" size="40" aria-describedby="slug-description" />
<p class="description" id="slug-description"><?php echo $tax->labels->slug_field_description; ?></p></td>
</tr>
<?php } ?>
<?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?>
<tr class="form-field term-parent-wrap">
<th scope="row"><label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label></th>

View File

@ -280,9 +280,7 @@ if ( 'category' === $taxonomy || 'link_category' === $taxonomy || 'post_tag' ===
$help .= '<ul>' .
'<li>' . __( '<strong>Name</strong> &mdash; The name is how it appears on your site.' ) . '</li>';
if ( ! global_terms_enabled() ) {
$help .= '<li>' . __( '<strong>Slug</strong> &mdash; The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' ) . '</li>';
}
$help .= '<li>' . __( '<strong>Slug</strong> &mdash; The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' ) . '</li>';
if ( 'category' === $taxonomy ) {
$help .= '<li>' . __( '<strong>Parent</strong> &mdash; Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have child categories for Bebop and Big Band. Totally optional. To create a subcategory, just choose another category from the Parent dropdown.' ) . '</li>';
@ -456,13 +454,11 @@ if ( $can_edit_terms ) {
<input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" aria-describedby="name-description" />
<p id="name-description"><?php echo $tax->labels->name_field_description; ?></p>
</div>
<?php if ( ! global_terms_enabled() ) : ?>
<div class="form-field term-slug-wrap">
<label for="tag-slug"><?php _e( 'Slug' ); ?></label>
<input name="slug" id="tag-slug" type="text" value="" size="40" aria-describedby="slug-description" />
<p id="slug-description"><?php echo $tax->labels->slug_field_description; ?></p>
</div>
<?php endif; // global_terms_enabled() ?>
<?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?>
<div class="form-field term-parent-wrap">
<label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label>

View File

@ -665,12 +665,10 @@ class WP_Terms_List_Table extends WP_List_Table {
<span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
</label>
<?php if ( ! global_terms_enabled() ) : ?>
<label>
<span class="title"><?php _e( 'Slug' ); ?></span>
<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
</label>
<?php endif; ?>
<label>
<span class="title"><?php _e( 'Slug' ); ?></span>
<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
</label>
</div>
</fieldset>

View File

@ -22,9 +22,6 @@ add_action( 'wpmueditblogaction', 'upload_space_setting' );
// Network hooks.
add_action( 'update_site_option_admin_email', 'wp_network_admin_email_change_notification', 10, 4 );
// Taxonomy hooks.
add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
// Post hooks.
add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );

View File

@ -108,3 +108,33 @@ function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
* @deprecated 3.5.0
*/
function ms_deprecated_blogs_file() {}
if ( ! function_exists( 'install_global_terms' ) ) :
/**
* Install global terms.
*
* @since 3.0.0
* @since 6.1.0 This function no longer does anything.
* @deprecated 6.1.0
*/
function install_global_terms() {
_deprecated_function( __FUNCTION__, '6.1.0' );
}
endif;
/**
* Synchronizes category and post tag slugs when global terms are enabled.
*
* @since 3.0.0
* @since 6.1.0 This function no longer does anything.
* @deprecated 6.1.0
*
* @param WP_Term|array $term The term.
* @param string $taxonomy The taxonomy for `$term`.
* @return WP_Term|array Always returns `$term`.
*/
function sync_category_tag_slugs( $term, $taxonomy ) {
_deprecated_function( __FUNCTION__, '6.1.0' );
return $term;
}

View File

@ -543,29 +543,6 @@ function format_code_lang( $code = '' ) {
return strtr( $code, $lang_codes );
}
/**
* Synchronizes category and post tag slugs when global terms are enabled.
*
* @since 3.0.0
*
* @param WP_Term|array $term The term.
* @param string $taxonomy The taxonomy for `$term`. Should be 'category' or 'post_tag', as these are
* the only taxonomies which are processed by this function; anything else
* will be returned untouched.
* @return WP_Term|array Returns `$term`, after filtering the 'slug' field with `sanitize_title()`
* if `$taxonomy` is 'category' or 'post_tag'.
*/
function sync_category_tag_slugs( $term, $taxonomy ) {
if ( global_terms_enabled() && ( 'category' === $taxonomy || 'post_tag' === $taxonomy ) ) {
if ( is_object( $term ) ) {
$term->slug = sanitize_title( $term->name );
} else {
$term['slug'] = sanitize_title( $term['name'] );
}
}
return $term;
}
/**
* Displays an access denied message when a user tries to view a site's dashboard they
* do not have access to.

View File

@ -1270,7 +1270,6 @@ We hope you enjoy your new site. Thanks!
'add_new_users' => '0',
'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
'subdomain_install' => $subdomain_install,
'global_terms_enabled' => global_terms_enabled() ? '1' : '0',
'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
'user_count' => get_site_option( 'user_count' ),
'initial_db_version' => get_option( 'initial_db_version' ),

View File

@ -159,24 +159,7 @@ if ( ! function_exists( 'wp_install_defaults' ) ) :
/* translators: Default category slug. */
$cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
if ( global_terms_enabled() ) {
$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
if ( null == $cat_id ) {
$wpdb->insert(
$wpdb->sitecategories,
array(
'cat_ID' => 0,
'cat_name' => $cat_name,
'category_nicename' => $cat_slug,
'last_updated' => current_time( 'mysql', true ),
)
);
$cat_id = $wpdb->insert_id;
}
update_option( 'default_category', $cat_id );
} else {
$cat_id = 1;
}
$cat_id = 1;
$wpdb->insert(
$wpdb->terms,
@ -3537,33 +3520,6 @@ function pre_schema_upgrade() {
}
}
if ( ! function_exists( 'install_global_terms' ) ) :
/**
* Install global terms.
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global string $charset_collate
*/
function install_global_terms() {
global $wpdb, $charset_collate;
$ms_queries = "
CREATE TABLE $wpdb->sitecategories (
cat_ID bigint(20) NOT NULL auto_increment,
cat_name varchar(55) NOT NULL default '',
category_nicename varchar(200) NOT NULL default '',
last_updated timestamp NOT NULL,
PRIMARY KEY (cat_ID),
KEY category_nicename (category_nicename),
KEY last_updated (last_updated)
) $charset_collate;
";
// Now create tables.
dbDelta( $ms_queries );
}
endif;
/**
* Determine if global tables should be upgraded.
*

View File

@ -100,7 +100,6 @@ if ( $_POST ) {
'welcome_email',
'welcome_user_email',
'fileupload_maxk',
'global_terms_enabled',
'illegal_names',
'limited_email_domains',
'banned_email_domains',

View File

@ -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();

View File

@ -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.
*

View File

@ -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 );

View File

@ -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;
}

View File

@ -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.
*

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-54239';
$wp_version = '6.1-alpha-54240';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.