|
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() { |
|
|
|
|
|
|
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 ) { |
|
|
|
|
|
|
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
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.