PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / json / type / claimreview.php

claimreview.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/json/type/claimreview.php

142 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2016-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 if ( ! class_exists( 'WpssoJsonTypeClaimReview' ) ) {
14
15 class WpssoJsonTypeClaimReview {
16
17 private $p; // Wpsso class object.
18
19 /*
20 * Instantiated by Wpsso->init_json_filters().
21 */
22 public function __construct( &$plugin ) {
23
24 $this->p =& $plugin;
25
26 if ( $this->p->debug->enabled ) {
27
28 $this->p->debug->mark();
29 }
30
31 $this->p->util->add_plugin_filters( $this, array(
32 'json_data_https_schema_org_claimreview' => 5,
33 ) );
34 }
35
36 public function filter_json_data_https_schema_org_claimreview( $json_data, $mod, $mt_og, $page_type_id, $is_main ) {
37
38 if ( $this->p->debug->enabled ) {
39
40 $this->p->debug->mark();
41 }
42
43 $json_ret = array();
44 $md_opts = array();
45
46 WpssoSchema::add_type_opts_md_pad( $md_opts, $mod );
47
48 /*
49 * Create the 'appearance' property value.
50 *
51 * Inherit the 'itemReviewed' property value from https://schema.org/Review.
52 */
53 if ( ! empty( $json_data[ 'itemReviewed' ] ) ) {
54
55 $appear_type_obj = $json_data[ 'itemReviewed' ];
56 $appear_type_url = $this->p->schema->get_data_type_url( $appear_type_obj );
57 $claim_review_url = $this->p->schema->get_schema_type_url( 'review.claim' );
58
59 /*
60 * The subject of a claim review cannot be another claim review.
61 */
62 if ( $claim_review_url === $appear_type_url ) {
63
64 /*
65 * Add notice only if the admin notices have not already been shown.
66 */
67 if ( $this->p->notice->is_admin_pre_notices() ) {
68
69 $notice_msg = __( 'A claim review cannot be the subject of another claim review.', 'wpsso' ) . ' ';
70
71 $notice_msg .= __( 'CreativeWork will be used instead as the Schema type for the subject of the webpage (ie. the content) being reviewed.', 'wpsso' );
72
73 $this->p->notice->err( $notice_msg );
74 }
75
76 $appear_type_url = $this->p->schema->get_schema_type_url( 'creative.work' );
77 $appear_type_obj = $this->p->schema->get_schema_type_context( $appear_type_url, $appear_type_obj );
78 }
79
80 } else {
81
82 $appear_type_url = $this->p->schema->get_schema_type_url( 'creative.work' );
83 $appear_type_obj = $this->p->schema->get_schema_type_context( $appear_type_url );
84 }
85
86 /*
87 * Re-define the 'itemReviewed' property as a https://schema.org/Claim and set the 'appearance' property.
88 */
89 $claim_type_url = $this->p->schema->get_schema_type_url( 'claim' );
90
91 $json_ret[ 'itemReviewed' ] = WpssoSchema::get_schema_type_context( $claim_type_url );
92
93 /*
94 * Google suggests adding the 'author' and 'datePublished' properties to the Schema Claim type, if
95 * available.
96 */
97 foreach ( array( 'author', 'datePublished' ) as $prop_name ) {
98
99 if ( ! empty( $appear_type_obj[ $prop_name ] ) ) {
100
101 $json_ret[ 'itemReviewed' ][ $prop_name ] = $appear_type_obj[ $prop_name ];
102 }
103 }
104
105 $json_ret[ 'itemReviewed' ][ 'appearance' ] = $appear_type_obj;
106
107 /*
108 * https://schema.org/claimReviewed
109 *
110 * A short summary of the specific claims reviewed in a ClaimReview.
111 *
112 * Used on these types:
113 *
114 * ClaimReview
115 */
116 if ( ! empty( $md_opts[ 'schema_review_claim_reviewed' ] ) ) {
117
118 $json_ret[ 'claimReviewed' ] = $md_opts[ 'schema_review_claim_reviewed' ];
119 }
120
121 /*
122 * If there's a first appearance URL, add the URL using a CreativeWork object as well.
123 */
124 if ( ! empty( $md_opts[ 'schema_review_claim_first_url' ] ) ) {
125
126 $json_ret[ 'itemReviewed' ][ 'firstAppearance' ] = WpssoSchema::get_schema_type_context( $appear_type_url );
127
128 WpssoSchema::add_data_itemprop_from_assoc( $json_ret[ 'itemReviewed' ][ 'firstAppearance' ], $md_opts, array(
129 'url' => 'schema_review_claim_first_url',
130 ) );
131 }
132
133 if ( $this->p->debug->enabled ) {
134
135 $this->p->debug->log( 'merging json_data and json_ret arrays' );
136 }
137
138 return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main );
139 }
140 }
141 }
142