Completed
Pull Request — develop (#1369)
by
unknown
03:28
created

Term_Jsonld   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A wl_term_jsonld_array() 0 15 2
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
}