Add filter to story page cover HTML

This commit is contained in:
Tetrakern 2024-10-30 20:56:06 +01:00
parent e21c5ac1c1
commit f14abaa298
2 changed files with 25 additions and 2 deletions

View File

@ -2126,6 +2126,26 @@ Filters the intermediate output array in the `_story-header.php` partial before
--- ---
### `apply_filters( 'fictioneer_filter_story_page_cover_html', $html, $story, $args )`
Filters the HTML of the story page cover returned by the `fictioneer_get_story_page_cover()` function.
**Parameters:**
* $html (string) The HTML to be rendered.
* $story (array) Array of story data.
* $args (array) Optional arguments.
**Example:**
```php
function child_add_status_to_story_page_cover( $html, $story ) {
$extra_html = '<div>' . fcntr( $story['status'] ) . '</div></figure>'; // Does not have styling, though
return mb_ereg_replace( '</figure>', $extra_html, $html ); // Multi-byte safe
}
add_filter( 'fictioneer_filter_story_page_cover_html', 'child_add_status_to_story_page_cover', 10, 2 );
```
---
### `apply_filters( 'fictioneer_filter_story_word_count', $word_count, $post_id )` ### `apply_filters( 'fictioneer_filter_story_word_count', $word_count, $post_id )`
Filters the total word count of a story after sanitization (greater than or equal to 0) and before `fictioneer_multiply_word_count()` is applied, returning a positive integer. The word count is only calculated and updated when a post associated with the story is saved. Filters the total word count of a story after sanitization (greater than or equal to 0) and before `fictioneer_multiply_word_count()` is applied, returning a positive integer. The word count is only calculated and updated when a post associated with the story is saved.

View File

@ -594,6 +594,7 @@ if ( ! function_exists( 'fictioneer_get_story_page_cover' ) ) {
* *
* @since 5.0.0 * @since 5.0.0
* @since 5.9.4 - Removed output buffer. * @since 5.9.4 - Removed output buffer.
* @since 5.26.0 - Added filter.
* *
* @param array $story Collection of story data. * @param array $story Collection of story data.
* @param array $args Optional. Additional arguments. * @param array $args Optional. Additional arguments.
@ -605,8 +606,8 @@ if ( ! function_exists( 'fictioneer_get_story_page_cover' ) ) {
// Setup // Setup
$classes = $args['classes'] ?? ''; $classes = $args['classes'] ?? '';
// Build and return // Build, filter, and return
return sprintf( $html = sprintf(
'<figure class="story__thumbnail ' . $classes . '"><a href="%s" %s>%s<div id="ribbon-read" class="story__thumbnail-ribbon hidden"><div class="ribbon">%s</div></div></a></figure>', '<figure class="story__thumbnail ' . $classes . '"><a href="%s" %s>%s<div id="ribbon-read" class="story__thumbnail-ribbon hidden"><div class="ribbon">%s</div></div></a></figure>',
get_the_post_thumbnail_url( $story['id'], 'full' ), get_the_post_thumbnail_url( $story['id'], 'full' ),
fictioneer_get_lightbox_attribute(), fictioneer_get_lightbox_attribute(),
@ -616,6 +617,8 @@ if ( ! function_exists( 'fictioneer_get_story_page_cover' ) ) {
)), )),
_x( 'Read', 'Caption of the _read_ ribbon.', 'fictioneer' ) _x( 'Read', 'Caption of the _read_ ribbon.', 'fictioneer' )
); );
return apply_filters( 'fictioneer_filter_story_page_cover_html', $html, $story, $args );
} }
} }