Completed
Push — develop ( 1d77a8...e2550f )
by David
02:34
created

Wordlift_Website_Jsonld_Converter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create_schema() 0 20 1
A set_search_action() 0 17 1
1
<?php
2
/**
3
 * Converters: JSON-LD Website Converter.
4
 *
5
 * This file defines a converter for home and blog pages to JSON-LD array.
6
 *
7
 * @since   3.14.0
8
 * @package Wordlift
9
 */
10
11
/**
12
 * Define the {@link Wordlift_Website_Jsonld_Converter} class.
13
 *
14
 * @since 3.14.0
15
 */
16
class Wordlift_Website_Jsonld_Converter extends Wordlift_Post_To_Jsonld_Converter {
17
18
	/**
19
	 * Convert the home/blog page to a JSON-LD array.
20
	 *
21
	 * @since 3.14.0
22
	 *
23
	 * @return array A JSON-LD array.
24
	 */
25
	public function create_schema() {
26
27
		// Create new jsonld.
28
		$jsonld = array(
29
			'@context'      => 'http://schema.org',
30
			'@type'         => 'WebSite',
31
			'name'          => get_bloginfo( 'name' ),
32
			'alternateName' => get_bloginfo( 'description' ),
33
			'url'           => home_url( '/' ),
34
		);
35
36
		// Add publisher information.
37
		$this->set_publisher( $jsonld );
38
39
		// Add search action.
40
		$this->set_search_action( $jsonld );
41
42
		// Return the jsonld schema.
43
		return $jsonld;
44
	}
45
46
	/**
47
	 * Add SearchAction part to the schema
48
	 *
49
	 * @since 3.14.0
50
	 *
51
	 * @param array $params The parameters array.
52
	 */
53
	private function set_search_action( &$params ) {
54
		/**
55
		 * Filter: 'wordlift_json_ld_search_url' - Allows filtering of the search URL.
56
		 *
57
		 * @since  3.14.0
58
		 * @api    string $search_url The search URL for this site with a `{search_term_string}` variable.
59
		 */
60
		$search_url = apply_filters( 'wordlift_json_ld_search_url', home_url( '/' ) . '?s={search_term_string}' );
61
62
		// Add search action
63
		$params['potentialAction'] = array(
64
			'@type'       => 'SearchAction',
65
			'target'      => $search_url,
66
			'query-input' => 'required name=search_term_string',
67
		);
68
69
	}
70
71
}
72