Multisite: Ensure first page/post/comment content is not empty when setting up a new site.
This prevents creating page without any content when the options are populated with an empty string. Props shadyvb. Fixes #40036. git-svn-id: https://develop.svn.wordpress.org/trunk@40296 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
eb7a3d1a2f
commit
e14051c031
@ -194,18 +194,19 @@ function wp_install_defaults( $user_id ) {
|
||||
$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
|
||||
|
||||
// Default comment
|
||||
$first_comment_author = __( 'A WordPress Commenter' );
|
||||
$first_comment_email = 'wapuu@wordpress.example';
|
||||
$first_comment_url = 'https://wordpress.org/';
|
||||
$first_comment = __( 'Hi, this is a comment.
|
||||
if ( is_multisite() ) {
|
||||
$first_comment_author = get_site_option( 'first_comment_author' );
|
||||
$first_comment_email = get_site_option( 'first_comment_email' );
|
||||
$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
|
||||
$first_comment = get_site_option( 'first_comment' );
|
||||
}
|
||||
|
||||
$first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
|
||||
$first_comment_email = ! empty( $first_comment_email ) ? $first_comment_email : 'wapuu@wordpress.example';
|
||||
$first_comment_url = ! empty( $first_comment_url ) ? $first_comment_url : 'https://wordpress.org/';
|
||||
$first_comment = ! empty( $first_comment ) ? $first_comment : __( 'Hi, this is a comment.
|
||||
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
|
||||
Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' );
|
||||
if ( is_multisite() ) {
|
||||
$first_comment_author = get_site_option( 'first_comment_author', $first_comment_author );
|
||||
$first_comment_email = get_site_option( 'first_comment_email', $first_comment_email );
|
||||
$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
|
||||
$first_comment = get_site_option( 'first_comment', $first_comment );
|
||||
}
|
||||
$wpdb->insert( $wpdb->comments, array(
|
||||
'comment_post_ID' => 1,
|
||||
'comment_author' => $first_comment_author,
|
||||
@ -217,17 +218,19 @@ Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' );
|
||||
));
|
||||
|
||||
// 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:
|
||||
|
||||
<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ña coladas. (And gettin' caught in the rain.)</blockquote>
|
||||
|
||||
...or something like this:
|
||||
|
||||
<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>
|
||||
|
||||
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() );
|
||||
if ( is_multisite() )
|
||||
$first_page = get_site_option( 'first_page', $first_page );
|
||||
$first_page = get_site_option( 'first_page' );
|
||||
|
||||
$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:
|
||||
|
||||
<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ña coladas. (And gettin' caught in the rain.)</blockquote>
|
||||
|
||||
...or something like this:
|
||||
|
||||
<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>
|
||||
|
||||
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() );
|
||||
|
||||
$first_post_guid = get_option('home') . '/?page_id=2';
|
||||
$wpdb->insert( $wpdb->posts, array(
|
||||
'post_author' => $user_id,
|
||||
|
81
tests/phpunit/tests/multisite/wpInstallDefaults.php
Normal file
81
tests/phpunit/tests/multisite/wpInstallDefaults.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
if ( is_multisite() ) :
|
||||
/**
|
||||
* Saving network settings without altering starter content ( first page, post, and comment ) shouldn't affect
|
||||
* the way it is added to new sites.
|
||||
*
|
||||
* @group ms-site
|
||||
* @group multisite
|
||||
*/
|
||||
class Tests_Multisite_Install_Defaults extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 40036
|
||||
*/
|
||||
public function test_option_should_not_be_empty_by_default() {
|
||||
$blog_id = $this->factory->blog->create();
|
||||
|
||||
switch_to_blog( $blog_id );
|
||||
|
||||
$first_page = get_page_by_path( '/sample-page' );
|
||||
$first_comment = get_comments();
|
||||
|
||||
restore_current_blog();
|
||||
wpmu_delete_blog( $blog_id, true );
|
||||
|
||||
$this->assertNotEmpty( $first_page->post_content );
|
||||
$this->assertNotEmpty( $first_comment[0]->comment_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40036
|
||||
*/
|
||||
public function test_empty_option_should_fall_back_to_default() {
|
||||
/*
|
||||
* Update first_page / first_comment options,
|
||||
* just like what happens when the network settings page is saved
|
||||
*/
|
||||
update_site_option( 'first_page', '' );
|
||||
update_site_option( 'first_comment', '' );
|
||||
|
||||
$blog_id = $this->factory->blog->create();
|
||||
|
||||
switch_to_blog( $blog_id );
|
||||
|
||||
$first_page = get_page_by_path( '/sample-page' );
|
||||
$first_comment = get_comments();
|
||||
|
||||
restore_current_blog();
|
||||
wpmu_delete_blog( $blog_id, true );
|
||||
|
||||
$this->assertNotEmpty( $first_page->post_content );
|
||||
$this->assertNotEmpty( $first_comment[0]->comment_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40036
|
||||
*/
|
||||
public function test_non_default_option_values() {
|
||||
/*
|
||||
* Update first_page / first_comment options,
|
||||
* just like what happens when the network settings page is saved
|
||||
*/
|
||||
update_site_option( 'first_page', 'Some page content' );
|
||||
update_site_option( 'first_comment', 'Some comment content' );
|
||||
|
||||
$blog_id = $this->factory->blog->create();
|
||||
|
||||
switch_to_blog( $blog_id );
|
||||
|
||||
$first_page = get_page_by_path( '/sample-page' );
|
||||
$first_comment = get_comments();
|
||||
|
||||
restore_current_blog();
|
||||
wpmu_delete_blog( $blog_id, true );
|
||||
|
||||
$this->assertEquals( 'Some page content', $first_page->post_content );
|
||||
$this->assertEquals( 'Some comment content', $first_comment[0]->comment_content );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
Loading…
Reference in New Issue
Block a user