<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13715] trunk: first pass on optional global terms, see #12589</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13715">13715</a></dd>
<dt>Author</dt> <dd>wpmuguru</dd>
<dt>Date</dt> <dd>2010-03-16 17:17:55 +0000 (Tue, 16 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>first pass on optional global terms, see <a href="http://trac.wordpress.org/ticket/12589">#12589</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditlinkcategoriesphp">trunk/wp-admin/edit-link-categories.php</a></li>
<li><a href="#trunkwpadminedittagformphp">trunk/wp-admin/edit-tag-form.php</a></li>
<li><a href="#trunkwpadminincludesmsphp">trunk/wp-admin/includes/ms.php</a></li>
<li><a href="#trunkwpadminincludesschemaphp">trunk/wp-admin/includes/schema.php</a></li>
<li><a href="#trunkwpadminincludesupgradephp">trunk/wp-admin/includes/upgrade.php</a></li>
<li><a href="#trunkwpadminmseditphp">trunk/wp-admin/ms-edit.php</a></li>
<li><a href="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
<li><a href="#trunkwpincludesmsfunctionsphp">trunk/wp-includes/ms-functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditlinkcategoriesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-link-categories.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-link-categories.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-admin/edit-link-categories.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -200,7 +200,7 @@
</span><span class="cx">         &lt;label for=&quot;name&quot;&gt;&lt;?php _e('Link Category name') ?&gt;&lt;/label&gt;
</span><span class="cx">         &lt;input name=&quot;name&quot; id=&quot;name&quot; type=&quot;text&quot; value=&quot;&quot; size=&quot;40&quot; aria-required=&quot;true&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><del>-&lt;?php if ( !is_multisite() ) { ?&gt;
</del><ins>+&lt;?php if ( !global_terms_enabled() ) { ?&gt;
</ins><span class="cx"> &lt;div class=&quot;form-field&quot;&gt;
</span><span class="cx">         &lt;label for=&quot;slug&quot;&gt;&lt;?php _e('Link Category slug') ?&gt;&lt;/label&gt;
</span><span class="cx">         &lt;input name=&quot;slug&quot; id=&quot;slug&quot; type=&quot;text&quot; value=&quot;&quot; size=&quot;40&quot; /&gt;
</span></span></pre></div>
<a id="trunkwpadminedittagformphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-tag-form.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-tag-form.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-admin/edit-tag-form.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx">                         &lt;td&gt;&lt;input name=&quot;name&quot; id=&quot;name&quot; type=&quot;text&quot; value=&quot;&lt;?php if ( isset( $tag-&gt;name ) ) echo esc_attr($tag-&gt;name); ?&gt;&quot; size=&quot;40&quot; aria-required=&quot;true&quot; /&gt;
</span><span class="cx">                         &lt;p class=&quot;description&quot;&gt;&lt;?php _e('The name is how it appears on your site.'); ?&gt;&lt;/p&gt;&lt;/td&gt;
</span><span class="cx">                 &lt;/tr&gt;
</span><del>-&lt;?php if ( !is_multisite() ) { ?&gt;
</del><ins>+&lt;?php if ( !global_terms_enabled() ) { ?&gt;
</ins><span class="cx">                 &lt;tr class=&quot;form-field&quot;&gt;
</span><span class="cx">                         &lt;th scope=&quot;row&quot; valign=&quot;top&quot;&gt;&lt;label for=&quot;slug&quot;&gt;&lt;?php echo _x('Slug', 'Taxonomy Slug'); ?&gt;&lt;/label&gt;&lt;/th&gt;
</span><span class="cx">                         &lt;td&gt;&lt;input name=&quot;slug&quot; id=&quot;slug&quot; type=&quot;text&quot; value=&quot;&lt;?php if ( isset( $tag-&gt;slug ) ) echo esc_attr(apply_filters('editable_slug', $tag-&gt;slug)); ?&gt;&quot; size=&quot;40&quot; /&gt;
</span></span></pre></div>
<a id="trunkwpadminincludesmsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/ms.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/ms.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-admin/includes/ms.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -520,7 +520,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function sync_category_tag_slugs( $term, $taxonomy ) {
</span><del>-        if ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) {
</del><ins>+        if ( global_terms_enabled() &amp;&amp; ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
</ins><span class="cx">                 if ( is_object( $term ) ) {
</span><span class="cx">                         $term-&gt;slug = sanitize_title( $term-&gt;name );
</span><span class="cx">                 } else {
</span></span></pre></div>
<a id="trunkwpadminincludesschemaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/schema.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/schema.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-admin/includes/schema.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -659,9 +659,6 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( !is_multisite() ) {
</span><del>-
-                $wpdb-&gt;query( &quot;INSERT INTO $wpdb-&gt;sitecategories (cat_id, cat_name, category_nicename, last_updated) SELECT term_id, `name`, slug, NOW() FROM $wpdb-&gt;terms&quot; );
-
</del><span class="cx">                 $site_admins = array( $site_user-&gt;user_login );
</span><span class="cx">                 $users = get_users_of_blog();
</span><span class="cx">                 if ( $users ) {
</span><span class="lines">@@ -708,11 +705,8 @@
</span><span class="cx">                 'add_new_users' =&gt; '0',
</span><span class="cx">                 'upload_space_check_disabled' =&gt; '0',
</span><span class="cx">                 'subdomain_install' =&gt; intval( $subdomain_install ),
</span><ins>+                'global_terms_enabled' =&gt; global_terms_enabled() ? '1' : '0'
</ins><span class="cx">         );
</span><del>-        if ( is_multisite() )
-                $sitemeta[ 'global_terms_enabled' ] = get_site_option( 'global_terms_enabled', '0' );
-        else
-                $sitemeta[ 'global_terms_enabled' ] = '0';
</del><span class="cx"> 
</span><span class="cx">         $insert = '';
</span><span class="cx">         foreach ( $sitemeta as $meta_key =&gt; $meta_value ) {
</span></span></pre></div>
<a id="trunkwpadminincludesupgradephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/upgrade.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/upgrade.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-admin/includes/upgrade.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -110,7 +110,7 @@
</span><span class="cx">         /* translators: Default category slug */
</span><span class="cx">         $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
</span><span class="cx"> 
</span><del>-        if ( is_multisite() ) {
</del><ins>+        if ( global_terms_enabled() ) {
</ins><span class="cx">                 $cat_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT cat_ID FROM {$wpdb-&gt;sitecategories} WHERE category_nicename = %s&quot;, $cat_slug ) );
</span><span class="cx">                 if ( $cat_id == null ) {
</span><span class="cx">                         $wpdb-&gt;insert( $wpdb-&gt;sitecategories, array('cat_ID' =&gt; 0, 'cat_name' =&gt; $cat_name, 'category_nicename' =&gt; $cat_slug, 'last_updated' =&gt; current_time('mysql', true)) );
</span><span class="lines">@@ -130,7 +130,7 @@
</span><span class="cx">         /* translators: Default link category slug */
</span><span class="cx">         $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
</span><span class="cx"> 
</span><del>-        if ( is_multisite() ) {
</del><ins>+        if ( global_terms_enabled() ) {
</ins><span class="cx">                 $blogroll_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT cat_ID FROM {$wpdb-&gt;sitecategories} WHERE category_nicename = %s&quot;, $cat_slug ) );
</span><span class="cx">                 if ( $blogroll_id == null ) {
</span><span class="cx">                         $wpdb-&gt;insert( $wpdb-&gt;sitecategories, array('cat_ID' =&gt; 0, 'cat_name' =&gt; $cat_name, 'category_nicename' =&gt; $cat_slug, 'last_updated' =&gt; current_time('mysql', true)) );
</span><span class="lines">@@ -1917,15 +1917,6 @@
</span><span class="cx">   KEY meta_key (meta_key),
</span><span class="cx">   KEY site_id (site_id)
</span><span class="cx"> ) $charset_collate;
</span><del>-CREATE TABLE $wpdb-&gt;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;
</del><span class="cx"> CREATE TABLE $wpdb-&gt;signups (
</span><span class="cx">   domain varchar(200) NOT NULL default '',
</span><span class="cx">   path varchar(100) NOT NULL default '',
</span><span class="lines">@@ -1945,4 +1936,29 @@
</span><span class="cx">         dbDelta( $ms_queries );
</span><span class="cx"> }
</span><span class="cx"> endif;
</span><ins>+
+/**
+ * Install global terms.
+ *
+ * @since 3.0
+ *
+ */
+if ( !function_exists( 'install_global_terms' ) ) :
+function install_global_terms() {
+        global $wpdb, $charset_collate;
+        $ms_queries = &quot;
+CREATE TABLE $wpdb-&gt;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;
+&quot;;
+// now create tables
+        dbDelta( $ms_queries );
+}
+endif;
</ins><span class="cx"> ?&gt;
</span></span></pre></div>
<a id="trunkwpadminmseditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/ms-edit.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/ms-edit.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-admin/ms-edit.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -107,6 +107,12 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">                 update_site_option( &quot;dashboard_blog&quot;, $dashboard_blog_id );
</span><ins>+                // global terms
+                if ( !global_terms_enabled() &amp;&amp; '1' == $_POST[ 'global_terms_enabled' ] ) {
+                        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
+                        // create global terms table
+                        install_global_terms();
+                }
</ins><span class="cx">                 $options = array( 'registrationnotification', 'registration', 'add_new_users', 'menu_items', 'mu_media_buttons', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'admin_notice_feed', 'global_terms_enabled' );
</span><span class="cx">                 $checked_options = array('mu_media_buttons', 'menu_items');
</span><span class="cx">                 foreach ( $checked_options as $option_name ) {
</span></span></pre></div>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-includes/functions.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -447,7 +447,7 @@
</span><span class="cx">         if ( empty($site_id) )
</span><span class="cx">                 $site_id = $wpdb-&gt;siteid;
</span><span class="cx"> 
</span><del>-        $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'dashboard_blog', 'can_compress_scripts');
</del><ins>+        $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'dashboard_blog', 'can_compress_scripts', 'global_terms_enabled' );
</ins><span class="cx"> 
</span><span class="cx">         $core_options_in = &quot;'&quot; . implode(&quot;', '&quot;, $core_options) . &quot;'&quot;;
</span><span class="cx">         $options = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT meta_key, meta_value FROM $wpdb-&gt;sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d&quot;, $site_id) );
</span><span class="lines">@@ -3691,6 +3691,22 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * are global terms enabled
+ *
+ *
+ * @since 3.0.0
+ * @package WordPress
+ *
+ * @return bool True if multisite and global terms enabled
+ */
+function global_terms_enabled() {
+        if ( is_multisite() &amp;&amp; '1' == get_site_option( 'global_terms_enabled' ) )
+                return true;
+
+        return false;
+}
+
+/**
</ins><span class="cx">  * gmt_offset modification for smart timezone handling
</span><span class="cx">  *
</span><span class="cx">  * Overrides the gmt_offset option if we have a timezone_string available
</span></span></pre></div>
<a id="trunkwpincludesmsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-functions.php (13714 => 13715)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-functions.php        2010-03-16 16:34:30 UTC (rev 13714)
+++ trunk/wp-includes/ms-functions.php        2010-03-16 17:17:55 UTC (rev 13715)
</span><span class="lines">@@ -1210,6 +1210,9 @@
</span><span class="cx"> function global_terms( $term_id, $deprecated = '' ) {
</span><span class="cx">         global $wpdb;
</span><span class="cx"> 
</span><ins>+        if ( !global_terms_enabled() )
+                return $term_id;
+
</ins><span class="cx">         $term_id = intval( $term_id );
</span><span class="cx">         $c = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;terms WHERE term_id = %d&quot;, $term_id ) );
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>