Make WordPress Core

Changeset 12776


Ignore:
Timestamp:
01/20/2010 08:09:41 PM (15 years ago)
Author:
ryan
Message:

Deprecate wp_install_blog_defaults(). Use wp_install_defaults() instead. fixes #11747 see #11644

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/upgrade.php

    r12756 r12776  
    9797 */
    9898function wp_install_defaults($user_id) {
    99     global $wpdb;
     99    global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    100100
    101101    // Default category
     
    162162    $first_post_guid = get_option('home') . '/?p=1';
    163163
     164    if ( is_multisite() ) {
     165        $first_post = get_site_option( 'first_post' );
     166
     167        if ( empty($first_post) )
     168            $first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) );
     169
     170        $first_post = str_replace( "SITE_URL", clean_url("http://" . $current_site->domain . $current_site->path), $first_post );
     171        $first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post );
     172    } else {
     173        $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
     174    }
     175
    164176    $wpdb->insert( $wpdb->posts, array(
    165177                                'post_author' => $user_id,
    166178                                'post_date' => $now,
    167179                                'post_date_gmt' => $now_gmt,
    168                                 'post_content' => __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'),
     180                                'post_content' => $first_post,
    169181                                'post_excerpt' => '',
    170182                                'post_title' => __('Hello world!'),
     
    182194
    183195    // Default comment
     196    if ( is_multisite() ) {
     197        $first_comment_author = get_site_option( 'first_comment_author' );
     198        $first_comment_url = get_site_option( 'first_comment_url' );
     199        $first_comment = get_site_option( 'first_comment' );
     200    } else {
     201        $first_comment_author = __('Mr WordPress');
     202        $first_comment_url = 'http://wordpress.org/';
     203        $first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
     204    }   
    184205    $wpdb->insert( $wpdb->comments, array(
    185206                                'comment_post_ID' => 1,
    186                                 'comment_author' => __('Mr WordPress'),
     207                                'comment_author' => $first_comment_author,
    187208                                'comment_author_email' => '',
    188209                                'comment_author_url' => 'http://wordpress.org/',
    189210                                'comment_date' => $now,
    190211                                'comment_date_gmt' => $now_gmt,
    191                                 'comment_content' => __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.')
     212                                'comment_content' => $first_comment
    192213                                ));
     214
    193215    // First Page
     216    if ( is_multisite() && get_site_option( 'first_page' ) )
     217        $first_page = get_site_option( 'first_page' );
     218    else
     219        $first_page = __('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.');
    194220    $first_post_guid = get_option('home') . '/?page_id=2';
    195221    $wpdb->insert( $wpdb->posts, array(
     
    197223                                'post_date' => $now,
    198224                                'post_date_gmt' => $now_gmt,
    199                                 'post_content' => __('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'),
     225                                'post_content' => $first_page,
    200226                                'post_excerpt' => '',
    201227                                'post_title' => __('About'),
     
    210236                                'post_content_filtered' => ''
    211237                                ));
     238
     239    if ( is_multisite() ) {
     240        // Flush rules to pick up the new page.
     241        $wp_rewrite->init();
     242        $wp_rewrite->flush_rules();
     243
     244        $user = new WP_User($user_id);
     245        $wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') );
     246
     247        // Remove all perms except for the login user.
     248        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') );
     249        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') );
     250
     251        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
     252        if ( !is_super_admin( $user_id ) && $user_id != 1 )
     253            $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $wpdb->base_prefix.'1_capabilities') );
     254    }
    212255}
    213256endif;
  • trunk/wp-includes/ms-functions.php

    r12768 r12776  
    12661266    switch_to_blog($blog_id);
    12671267    install_blog($blog_id, $title);
    1268     install_blog_defaults($blog_id, $user_id);
     1268    wp_install_defaults($user_id);
    12691269
    12701270    add_user_to_blog($blog_id, $user_id, 'administrator');
     
    14161416}
    14171417
     1418// Deprecated, use wp_install_defaults()
    14181419// should be switched already as $blog_id is ignored.
    14191420function install_blog_defaults($blog_id, $user_id) {
    1420     global $wpdb, $wp_rewrite, $current_site, $table_prefix;
     1421    global $wpdb;
     1422
     1423    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    14211424
    14221425    $wpdb->suppress_errors();
    14231426
    1424     // Cast for security
    1425     $user_id = (int) $user_id;
    1426     $blog_id = (int) $blog_id;
    1427 
    1428     // Default links
    1429     $wpdb->insert( $wpdb->links, array( 'link_url' => 'http://wordpress.com/', 'link_name' => 'WordPress.com', 'link_owner' => $user_id, 'link_rss' => 'http://en.blog.wordpress.com/feed/', 'link_notes' => '' ) );
    1430     $wpdb->insert( $wpdb->links, array( 'link_url' => 'http://wordpress.org/', 'link_name' => 'WordPress.org', 'link_owner' => $user_id, 'link_rss' => 'http://wordpress.org/development/feed/', 'link_notes' => '' ) );
    1431     $wpdb->insert( $wpdb->term_relationships, array('object_id' => 1, 'term_taxonomy_id' => 2));
    1432     $wpdb->insert( $wpdb->term_relationships, array('object_id' => 2, 'term_taxonomy_id' => 2));
    1433 
    1434     // First post
    1435     $now = date('Y-m-d H:i:s');
    1436     $now_gmt = gmdate('Y-m-d H:i:s');
    1437     $first_post = get_site_option( 'first_post' );
    1438 
    1439     if ( $first_post == false )
    1440         $first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) );
    1441 
    1442     $first_post = str_replace( "SITE_URL", clean_url("http://" . $current_site->domain . $current_site->path), $first_post );
    1443     $first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post );
    1444     $wpdb->insert( $wpdb->posts, array(
    1445         'post_author' => $user_id,
    1446         'post_date' => $now,
    1447         'post_date_gmt' => $now_gmt,
    1448         'post_content' => stripslashes( $first_post ),
    1449         'post_excerpt' => '',
    1450         'post_title' => __('Hello world!'),
    1451         'post_name' => __('hello-world'),
    1452         'post_modified' => $now,
    1453         'post_modified_gmt' => $now_gmt,
    1454         'comment_count' => 1,
    1455         'to_ping' => '',
    1456         'pinged' => '',
    1457         'post_content_filtered' => ''
    1458     ) );
    1459     $wpdb->insert( $wpdb->term_relationships, array('object_id' => 1, 'term_taxonomy_id' => 1));
    1460     update_option( "post_count", 1 );
    1461 
    1462     // First page
    1463     $wpdb->insert( $wpdb->posts, array(
    1464         'post_author' => $user_id,
    1465         'post_date' => $now,
    1466         'post_date_gmt' => $now_gmt,
    1467         'post_content' => get_site_option( 'first_page' ),
    1468         'post_excerpt' => '',
    1469         'post_title' => __('About'),
    1470         'post_name' => __('about'),
    1471         'post_modified' => $now,
    1472         'post_modified_gmt' => $now_gmt,
    1473         'post_status' => 'publish',
    1474         'post_type' => 'page',
    1475         'to_ping' => '',
    1476         'pinged' => '',
    1477         'post_content_filtered' => ''
    1478     ) );
    1479 
    1480     // Flush rules to pick up the new page.
    1481     $wp_rewrite->init();
    1482     $wp_rewrite->flush_rules();
    1483 
    1484     // Default comment
    1485     $wpdb->insert( $wpdb->comments, array(
    1486         'comment_post_ID' => '1',
    1487         'comment_author' => __( get_site_option( 'first_comment_author' ) ),
    1488         'comment_author_email' => '',
    1489         'comment_author_url' => get_site_option( 'first_comment_url' ),
    1490         'comment_author_IP' => '127.0.0.1',
    1491         'comment_date' => $now,
    1492         'comment_date_gmt' => $now_gmt,
    1493         'comment_content' => __( get_site_option( 'first_comment' ) )
    1494     ) );
    1495 
    1496     $user = new WP_User($user_id);
    1497     $wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') );
    1498 
    1499     // Remove all perms except for the login user.
    1500     $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') );
    1501     $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') );
    1502 
    1503     // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
    1504     if ( !is_super_admin( $user->user_login ) && $user_id != 1 )
    1505         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $wpdb->base_prefix.'1_capabilities') );
     1427    wp_install_defaults($user_id);
    15061428
    15071429    $wpdb->suppress_errors( false );
Note: See TracChangeset for help on using the changeset viewer.