Refactor chapter navigation button to allow status customization

This commit is contained in:
iniznet 2024-09-25 22:03:40 +07:00
parent 0c24102400
commit d252dd5d27
2 changed files with 13 additions and 1 deletions

View File

@ -258,6 +258,15 @@ Filters the intermediate output array of the chapter micro menu in the `fictione
---
### `apply_filters( 'fictioneer_filter_chapter_nav_buttons_allowed_status', $statuses, $post_id )`
Filters the array of allowed post statuses for the chapter navigation buttons in the `fictioneer_chapter_nav_buttons( $args, $location )` function. The default is `array('publish')`, but you could add `'private'` or `'future'` if you want to allow the navigation to render with these statuses.
**Parameters:**
* $statuses (array) Array of allowed post statuses.
* $post_id (int) Current post ID.
---
### `apply_filters( 'fictioneer_filter_chapter_support_links', $support_links, $args )`
Filters the intermediate output array of the chapter support links in the `fictioneer_chapter_support_links( $args )` function before it is looped and rendered. Each item is another array with `'label'`, `'icon'` markup, and `'link'`.

View File

@ -315,8 +315,11 @@ function fictioneer_chapter_nav_buttons( $args, $location ) {
$post_status = get_post_status( $post_id );
$unlisted = get_post_meta( $post_id, 'fictioneer_chapter_hidden', true );
// Filter allowed status
$allowed_status = apply_filters( 'fictioneer_filter_chapter_nav_buttons_allowed_status', array( 'publish' ), $post_id );
// Do not render on hidden posts
if ( $post_status !== 'publish' ) {
if ( ! in_array( $post_status, $allowed_status ) ) {
return;
}