WordPress.org

Make WordPress Core

Ticket #11644: defaults_cleanup.diff

File defaults_cleanup.diff, 5.1 KB (added by ryan, 3 years ago)

Cleanup installation of default terms.

  • wp-includes/ms-functions.php

     
    14191419        update_option('admin_email', ''); 
    14201420        $wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') ); 
    14211421 
    1422         // Default category 
    1423         $wpdb->insert( $wpdb->terms, array('term_id' => 1, 'name' => __('Uncategorized'), 'slug' => sanitize_title(__('Uncategorized')), 'term_group' => 0) ); 
    1424         $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => 1, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1) ); 
    1425  
    1426         // Default link category 
    1427         $cat_name = __('Blogroll'); 
    1428         $cat_slug = sanitize_title($cat_name); 
    1429  
    1430         $blogroll_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); 
    1431  
    1432         if ( $blogroll_id == null ) { 
    1433                 $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) ); 
    1434                 $blogroll_id = $wpdb->insert_id; 
    1435         } 
    1436         $wpdb->insert( $wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); 
    1437         $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 2) ); 
    1438         update_option('default_link_category', $blogroll_id); 
    1439  
    14401422        // remove all perms 
    14411423        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'user_level') ); 
    14421424        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'capabilities') ); 
  • wp-admin/includes/upgrade.php

     
    103103        /* translators: Default category slug */ 
    104104        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug')); 
    105105 
    106         $wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); 
    107         $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '1', 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1)); 
     106        if ( is_multisite() ) { 
     107                $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); 
     108                if ( $cat_id == null ) { 
     109                        $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) ); 
     110                        $cat_id = $wpdb->insert_id; 
     111                } 
     112                update_option('default_category', $cat_id); 
     113        } else { 
     114                $cat_id = 1; 
     115        } 
    108116 
     117        $wpdb->insert( $wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); 
     118        $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1)); 
     119        $cat_tt_id = $wpdb->insert_id; 
     120 
    109121        // Default link category 
    110122        $cat_name = __('Blogroll'); 
    111123        /* translators: Default link category slug */ 
    112124        $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug')); 
    113125 
    114         $wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); 
    115         $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '2', 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7)); 
     126        if ( is_multisite() ) { 
     127                $blogroll_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); 
     128                if ( $blogroll_id == null ) { 
     129                        $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) ); 
     130                        $blogroll_id = $wpdb->insert_id; 
     131                } 
     132                update_option('default_link_category', $blogroll_id); 
     133        } else { 
     134                $blogroll_id = 2; 
     135        } 
    116136 
     137        $wpdb->insert( $wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); 
     138        $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7)); 
     139        $blogroll_tt_id = $wpdb->insert_id; 
     140 
    117141        // Now drop in some default links 
    118142        $default_links = array(); 
    119143        $default_links[] = array(       'link_url' => 'http://codex.wordpress.org/', 
     
    153177 
    154178        foreach ( $default_links as $link ) { 
    155179                $wpdb->insert( $wpdb->links, $link); 
    156                 $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 2, 'object_id' => $wpdb->insert_id) ); 
     180                $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id) ); 
    157181        } 
    158182 
    159183        // First post 
     
    190214                                                                'pinged' => '', 
    191215                                                                'post_content_filtered' => '' 
    192216                                                                )); 
    193         $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 1, 'object_id' => 1) ); 
     217        $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) ); 
    194218 
    195219        // Default comment 
    196220        $first_comment_author = __('Mr WordPress');