PrimaryTaxonomy.php
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace ACA\YoastSeo\Column\Post;
use AC;
use ACA\YoastSeo;
use ACA\YoastSeo\Editing;
use ACA\YoastSeo\Filtering;
use ACP;
use WP_Term;
class PrimaryTaxonomy extends AC\Column\Meta
implements ACP\Editing\Editable, ACP\Filtering\Filterable, ACP\Export\Exportable, ACP\ConditionalFormat\Formattable
{
use ACP\ConditionalFormat\FilteredHtmlFormatTrait;
public function __construct()
{
$this->set_label(__('Primary Taxonomy', 'codepress-admin-columns'))
->set_group('yoast-seo')
->set_type('column-wpseo_column_taxonomy');
}
public function get_value($id)
{
$raw_value = $this->get_raw_value($id);
if ( ! $raw_value) {
return $this->get_empty_char();
}
$term = get_term($raw_value, $this->get_taxonomy());
if ( ! $term instanceof WP_Term) {
return $this->get_empty_char();
}
$terms = ac_helper()->taxonomy->get_term_links(
[
$term,
],
$this->get_post_type() ?: null
);
if (empty($terms)) {
return $this->get_empty_char();
}
return ac_helper()->string->enumeration_list($terms, 'and');
}
public function get_meta_key()
{
return '_yoast_wpseo_primary_' . $this->get_taxonomy();
}
protected function register_settings()
{
$this->add_setting(new YoastSeo\Setting\PrimaryTaxonomy($this));
}
public function editing()
{
return new Editing\Service\Post\PrimaryTaxonomy($this->get_taxonomy());
}
public function filtering()
{
return new Filtering\Post\PrimaryTaxonomy($this);
}
public function export()
{
return new ACP\Export\Model\StrippedValue($this);
}
/**
* @return string
*/
public function get_taxonomy()
{
$setting = $this->get_setting('primary_taxonomy');
if ( ! $setting instanceof YoastSeo\Setting\PrimaryTaxonomy) {
return '';
}
return $setting->get_primary_taxonomy();
}
}