Organizer.php
1.03 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
<?php
namespace ACA\EC\Editing\Service\Event;
use ACP;
use ACP\Editing\View;
class Organizer implements ACP\Editing\Service, ACP\Editing\PaginatedOptions {
const META_KEY = '_EventOrganizerID';
public function get_view( string $context ): ?View {
return ( new ACP\Editing\View\AjaxSelect() )
->set_multiple( true )
->set_clear_button( true );
}
public function get_value( $id ) {
$values = [];
$ids = get_post_meta( $id, self::META_KEY, false );
if ( ! $ids ) {
return $values;
}
foreach ( array_filter( $ids ) as $_id ) {
$values[ $_id ] = html_entity_decode( get_the_title( $_id ) );
}
return $values;
}
public function update( int $id, $data ): void {
delete_post_meta( $id, self::META_KEY );
if ( empty( $data ) ) {
$data = [];
}
foreach ( $data as $value ) {
add_post_meta( $id, self::META_KEY, $value );
}
}
public function get_paginated_options( $s, $paged, $id = null ) {
return new ACP\Helper\Select\Paginated\Posts( $s, $paged, [
'post_type' => 'tribe_organizer',
] );
}
}