Adopt reusable CI standard + PHPUnit conversion (#22)

Squash-merge of PR #22: adopt shared reusable CI workflow, convert PHPUnit to stubs, update branch-protection contexts.

QA-approved at 05d8094a1d. All required CI checks green.

Agent-Session: 2026-06-17-prcore-ci-deploy
This commit is contained in:
peptiderepo
2026-06-17 01:12:00 +07:00
committed by GitHub
parent d0b5875fd8
commit 665d7fa9e1
72 changed files with 4604 additions and 1212 deletions

View File

@@ -1,11 +1,24 @@
<?php
/**
* Jsonld.
*
* @package Peptide_Repo_Core
*/
declare(strict_types=1);
/**
* Integrates Drug, MedicalWebPage, and FAQPage schema into Yoast's graph
*
* @package Peptide_Repo_Core
*/
/**
* JSON-LD / schema.org structured data emission for peptide pages.
*
* What: Integrates Drug, MedicalWebPage, and FAQPage schema into Yoast's graph
* on single peptide pages. When Yoast is inactive, emits a standalone
*
* @graph block via wp_head as a fallback.
*
* Who calls it: PR_Core::init() calls register_hooks(). Yoast hooks fire on
@@ -34,13 +47,25 @@ declare(strict_types=1);
*/
class PR_Core_Jsonld {
/** @var PR_Core_Jsonld_Drug Drug piece builder. */
/**
* Drug piece builder.
*
* @var PR_Core_Jsonld_Drug Drug piece builder.
*/
private PR_Core_Jsonld_Drug $drug_builder;
/** @var PR_Core_Jsonld_Webpage MedicalWebPage enricher. */
/**
* MedicalWebPage enricher.
*
* @var PR_Core_Jsonld_Webpage MedicalWebPage enricher.
*/
private PR_Core_Jsonld_Webpage $webpage_enricher;
/** @var PR_Core_Jsonld_Faq FAQ piece builder. */
/**
* FAQ piece builder.
*
* @var PR_Core_Jsonld_Faq FAQ piece builder.
*/
private PR_Core_Jsonld_Faq $faq_builder;
/**
@@ -67,19 +92,19 @@ class PR_Core_Jsonld {
*/
public function register_hooks(): void {
// wpseo_schema_webpage_type: retype WebPage -> MedicalWebPage on peptide singles.
add_filter( 'wpseo_schema_webpage_type', [ $this->webpage_enricher, 'retype_to_medical_webpage' ] );
add_filter( 'wpseo_schema_webpage_type', array( $this->webpage_enricher, 'retype_to_medical_webpage' ) );
// wpseo_schema_graph: two callbacks at different priorities.
// Priority 11 -- enrich_webpage_piece: merge lastReviewed/reviewedBy/audience into the
// existing WebPage node that Yoast already emitted.
// Priority 11 -- enrich_webpage_piece: merge lastReviewed/reviewedBy/audience into the.
// existing WebPage node that Yoast already emitted.
// Priority 12 -- inject_graph_nodes: append Drug + FAQPage arrays to the graph.
// Must run after enrich_webpage_piece so the WebPage node is already
// enriched before Drug/FAQ are appended.
add_filter( 'wpseo_schema_graph', [ $this->webpage_enricher, 'enrich_webpage_piece' ], 11, 2 );
add_filter( 'wpseo_schema_graph', [ $this, 'inject_graph_nodes' ], 12, 2 );
// Must run after enrich_webpage_piece so the WebPage node is already.
// enriched before Drug/FAQ are appended.
add_filter( 'wpseo_schema_graph', array( $this->webpage_enricher, 'enrich_webpage_piece' ), 11, 2 );
add_filter( 'wpseo_schema_graph', array( $this, 'inject_graph_nodes' ), 12, 2 );
// Standalone fallback: emits only when Yoast is not producing output.
add_action( 'wp_head', [ $this, 'emit_standalone_fallback' ], 99 );
add_action( 'wp_head', array( $this, 'emit_standalone_fallback' ), 99 );
}
/**
@@ -90,8 +115,8 @@ class PR_Core_Jsonld {
* Appending plain Drug/FAQ arrays here is safe -- unlike wpseo_schema_graph_pieces
* which calls get_class() and is_needed() on each item expecting objects.
*
* @param array<int, array<string, mixed>> $graph Assembled Yoast graph.
* @param \Yoast\WP\SEO\Context\Meta_Tags_Context|null $context Yoast schema context.
* @param array<int, array<string, mixed>> $graph Assembled Yoast graph.
* @param \Yoast\WP\SEO\Context\Meta_Tags_Context|null $context Yoast schema context.
* @return array<int, array<string, mixed>> Graph with Drug (and optionally FAQ) appended.
*/
public function inject_graph_nodes( array $graph, $context ): array {
@@ -150,7 +175,7 @@ class PR_Core_Jsonld {
}
$permalink = get_permalink( (int) $post_id );
$graph = [ $this->drug_builder->build( $peptide ) ];
$graph = array( $this->drug_builder->build( $peptide ) );
$faq_node = $this->faq_builder->build( (int) $post_id, $permalink );
if ( null !== $faq_node ) {
@@ -160,7 +185,10 @@ class PR_Core_Jsonld {
printf(
'<script type="application/ld+json">%s</script>' . "\n",
wp_json_encode(
[ '@context' => 'https://schema.org', '@graph' => $graph ],
array(
'@context' => 'https://schema.org',
'@graph' => $graph,
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
)
);