MediaLink.php
1.49 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace AC\Settings\Column;
use AC;
use AC\Settings;
use AC\View;
class MediaLink extends Settings\Column
implements Settings\FormatValue {
/**
* @var string
*/
protected $media_link_to;
protected function define_options() {
return [
'media_link_to' => '',
];
}
public function format( $value, $original_value ) {
$id = $original_value;
switch ( $this->get_media_link_to() ) {
case 'view' :
case 'download' :
$link = wp_get_attachment_url( $id );
break;
default :
$link = false;
}
if ( $link ) {
$attributes = [];
if ( 'download' === $this->get_media_link_to() ) {
$attributes['download'] = '';
}
$value = ac_helper()->html->link( $link, $value, $attributes );
}
return $value;
}
public function create_view() {
$select = $this->create_element( 'select' )->set_options( $this->get_link_options() );
$view = new View( [
'label' => __( 'Link To', 'codepress-admin-columns' ),
'setting' => $select,
] );
return $view;
}
protected function get_link_options() {
return [
'' => __( 'None' ),
'view' => __( 'View', 'codepress-admin-columns' ),
'download' => __( 'Download', 'codepress-admin-columns' ),
];
}
/**
* @return string
*/
public function get_media_link_to() {
return $this->media_link_to;
}
/**
* @param string $media_link_to
*
* @return bool
*/
public function set_media_link_to( $media_link_to ) {
$this->media_link_to = $media_link_to;
return true;
}
}