Extend fictioneer_post_{*} action hooks

This commit is contained in:
Tetrakern 2024-10-14 11:36:10 +02:00
parent 071157d5dd
commit 69d8f77432
6 changed files with 82 additions and 31 deletions

View File

@ -816,37 +816,61 @@ Fires after opening the `.main-navigation__wrapper` container in the `_navigatio
--- ---
### `do_action( 'fictioneer_post_after_content', $post_id )` ### `do_action( 'fictioneer_post_after_content', $post_id, $args )`
Fires between the article content and featured list (if any) in the `single-post.php` template. 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:** **Parameters:**
* $post_id (int) Current post ID. * $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:** **Hooked Actions:**
* `fictioneer_post_tags( $post_id )` Tags of the post. Priority 10. * `fictioneer_post_tags( $post_id, $args )` Tags of the post. Priority 10.
* `fictioneer_post_featured_list( $post_id )` Items featured in the post. Priority 20. * `fictioneer_post_featured_list( $post_id, $args )` Items featured in the post. Priority 20.
--- ---
### `do_action( 'fictioneer_post_footer_left', $post_id )` ### `do_action( 'fictioneer_post_footer_left', $post_id, $args )`
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. 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:** **Parameters:**
* $post_id (int) Current post ID. * $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:** **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 )` ### `do_action( 'fictioneer_post_footer_right', $post_id, $args )`
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. 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:** **Parameters:**
* $post_id (int) Current post ID. * $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:** **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.
--- ---

View File

@ -1643,7 +1643,7 @@ function fictioneer_shortcode_blog( $attr ) {
<?php <?php
while ( $blog_query->have_posts() ) { while ( $blog_query->have_posts() ) {
$blog_query->the_post(); $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(); wp_reset_postdata();

View File

@ -8,11 +8,18 @@
* Outputs the HTML for the post tags * Outputs the HTML for the post tags
* *
* @since 5.0.0 * @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 // Setup
$tags = get_the_tags( $post_id ); $tags = get_the_tags( $post_id );
@ -27,7 +34,7 @@ function fictioneer_post_tags( $post_id ) {
</section> </section>
<?php // <--- End HTML <?php // <--- End HTML
} }
add_action( 'fictioneer_post_after_content', 'fictioneer_post_tags', 10 ); add_action( 'fictioneer_post_after_content', 'fictioneer_post_tags', 10, 2 );
// ============================================================================= // =============================================================================
// FEATURED // FEATURED
@ -37,11 +44,18 @@ add_action( 'fictioneer_post_after_content', 'fictioneer_post_tags', 10 );
* Outputs the HTML for featured items in the post * Outputs the HTML for featured items in the post
* *
* @since 5.0.0 * @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_featured_list( $post_id ) { function fictioneer_post_featured_list( $post_id, $args ) {
// Check render context
if ( ( $args['context'] ?? 0 ) !== 'single-post' ) {
return;
}
global $post; global $post;
// Abort if... // Abort if...
@ -106,7 +120,7 @@ function fictioneer_post_featured_list( $post_id ) {
</section> </section>
<?php // <--- End HTML <?php // <--- End HTML
} }
add_action( 'fictioneer_post_after_content', 'fictioneer_post_featured_list', 20 ); add_action( 'fictioneer_post_after_content', 'fictioneer_post_featured_list', 20, 2 );
// ============================================================================= // =============================================================================
// POST MEDIA BUTTONS // POST MEDIA BUTTONS
@ -116,18 +130,22 @@ add_action( 'fictioneer_post_after_content', 'fictioneer_post_featured_list', 20
* Outputs the HTML for the post media buttons * Outputs the HTML for the post media buttons
* *
* @since 5.0.0 * @since 5.0.0
* @since 5.25.0 - Added parameters.
*
* @param int $post_id The post ID.
* @param array $args Additional arguments.
*/ */
function fictioneer_post_media_buttons() { function fictioneer_post_media_buttons( $post_id, $args ) {
// Abort if... // Abort if...
if ( post_password_required() ) { if ( post_password_required() || ( $args['context'] ?? 0 ) !== 'single-post' ) {
return; return;
} }
// Render media buttons // Render media buttons
echo fictioneer_get_media_buttons(); echo fictioneer_get_media_buttons();
} }
add_action( 'fictioneer_post_footer_left', 'fictioneer_post_media_buttons', 10 ); add_action( 'fictioneer_post_footer_left', 'fictioneer_post_media_buttons', 10, 2 );
// ============================================================================= // =============================================================================
// POST SUBSCRIBE BUTTONS // POST SUBSCRIBE BUTTONS
@ -137,11 +155,15 @@ add_action( 'fictioneer_post_footer_left', 'fictioneer_post_media_buttons', 10 )
* Outputs the HTML for the post subscribe button with popup menu * Outputs the HTML for the post subscribe button with popup menu
* *
* @since 5.0.0 * @since 5.0.0
* @since 5.25.0 - Added parameters.
*
* @param int $post_id The post ID.
* @param array $args Additional arguments.
*/ */
function fictioneer_post_subscribe_button() { function fictioneer_post_subscribe_button( $post_id, $args ) {
// Abort if... // Abort if...
if ( post_password_required() ) { if ( post_password_required() || ( $args['context'] ?? 0 ) !== 'single-post' ) {
return; return;
} }
@ -157,4 +179,4 @@ function fictioneer_post_subscribe_button() {
<?php // <--- End HTML <?php // <--- End HTML
} }
} }
add_action( 'fictioneer_post_footer_right', 'fictioneer_post_subscribe_button', 10 ); add_action( 'fictioneer_post_footer_right', 'fictioneer_post_subscribe_button', 10, 2 );

View File

@ -22,7 +22,7 @@ defined( 'ABSPATH' ) OR exit;
<?php <?php
while ( have_posts() ) { while ( have_posts() ) {
the_post(); the_post();
get_template_part( 'partials/_post' ); get_template_part( 'partials/_post', null, array( 'context' => 'loop' ) );
} }
$pag_args = array( $pag_args = array(

View File

@ -10,7 +10,8 @@
* @since 2.0 * @since 2.0
* @see partials/_loop.php * @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 (
<article id="post-<?php echo $post_id; ?>" class="post"> <article id="post-<?php echo $post_id; ?>" class="post">
<header class="post__header"> <header class="post__header">
<?php do_action( 'fictioneer_post_header_open', $post_id, $args ); ?>
<h2 class="post__title h1"><a href="<?php the_permalink(); ?>"><?php echo $title; ?></a></h2> <h2 class="post__title h1"><a href="<?php the_permalink(); ?>"><?php echo $title; ?></a></h2>
<div class="post__meta layout-links"><?php echo fictioneer_get_post_meta_items(); ?></div> <div class="post__meta layout-links"><?php echo fictioneer_get_post_meta_items(); ?></div>
</header> </header>
<section class="post__main content-section"><?php echo $content; ?></section> <section class="post__main content-section"><?php echo $content; ?></section>
<?php if ( has_action( 'fictioneer_blog_posts_footers_left' ) || has_action( 'fictioneer_blog_posts_footers_right' ) ) : ?> <?php do_action( 'fictioneer_post_after_content', $post_id, $args ); ?>
<?php if ( has_action( 'fictioneer_post_footer_left' ) || has_action( 'fictioneer_post_footer_right' ) ) : ?>
<footer class="post__footer"> <footer class="post__footer">
<div class="post__footer-box post__footer-left"> <div class="post__footer-box post__footer-left">
<?php do_action( 'fictioneer_blog_posts_footers_left', $post_id ); ?> <?php do_action( 'fictioneer_post_footer_left', $post_id, $args ); ?>
</div> </div>
<div class="post__footer-box post__footer-right"> <div class="post__footer-box post__footer-right">
<?php do_action( 'fictioneer_blog_posts_footers_right', $post_id ); ?> <?php do_action( 'fictioneer_post_footer_right', $post_id, $args ); ?>
</div> </div>
</footer> </footer>
<?php endif; ?> <?php endif; ?>

View File

@ -35,21 +35,22 @@ get_header();
<article id="post-<?php the_ID(); ?>" class="post__article"> <article id="post-<?php the_ID(); ?>" class="post__article">
<header class="post__header"> <header class="post__header">
<?php do_action( 'fictioneer_post_header_open', $post_id, array( 'context' => 'single-post' ) ); ?>
<h1 class="post__title"><?php echo $title; ?></h1> <h1 class="post__title"><?php echo $title; ?></h1>
<div class="post__meta layout-links"><?php echo fictioneer_get_post_meta_items(); ?></div> <div class="post__meta layout-links"><?php echo fictioneer_get_post_meta_items(); ?></div>
</header> </header>
<section class="post__main content-section"><?php the_content(); ?></section> <section class="post__main content-section"><?php the_content(); ?></section>
<?php do_action( 'fictioneer_post_after_content', $post->ID ); ?> <?php do_action( 'fictioneer_post_after_content', $post->ID, array( 'context' => 'single-post' ) ); ?>
<?php if ( ! $password_required && ( has_action( 'fictioneer_post_footer_left' ) || has_action( 'fictioneer_post_footer_right' ) ) ) : ?> <?php if ( ! $password_required && ( has_action( 'fictioneer_post_footer_left' ) || has_action( 'fictioneer_post_footer_right' ) ) ) : ?>
<footer class="post__footer"> <footer class="post__footer">
<div class="post__footer-box post__footer-left"> <div class="post__footer-box post__footer-left">
<?php do_action( 'fictioneer_post_footer_left', $post->ID ); ?> <?php do_action( 'fictioneer_post_footer_left', $post->ID, array( 'context' => 'single-post' ) ); ?>
</div> </div>
<div class="post__footer-box post__footer-right"> <div class="post__footer-box post__footer-right">
<?php do_action( 'fictioneer_post_footer_right', $post->ID ); ?> <?php do_action( 'fictioneer_post_footer_right', $post->ID, array( 'context' => 'single-post' ) ); ?>
</div> </div>
</footer> </footer>
<?php endif; ?> <?php endif; ?>