Completed
Push — develop ( 0f5c00...04d5ed )
by
unknown
28s queued 13s
created

Term_Jsonld::wl_term_jsonld_array()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @since 3.31.2
4
 * @author Naveen Muthusamy <[email protected]>
5
 */
6
7
namespace Wordlift\Vocabulary\Jsonld;
8
9
class Term_Jsonld {
10
11
	public function init() {
12
		add_action( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
13
	}
14
15
	public function wl_term_jsonld_array( $jsonld_array, $term_id ) {
16
17
		$entities = Jsonld_Utils::get_matched_entities_for_term( $term_id );
18
19
		if ( count( $entities ) > 0 ) {
20
			$entity                     = array_shift( $entities );
21
			$entity['@context']         = 'http://schema.org';
22
			$entity['@id']              = get_term_link( $term_id ) . "/#id";
23
			$entity['url']              = get_term_link( $term_id );
24
			$entity['mainEntityOfPage'] = get_term_link( $term_id );
25
			$jsonld_array['jsonld'][] = $entity;
26
		}
27
28
		return $jsonld_array;
29
	}
30
31
}