1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Overrides; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Database; |
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
7
|
|
|
|
8
|
|
|
class ReviewsListTable extends \WP_Posts_List_Table |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param \WP_Post $post |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function column_cb($post) |
15
|
|
|
{ |
16
|
|
|
parent::column_cb($post); |
17
|
|
|
if (!glsr()->can('edit_post', $post->ID) && glsr()->can('respond_to_post', $post->ID)) { |
18
|
|
|
glsr()->render('partials/screen/locked-indicator'); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \WP_Post $post |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function column_title($post) |
27
|
|
|
{ |
28
|
|
|
if (glsr()->can('respond_to_post', $post->ID)) { |
29
|
|
|
$this->renderInlineData($post); |
30
|
|
|
$this->renderLockedInfo($post); |
31
|
|
|
} |
32
|
|
|
parent::column_title($post); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function inline_edit() |
39
|
|
|
{ |
40
|
|
|
global $mode; |
41
|
|
|
glsr()->render('partials/screen/inline-edit', [ |
42
|
|
|
'additional_fieldsets' => $this->getAdditionalFieldsets(), |
43
|
|
|
'author_dropdown' => $this->getAuthorDropdown(), |
44
|
|
|
'columns' => $this->get_column_count(), |
45
|
|
|
'mode' => esc_attr((isset($mode) && 'excerpt' === $mode) ? 'excerpt' : 'list'), |
46
|
|
|
'screen_id' => esc_attr($this->screen->id), |
47
|
|
|
'taxonomy' => get_taxonomy(glsr()->taxonomy), |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getAdditionalFieldsets() |
52
|
|
|
{ |
53
|
|
|
ob_start(); |
54
|
|
|
list($columns) = $this->get_column_info(); |
55
|
|
|
$coreColumns = ['author', 'categories', 'cb', 'comments', 'date', 'tags', 'title']; |
56
|
|
|
foreach ($columns as $columnName => $columnTitle) { |
57
|
|
|
if (!in_array($columnName, $coreColumns)) { |
58
|
|
|
do_action('bulk_edit_custom_box', $columnName, glsr()->post_type); // @since WP 2.7.0 |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
return ob_get_clean(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
protected function getAuthorDropdown() |
68
|
|
|
{ |
69
|
|
|
if (!glsr()->can('edit_others_posts')) { |
70
|
|
|
return ''; |
71
|
|
|
} |
72
|
|
|
$args = [ |
73
|
|
|
'class' => 'authors', |
74
|
|
|
'echo' => 0, |
75
|
|
|
'hide_if_only_one_author' => false, |
76
|
|
|
'multi' => 1, |
77
|
|
|
'name' => 'post_author', |
78
|
|
|
'show' => 'display_name_with_login', |
79
|
|
|
'show_option_none' => '— '._x('No Change', 'admin-text', 'site-reviews').' —', |
80
|
|
|
'who' => 'authors', |
81
|
|
|
]; |
82
|
|
|
$args = apply_filters('quick_edit_dropdown_authors_args', $args, $bool = true); // @since WP 5.6.0 |
83
|
|
|
return wp_dropdown_users($args); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
protected function renderInlineData(\WP_Post $post) |
90
|
|
|
{ |
91
|
|
|
$response = Cast::toString(glsr(Database::class)->meta($post->ID, 'response')); |
92
|
|
|
glsr()->render('partials/screen/inline-data', [ |
93
|
|
|
'content' => esc_textarea(trim($post->post_content)), |
94
|
|
|
'postId' => $post->ID, |
95
|
|
|
'response' => esc_textarea(trim($response)), |
96
|
|
|
]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
protected function renderLockedInfo(\WP_Post $post) |
103
|
|
|
{ |
104
|
|
|
if ('trash' !== $post->post_status) { |
105
|
|
|
$lockHolder = wp_check_post_lock($post->ID); |
106
|
|
|
if (false !== $lockHolder) { |
107
|
|
|
$lockHolder = get_userdata($lockHolder); |
108
|
|
|
$lockedAvatar = get_avatar($lockHolder->ID, 18); |
109
|
|
|
$lockedText = esc_html(sprintf(_x('%s is currently editing', 'admin-text', 'site-reviews'), $lockHolder->display_name)); |
110
|
|
|
} else { |
111
|
|
|
$lockedAvatar = ''; |
112
|
|
|
$lockedText = ''; |
113
|
|
|
} |
114
|
|
|
glsr()->render('partials/screen/locked-info', [ |
115
|
|
|
'lockedAvatar' => $lockedAvatar, |
116
|
|
|
'lockedText' => $lockedText, |
117
|
|
|
]); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|