1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Metaboxes; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\MetaboxContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
7
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\MetaboxBuilder; |
8
|
|
|
use GeminiLabs\SiteReviews\Review; |
9
|
|
|
|
10
|
|
|
class AuthorMetabox implements MetaboxContract |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
public function register($post) |
16
|
|
|
{ |
17
|
|
|
if (!Review::isReview($post) || !glsr()->can('edit_others_posts')) { |
18
|
|
|
return; |
19
|
|
|
} |
20
|
|
|
$id = glsr()->post_type.'-authordiv'; |
21
|
|
|
$title = _x('Author', 'admin-text', 'site-reviews'); |
22
|
|
|
add_meta_box($id, $title, [$this, 'render'], null, 'side'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function render($post) |
29
|
|
|
{ |
30
|
|
|
$placeholder = _x('Author Unknown', 'admin-text', 'site-reviews'); |
31
|
|
|
$selected = $placeholder; |
32
|
|
|
$value = (empty($post->ID) ? get_current_user_id() : $post->post_author); |
33
|
|
|
if ($user = get_user_by('id', $value)) { |
34
|
|
|
$selected = $user->display_name; |
35
|
|
|
} |
36
|
|
|
echo glsr(MetaboxBuilder::class)->label([ |
37
|
|
|
'class' => 'screen-reader-text', |
38
|
|
|
'for' => 'post_author_override', |
39
|
|
|
'text' => _x('Author', 'admin-text', 'site-reviews'), |
40
|
|
|
]); |
41
|
|
|
echo glsr()->build('partials/listtable/filter', [ |
42
|
|
|
'action' => 'filter-author', |
43
|
|
|
'class' => '', |
44
|
|
|
'id' => 'post_author_override', |
45
|
|
|
'name' => 'post_author_override', |
46
|
|
|
'options' => [0 => $placeholder], |
47
|
|
|
'placeholder' => $placeholder, |
48
|
|
|
'selected' => $selected, |
49
|
|
|
'value' => Cast::toInt($value), |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|