Completed
Pull Request — develop (#1369)
by Naveen
02:57
created

Term_Jsonld::wl_term_jsonld_array()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 19
rs 9.6333
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
21
			$entities_with_context = array_map( function ( $entity ) use ( $term_id ) {
22
				$entity['@context'] = 'http://schema.org';
23
				$entity['@id']      = get_term_link( $term_id ) . "/#id";
24
				$entity['url']      = get_term_link( $term_id );
25
				$entity['mainEntityOfPage']      = get_term_link( $term_id );
26
				return $entity;
27
			}, $entities );
28
29
			$jsonld_array['jsonld'] = array_merge( $jsonld_array['jsonld'], $entities_with_context );
30
		}
31
32
		return $jsonld_array;
33
	}
34
35
}