Improve static post content filters

And add missing documentation.
This commit is contained in:
Tetrakern 2024-05-22 12:38:01 +02:00
parent 10c2ee96f8
commit b98a429448
2 changed files with 24 additions and 5 deletions

View File

@ -1401,6 +1401,24 @@ Filters the intermediate output array of the `fictioneer_filter_media_buttons( $
---
### `apply_filters( 'fictioneer_filter_static_content', $content, $post )`
Filters the HTML returned by `fictioneer_get_static_content()`. Allows you to customize the cached content itself, the result not being cached. The filter is also applied if the static cache is disabled for the post, so this can be used in place for the `the_content` filter. Relies on the global post and currently only used in chapters.
**Parameters:**
* $content (string) The post content as HTML, all normal filters applied.
* $post (WP_Post) The global post object.
---
### `apply_filters( 'fictioneer_filter_static_content_true', $force, $post )`
Filters the last guard clause for returning the cached content, default `true`. Allows you to exclude posts based on broader conditions. Relies on the global post and currently only used in chapters.
**Parameters:**
* $force (boolean) Whether to return the cached HTML. Default `true`.
* $post (WP_Post) The global post object.
---
### `apply_filters( 'fictioneer_filter_story_card_footer', $footer_items, $post, $story, $args )`
Filters the intermediate output array in the `_card-story.php` partial before it is imploded and rendered. Contains statistics with icons such as the number of chapters, publishing date, comments, and so forth.

View File

@ -981,13 +981,14 @@ function fictioneer_get_static_content( $more_link_text = \null, $strip_teaser =
if (
! FICTIONEER_ENABLE_PARTIAL_CACHING ||
! empty( $post->post_password ) ||
get_post_meta( $post->ID, 'fictioneer_chapter_disable_partial_caching', true )
get_post_meta( $post->ID, 'fictioneer_chapter_disable_partial_caching', true ) ||
! apply_filters( 'fictioneer_filter_static_content_true', true, $post )
) {
$content = get_the_content( $more_link_text, $strip_teaser );
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
return apply_filters( 'fictioneer_get_static_content', $content );
return apply_filters( 'fictioneer_filter_static_content', $content, $post );
}
// Setup
@ -1001,7 +1002,7 @@ function fictioneer_get_static_content( $more_link_text = \null, $strip_teaser =
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
return apply_filters( 'fictioneer_get_static_content', $content );
return apply_filters( 'fictioneer_filter_static_content', $content, $post );
}
// Get static file if not expired
@ -1009,7 +1010,7 @@ function fictioneer_get_static_content( $more_link_text = \null, $strip_teaser =
$filemtime = filemtime( $path );
if ( time() - $filemtime < FICTIONEER_PARTIAL_CACHE_EXPIRATION_TIME ) {
return apply_filters( 'fictioneer_get_static_content', file_get_contents( $path ) );
return apply_filters( 'fictioneer_filter_static_content', file_get_contents( $path ), $post );
}
}
@ -1022,7 +1023,7 @@ function fictioneer_get_static_content( $more_link_text = \null, $strip_teaser =
file_put_contents( $path, $content );
// Return content
return apply_filters( 'fictioneer_get_static_content', $content );
return apply_filters( 'fictioneer_filter_static_content', $content, $post );
}
/**