From 99dd0191e5c6b5886544d1452f3699bfd94c9704 Mon Sep 17 00:00:00 2001 From: Sim Brody Date: Wed, 13 May 2026 12:14:47 +0100 Subject: [PATCH 1/3] Add filter for allowed nav item post status --- src/ChapterNavigation.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ChapterNavigation.php b/src/ChapterNavigation.php index 284419a..597da2b 100644 --- a/src/ChapterNavigation.php +++ b/src/ChapterNavigation.php @@ -6,10 +6,8 @@ class ChapterNavigation { public function getItems(): array { - $postStatus = ['publish']; - if(current_user_can('edit_posts')) { - array_push($postStatus, 'draft'); - } + $postStatus = apply_filters('long_read_plugin_post_status', ['publish']); + global $post; $potentialParent = get_post_parent($post); $parentPost = $potentialParent ? $potentialParent : $post; From e758904be645c58e86436e524fba0962d9079d3f Mon Sep 17 00:00:00 2001 From: Sim Brody Date: Wed, 13 May 2026 13:54:16 +0100 Subject: [PATCH 2/3] Update tests to include post status filter --- spec/chapter_navigation.spec.php | 13 ++++++++----- src/ChapterNavigation.php | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/chapter_navigation.spec.php b/spec/chapter_navigation.spec.php index 4288023..b4f1262 100644 --- a/spec/chapter_navigation.spec.php +++ b/spec/chapter_navigation.spec.php @@ -15,7 +15,7 @@ 'ID' => 123, 'post_title' => 'Chapter One' ]; - allow('current_user_can')->toBeCalled(); + allow('apply_filters')->toBeCalled()->andReturn(['publish']); allow('get_post_parent')->toBeCalled()->andReturn(false); allow('get_posts')->toBeCalled()->andReturn([ (object) [ @@ -27,6 +27,7 @@ 'post_title' => 'Chapter Three' ], ]); + expect('apply_filters')->toBeCalled()->once()->with('long_read_plugin_post_status', ['publish']); expect('get_posts')->toBeCalled()->once()->with([ 'post_parent' => 123, 'post_status' => ['publish'], @@ -60,7 +61,7 @@ 'ID' => 123, 'post_title' => 'Chapter One' ]; - allow('current_user_can')->toBeCalled(); + allow('apply_filters')->toBeCalled()->andReturn(['publish']); allow('get_post_parent')->toBeCalled()->andReturn($parentPost); allow('get_posts')->toBeCalled()->andReturn([ $post = (object) [ @@ -72,6 +73,7 @@ 'post_title' => 'Chapter Three' ] ]); + expect('apply_filters')->toBeCalled()->once()->with('long_read_plugin_post_status', ['publish']); expect('get_posts')->toBeCalled()->once()->with([ 'post_parent' => 123, 'post_status' => ['publish'], @@ -94,8 +96,8 @@ }); }); - context('when the current logged in user can edit posts', function () { - it('includes draft posts in the query and returns them in the result', function () { + context('when long read post status filter includes drafts', function () { + it('queries with filtered post statuses and returns those posts', function () { global $post; $post = (object) [ 'ID' => 1011, @@ -106,7 +108,7 @@ 'post_title' => 'Chapter One', 'post_status' => 'publish' ]; - allow('current_user_can')->toBeCalled()->andReturn(true); + allow('apply_filters')->toBeCalled()->andReturn(['publish', 'draft']); allow('get_post_parent')->toBeCalled()->andReturn($parentPost); allow('get_posts')->toBeCalled()->andReturn([ (object) [ @@ -120,6 +122,7 @@ 'post_status' => 'draft' ] ]); + expect('apply_filters')->toBeCalled()->once()->with('long_read_plugin_post_status', ['publish']); expect('get_posts')->toBeCalled()->once()->with([ 'post_parent' => 123, 'post_status' => ['publish', 'draft'], diff --git a/src/ChapterNavigation.php b/src/ChapterNavigation.php index 597da2b..fd41acb 100644 --- a/src/ChapterNavigation.php +++ b/src/ChapterNavigation.php @@ -7,7 +7,7 @@ class ChapterNavigation public function getItems(): array { $postStatus = apply_filters('long_read_plugin_post_status', ['publish']); - + global $post; $potentialParent = get_post_parent($post); $parentPost = $potentialParent ? $potentialParent : $post; From f54bfade146ac0bcc67bb896d8f6d60efa0ce633 Mon Sep 17 00:00:00 2001 From: Sim Brody Date: Wed, 13 May 2026 14:02:30 +0100 Subject: [PATCH 3/3] Changelog update --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87fe4b8..9130251 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Filter replaces hard-coded addition of draft posts to navigation + ## [v2.3.0] - 2026-04-29 ### Changed