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 ---> ?> -
  • +
  • >
    diff --git a/partials/_card-chapter.php b/partials/_card-chapter.php index bde57149..1a391a39 100644 --- a/partials/_card-chapter.php +++ b/partials/_card-chapter.php @@ -63,6 +63,14 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-chapter' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?>
  • >
    diff --git a/partials/_card-collection.php b/partials/_card-collection.php index 3a106668..f2d0fb1c 100644 --- a/partials/_card-collection.php +++ b/partials/_card-collection.php @@ -78,9 +78,17 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-collection' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?> -
  • +
  • >
    diff --git a/partials/_card-hidden.php b/partials/_card-hidden.php index 1a982c36..c74a129e 100644 --- a/partials/_card-hidden.php +++ b/partials/_card-hidden.php @@ -26,9 +26,17 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-hidden' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?> -
  • +
  • >
    diff --git a/partials/_card-page.php b/partials/_card-page.php index 1c4b3764..eb565ea0 100644 --- a/partials/_card-page.php +++ b/partials/_card-page.php @@ -26,9 +26,17 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-page' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?> -
  • +
  • >
    diff --git a/partials/_card-post.php b/partials/_card-post.php index 8177d18c..6619f874 100644 --- a/partials/_card-post.php +++ b/partials/_card-post.php @@ -27,9 +27,17 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-post' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?> -
  • +
  • >
    diff --git a/partials/_card-recommendation.php b/partials/_card-recommendation.php index 0b3e301f..d4d887aa 100644 --- a/partials/_card-recommendation.php +++ b/partials/_card-recommendation.php @@ -55,9 +55,17 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-recommendation' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?> -
  • +
  • >
    diff --git a/partials/_card-story.php b/partials/_card-story.php index 80c3c5f9..17b0ab1f 100644 --- a/partials/_card-story.php +++ b/partials/_card-story.php @@ -54,6 +54,14 @@ if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } +// Card attributes +$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-story' ); +$card_attributes = ''; + +foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; +} + ?>
  • >
    diff --git a/partials/_latest-chapters-compact.php b/partials/_latest-chapters-compact.php index d6b2b210..f7ca9848 100644 --- a/partials/_latest-chapters-compact.php +++ b/partials/_latest-chapters-compact.php @@ -154,9 +154,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( ++$card_counter > $args['count'] ) { break; } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-chapters-compact' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-chapters.php b/partials/_latest-chapters.php index 4e75440d..7f5ddee2 100644 --- a/partials/_latest-chapters.php +++ b/partials/_latest-chapters.php @@ -156,9 +156,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( ++$card_counter > $args['count'] ) { break; } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-chapters' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-recommendations-compact.php b/partials/_latest-recommendations-compact.php index 806771c3..0aa0bb4e 100644 --- a/partials/_latest-recommendations-compact.php +++ b/partials/_latest-recommendations-compact.php @@ -115,9 +115,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-recommendations-compact' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-recommendations.php b/partials/_latest-recommendations.php index 9c30efdd..4feb92f7 100644 --- a/partials/_latest-recommendations.php +++ b/partials/_latest-recommendations.php @@ -134,9 +134,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); $url = $urls[0]; $tuple = explode( '|', $url ); $tuple = array_map( 'trim', $tuple ); + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-recommendations' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-stories-compact.php b/partials/_latest-stories-compact.php index 715b6c61..178cd913 100644 --- a/partials/_latest-stories-compact.php +++ b/partials/_latest-stories-compact.php @@ -139,9 +139,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-stories-compact' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-stories.php b/partials/_latest-stories.php index ec3b6a4a..612566ba 100644 --- a/partials/_latest-stories.php +++ b/partials/_latest-stories.php @@ -131,9 +131,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) { $card_classes[] = '_' . get_theme_mod( 'card_style' ); } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-stories' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index 1ed1707b..75c39abd 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -169,9 +169,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( ++$card_counter > $args['count'] ) { break; } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-updates-compact' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >
    diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index 6a4c820d..8121c29c 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -172,9 +172,17 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); if ( ++$card_counter > $args['count'] ) { break; } + + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-latest-updates' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } ?> -
  • +
  • >