Reduce yet more unnecessary get_the_ID calls

This commit is contained in:
Tetrakern 2023-12-02 11:58:58 +01:00
parent ca5b57aeec
commit eeeb2fdcee
14 changed files with 58 additions and 41 deletions

View File

@ -15,6 +15,7 @@
<?php
// Setup
$post_id = get_the_ID();
$page = get_query_var( 'paged', 1 ) ?: 1; // Main query
$order = array_intersect( [sanitize_key( $_GET['order'] ?? 0 )], ['desc', 'asc'] );
$order = reset( $order ) ?: 'desc';
@ -50,7 +51,7 @@ $query_args = array(
$query_args = fictioneer_append_date_query( $query_args, $ago, $orderby );
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_chapters_query_args', $query_args, get_the_ID() );
$query_args = apply_filters( 'fictioneer_filter_chapters_query_args', $query_args, $post_id );
// Query chapters
$list_of_chapters = new WP_Query( $query_args );
@ -77,12 +78,12 @@ if ( function_exists( 'update_post_author_caches' ) ) {
// Setup
$title = trim( get_the_title() );
$breadcrumb_name = empty( $title ) ? __( 'Chapters', 'fictioneer' ) : $title;
$this_breadcrumb = [$breadcrumb_name, get_the_permalink()];
$this_breadcrumb = [ $breadcrumb_name, get_the_permalink() ];
// Arguments for hooks and templates/etc.
$hook_args = array(
'current_page' => $page,
'post_id' => get_the_ID(),
'post_id' => $post_id,
'chapters' => $list_of_chapters,
'queried_type' => 'fcn_chapter',
'query_args' => $query_args,
@ -92,7 +93,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
);
?>
<article id="singular-<?php the_ID(); ?>" class="singular__article chapters__article padding-top padding-left padding-right padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article chapters__article padding-top padding-left padding-right padding-bottom">
<?php if ( ! empty( $title ) ) : ?>
<header class="singular__header stories__header">
@ -118,7 +119,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => get_the_ID(),
'post_id' => $post_id,
'current_page' => $page,
'chapters' => $list_of_chapters,
'breadcrumbs' => array(

View File

@ -15,6 +15,7 @@
<?php
// Setup
$post_id = get_the_ID();
$page = get_query_var( 'paged', 1 ) ?: 1; // Main query
$order = array_intersect( [sanitize_key( $_GET['order'] ?? 0 )], ['desc', 'asc'] );
$order = reset( $order ) ?: 'desc';
@ -39,7 +40,7 @@ $query_args = array (
$query_args = fictioneer_append_date_query( $query_args, $ago, $orderby );
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_collections_query_args', $query_args, get_the_ID() );
$query_args = apply_filters( 'fictioneer_filter_collections_query_args', $query_args, $post_id );
// Query collections
$list_of_collections = new WP_Query( $query_args );
@ -66,12 +67,12 @@ if ( function_exists( 'update_post_author_caches' ) ) {
// Setup
$title = trim( get_the_title() );
$breadcrumb_name = empty( $title ) ? __( 'Collections', 'fictioneer' ) : $title;
$this_breadcrumb = [$breadcrumb_name, get_the_permalink()];
$this_breadcrumb = [ $breadcrumb_name, get_the_permalink() ];
// Arguments for hooks and templates/etc.
$hook_args = array(
'current_page' => $page,
'post_id' => get_the_ID(),
'post_id' => $post_id,
'collections' => $list_of_collections,
'queried_type' => 'fcn_collection',
'query_args' => $query_args,
@ -81,7 +82,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
);
?>
<article id="singular-<?php the_ID(); ?>" class="singular__article collections__article padding-top padding-left padding-right padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article collections__article padding-top padding-left padding-right padding-bottom">
<?php if ( ! empty( $title ) ) : ?>
<header class="singular__header stories__header">
@ -107,7 +108,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => get_the_ID(),
'post_id' => $post_id,
'current_page' => $page,
'collections' => $list_of_collections,
'breadcrumbs' => array(

View File

@ -24,7 +24,7 @@ function fictioneer_allowed_orderby() {
if ( ! function_exists( 'fictioneer_get_card_list' ) ) {
/**
* Returns the query and HTML list items for a post type.
* Returns the query and HTML list items for a post type
*
* @since Fictioneer 5.0
*
@ -131,10 +131,11 @@ if ( ! function_exists( 'fictioneer_get_card_list' ) ) {
while ( $query->have_posts() ) {
$query->the_post();
$card_post_id = get_the_ID();
switch ( $post_type ) {
case 'fcn_story':
if ( get_post_meta( get_the_ID(), 'fictioneer_story_hidden', true ) ) {
if ( get_post_meta( $card_post_id, 'fictioneer_story_hidden', true ) ) {
get_template_part( 'partials/_card-hidden', null, $the_card_args );
} else {
get_template_part( $card_partial, null, $the_card_args );
@ -142,8 +143,8 @@ if ( ! function_exists( 'fictioneer_get_card_list' ) ) {
break;
case 'fcn_chapter':
if (
get_post_meta( get_the_ID(), 'fictioneer_chapter_hidden', true ) ||
get_post_meta( get_the_ID(), 'fictioneer_chapter_no_chapter', true )
get_post_meta( $card_post_id, 'fictioneer_chapter_hidden', true ) ||
get_post_meta( $card_post_id, 'fictioneer_chapter_no_chapter', true )
) {
get_template_part( 'partials/_card-hidden', null, $the_card_args );
} else {

View File

@ -361,10 +361,10 @@ function fictioneer_output_rss( $post_id = null ) {
$title = sprintf(
_x( '%1$s - %2$s Chapters', 'Story Feed: [Site] - [Story] Chapters.', 'fictioneer' ),
get_bloginfo( 'name' ),
get_the_title( get_the_ID() )
get_the_title( $post_id )
);
$url = esc_url( add_query_arg( 'story_id', get_the_ID(), home_url( 'feed/rss-chapters' ) ) );
$url = esc_url( add_query_arg( 'story_id', $post_id, home_url( 'feed/rss-chapters' ) ) );
$rss_link = '<link rel="alternate" type="application/rss+xml" title="' . $title . '" href="' . $url . '" />';
}

View File

@ -132,6 +132,7 @@ function fictioneer_change_submit_field( $submit_field, $args ) {
remove_filter( 'cancel_comment_reply_link', '__return_empty_string' );
// Setup
$post_id = get_the_ID();
$close_bottom_container = is_user_logged_in() ? '' : '</div>';
$is_ajax = get_option( 'fictioneer_enable_ajax_comment_form' ) || get_option( 'fictioneer_enable_ajax_comments' );
$hidden = FICTIONEER_COLLAPSE_COMMENT_FORM ? 'hidden' : '';
@ -196,7 +197,7 @@ function fictioneer_change_submit_field( $submit_field, $args ) {
return sprintf(
$close_bottom_container . '<div class="form-submit fictioneer-respond__form-actions ' . $hidden . '"><div class="fictioneer-respond__form-actions-wrapper">' . $private_toggle . $notification_toggle . '%1$s %2$s</div>%3$s</div><div class="fictioneer-respond__notices">' . $private_notice . '</div>',
$submit_button,
get_the_ID() ? get_comment_id_fields( get_the_ID() ) : ( $parent_field . $comment_post_id ),
$post_id ? get_comment_id_fields( $post_id ) : ( $parent_field . $comment_post_id ),
preg_replace( '/<a/', '<a class="button _secondary"', get_cancel_comment_reply_link( 'Cancel' ) )
);
}

View File

@ -19,16 +19,20 @@ function fictioneer_add_fiction_css() {
* removes any "<" for good measure since CSS does not use it.
*/
$post_id = get_the_ID();
$custom_css = '';
$custom_css .= get_post_meta( get_the_ID(), 'fictioneer_custom_css', true );
$custom_css .= get_post_meta( $post_id, 'fictioneer_custom_css', true );
if ( get_post_type( get_the_ID() ) == 'fcn_story' ) {
$custom_css .= get_post_meta( get_the_ID(), 'fictioneer_story_css', true );
if ( get_post_type( $post_id ) == 'fcn_story' ) {
$custom_css .= get_post_meta( $post_id, 'fictioneer_story_css', true );
}
if ( get_post_type( get_the_ID() ) == 'fcn_chapter' ) {
$story_id = get_post_meta( get_the_ID(), 'fictioneer_chapter_story', true );
$custom_css .= get_post_meta( $story_id, 'fictioneer_story_css', true );
if ( get_post_type( $post_id ) == 'fcn_chapter' ) {
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
if ( ! empty( $story_id ) ) {
$custom_css .= get_post_meta( $story_id, 'fictioneer_story_css', true );
}
}
if ( ! empty( $custom_css ) && ! preg_match( '#</?\w+#', $custom_css ) ) {

View File

@ -20,7 +20,8 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$title = fictioneer_get_safe_title( get_the_ID() );
$post_id = get_the_ID();
$title = fictioneer_get_safe_title( $post_id );
$label = esc_attr( sprintf( _x( 'Continue reading %s', 'Read more link aria label', 'fictioneer' ), $title ) );
$nested = $args['nested'] ?? false;
@ -47,10 +48,10 @@ if (
<?php if ( has_action( 'fictioneer_blog_posts_footers_left' ) || has_action( 'fictioneer_blog_posts_footers_right' ) ) : ?>
<footer class="post__footer">
<div class="post__footer-box post__footer-left">
<?php do_action( 'fictioneer_blog_posts_footers_left', get_the_ID() ); ?>
<?php do_action( 'fictioneer_blog_posts_footers_left', $post_id ); ?>
</div>
<div class="post__footer-box post__footer-right">
<?php do_action( 'fictioneer_blog_posts_footers_right', get_the_ID() ); ?>
<?php do_action( 'fictioneer_blog_posts_footers_right', $post_id ); ?>
</div>
</footer>
<?php endif; ?>

View File

@ -18,9 +18,10 @@
defined( 'ABSPATH' ) OR exit;
// Setup
$post_id = get_the_ID();
$feed = fictioneer_get_rss_link();
$show_feed = get_post_type() !== 'fcn_story' ||
( get_post_type() === 'fcn_story' && get_post_meta( get_the_ID(), 'fictioneer_story_status', true ) !== 'Oneshot' )
( get_post_type() === 'fcn_story' && get_post_meta( $post_id, 'fictioneer_story_status', true ) !== 'Oneshot' );
?>
@ -36,7 +37,7 @@ $show_feed = get_post_type() !== 'fcn_story' ||
<?php $feed_url = urlencode( $feed ); ?>
<?php if ( get_post_type() === 'fcn_story' && ! get_post_meta( get_the_ID(), 'fictioneer_story_hidden', true ) ) : ?>
<?php if ( get_post_type() === 'fcn_story' && ! get_post_meta( $post_id, 'fictioneer_story_hidden', true ) ) : ?>
<a
href="<?php echo $feed; ?>"
class="rss-link tooltipped media-buttons__item"

View File

@ -82,7 +82,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
);
?>
<article id="singular-<?php the_ID(); ?>" class="singular__article recommendations__article padding-top padding-left padding-right padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article recommendations__article padding-top padding-left padding-right padding-bottom">
<?php if ( ! empty( $title ) ) : ?>
<header class="singular__header recommendations__header">

View File

@ -30,7 +30,7 @@ get_header( null, array( 'type' => 'fcn_recommendation' ) );
<?php
// Setup
$title = fictioneer_get_safe_title( $post->ID );
$this_breadcrumb = [$title, get_the_permalink()];
$this_breadcrumb = [ $title, get_the_permalink() ];
// Arguments for hooks and templates/etc.
$hook_args = array(

View File

@ -41,7 +41,7 @@ get_header( null, $header_args );
$story_id = $post->ID;
$story = fictioneer_get_story_data( $post->ID );
$epub_name = sanitize_file_name( strtolower( get_the_title() ) );
$this_breadcrumb = [$story['title'], get_the_permalink()];
$this_breadcrumb = [ $story['title'], get_the_permalink() ];
$password_note = fictioneer_get_content_field( 'fictioneer_story_password_note', $post->ID );
// Flags

View File

@ -11,6 +11,9 @@
<?php
// Setup
$post_id = get_the_ID();
// Header
get_header();
@ -27,11 +30,11 @@ get_header();
<?php
// Setup
$title = fictioneer_get_safe_title( get_the_ID() );
$this_breadcrumb = [$title, get_the_permalink()];
$title = fictioneer_get_safe_title( $post_id );
$this_breadcrumb = [ $title, get_the_permalink() ];
?>
<article id="singular-<?php the_ID(); ?>" class="singular__article padding-left padding-right padding-top padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article padding-left padding-right padding-top padding-bottom">
<section class="singular__content content-section"><?php the_content(); ?></section>
@ -55,7 +58,7 @@ get_header();
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => get_the_ID(),
'post_id' => $post_id,
'breadcrumbs' => array(
[fcntr( 'frontpage' ), get_home_url()]
)

View File

@ -11,6 +11,9 @@
<?php
// Setup
$post_id = get_the_ID();
// Header
get_header();
@ -27,11 +30,11 @@ get_header();
<?php
// Setup
$title = fictioneer_get_safe_title( get_the_ID() );
$title = fictioneer_get_safe_title( $post_id );
$this_breadcrumb = [$title, get_the_permalink()];
?>
<article id="singular-<?php the_ID(); ?>" class="singular__article padding-left padding-right padding-top padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article padding-left padding-right padding-top padding-bottom">
<header class="singular__header">
<h1 class="singular__title"><?php echo $title; ?></h1>
@ -59,7 +62,7 @@ get_header();
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => get_the_ID(),
'post_id' => $post_id,
'breadcrumbs' => array(
[fcntr( 'frontpage' ), get_home_url()]
)

View File

@ -16,6 +16,7 @@
<?php
// Setup
$post_id = get_the_ID();
$page = get_query_var( 'paged', 1 ) ?: 1; // Main query
$order = array_intersect( [sanitize_key( $_GET['order'] ?? 0 )], ['desc', 'asc'] );
$order = reset( $order ) ?: 'desc';
@ -57,7 +58,7 @@ if ( FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER && $orderby === 'modified' ) {
$query_args = fictioneer_append_date_query( $query_args, $ago, $orderby );
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_stories_query_args', $query_args, get_the_ID() );
$query_args = apply_filters( 'fictioneer_filter_stories_query_args', $query_args, $post_id );
// Query stories
$list_of_stories = new WP_Query( $query_args );
@ -99,7 +100,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
);
?>
<article id="singular-<?php the_ID(); ?>" class="singular__article stories__article padding-top padding-left padding-right padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article stories__article padding-top padding-left padding-right padding-bottom">
<?php if ( ! empty( $title ) ) : ?>
<header class="singular__header stories__header">
@ -128,7 +129,7 @@ if ( function_exists( 'update_post_author_caches' ) ) {
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => $post->ID,
'post_id' => $post_id,
'current_page' => $page,
'stories' => $list_of_stories,
'breadcrumbs' => array(