Preview.php
1.16 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
<?php
namespace AC\Column\Media;
use AC\Column;
class Preview extends Column implements Column\AjaxValue {
public function __construct() {
$this->set_type( 'column-preview' )
->set_label( __( 'Preview', 'codepress-admin-columns' ) );
}
private function has_image( $id ) {
return null !== $this->get_image_url( $id );
}
private function get_download_url( $id ) {
return wp_get_attachment_url( $id );
}
private function get_image_url( $id ) {
$image = wp_get_attachment_image_src( $id, false );
if ( empty( $image ) ) {
return null;
}
return (string) $image[0];
}
public function get_value( $id ) {
if ( ! $this->has_image( $id ) ) {
return $this->get_empty_char();
}
return ac_helper()->html->get_ajax_modal_link(
__( 'View', 'codepress-admin-columns' ),
[
'title' => get_the_title( $id ),
'edit_link' => get_edit_post_link( $id ),
'download_link' => $this->get_download_url( $id ) ?: null,
'id' => $id,
'class' => "-nopadding -preview",
]
);
}
public function get_ajax_value( $id ) {
return sprintf( '<img src="%s" alt="">', esc_url( $this->get_image_url( $id ) ) );
}
}