| 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( 'WpssoJsonTypeReview' ) ) { |
| 14 |
|
| 15 |
class WpssoJsonTypeReview { |
| 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_review' => 5, |
| 33 |
) ); |
| 34 |
} |
| 35 |
|
| 36 |
public function filter_json_data_https_schema_org_review( $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 |
|
| 45 |
$md_opts = array(); |
| 46 |
|
| 47 |
WpssoSchema::add_type_opts_md_pad( $md_opts, $mod ); |
| 48 |
|
| 49 |
/* |
| 50 |
* See https://schema.org/itemReviewed. |
| 51 |
*/ |
| 52 |
WpssoSchema::add_item_reviewed_data( $json_ret[ 'itemReviewed' ], $mod, $md_opts ); |
| 53 |
|
| 54 |
/* |
| 55 |
* See https://schema.org/reviewRating. |
| 56 |
*/ |
| 57 |
$json_ret[ 'reviewRating' ] = WpssoSchema::get_schema_type_context( 'https://schema.org/Rating' ); |
| 58 |
|
| 59 |
WpssoSchema::add_data_itemprop_from_assoc( $json_ret[ 'reviewRating' ], $md_opts, array( |
| 60 |
'alternateName' => 'schema_review_rating_alt_name', |
| 61 |
'ratingValue' => 'schema_review_rating', |
| 62 |
'worstRating' => 'schema_review_rating_min', |
| 63 |
'bestRating' => 'schema_review_rating_max', |
| 64 |
) ); |
| 65 |
|
| 66 |
$filter_name = 'wpsso_json_prop_https_schema_org_reviewrating'; |
| 67 |
|
| 68 |
if ( $this->p->debug->enabled ) { |
| 69 |
|
| 70 |
$this->p->debug->log( 'applying filters "' . $filter_name . '"' ); |
| 71 |
} |
| 72 |
|
| 73 |
$json_ret[ 'reviewRating' ] = apply_filters( $filter_name, $json_ret[ 'reviewRating' ], $mod, $mt_og, $page_type_id, $is_main ); |
| 74 |
|
| 75 |
if ( $this->p->debug->enabled ) { |
| 76 |
|
| 77 |
$this->p->debug->log( 'merging json_data and json_ret arrays' ); |
| 78 |
} |
| 79 |
|
| 80 |
return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main ); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|