Skip to content

Commit 5b9468d

Browse files
authored
Merge pull request #84 from n49/slider_v1.1.13
feat: use backend API for JSON schema, bump v1.1.13
2 parents 7d8af1a + 8b332ef commit 5b9468d

8 files changed

Lines changed: 146 additions & 695 deletions

includes/admin-reviews-slider-horizontal-carousel-template.php

Lines changed: 18 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -509,123 +509,26 @@ function isMobileDevice() {
509509

510510
<?php if(isset($filteredReviews) && count(array_slice($filteredReviews, 0, 8)) > 3) { ?>
511511

512-
<?php if(isset($feed_object->schema_enabled) && $feed_object->schema_enabled == 'yes'
513-
&& isset($business) && !empty($business["name"])
514-
&& isset($aggregateRating) && $aggregateRating > 0
515-
&& isset($totalReviews) && $totalReviews > 0) { ?>
516-
517-
<!-- JSON schema starts-->
518-
519-
<?php if(isset($feed_object->schema_type) && $feed_object->schema_type == 'local') { ?>
520-
<script id="jsonldSchema" type="application/ld+json">
521-
<?php $count=1; ?>
522-
{
523-
"@context": "http://schema.org",
524-
"@type": "LocalBusiness",
525-
"name": "<?php echo $business["name"]?>",
526-
"image": "<?php echo esc_url(OPIO_ASSETS_URL) . 'img/opio-blue-logo.png'; ?>",
527-
"address": {
528-
"@type": "PostalAddress",
529-
"streetAddress": "<?php echo esc_attr($business["address"]["address1"]); ?>",
530-
"addressRegion": "<?php echo esc_attr($business["address"]["province"]); ?>",
531-
"postalCode": "<?php echo esc_attr($business["address"]["postalCode"]); ?>"
532-
},
533-
"aggregateRating": {
534-
"@type": "AggregateRating",
535-
"ratingValue": "<?php echo esc_attr($aggregateRating); ?>",
536-
"reviewCount": "<?php echo esc_attr($totalReviews); ?>"
537-
},
538-
"review": [
539-
<?php foreach(array_slice($filteredReviews, 0, 8) as $key => $review) { ?>
540-
{
541-
"@type": "Review",
542-
<?php if(isset($review['user']['firstName'])) { ?>
543-
"author": {
544-
"@type": "Person",
545-
"name": "<?php echo esc_attr($review['user']['firstName']); ?>"
546-
},
547-
<?php } ?>
548-
"datePublished": "<?php echo esc_attr(date('M d, Y', $review["dateCreated"]/1000)); ?>",
549-
"reviewBody": "<?php echo esc_attr($review['content']); ?>",
550-
"reviewRating": {
551-
"@type": "Rating",
552-
"ratingValue": <?php echo esc_attr($review['propertyInfo']['name'] === 'facebook' ? $review['rating'] === 'positive' ? 5 : 1 : $review['rating']); ?>
553-
},
554-
"publisher": {
555-
"@type": "Organization",
556-
"name": "op.io",
557-
"sameAs": "https://www.op.io"
558-
}
559-
}
560-
<?php if($count < count(array_slice($filteredReviews, 0, 8))){
561-
echo ",";
562-
}
563-
?>
564-
<?php $count = $count + 1; ?>
565-
<?php } ?>
566-
]
512+
<?php if(isset($feed_object->schema_enabled) && $feed_object->schema_enabled == 'yes') {
513+
$schema_url = 'https://op.io/review-schema.json/?entid=' . $feed_object->biz_id;
514+
if($review_type === 'orgfeed') {
515+
$schema_url = 'https://op.io/review-schema.json/?orgid=' . $feed_object->org_id;
567516
}
568-
</script>
569-
570-
<?php } else { ?>
571-
<script id="jsonldSchema" type="application/ld+json">
572-
<?php $count=1; ?>
573-
{
574-
"@context": "http://schema.org",
575-
"@type": "Product",
576-
"name": "<?php echo $business["name"]?>",
577-
"image": "<?php echo esc_url(OPIO_ASSETS_URL) . 'img/opio-blue-logo.png'; ?>",
578-
"aggregateRating": {
579-
"@type": "AggregateRating",
580-
"ratingValue": "<?php echo esc_attr($aggregateRating); ?>",
581-
"reviewCount": "<?php echo esc_attr($totalReviews); ?>"
582-
},
583-
<?php if(isset($business['lowPriceRange']) && isset($business['highPriceRange']) && $business['lowPriceRange'] !== null && $business['highPriceRange'] !== null) { ?>
584-
"offers": {
585-
"@type": "AggregateOffer",
586-
"offerCount": 5,
587-
"lowPrice": "<?php echo $business['lowPriceRange']?>",
588-
"highPrice": "<?php echo $business['highPriceRange']?>",
589-
"priceCurrency": "CAD"
590-
},
591-
<?php } ?>
592-
"review": [
593-
<?php foreach(array_slice($filteredReviews, 0, 8) as $key => $review) { ?>
594-
595-
{
596-
"@type": "Review",
597-
<?php if(isset($review['user']['firstName'])) { ?>
598-
"author": {
599-
"@type": "Person",
600-
"name": "<?php echo esc_attr($review['user']['firstName']); ?>"
601-
},
602-
<?php } ?>
603-
"datePublished": "<?php echo esc_attr(date('M d, Y', $review["dateCreated"]/1000)); ?>",
604-
"reviewBody": "<?php echo esc_attr($review['content']); ?>",
605-
"reviewRating": {
606-
"@type": "Rating",
607-
"ratingValue": <?php echo esc_attr($review['propertyInfo']['name'] === 'facebook' ? $review['rating'] === 'positive' ? 5 : 1 : $review['rating']); ?>
608-
},
609-
"publisher": {
610-
"@type": "Organization",
611-
"name": "op.io",
612-
"sameAs": "https://www.op.io"
613-
}
614-
}
615-
<?php if($count < count(array_slice($filteredReviews, 0, 8))){
616-
echo ",";
617-
}
618-
?>
619-
<?php $count = $count + 1; ?>
620-
621-
<?php } ?>
622-
]
517+
if(isset($feed_object->schema_type) && $feed_object->schema_type == 'local') {
518+
$schema_url .= '&type=local';
623519
}
520+
$schema_response = wp_remote_get($schema_url, ['timeout' => 5]);
521+
if(!is_wp_error($schema_response) && $schema_response['response']['code'] === 200) {
522+
$schema_json = $schema_response['body'];
523+
if(!empty($schema_json) && $schema_json !== '{}' && $schema_json !== 'null') {
524+
?>
525+
<!-- JSON schema from op.io API -->
526+
<script type="application/ld+json">
527+
<?php echo $schema_json; ?>
624528
</script>
625-
<?php } ?>
626-
627-
<!-- JSON schema ends-->
628-
629-
<?php } ?>
529+
<?php
530+
}
531+
}
532+
} ?>
630533

631534
<?php } ?>

includes/admin-reviews-slider-horizontal-template.php

Lines changed: 18 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -491,123 +491,26 @@ function randomColor() {
491491

492492
<?php if(isset($filteredReviews) && count(array_slice($filteredReviews, 0, 8)) > 3) { ?>
493493

494-
<?php if(isset($feed_object->schema_enabled) && $feed_object->schema_enabled == 'yes'
495-
&& isset($business) && !empty($business["name"])
496-
&& isset($aggregateRating) && $aggregateRating > 0
497-
&& isset($totalReviews) && $totalReviews > 0) { ?>
498-
499-
<!-- JSON schema starts-->
500-
501-
<?php if(isset($feed_object->schema_type) && $feed_object->schema_type == 'local') { ?>
502-
<script id="jsonldSchema" type="application/ld+json">
503-
<?php $count=1; ?>
504-
{
505-
"@context": "http://schema.org",
506-
"@type": "LocalBusiness",
507-
"name": "<?php echo $business["name"]?>",
508-
"image": "<?php echo esc_url(OPIO_ASSETS_URL) . 'img/opio-blue-logo.png'; ?>",
509-
"aggregateRating": {
510-
"@type": "AggregateRating",
511-
"ratingValue": "<?php echo esc_attr($aggregateRating); ?>",
512-
"reviewCount": "<?php echo esc_attr($totalReviews); ?>"
513-
},
514-
"review": [
515-
<?php foreach(array_slice($filteredReviews, 0, 8) as $key => $review) { ?>
516-
{
517-
"@type": "Review",
518-
<?php if(isset($review['user']['firstName'])) { ?>
519-
"author": {
520-
"@type": "Person",
521-
"name": "<?php echo esc_attr($review['user']['firstName']); ?>"
522-
},
523-
<?php } ?>
524-
"datePublished": "<?php echo esc_attr(date('M d, Y', $review["dateCreated"]/1000)); ?>",
525-
"reviewBody": "<?php echo esc_attr($review['content']); ?>",
526-
"reviewRating": {
527-
"@type": "Rating",
528-
"ratingValue": <?php echo esc_attr($review['propertyInfo']['name'] === 'facebook' ? $review['rating'] === 'positive' ? 5 : 1 : $review['rating']); ?>
529-
},
530-
"publisher": {
531-
"@type": "Organization",
532-
"name": "op.io",
533-
"sameAs": "https://www.op.io"
534-
}
535-
}
536-
<?php if($count < count(array_slice($filteredReviews, 0, 8))){
537-
echo ",";
538-
}
539-
?>
540-
<?php $count = $count + 1; ?>
541-
<?php } ?>
542-
]
494+
<?php if(isset($feed_object->schema_enabled) && $feed_object->schema_enabled == 'yes') {
495+
$schema_url = 'https://op.io/review-schema.json/?entid=' . $feed_object->biz_id;
496+
if($review_type === 'orgfeed') {
497+
$schema_url = 'https://op.io/review-schema.json/?orgid=' . $feed_object->org_id;
543498
}
544-
</script>
545-
546-
<?php } else { ?>
547-
<script id="jsonldSchema" type="application/ld+json">
548-
<?php $count=1; ?>
549-
{
550-
"@context": "http://schema.org",
551-
"@type": "Product",
552-
"name": "<?php echo $business["name"]?>",
553-
"image": "<?php echo esc_url(OPIO_ASSETS_URL) . 'img/opio-blue-logo.png'; ?>",
554-
"address": {
555-
"@type": "PostalAddress",
556-
"streetAddress": "<?php echo esc_attr($business["address"]["address1"]); ?>",
557-
"addressRegion": "<?php echo esc_attr($business["address"]["province"]); ?>",
558-
"postalCode": "<?php echo esc_attr($business["address"]["postalCode"]); ?>"
559-
},
560-
<?php if(isset($business['lowPriceRange']) && isset($business['highPriceRange']) && $business['lowPriceRange'] !== null && $business['highPriceRange'] !== null) { ?>
561-
"offers": {
562-
"@type": "AggregateOffer",
563-
"offerCount": 5,
564-
"lowPrice": "<?php echo $business['lowPriceRange']?>",
565-
"highPrice": "<?php echo $business['highPriceRange']?>",
566-
"priceCurrency": "CAD"
567-
},
568-
<?php } ?>
569-
"aggregateRating": {
570-
"@type": "AggregateRating",
571-
"ratingValue": "<?php echo esc_attr($aggregateRating); ?>",
572-
"reviewCount": "<?php echo esc_attr($totalReviews); ?>"
573-
},
574-
"review": [
575-
<?php foreach(array_slice($filteredReviews, 0, 8) as $key => $review) { ?>
576-
577-
{
578-
"@type": "Review",
579-
<?php if(isset($review['user']['firstName'])) { ?>
580-
"author": {
581-
"@type": "Person",
582-
"name": "<?php echo esc_attr($review['user']['firstName']); ?>"
583-
},
584-
<?php } ?>
585-
"datePublished": "<?php echo esc_attr(date('M d, Y', $review["dateCreated"]/1000)); ?>",
586-
"reviewBody": "<?php echo esc_attr($review['content']); ?>",
587-
"reviewRating": {
588-
"@type": "Rating",
589-
"ratingValue": <?php echo esc_attr($review['propertyInfo']['name'] === 'facebook' ? $review['rating'] === 'positive' ? 5 : 1 : $review['rating']); ?>
590-
},
591-
"publisher": {
592-
"@type": "Organization",
593-
"name": "op.io",
594-
"sameAs": "https://www.op.io"
595-
}
596-
}
597-
<?php if($count < count(array_slice($filteredReviews, 0, 8))){
598-
echo ",";
599-
}
600-
?>
601-
<?php $count = $count + 1; ?>
602-
603-
<?php } ?>
604-
]
499+
if(isset($feed_object->schema_type) && $feed_object->schema_type == 'local') {
500+
$schema_url .= '&type=local';
605501
}
502+
$schema_response = wp_remote_get($schema_url, ['timeout' => 5]);
503+
if(!is_wp_error($schema_response) && $schema_response['response']['code'] === 200) {
504+
$schema_json = $schema_response['body'];
505+
if(!empty($schema_json) && $schema_json !== '{}' && $schema_json !== 'null') {
506+
?>
507+
<!-- JSON schema from op.io API -->
508+
<script type="application/ld+json">
509+
<?php echo $schema_json; ?>
606510
</script>
607-
<?php } ?>
608-
609-
<!-- JSON schema ends-->
610-
611-
<?php } ?>
511+
<?php
512+
}
513+
}
514+
} ?>
612515

613516
<?php } ?>

0 commit comments

Comments
 (0)