WordPress.org

Make WordPress Core

Ticket #40036: 40036.diff

File 40036.diff, 6.8 KB (added by swissspidy, 3 years ago)
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index 8ce5c2aac8..94ad771761 100644
    function wp_install_defaults( $user_id ) { 
    194194        $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
    195195
    196196        // Default comment
    197         $first_comment_author = __( 'A WordPress Commenter' );
    198         $first_comment_email = 'wapuu@wordpress.example';
    199         $first_comment_url = 'https://wordpress.org/';
    200         $first_comment = __( 'Hi, this is a comment.
    201 To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    202 Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' );
    203197        if ( is_multisite() ) {
    204                 $first_comment_author = get_site_option( 'first_comment_author', $first_comment_author );
    205                 $first_comment_email = get_site_option( 'first_comment_email', $first_comment_email );
     198                $first_comment_author = get_site_option( 'first_comment_author' );
     199                $first_comment_email = get_site_option( 'first_comment_email' );
    206200                $first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
    207                 $first_comment = get_site_option( 'first_comment', $first_comment );
     201                $first_comment = get_site_option( 'first_comment' );
    208202        }
     203
     204        $first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
     205        $first_comment_email = ! empty( $first_comment_email ) ? $first_comment_email : 'wapuu@wordpress.example';
     206        $first_comment_url = ! empty( $first_comment_url ) ? $first_comment_url : 'https://wordpress.org/';
     207        $first_comment = ! empty( $first_comment ) ? $first_comment :  __( 'Hi, this is a comment.
     208To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
     209Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' );
    209210        $wpdb->insert( $wpdb->comments, array(
    210211                'comment_post_ID' => 1,
    211212                'comment_author' => $first_comment_author,
    Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' ); 
    217218        ));
    218219
    219220        // First Page
    220         $first_page = sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:
    221 
    222 <blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>
    223 
    224 ...or something like this:
    225 
    226 <blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>
    227 
    228 As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() );
    229221        if ( is_multisite() )
    230                 $first_page = get_site_option( 'first_page', $first_page );
     222                $first_page = get_site_option( 'first_page' );
     223
     224        $first_page = ! empty( $first_page ) ? $first_page : sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:
     225               
     226                <blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>
     227               
     228                ...or something like this:
     229               
     230                <blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>
     231               
     232                As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() );
     233
    231234        $first_post_guid = get_option('home') . '/?page_id=2';
    232235        $wpdb->insert( $wpdb->posts, array(
    233236                'post_author' => $user_id,
  • new file tests/phpunit/tests/multisite/wpInstallDefaults.php

    diff --git tests/phpunit/tests/multisite/wpInstallDefaults.php tests/phpunit/tests/multisite/wpInstallDefaults.php
    new file mode 100644
    index 0000000000..04db29e354
    - +  
     1<?php
     2
     3if ( is_multisite() ) :
     4/**
     5 * Saving network settings without altering starter content ( first page, post, and comment ) shouldn't affect
     6 * the way it is added to new sites.
     7 *
     8 * @group ms-site
     9 * @group multisite
     10 */
     11class Tests_Multisite_Install_Defaults extends WP_UnitTestCase {
     12        /**
     13         * @ticket 40036
     14         */
     15        public function test_option_should_not_be_empty_by_default() {
     16                $blog_id = $this->factory->blog->create();
     17
     18                switch_to_blog( $blog_id );
     19
     20                $first_page = get_page_by_path( '/sample-page' );
     21                $first_comment = get_comments();
     22
     23                restore_current_blog();
     24                wpmu_delete_blog( $blog_id, true );
     25
     26                $this->assertNotEmpty( $first_page->post_content );
     27                $this->assertNotEmpty( $first_comment[0]->comment_content );
     28        }
     29
     30        /**
     31         * @ticket 40036
     32         */
     33        public function test_empty_option_should_fall_back_to_default() {
     34                /*
     35                 * Update first_page / first_comment options,
     36                 * just like what happens when the network settings page is saved
     37                 */
     38                update_site_option( 'first_page', '' );
     39                update_site_option( 'first_comment', '' );
     40
     41                $blog_id = $this->factory->blog->create();
     42
     43                switch_to_blog( $blog_id );
     44
     45                $first_page = get_page_by_path( '/sample-page' );
     46                $first_comment = get_comments();
     47
     48                restore_current_blog();
     49                wpmu_delete_blog( $blog_id, true );
     50
     51                $this->assertNotEmpty( $first_page->post_content );
     52                $this->assertNotEmpty( $first_comment[0]->comment_content );
     53        }
     54
     55        /**
     56         * @ticket 40036
     57         */
     58        public function test_non_default_option_values() {
     59                /*
     60                 * Update first_page / first_comment options,
     61                 * just like what happens when the network settings page is saved
     62                 */
     63                update_site_option( 'first_page', 'Some page content' );
     64                update_site_option( 'first_comment', 'Some comment content' );
     65
     66                $blog_id = $this->factory->blog->create();
     67
     68                switch_to_blog( $blog_id );
     69
     70                $first_page = get_page_by_path( '/sample-page' );
     71                $first_comment = get_comments();
     72
     73                restore_current_blog();
     74                wpmu_delete_blog( $blog_id, true );
     75
     76                $this->assertEquals( 'Some page content', $first_page->post_content );
     77                $this->assertEquals( 'Some comment content', $first_comment[0]->comment_content );
     78        }
     79}
     80
     81endif;