Make WordPress Core

Changeset 54240


Ignore:
Timestamp:
09/20/2022 02:49:25 AM (2 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.

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-tag-form.php

    r53913 r54240  
    149149            <p class="description" id="name-description"><?php echo $tax->labels->name_field_description; ?></p></td>
    150150        </tr>
    151 <?php if ( ! global_terms_enabled() ) { ?>
    152151        <tr class="form-field term-slug-wrap">
    153152            <th scope="row"><label for="slug"><?php _e( 'Slug' ); ?></label></th>
     
    171170            <p class="description" id="slug-description"><?php echo $tax->labels->slug_field_description; ?></p></td>
    172171        </tr>
    173 <?php } ?>
    174172<?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?>
    175173        <tr class="form-field term-parent-wrap">
  • trunk/src/wp-admin/edit-tags.php

    r53913 r54240  
    281281        '<li>' . __( '<strong>Name</strong> &mdash; The name is how it appears on your site.' ) . '</li>';
    282282
    283         if ( ! global_terms_enabled() ) {
    284             $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>';
    285         }
     283        $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>';
    286284
    287285        if ( 'category' === $taxonomy ) {
     
    457455    <p id="name-description"><?php echo $tax->labels->name_field_description; ?></p>
    458456</div>
    459     <?php if ( ! global_terms_enabled() ) : ?>
    460457<div class="form-field term-slug-wrap">
    461458    <label for="tag-slug"><?php _e( 'Slug' ); ?></label>
     
    463460    <p id="slug-description"><?php echo $tax->labels->slug_field_description; ?></p>
    464461</div>
    465 <?php endif; // global_terms_enabled() ?>
    466462    <?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?>
    467463<div class="form-field term-parent-wrap">
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r54071 r54240  
    666666                </label>
    667667
    668                 <?php if ( ! global_terms_enabled() ) : ?>
    669                     <label>
    670                         <span class="title"><?php _e( 'Slug' ); ?></span>
    671                         <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
    672                     </label>
    673                 <?php endif; ?>
     668                <label>
     669                    <span class="title"><?php _e( 'Slug' ); ?></span>
     670                    <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
     671                </label>
    674672                </div>
    675673            </fieldset>
  • trunk/src/wp-admin/includes/ms-admin-filters.php

    r47119 r54240  
    2323add_action( 'update_site_option_admin_email', 'wp_network_admin_email_change_notification', 10, 4 );
    2424
    25 // Taxonomy hooks.
    26 add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
    27 
    2825// Post hooks.
    2926add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
  • trunk/src/wp-admin/includes/ms-deprecated.php

    r45932 r54240  
    109109 */
    110110function ms_deprecated_blogs_file() {}
     111
     112if ( ! function_exists( 'install_global_terms' ) ) :
     113    /**
     114     * Install global terms.
     115     *
     116     * @since 3.0.0
     117     * @since 6.1.0 This function no longer does anything.
     118     * @deprecated 6.1.0
     119     */
     120    function install_global_terms() {
     121        _deprecated_function( __FUNCTION__, '6.1.0' );
     122    }
     123endif;
     124
     125/**
     126 * Synchronizes category and post tag slugs when global terms are enabled.
     127 *
     128 * @since 3.0.0
     129 * @since 6.1.0 This function no longer does anything.
     130 * @deprecated 6.1.0
     131 *
     132 * @param WP_Term|array $term     The term.
     133 * @param string        $taxonomy The taxonomy for `$term`.
     134 * @return WP_Term|array Always returns `$term`.
     135 */
     136function sync_category_tag_slugs( $term, $taxonomy ) {
     137    _deprecated_function( __FUNCTION__, '6.1.0' );
     138
     139    return $term;
     140}
  • trunk/src/wp-admin/includes/ms.php

    r53203 r54240  
    545545
    546546/**
    547  * Synchronizes category and post tag slugs when global terms are enabled.
    548  *
    549  * @since 3.0.0
    550  *
    551  * @param WP_Term|array $term     The term.
    552  * @param string        $taxonomy The taxonomy for `$term`. Should be 'category' or 'post_tag', as these are
    553  *                                the only taxonomies which are processed by this function; anything else
    554  *                                will be returned untouched.
    555  * @return WP_Term|array Returns `$term`, after filtering the 'slug' field with `sanitize_title()`
    556  *                       if `$taxonomy` is 'category' or 'post_tag'.
    557  */
    558 function sync_category_tag_slugs( $term, $taxonomy ) {
    559     if ( global_terms_enabled() && ( 'category' === $taxonomy || 'post_tag' === $taxonomy ) ) {
    560         if ( is_object( $term ) ) {
    561             $term->slug = sanitize_title( $term->name );
    562         } else {
    563             $term['slug'] = sanitize_title( $term['name'] );
    564         }
    565     }
    566     return $term;
    567 }
    568 
    569 /**
    570547 * Displays an access denied message when a user tries to view a site's dashboard they
    571548 * do not have access to.
  • trunk/src/wp-admin/includes/schema.php

    r54232 r54240  
    12711271        'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
    12721272        'subdomain_install'           => $subdomain_install,
    1273         'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',
    12741273        'ms_files_rewriting'          => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
    12751274        'user_count'                  => get_site_option( 'user_count' ),
  • trunk/src/wp-admin/includes/upgrade.php

    r53897 r54240  
    160160        $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
    161161
    162         if ( global_terms_enabled() ) {
    163             $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
    164             if ( null == $cat_id ) {
    165                 $wpdb->insert(
    166                     $wpdb->sitecategories,
    167                     array(
    168                         'cat_ID'            => 0,
    169                         'cat_name'          => $cat_name,
    170                         'category_nicename' => $cat_slug,
    171                         'last_updated'      => current_time( 'mysql', true ),
    172                     )
    173                 );
    174                 $cat_id = $wpdb->insert_id;
    175             }
    176             update_option( 'default_category', $cat_id );
    177         } else {
    178             $cat_id = 1;
    179         }
     162        $cat_id = 1;
    180163
    181164        $wpdb->insert(
     
    35383521}
    35393522
    3540 if ( ! function_exists( 'install_global_terms' ) ) :
    3541     /**
    3542      * Install global terms.
    3543      *
    3544      * @since 3.0.0
    3545      *
    3546      * @global wpdb   $wpdb            WordPress database abstraction object.
    3547      * @global string $charset_collate
    3548      */
    3549     function install_global_terms() {
    3550         global $wpdb, $charset_collate;
    3551         $ms_queries = "
    3552 CREATE TABLE $wpdb->sitecategories (
    3553   cat_ID bigint(20) NOT NULL auto_increment,
    3554   cat_name varchar(55) NOT NULL default '',
    3555   category_nicename varchar(200) NOT NULL default '',
    3556   last_updated timestamp NOT NULL,
    3557   PRIMARY KEY  (cat_ID),
    3558   KEY category_nicename (category_nicename),
    3559   KEY last_updated (last_updated)
    3560 ) $charset_collate;
    3561 ";
    3562         // Now create tables.
    3563         dbDelta( $ms_queries );
    3564     }
    3565 endif;
    3566 
    35673523/**
    35683524 * Determine if global tables should be upgraded.
  • trunk/src/wp-admin/network/settings.php

    r53131 r54240  
    101101        'welcome_user_email',
    102102        'fileupload_maxk',
    103         'global_terms_enabled',
    104103        'illegal_names',
    105104        'limited_email_domains',
  • trunk/src/wp-includes/class-wpdb.php

    r54133 r54240  
    341341        'site',
    342342        'sitemeta',
    343         'sitecategories',
    344343        'registration_log',
    345344    );
     345
     346    /**
     347     * List of deprecated WordPress Multisite global tables.
     348     *
     349     * @since 6.1.0
     350     *
     351     * @see wpdb::tables()
     352     * @var string[]
     353     */
     354    public $old_ms_global_tables = array( 'sitecategories' );
    346355
    347356    /**
     
    11241133     *
    11251134     * @since 3.0.0
     1135     * @since 6.1.0 `old` now includes deprecated multisite global tables only on multisite.
    11261136     *
    11271137     * @uses wpdb::$tables
     
    11291139     * @uses wpdb::$global_tables
    11301140     * @uses wpdb::$ms_global_tables
     1141     * @uses wpdb::$old_ms_global_tables
    11311142     *
    11321143     * @param string $scope   Optional. Possible values include 'all', 'global', 'ms_global', 'blog',
     
    11601171            case 'old':
    11611172                $tables = $this->old_tables;
     1173                if ( is_multisite() ) {
     1174                    $tables = array_merge( $tables, $this->old_ms_global_tables );
     1175                }
    11621176                break;
    11631177            default:
  • trunk/src/wp-includes/functions.php

    r54233 r54240  
    62216221
    62226222/**
    6223  * Determines whether global terms are enabled.
    6224  *
    6225  * @since 3.0.0
    6226  *
    6227  * @return bool True if multisite and global terms enabled.
    6228  */
    6229 function global_terms_enabled() {
    6230     if ( ! is_multisite() ) {
    6231         return false;
    6232     }
    6233 
    6234     static $global_terms = null;
    6235     if ( is_null( $global_terms ) ) {
    6236 
    6237         /**
    6238          * Filters whether global terms are enabled.
    6239          *
    6240          * Returning a non-null value from the filter will effectively short-circuit the function
    6241          * and return the value of the 'global_terms_enabled' site option instead.
    6242          *
    6243          * @since 3.0.0
    6244          *
    6245          * @param null $enabled Whether global terms are enabled.
    6246          */
    6247         $filter = apply_filters( 'global_terms_enabled', null );
    6248         if ( ! is_null( $filter ) ) {
    6249             $global_terms = (bool) $filter;
    6250         } else {
    6251             $global_terms = (bool) get_site_option( 'global_terms_enabled', false );
    6252         }
    6253     }
    6254     return $global_terms;
    6255 }
    6256 
    6257 /**
    62586223 * Determines whether site meta is enabled.
    62596224 *
  • trunk/src/wp-includes/ms-default-filters.php

    r53011 r54240  
    7676
    7777// Administration.
    78 add_filter( 'term_id_filter', 'global_terms', 10, 2 );
    7978add_action( 'after_delete_post', '_update_posts_count_on_delete' );
    8079add_action( 'delete_post', '_update_blog_date_on_post_delete' );
  • trunk/src/wp-includes/ms-deprecated.php

    r53458 r54240  
    731731    return $value;
    732732}
     733/**
     734 * Determines whether global terms are enabled.
     735 *
     736 * @since 3.0.0
     737 * @since 6.1.0 This function now always returns false.
     738 * @deprecated 6.1.0
     739 *
     740 * @return bool Always returns false.
     741 */
     742function global_terms_enabled() {
     743    _deprecated_function( __FUNCTION__, '6.1.0' );
     744
     745    return false;
     746}
     747
     748/**
     749 * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
     750 *
     751 * @since 3.0.0
     752 * @since 6.1.0 This function no longer does anything.
     753 * @deprecated 6.1.0
     754 *
     755 * @param int    $term_id    An ID for a term on the current blog.
     756 * @param string $deprecated Not used.
     757 * @return int An ID from the global terms table mapped from $term_id.
     758 */
     759function global_terms( $term_id, $deprecated = '' ) {
     760    _deprecated_function( __FUNCTION__, '6.1.0' );
     761
     762    return $term_id;
     763}
  • 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 *
  • trunk/tests/phpunit/tests/pluggable.php

    r54218 r54240  
    8383            'wp_new_blog_notification',
    8484            'wp_upgrade',
    85             'install_global_terms',
    8685        );
    8786        $test_files     = array(
     
    258257            'wp_new_blog_notification'        => array( 'blog_title', 'blog_url', 'user_id', 'password' ),
    259258            'wp_upgrade'                      => array(),
    260             'install_global_terms'            => array(),
    261259        );
    262260
Note: See TracChangeset for help on using the changeset viewer.