From 69d8f77432b4583a244eb23eb7f9aecf144427bd Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Mon, 14 Oct 2024 11:36:10 +0200 Subject: [PATCH] Extend fictioneer_post_{*} action hooks --- ACTIONS.md | 44 +++++++++++++++++------ includes/functions/_setup-shortcodes.php | 2 +- includes/functions/hooks/_post_hooks.php | 46 +++++++++++++++++------- partials/_loop.php | 2 +- partials/_post.php | 12 ++++--- single-post.php | 7 ++-- 6 files changed, 82 insertions(+), 31 deletions(-) diff --git a/ACTIONS.md b/ACTIONS.md index 0ec3355c..0bbedec9 100644 --- a/ACTIONS.md +++ b/ACTIONS.md @@ -816,37 +816,61 @@ Fires after opening the `.main-navigation__wrapper` container in the `_navigatio --- -### `do_action( 'fictioneer_post_after_content', $post_id )` -Fires between the article content and featured list (if any) in the `single-post.php` template. +### `do_action( 'fictioneer_post_after_content', $post_id, $args )` +Fires right after the article content in the `_post.php` partial and `single-post.php` template. Mind the render context, which can be `'loop'`, `'shortcode_fictioneer_blog'`, or `'single-post'`. **Parameters:** * $post_id (int) – Current post ID. +**$args:** +* `context` (string) – Render context of the partial. +* `nested` (boolean|null) – Optional. Whether the post is nested inside another query. + **Hooked Actions:** -* `fictioneer_post_tags( $post_id )` – Tags of the post. Priority 10. -* `fictioneer_post_featured_list( $post_id )` – Items featured in the post. Priority 20. +* `fictioneer_post_tags( $post_id, $args )` – Tags of the post. Priority 10. +* `fictioneer_post_featured_list( $post_id, $args )` – Items featured in the post. Priority 20. --- -### `do_action( 'fictioneer_post_footer_left', $post_id )` -Fires inside the `.post__footer-left` container within the article footer in the `single-post.php` template. Normally includes the sharing modal toggle and feed links. +### `do_action( 'fictioneer_post_footer_left', $post_id, $args )` +Fires inside the `.post__footer-left` container within the article footer in the `_post.php` partial and `single-post.php` template. Mind the render context, which can be `'loop'`, `'shortcode_fictioneer_blog'`, or `'single-post'`. **Parameters:** * $post_id (int) – Current post ID. +**$args:** +* `context` (string) – Render context of the partial. +* `nested` (boolean|null) – Optional. Whether the post is nested inside another query. + **Hooked Actions:** -* `fictioneer_post_media_buttons()` – Buttons for sharing and webfeeds. Priority 10. +* `fictioneer_post_media_buttons( $post_id, $args )` – Buttons for sharing and webfeeds. Priority 10. --- -### `do_action( 'fictioneer_post_footer_right', $post_id )` -Fires inside the `.post__footer-right` container within the article footer in the `single-post.php` template. Normally includes the subscribe button with popup menu. +### `do_action( 'fictioneer_post_footer_right', $post_id, $args )` +Fires inside the `.post__footer-right` container within the article footer in the `_post.php` partial and `single-post.php` template. Mind the render context, which can be `'loop'`, `'shortcode_fictioneer_blog'`, or `'single-post'`. **Parameters:** * $post_id (int) – Current post ID. +**$args:** +* `context` (string) – Render context of the partial. +* `nested` (boolean|null) – Optional. Whether the post is nested inside another query. + **Hooked Actions:** -* `fictioneer_post_subscribe_button()` – Subscription popup menu. Priority 10. +* `fictioneer_post_subscribe_button( $post_id, $args )` – Subscription popup menu. Priority 10. + +--- + +### `do_action( 'fictioneer_post_header_open', $post_id, $args )` +Fires right after the post header is opened in the `_post.php` partial and `single-post.php` template, before anything else is rendered. Mind the render context, which can be `'loop'`, `'shortcode_fictioneer_blog'`, or `'single-post'`. + +**Parameter:** +* $post_id (int) – The ID of the post. + +**$args:** +* `context` (string) – Render context of the partial. +* `nested` (boolean|null) – Optional. Whether the post is nested inside another query. --- diff --git a/includes/functions/_setup-shortcodes.php b/includes/functions/_setup-shortcodes.php index feecfef2..7839d159 100644 --- a/includes/functions/_setup-shortcodes.php +++ b/includes/functions/_setup-shortcodes.php @@ -1643,7 +1643,7 @@ function fictioneer_shortcode_blog( $attr ) { have_posts() ) { $blog_query->the_post(); - get_template_part( 'partials/_post', null, array( 'nested' => true ) ); + get_template_part( 'partials/_post', null, array( 'nested' => true, 'context' => 'shortcode_fictioneer_blog' ) ); } wp_reset_postdata(); diff --git a/includes/functions/hooks/_post_hooks.php b/includes/functions/hooks/_post_hooks.php index b38074ac..aaca337f 100644 --- a/includes/functions/hooks/_post_hooks.php +++ b/includes/functions/hooks/_post_hooks.php @@ -8,11 +8,18 @@ * Outputs the HTML for the post tags * * @since 5.0.0 + * @since 5.25.0 - Added $args. * - * @param int $post_id The post ID. + * @param int $post_id The post ID. + * @param array $args Additional arguments. */ -function fictioneer_post_tags( $post_id ) { +function fictioneer_post_tags( $post_id, $args ) { + // Check render context + if ( ( $args['context'] ?? 0 ) !== 'single-post' ) { + return; + } + // Setup $tags = get_the_tags( $post_id ); @@ -27,7 +34,7 @@ function fictioneer_post_tags( $post_id ) { 'loop' ) ); } $pag_args = array( diff --git a/partials/_post.php b/partials/_post.php index 93fa480b..2d4c848e 100644 --- a/partials/_post.php +++ b/partials/_post.php @@ -10,7 +10,8 @@ * @since 2.0 * @see partials/_loop.php * - * @internal $args['nested'] Whether the post is nested inside another query. Default null. + * @internal $args['nested'] Whether the post is nested inside another query. Default null. + * @internal $args['context'] Render context of the partial ('loop' or 'shortcode_fictioneer_blog'). */ @@ -36,19 +37,22 @@ if (
+

- + + + diff --git a/single-post.php b/single-post.php index 14425934..550c6f1c 100644 --- a/single-post.php +++ b/single-post.php @@ -35,21 +35,22 @@ get_header();
+ 'single-post' ) ); ?>

- ID ); ?> + ID, array( 'context' => 'single-post' ) ); ?>