Skip to content

Commit

Permalink
Ensure that when an archiveless post is created manually the meta is …
Browse files Browse the repository at this point in the history
…still set
  • Loading branch information
srtfisher committed Nov 28, 2023
1 parent d143886 commit a5f5dbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inc/class-archiveless.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/test-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down

0 comments on commit a5f5dbe

Please sign in to comment.