From abecf5249f0a21e8a2a7d6ad6fe2cd2293e9b247 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Mon, 4 Mar 2024 01:54:53 +0100 Subject: [PATCH] Add output and filter for card attributes --- FILTERS.md | 9 +++++++++ partials/_article-cards.php | 10 +++++++++- partials/_card-chapter.php | 9 +++++++++ partials/_card-collection.php | 10 +++++++++- partials/_card-hidden.php | 10 +++++++++- partials/_card-page.php | 10 +++++++++- partials/_card-post.php | 10 +++++++++- partials/_card-recommendation.php | 10 +++++++++- partials/_card-story.php | 9 +++++++++ partials/_latest-chapters-compact.php | 10 +++++++++- partials/_latest-chapters.php | 10 +++++++++- partials/_latest-recommendations-compact.php | 10 +++++++++- partials/_latest-recommendations.php | 10 +++++++++- partials/_latest-stories-compact.php | 10 +++++++++- partials/_latest-stories.php | 10 +++++++++- partials/_latest-updates-compact.php | 10 +++++++++- partials/_latest-updates.php | 10 +++++++++- 17 files changed, 153 insertions(+), 14 deletions(-) diff --git a/FILTERS.md b/FILTERS.md index 9a32cfa5..27dc5db7 100644 --- a/FILTERS.md +++ b/FILTERS.md @@ -97,6 +97,15 @@ Filters the array of breadcrumb tuples inside the `fictioneer_get_breadcrumbs( $ --- +### `apply_filters( 'fictioneer_filter_card_attributes', $post, $context )` +Filters the intermediate output array of HTML attributes inside the `.card` element before they are rendered. The keys are used as attribute names. Make sure to account for already existing attributes. + +**Parameters:** +* $post (WP_Post) – The current post object. +* $context (string|null) - Context regarding where or how the card is rendered. Unsafe. + +--- + ### `apply_filters( 'fictioneer_filter_card_control_icons', $icons, $story_id, $chapter_id )` Filters the intermediate output array of the card control icons inside the `fictioneer_get_card_controls( $story_id, $chapter_id )` function before being rendered. Note that card controls will not be rendered without a story ID. diff --git a/partials/_article-cards.php b/partials/_article-cards.php index b449668a..5d2a24ad 100644 --- a/partials/_article-cards.php +++ b/partials/_article-cards.php @@ -156,8 +156,16 @@ $pag_args = array( $card_classes[] = '_' . get_theme_mod( 'card_style' ); } + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-article-cards' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } + // Start HTML ---> ?> -