Make WordPress Core


Ignore:
Timestamp:
09/20/2022 02:49:25 AM (4 years ago)
Author:
desrosj
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-functions.php

    r54080 r54240  
    20512051
    20522052/**
    2053  * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
    2054  *
    2055  * @since 3.0.0
    2056  *
    2057  * @see term_id_filter
    2058  *
    2059  * @global wpdb $wpdb WordPress database abstraction object.
    2060  *
    2061  * @param int    $term_id    An ID for a term on the current blog.
    2062  * @param string $deprecated Not used.
    2063  * @return int An ID from the global terms table mapped from $term_id.
    2064  */
    2065 function global_terms( $term_id, $deprecated = '' ) {
    2066         global $wpdb;
    2067         static $global_terms_recurse = null;
    2068 
    2069         if ( ! global_terms_enabled() ) {
    2070                 return $term_id;
    2071         }
    2072 
    2073         // Prevent a race condition.
    2074         $recurse_start = false;
    2075         if ( null === $global_terms_recurse ) {
    2076                 $recurse_start        = true;
    2077                 $global_terms_recurse = 1;
    2078         } elseif ( 10 < $global_terms_recurse++ ) {
    2079                 return $term_id;
    2080         }
    2081 
    2082         $term_id = (int) $term_id;
    2083         $c       = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) );
    2084 
    2085         $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) );
    2086         if ( null == $global_id ) {
    2087                 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) );
    2088                 if ( null == $used_global_id ) {
    2089                         $wpdb->insert(
    2090                                 $wpdb->sitecategories,
    2091                                 array(
    2092                                         'cat_ID'            => $term_id,
    2093                                         'cat_name'          => $c->name,
    2094                                         'category_nicename' => $c->slug,
    2095                                 )
    2096                         );
    2097                         $global_id = $wpdb->insert_id;
    2098                         if ( empty( $global_id ) ) {
    2099                                 return $term_id;
    2100                         }
    2101                 } else {
    2102                         $max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" );
    2103                         $max_local_id  = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" );
    2104                         $new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 );
    2105                         $wpdb->insert(
    2106                                 $wpdb->sitecategories,
    2107                                 array(
    2108                                         'cat_ID'            => $new_global_id,
    2109                                         'cat_name'          => $c->name,
    2110                                         'category_nicename' => $c->slug,
    2111                                 )
    2112                         );
    2113                         $global_id = $wpdb->insert_id;
    2114                 }
    2115         } elseif ( $global_id != $term_id ) {
    2116                 $local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) );
    2117                 if ( null != $local_id ) {
    2118                         global_terms( $local_id );
    2119                         if ( 10 < $global_terms_recurse ) {
    2120                                 $global_id = $term_id;
    2121                         }
    2122                 }
    2123         }
    2124 
    2125         if ( $global_id != $term_id ) {
    2126                 if ( get_option( 'default_category' ) == $term_id ) {
    2127                         update_option( 'default_category', $global_id );
    2128                 }
    2129 
    2130                 $wpdb->update( $wpdb->terms, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) );
    2131                 $wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) );
    2132                 $wpdb->update( $wpdb->term_taxonomy, array( 'parent' => $global_id ), array( 'parent' => $term_id ) );
    2133 
    2134                 clean_term_cache( $term_id );
    2135         }
    2136         if ( $recurse_start ) {
    2137                 $global_terms_recurse = null;
    2138         }
    2139 
    2140         return $global_id;
    2141 }
    2142 
    2143 /**
    21442053 * Ensures that the current site's domain is listed in the allowed redirect host list.
    21452054 *
Note: See TracChangeset for help on using the changeset viewer.