diff --git a/inc/class-archiveless.php b/inc/class-archiveless.php index b29bd54b..c8ce6e30 100644 --- a/inc/class-archiveless.php +++ b/inc/class-archiveless.php @@ -348,6 +348,10 @@ public function save_post( $post_id ): void { if ( isset( $_POST[ self::$meta_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing update_post_meta( $post_id, self::$meta_key, intval( $_POST[ self::$meta_key ] ) ); + } elseif ( static::$status === get_post_status( $post_id ) ) { + // If the post status is `archiveless`, ensure the post's + // archiveless meta is set to true. + update_post_meta( $post_id, self::$meta_key, 1 ); } } diff --git a/tests/test-general.php b/tests/test-general.php index 7c6ce59f..db1a6298 100644 --- a/tests/test-general.php +++ b/tests/test-general.php @@ -322,6 +322,23 @@ public function test_post_meta_hooks() { $this->assertEquals( 'archiveless', get_post_status( $post_id ) ); } + public function test_post_meta_applied_when_manually_created() { + $post_id = static::factory()->post->create(); + + $this->assertEmpty( get_post_meta( $post_id, 'archiveless', true ) ); + + wp_update_post( + [ + 'ID' => $post_id, + 'post_status' => 'archiveless', + ], + true, + ); + + $this->assertEquals( 'archiveless', get_post_status( $post_id ) ); + $this->assertEquals( '1', get_post_meta( $post_id, 'archiveless', true ) ); + } + public function test_post_preview() { $post_id = static::factory()->post->create( [