diff --git a/src/wp-admin/includes/schema.php b/src/wp-admin/includes/schema.php index 8ea0b3680291c..923a079ec2abf 100644 --- a/src/wp-admin/includes/schema.php +++ b/src/wp-admin/includes/schema.php @@ -429,8 +429,8 @@ function populate_options( array $options = array() ) { 'mailserver_port' => 110, 'default_category' => 1, 'default_comment_status' => 'open', - 'default_ping_status' => 'open', - 'default_pingback_flag' => 1, + 'default_ping_status' => 'closed', + 'default_pingback_flag' => 0, 'posts_per_page' => 10, /* translators: Default date format, see https://www.php.net/manual/datetime.format.php */ 'date_format' => __( 'F j, Y' ), diff --git a/tests/phpunit/tests/comment/defaultPingStatus.php b/tests/phpunit/tests/comment/defaultPingStatus.php new file mode 100644 index 0000000000000..45d033559c853 --- /dev/null +++ b/tests/phpunit/tests/comment/defaultPingStatus.php @@ -0,0 +1,149 @@ +original_ping_status = get_option( 'default_ping_status' ); + $this->original_pingback_flag = get_option( 'default_pingback_flag' ); + } + + public function tear_down() { + update_option( 'default_ping_status', $this->original_ping_status ); + update_option( 'default_pingback_flag', $this->original_pingback_flag ); + + parent::tear_down(); + } + + /** + * Tests that default_ping_status defaults to 'closed' for fresh installations. + */ + public function test_default_ping_status_defaults_to_closed() { + $this->assertSame( 'closed', get_option( 'default_ping_status' ) ); + } + + /** + * Tests that default_pingback_flag defaults to 0 for fresh installations. + */ + public function test_default_pingback_flag_defaults_to_zero() { + $this->assertSame( 0, (int) get_option( 'default_pingback_flag' ) ); + } + + /** + * Tests that newly created posts default to ping_status 'closed'. + */ + public function test_new_post_defaults_to_closed_ping_status() { + $post = self::factory()->post->create_and_get(); + + $this->assertSame( 'closed', $post->ping_status ); + $this->assertFalse( pings_open( $post ) ); + } + + /** + * Tests that an explicit ping_status 'open' is respected on post creation. + */ + public function test_new_post_respects_explicit_open_ping_status() { + $post = self::factory()->post->create_and_get( + array( 'ping_status' => 'open' ) + ); + + $this->assertSame( 'open', $post->ping_status ); + $this->assertTrue( pings_open( $post ) ); + } + + /** + * Tests that get_default_comment_status() returns 'closed' for pingback and trackback. + */ + public function test_get_default_comment_status_returns_closed_for_pingback_and_trackback() { + $this->assertSame( 'closed', get_default_comment_status( 'post', 'pingback' ) ); + $this->assertSame( 'closed', get_default_comment_status( 'post', 'trackback' ) ); + $this->assertSame( 'open', get_default_comment_status( 'post', 'comment' ) ); + } + + /** + * Tests that modifying default_ping_status option updates new post creation defaults. + */ + public function test_updating_default_ping_status_option_updates_new_post_defaults() { + update_option( 'default_ping_status', 'open' ); + + $this->assertSame( 'open', get_default_comment_status( 'post', 'pingback' ) ); + + $post = self::factory()->post->create_and_get(); + $this->assertSame( 'open', $post->ping_status ); + $this->assertTrue( pings_open( $post ) ); + } + + /** + * Tests that publishing a post does not queue _pingme postmeta when default_pingback_flag is 0. + */ + public function test_publish_post_does_not_queue_pingme_when_flag_is_zero() { + update_option( 'default_pingback_flag', 0 ); + + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + 'post_content' => 'Link: Target', + ) + ); + + $this->assertSame( '', get_post_meta( $post_id, '_pingme', true ) ); + } + + /** + * Tests that publishing a post queues _pingme postmeta when default_pingback_flag is enabled. + */ + public function test_publish_post_queues_pingme_when_flag_is_enabled() { + update_option( 'default_pingback_flag', 1 ); + + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + 'post_content' => 'Link: Target', + ) + ); + + $this->assertSame( '1', get_post_meta( $post_id, '_pingme', true ) ); + } + + /** + * Tests that populate_options() does not overwrite existing site settings during upgrades. + */ + public function test_populate_options_does_not_overwrite_existing_settings() { + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + require_once ABSPATH . 'wp-admin/includes/schema.php'; + + update_option( 'default_ping_status', 'open' ); + update_option( 'default_pingback_flag', 1 ); + + populate_options(); + + $this->assertSame( 'open', get_option( 'default_ping_status' ) ); + $this->assertSame( 1, (int) get_option( 'default_pingback_flag' ) ); + } +} diff --git a/tests/phpunit/tests/comment/pingsOpen.php b/tests/phpunit/tests/comment/pingsOpen.php index 638f71f1b48d4..19dab918830b0 100644 --- a/tests/phpunit/tests/comment/pingsOpen.php +++ b/tests/phpunit/tests/comment/pingsOpen.php @@ -17,7 +17,9 @@ public function test_post_does_not_exist() { * @ticket 54159 */ public function test_post_exist_status_open() { - $post = self::factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get( + array( 'ping_status' => 'open' ) + ); $this->assertTrue( pings_open( $post ) ); } diff --git a/tests/phpunit/tests/post/wpInsertPost.php b/tests/phpunit/tests/post/wpInsertPost.php index 187ec7ceb0ab9..c02c6b05a671f 100644 --- a/tests/phpunit/tests/post/wpInsertPost.php +++ b/tests/phpunit/tests/post/wpInsertPost.php @@ -653,6 +653,7 @@ public function test_insert_programmatic_sanitized() { /** * @ticket 31168 + * @ticket 38207 */ public function test_wp_insert_post_default_comment_ping_status_open() { $post_id = self::factory()->post->create( @@ -663,7 +664,7 @@ public function test_wp_insert_post_default_comment_ping_status_open() { $post = get_post( $post_id ); $this->assertSame( 'open', $post->comment_status ); - $this->assertSame( 'open', $post->ping_status ); + $this->assertSame( 'closed', $post->ping_status ); } /** @@ -684,6 +685,7 @@ public function test_wp_insert_post_page_default_comment_ping_status_closed() { /** * @ticket 31168 + * @ticket 38207 */ public function test_wp_insert_post_cpt_default_comment_ping_status_open() { register_post_type( @@ -704,7 +706,7 @@ public function test_wp_insert_post_cpt_default_comment_ping_status_open() { _unregister_post_type( 'cpt' ); $this->assertSame( 'open', $post->comment_status ); - $this->assertSame( 'open', $post->ping_status ); + $this->assertSame( 'closed', $post->ping_status ); } /** diff --git a/tests/phpunit/tests/wp/sendHeaders.php b/tests/phpunit/tests/wp/sendHeaders.php index 4974d74caf8fc..131d6f2c0a97f 100644 --- a/tests/phpunit/tests/wp/sendHeaders.php +++ b/tests/phpunit/tests/wp/sendHeaders.php @@ -33,6 +33,26 @@ function ( $headers ) { } ); + $post_id = self::factory()->post->create( + array( + 'ping_status' => 'open', + ) + ); + $this->go_to( get_permalink( $post_id ) ); + } + + /** + * @ticket 56840 + * @ticket 38207 + */ + public function test_send_headers_does_not_set_x_pingback_when_pings_are_closed() { + add_action( + 'wp_headers', + function ( $headers ) { + $this->assertArrayNotHasKey( 'X-Pingback', $headers ); + } + ); + $post_id = self::factory()->post->create(); $this->go_to( get_permalink( $post_id ) ); } diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 5d209f1c79820..6ea906a3e5254 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -13254,7 +13254,7 @@ mockedApiResponse.PostsCollection = [ "author": 0, "featured_media": 0, "comment_status": "open", - "ping_status": "open", + "ping_status": "closed", "sticky": false, "template": "", "format": "standard", @@ -13372,7 +13372,7 @@ mockedApiResponse.PostModel = { "author": 0, "featured_media": 0, "comment_status": "open", - "ping_status": "open", + "ping_status": "closed", "sticky": false, "template": "", "format": "standard", @@ -14939,7 +14939,7 @@ mockedApiResponse.settings = { "page_on_front": 0, "page_for_posts": 0, "page_for_privacy_policy": 0, - "default_ping_status": "open", + "default_ping_status": "closed", "default_comment_status": "open", "site_logo": null, "site_icon": 0