Skip to content

Commit

Permalink
Add filter to story page cover HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetrakern committed Oct 30, 2024
1 parent e21c5ac commit f14abaa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions FILTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )`
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.

Expand Down
7 changes: 5 additions & 2 deletions includes/functions/_helpers-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ function fictioneer_get_breadcrumbs( $args ) {
*
* @since 5.0.0
* @since 5.9.4 - Removed output buffer.
* @since 5.26.0 - Added filter.
*
* @param array $story Collection of story data.
* @param array $args Optional. Additional arguments.
Expand All @@ -605,8 +606,8 @@ function fictioneer_get_story_page_cover( $story, $args = [] ) {
// Setup
$classes = $args['classes'] ?? '';

// Build and return
return sprintf(
// Build, filter, and return
$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>',
get_the_post_thumbnail_url( $story['id'], 'full' ),
fictioneer_get_lightbox_attribute(),
Expand All @@ -616,6 +617,8 @@ function fictioneer_get_story_page_cover( $story, $args = [] ) {
)),
_x( 'Read', 'Caption of the _read_ ribbon.', 'fictioneer' )
);

return apply_filters( 'fictioneer_filter_story_page_cover_html', $html, $story, $args );
}
}

Expand Down

0 comments on commit f14abaa

Please sign in to comment.