@@ -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 } ?>
0 commit comments