PrimaryTaxonomy.php
1.29 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
<?php
namespace ACP\ThirdParty\YoastSeo\Editing;
use AC;
use ACP;
use ACP\Editing;
use ACP\Helper\Select;
/**
* @property ACP\ThirdParty\YoastSeo\Column\PrimaryTaxonomy $column
*/
class PrimaryTaxonomy extends Editing\Model\Meta
implements Editing\PaginatedOptions {
/**
* @param int $id
*
* @return array|false
*/
public function get_edit_value( $id ) {
$term = $this->column->get_raw_value( $id );
if ( ! $term ) {
$terms = wp_get_post_terms( $id, $this->column->get_taxonomy() );
if ( empty( $terms ) || is_wp_error( $terms ) ) {
return null;
}
return false;
}
$term = get_term( $term, $this->column->get_taxonomy() );
return [
$term->term_id => $term->name,
];
}
public function get_view_settings() {
return [
self::VIEW_TYPE => 'select2_dropdown',
'multiple' => false,
'ajax_populate' => true,
self::VIEW_BULK_EDITABLE => false,
];
}
public function get_paginated_options( $search, $page, $id = null ) {
$entities = new Select\Entities\Taxonomy( [
'search' => $search,
'page' => $page,
'taxonomy' => $this->column->get_taxonomy(),
'object_ids' => [ $id ],
] );
return new AC\Helper\Select\Options\Paginated(
$entities,
new Select\Formatter\TermName( $entities )
);
}
}