docs/test: resolve QA P1s + P2 guards (v0.8.0)

P1-A: CONTEXT.md — add glossary entries for _prab_* namespace,
meta-reader pattern, ScholarlyArticle type, and honest-reviewedBy
integrity constraint (Person-vs-Organization branching rule).

P1-B: Master IA + app-map updated (workspace docs, not in this diff):
INFORMATION-ARCHITECTURE.md v1.3.2 — §5 cross-plugin data flow added
(PRAutoBlogger _prab_* meta → prcore JSON-LD Article emission); §4
version bumped to 0.8.0.
peptide-repo-core.md — two new classes in §2 file tree; §3 data flow
Mermaid extended with PRAB→MetaReader→Emitter chain; §5 cross-plugin
dependency noted; §6 hooks table updated; last-verified bumped to v0.8.0.

P1-C: JsonldArticleTest.php — add 5 new test methods:
  - test_standalone_fallback_emits_nothing_for_untriggered_post()
  - test_standalone_fallback_emits_valid_graph_for_triggered_post()
  - test_standalone_fallback_suppressed_when_yoast_active()
  - test_get_about_peptides_nonexistent_id_skipped()
  - test_get_about_peptides_wrong_post_type_skipped()
Also add test_is_triggered_cache_returns_same_value() for P2-5 cache.

P2-1: get_about_peptides() — skip entries where get_permalink() returns ''.
P2-2: get_reviewed_by() — empty display_name falls through to Organization.
P2-3: register_hooks() — explicit priority 10 on wpseo_schema_webpage_type.
P2-4: emit_standalone_fallback() — guard wp_json_encode() false return;
  also guard empty permalink before building the graph.
P2-5: is_triggered() — per-post  avoids triple
  get_post_meta reads when all three hooks fire for the same post.

P3s accepted (noted in QA verdict): P3-1 test-comment misleading;
P3-2 docblock @see gap on emit_standalone_fallback; P3-3 DOI regex.

Agent-Session: prcore-jsonld-remediation-20260623
This commit is contained in:
peptiderepo
2026-06-23 05:10:06 +00:00
parent 382a7ede5d
commit b2dc245c6e
4 changed files with 261 additions and 66 deletions

View File

@@ -62,7 +62,7 @@ class PR_Core_Jsonld_Article {
* @return void
*/
public function register_hooks(): void {
add_filter( 'wpseo_schema_webpage_type', array( $this, 'retype_article_page' ) );
add_filter( 'wpseo_schema_webpage_type', array( $this, 'retype_article_page' ), 10 );
add_filter( 'wpseo_schema_graph', array( $this, 'enrich_article_graph' ), 13, 2 );
add_action( 'wp_head', array( $this, 'emit_standalone_fallback' ), 99 );
}
@@ -151,7 +151,7 @@ class PR_Core_Jsonld_Article {
*
* Suppressed when Yoast is loaded. Emits Article + MedicalWebPage nodes
* with Yoast-parity @id conventions so consumers see one shape regardless
* of whether Yoast is present.
* of whether Yoast is present. Skips posts whose permalink cannot be resolved.
*
* @return void
*/
@@ -167,7 +167,11 @@ class PR_Core_Jsonld_Article {
return;
}
$permalink = (string) get_permalink( $post_id );
$permalink = (string) get_permalink( $post_id );
if ( '' === $permalink ) {
return;
}
$post = get_post( $post_id );
$review_mode = $this->reader->get_review_mode( $post_id );
$reviewed_at = $this->reader->get_reviewed_at( $post_id );
@@ -198,16 +202,19 @@ class PR_Core_Jsonld_Article {
$article['about'] = $about_stubs;
}
printf(
'<script type="application/ld+json">%s</script>' . "\n",
wp_json_encode(
array(
'@context' => 'https://schema.org',
'@graph' => array( $webpage, $article ),
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
)
$json = wp_json_encode(
array(
'@context' => 'https://schema.org',
'@graph' => array( $webpage, $article ),
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);
if ( false !== $json ) {
printf(
'<script type="application/ld+json">%s</script>' . "\n",
$json
);
}
}
// ── Private builders ─────────────────────────────────────────────────