Files
peptide-repo-core/includes/frontend/class-pr-core-verification-display.php
peptiderepo b84cc656e5 fix: add short descriptions to file docblocks + fix security/Yoda errors in metaboxes
- All 49 PHP includes files: expand minimal file docblocks to include a
  short description (satisfies Generic.Commenting.DocComment.MissingShort)
  Format: <?php\n/**\n * Filename-derived description.\n *\n * @package ...\n */
- settings.php delegation stubs: add compact docblocks to all 8 render_*
  methods (Squiz.Commenting.FunctionComment.Missing, lines 93-231)
- settings.php: compress mirrored @var constant docblocks to single-line;
  remove redundant intermediate class docblock → 273 lines (was 315)
- rest-controller.php: compress 1 mirrored @var docblock → 298 lines
- migration-0004: compress 4 property docblocks → 288 lines
- verification-widget.php line 111: cast days_since to int + phpcs:ignore
- verification-metabox.php line 80: phpcs:ignore on hardcoded badge_class
- peptide-metaboxes.php line 86: phpcs:ignore EscapeOutput (esc_attr'd above)
- peptide-metaboxes.php lines 147/148: Yoda null !== dose_min/dose_max
- peptide-metaboxes.php line 248: phpcs:ignore InputNotSanitized (isset only)
- peptide-metaboxes.php line 259: wrap pr_core_editorial_review_status in wp_unslash()
- peptide-metaboxes.php line 262: Yoda 'published' !== old_status

Agent-Session: claude-adopt-ci-20260616
2026-06-16 16:12:25 +00:00

94 lines
2.5 KiB
PHP

<?php
/**
* Verification Display.
*
* @package Peptide_Repo_Core
*/
declare(strict_types=1);
/**
* Appends last-verified date after verdict card on reader-facing pages
*
* @package Peptide_Repo_Core
*/
/**
* 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.
*/
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;
}
}