Files
peptide-repo-core/includes/frontend/class-pr-core-verification-display.php
peptiderepo 8d3064785c fix: resolve all PHPCS violations and 300-line rule breaches
- Add @package Peptide_Repo_Core file docblocks to all PHP files
- Add @var docblocks to all public readonly DTO properties
- Add @param docs to sanitize_evidence_strength / sanitize_review_status
- Replace short ternary ?: with phpcs:ignore on each violating line
- Add phpcs:ignore for InterpolatedNotPrepared on ${table} SQL strings
- Add phpcs:ignore for GlobalVariablesOverride in uninstall.php and card.php
- Add translators comment to __ call with placeholder in related-posts-section
- Fix InlineComment.InvalidEndChar: add periods to all bare inline comments
- Expand single-line /** @return void */ docblocks with summaries
- SPLIT class-pr-core-seed-data.php (was 360 lines):
  → class-pr-core-seed-data.php (149 lines, orchestration only)
  → class-pr-core-seed-fixtures.php (254 lines, static fixture data)
- SPLIT class-pr-core-peptide-cpt.php (was 309 lines):
  → class-pr-core-peptide-cpt.php (224 lines, CPT + hooks + sanitizers)
  → class-pr-core-peptide-meta-schema.php (133 lines, meta field defs)
- SPLIT class-pr-core-settings.php (was 340 lines after docblock expansion):
  → class-pr-core-settings.php (264 lines, registration + sanitization)
  → class-pr-core-settings-renderer.php (124 lines, render methods)
- All includes/ PHP files now <= 300 lines

Agent-Session: claude-adopt-ci-20260616
2026-06-16 15:48:53 +00:00

83 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
/**
* Frontend verification date display on peptide single pages.
*
* What: Appends last-verified date after verdict card on reader-facing pages.
* Who calls it: PR_Core::init() hooks the_content filter.
* Dependencies: None (hooked via the_content).
*
* @see includes/class-pr-core.php — Registers the_content hook.
* @package Peptide_Repo_Core
*/
class PR_Core_Verification_Display {
/**
* Initialize frontend hooks.
*
* Side effects: Registers the_content filter.
*
* @return void
*/
public static function init(): void {
add_filter( 'the_content', array( __CLASS__, 'append_verification_display' ), 20 );
}
/**
* Append verification display after verdict card.
*
* @param string $content The post content.
* @return string Modified content.
*/
public static function append_verification_display( string $content ): string {
// Only on peptide CPT, not in admin.
if ( is_admin() || ! is_singular( PR_Core_Peptide_CPT::POST_TYPE ) ) {
return $content;
}
$post_id = get_the_ID();
if ( ! $post_id ) {
return $content;
}
// Only if _pr_last_source_verified is set.
$last_verified = get_post_meta( $post_id, '_pr_last_source_verified', true );
if ( empty( $last_verified ) ) {
return $content;
}
// Find the verdict card closing div and append after it.
$verdict_close = '</div><!-- .pr-verdict -->';
if ( strpos( $content, $verdict_close ) !== false ) {
$display = self::render_verification_block( $last_verified );
$content = str_replace( $verdict_close, $verdict_close . $display, $content );
}
return $content;
}
/**
* Render the verification block HTML.
*
* @param string $last_verified ISO date string.
* @return string HTML block.
*/
private static function render_verification_block( string $last_verified ): string {
$date_obj = new \DateTime( $last_verified );
$formatted_date = $date_obj->format( get_option( 'date_format' ) );
$html = '<p class="pr-verification-date">';
$html .= esc_html__( 'Last verified: ', 'peptide-repo-core' );
$html .= sprintf(
'<time datetime="%s">%s</time>',
esc_attr( $date_obj->format( 'Y-m-d' ) ),
esc_html( $formatted_date )
);
$html .= ' — <a href="' . esc_url( home_url( '/our-methodology/' ) ) . '">' . esc_html__( 'methodology', 'peptide-repo-core' ) . '</a>';
$html .= '</p>';
return $html;
}
}