Completed
Push — master ( 48986a...95c69f )
by David
06:07
created

Wordlift_Seo_Service   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B get_wl_entity_type() 0 37 5
1
<?php
2
/**
3
 * Services: SEO Services.
4
 *
5
 * The file defines a class for SEO related manipulations.
6
 *
7
 * @link       https://wordlift.io
8
 *
9
 * @since      3.11.0
10
 *
11
 * @package    Wordlift
12
 * @subpackage Wordlift/public
13
 */
14
15
/**
16
 * Handles SEO related manipulation in the HTML header section
17
 *
18
 * @since      3.11.0
19
 * @package    Wordlift
20
 * @subpackage Wordlift/public
21
 */
22
class Wordlift_Seo_Service {
23
24
	/**
25
	 * @inheritdoc
26
	 */
27
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
29
		// If we are not on the admin, run the get_term filter for entity type terms.
30
		add_filter( 'get_wl_entity_type', array(
31
			$this,
32
			'get_wl_entity_type',
33
		), 10, 2 );
34
35
	}
36
37
	/**
38
	 * Filter the entity term object, and when not in admin context replace title
39
	 * and description with whatever was set in the entity settings page.
40
	 *
41
	 * @since    3.11
42
	 *
43
	 * @param WP_Term $term     The term to filters.
44
	 * @param string  $taxonomy The taxonomy name.
45
	 *
46
	 * @return WP_Term The {@link WP_Term} with fields changed.
47
	 */
48
	function get_wl_entity_type( $term, $taxonomy ) {
0 ignored issues
show
Unused Code introduced by
The parameter $taxonomy is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
50
		// Do nothing when in admin.
51
		if ( is_admin() ) {
52
			return $term;
53
		}
54
55
		// Get the terms' settings.
56
		$entity_settings = get_option( 'wl_entity_type_settings', array() );
57
58
		// If we have no settings for the specified term, then return the original
59
		// term.
60
		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
61
62
			return $term;
63
		}
64
65
		// Get the settings for the specified term.
66
		$settings = $entity_settings[ $term->term_id ];
67
68
		// Update the name.
69
		if ( ! empty( $settings['title'] ) ) {
70
71
			$term->name = $settings['title'];
72
73
		}
74
75
		// Update the description.
76
		if ( ! empty( $settings['description'] ) ) {
77
78
			$term->description = $settings['description'];
79
80
		}
81
82
		// Return the updated term.
83
		return $term;
84
	}
85
86
}
87