PrimaryTaxonomy.php
1.19 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
<?php
namespace ACA\YoastSeo\Setting;
use AC;
use AC\View;
class PrimaryTaxonomy extends AC\Settings\Column {
/**
* @var string
*/
private $primary_taxonomy;
protected function define_options() {
return [ 'primary_taxonomy' ];
}
public function create_view() {
$setting = $this->create_element( 'select' )
->set_attribute( 'data-label', 'update' )
->set_options( $this->get_taxonomies() );
$view = new View( [
'label' => __( 'Taxonomy' ),
'setting' => $setting,
] );
return $view;
}
/**
* @return array
*/
private function get_taxonomies() {
$taxonomies = get_object_taxonomies( $this->column->get_post_type(), 'objects' );
$options = [];
foreach ( $taxonomies as $taxonomy => $tax_object ) {
if ( ! $tax_object->hierarchical ) {
continue;
}
$options[ $taxonomy ] = $tax_object->label;
}
return $options;
}
/**
* @return string
*/
public function get_primary_taxonomy() {
return $this->primary_taxonomy;
}
/**
* @param string $primary_taxonomy
*
* @return bool
*/
public function set_primary_taxonomy( $primary_taxonomy ) {
$this->primary_taxonomy = $primary_taxonomy;
return true;
}
}