2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Author
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.6.0
|
2023-09-17 18:21:46 +02:00
|
|
|
* @see fictioneer_clause_sticky_stories()
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Get queried author
|
|
|
|
$author_id = get_queried_object_id();
|
|
|
|
$author = get_userdata( $author_id );
|
|
|
|
|
|
|
|
// Return home if not a valid author
|
|
|
|
if (
|
2023-06-12 00:16:05 +02:00
|
|
|
! fictioneer_is_author( $author_id ) ||
|
|
|
|
count_user_posts( $author_id, ['fcn_story', 'fcn_chapter'] ) < 1
|
2023-01-21 01:31:34 +01:00
|
|
|
) {
|
|
|
|
wp_redirect( home_url() );
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
$current_url = get_author_posts_url( $author_id );
|
2023-12-15 17:51:09 +01:00
|
|
|
$current_tab = sanitize_key( $_GET['tab'] ?? '' );
|
2023-06-12 00:16:05 +02:00
|
|
|
$current_page = get_query_var( 'pg', 1 ) ?: 1;
|
2024-04-24 12:17:08 +02:00
|
|
|
$order = fictioneer_sanitize_query_var( $_GET['order'] ?? 0, ['desc', 'asc'], 'desc' );
|
2023-01-21 01:31:34 +01:00
|
|
|
$author_page = get_the_author_meta( 'fictioneer_author_page', $author_id );
|
|
|
|
$author_page = $author_page > 0 ? $author_page : false;
|
2023-06-12 00:16:05 +02:00
|
|
|
$author_statistics = fictioneer_get_author_statistics( $author_id );
|
|
|
|
$max_pages = 1;
|
|
|
|
$tabs = [];
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-06-12 00:16:05 +02:00
|
|
|
// Stories tab
|
2023-01-21 01:31:34 +01:00
|
|
|
$tabs['stories'] = array(
|
|
|
|
'name' => __( 'Stories', 'fictioneer' ),
|
|
|
|
'query_args' => array(
|
2023-09-17 17:36:11 +02:00
|
|
|
'fictioneer_query_name' => 'author_stories',
|
2023-01-21 01:31:34 +01:00
|
|
|
'post_type' => 'fcn_story',
|
|
|
|
'author' => $author_id,
|
2023-08-07 12:07:48 +02:00
|
|
|
'orderby' => 'modified',
|
2023-01-21 01:31:34 +01:00
|
|
|
'paged' => $current_page,
|
2023-11-12 01:16:07 +01:00
|
|
|
'order' => $order
|
2023-01-21 01:31:34 +01:00
|
|
|
),
|
|
|
|
'classes' => [],
|
|
|
|
'empty' => __( 'No stories published yet.', 'fictioneer' )
|
|
|
|
);
|
|
|
|
|
2023-06-12 00:16:05 +02:00
|
|
|
// Chapters tab
|
2023-01-21 01:31:34 +01:00
|
|
|
$tabs['chapters'] = array(
|
|
|
|
'name' => __( 'Chapters', 'fictioneer' ),
|
|
|
|
'query_args' => array(
|
2023-09-17 17:36:11 +02:00
|
|
|
'fictioneer_query_name' => 'author_chapters',
|
2023-01-21 01:31:34 +01:00
|
|
|
'post_type' => 'fcn_chapter',
|
|
|
|
'author' => $author_id,
|
|
|
|
'paged' => $current_page,
|
2023-11-12 01:14:34 +01:00
|
|
|
'order' => $order
|
2023-01-21 01:31:34 +01:00
|
|
|
),
|
|
|
|
'classes' => [],
|
|
|
|
'empty' => __( 'No chapters published yet.', 'fictioneer' )
|
|
|
|
);
|
|
|
|
|
2023-06-12 00:16:05 +02:00
|
|
|
// Recommendations tab
|
2023-09-01 22:45:47 +02:00
|
|
|
if ( user_can( $author_id, 'publish_fcn_recommendations' ) ) {
|
|
|
|
$tabs['recommendations'] = array(
|
|
|
|
'name' => __( 'Recommendations', 'fictioneer' ),
|
|
|
|
'query_args' => array(
|
2023-09-17 17:36:11 +02:00
|
|
|
'fictioneer_query_name' => 'author_recommendations',
|
2023-09-01 22:45:47 +02:00
|
|
|
'post_type' => 'fcn_recommendation',
|
|
|
|
'author' => $author_id,
|
|
|
|
'paged' => $current_page,
|
|
|
|
'order' => $order
|
|
|
|
),
|
|
|
|
'classes' => [],
|
|
|
|
'empty' => __( 'No recommendations published yet.', 'fictioneer' )
|
|
|
|
);
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Use first tab if queried tab is not available
|
2023-08-08 13:38:11 +02:00
|
|
|
if ( ! array_key_exists( $current_tab, $tabs ) ) {
|
|
|
|
$current_tab = array_key_first( $tabs );
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Select tab
|
|
|
|
$tabs[ $current_tab ]['classes'][] = '_current';
|
|
|
|
|
2024-05-17 12:29:52 +02:00
|
|
|
// Header
|
|
|
|
get_header();
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-17 12:29:52 +02:00
|
|
|
?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<main id="main" class="main author-page singular">
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2024-06-14 00:31:31 +02:00
|
|
|
<?php do_action( 'fictioneer_main', 'author' ); ?>
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="main__wrapper">
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php do_action( 'fictioneer_main_wrapper' ); ?>
|
|
|
|
|
|
|
|
<article class="singular__article author-page__article padding-left padding-right padding-top padding-bottom">
|
|
|
|
|
|
|
|
<?php
|
|
|
|
$title = $author_page ? trim( get_the_title( $author_page ) ) : $author->display_name;
|
|
|
|
$title = empty( $title ) ? $author->display_name : $title;
|
|
|
|
$order_link = add_query_arg(
|
|
|
|
array(
|
|
|
|
'tab' => $current_tab,
|
2023-06-12 00:16:05 +02:00
|
|
|
'order' => $order === 'desc' ? 'asc' : 'desc'
|
2023-01-21 01:31:34 +01:00
|
|
|
),
|
|
|
|
$current_url
|
|
|
|
) . '#main';
|
|
|
|
?>
|
|
|
|
|
|
|
|
<header class="singular__header">
|
|
|
|
<h1 class="singular__title"><?php echo $title; ?></h1>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<?php if ( $author_page || ! empty( $author->user_description ) ) : ?>
|
|
|
|
<section class="singular__content author-page__content content-section">
|
|
|
|
<?php
|
|
|
|
if ( $author_page ) {
|
2023-09-26 21:33:35 +02:00
|
|
|
$post = get_post( $author_page );
|
|
|
|
setup_postdata( $post );
|
2023-01-21 01:31:34 +01:00
|
|
|
the_content();
|
2023-09-26 21:33:35 +02:00
|
|
|
wp_reset_postdata();
|
2023-01-21 01:31:34 +01:00
|
|
|
} elseif ( ! empty( $author->user_description ) ) {
|
|
|
|
echo $author->user_description;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</section>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2023-07-31 00:05:38 +02:00
|
|
|
<section class="statistics spacing-top">
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="statistics__inline-stat">
|
|
|
|
<strong><?php _e( 'Stories', 'fictioneer' ); ?></strong>
|
|
|
|
<span><?php echo number_format_i18n( $author_statistics['story_count'] ); ?></span>
|
|
|
|
</div>
|
|
|
|
<div class="statistics__inline-stat">
|
|
|
|
<strong><?php _e( 'Chapters', 'fictioneer' ); ?></strong>
|
|
|
|
<span><?php echo number_format_i18n( $author_statistics['chapter_count'] ); ?></span>
|
|
|
|
</div>
|
|
|
|
<div class="statistics__inline-stat">
|
2024-02-02 19:13:07 +01:00
|
|
|
<strong><?php _ex( 'Words', 'Word count caption in statistics.', 'fictioneer' ); ?></strong>
|
2023-01-21 01:31:34 +01:00
|
|
|
<span><?php echo fictioneer_shorten_number( $author_statistics['word_count'] ); ?></span>
|
|
|
|
</div>
|
|
|
|
<div class="statistics__inline-stat">
|
|
|
|
<strong><?php _e( 'Comments', 'fictioneer' ); ?></strong>
|
|
|
|
<span><?php echo number_format_i18n( $author_statistics['comment_count'] ); ?></span>
|
|
|
|
</div>
|
|
|
|
<div class="statistics__inline-stat">
|
|
|
|
<strong><?php _e( 'Reading', 'fictioneer' ); ?></strong>
|
|
|
|
<span><?php echo fictioneer_get_reading_time_nodes( $author_statistics['word_count'] ); ?></span>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
2023-09-16 02:52:18 +02:00
|
|
|
<section id="tabs" class="scroll-margin-top author-page__tabs tabs-wrapper spacing-top">
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="tabs">
|
|
|
|
<?php foreach ( $tabs as $key => $value ) : ?>
|
2023-06-12 00:16:05 +02:00
|
|
|
<a
|
|
|
|
href="<?php echo esc_url( add_query_arg( array( 'tab' => $key, 'order' => $order ), $current_url ) . '#main'); ?>"
|
|
|
|
class="tabs__item <?php echo implode( ' ', $value['classes'] )?>"
|
|
|
|
><?php echo $value['name']; ?></a>
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php endforeach; ?>
|
|
|
|
</div>
|
|
|
|
<div class="author-page__sorting">
|
|
|
|
<a class="list-button _order <?php echo $order == 'desc' ? '_on' : '_off'; ?>" href="<?php echo esc_url( $order_link ); ?>">
|
|
|
|
<i class="fa-solid fa-arrow-up-short-wide _off"></i>
|
|
|
|
<i class="fa-solid fa-arrow-down-wide-short _on"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// Setup pagination (cannot use main pagination due to different sub-queries)
|
|
|
|
$pag_args = array(
|
|
|
|
'base' => add_query_arg( 'pg', '%#%' ),
|
|
|
|
'format' => '?pg=%#%',
|
|
|
|
'current' => max( 1, $current_page ),
|
|
|
|
'prev_text' => fcntr( 'previous' ),
|
|
|
|
'next_text' => fcntr( 'next' ),
|
2023-06-12 00:16:05 +02:00
|
|
|
'add_args' => $current_tab ? array( 'tab' => $current_tab ) : null,
|
2023-01-21 01:31:34 +01:00
|
|
|
'add_fragment' => '#tabs',
|
|
|
|
'total' => 0
|
|
|
|
);
|
|
|
|
?>
|
|
|
|
|
2024-01-27 00:53:29 +01:00
|
|
|
<section id="list" class="author-page__list container-inline-size">
|
|
|
|
<ul class="card-list _no-mutation-observer">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
$list_items = fictioneer_get_card_list(
|
|
|
|
$tabs[ $current_tab ]['query_args']['post_type'],
|
|
|
|
$tabs[ $current_tab ]['query_args'],
|
|
|
|
$tabs[ $current_tab ]['empty'],
|
2023-06-12 00:16:05 +02:00
|
|
|
array(
|
|
|
|
'show_latest' => true
|
|
|
|
)
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Output list
|
|
|
|
echo $list_items['html'];
|
|
|
|
|
|
|
|
// Update pagination arguments
|
|
|
|
$pag_args['total'] = $list_items['query']->max_num_pages ?? 1;
|
|
|
|
|
|
|
|
// Output pagination
|
|
|
|
if ( $pag_args['total'] > 1 ) {
|
2023-06-09 11:31:40 +02:00
|
|
|
echo '<li class="pagination">' . fictioneer_paginate_links( $pag_args ) . '</li>';
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</ul>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
</article>
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
</main>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// Footer arguments
|
|
|
|
$footer_args = array(
|
|
|
|
'post_type' => null,
|
|
|
|
'post_id' => null,
|
|
|
|
'template' => 'author.php',
|
|
|
|
'breadcrumbs' => array(
|
2023-06-12 13:01:32 +02:00
|
|
|
[fcntr( 'frontpage' ), get_home_url()],
|
2024-06-19 12:15:19 +02:00
|
|
|
[__( 'Author', 'fictioneer' ), $current_url],
|
2023-06-12 13:01:32 +02:00
|
|
|
[$author->display_name, null]
|
2023-01-21 01:31:34 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get footer with breadcrumbs
|
|
|
|
get_footer( null, $footer_args );
|
|
|
|
?>
|