1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MslsCustomColumn |
4
|
|
|
* @author Dennis Ploetner <[email protected]> |
5
|
|
|
* @since 0.9.8 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace lloc\Msls; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Handling of existing/not existing translations in the backend listings of |
12
|
|
|
* various post types |
13
|
|
|
* @package Msls |
14
|
|
|
*/ |
15
|
|
|
class MslsCustomColumn extends MslsMain { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Factory |
19
|
|
|
* |
20
|
|
|
* @codeCoverageIgnore |
21
|
|
|
* |
22
|
|
|
* @return MslsCustomColumn |
23
|
|
|
*/ |
24
|
|
|
public static function init() { |
25
|
|
|
$options = MslsOptions::instance(); |
26
|
|
|
$collection = MslsBlogCollection::instance(); |
27
|
|
|
$obj = new static( $options, $collection ); |
28
|
|
|
|
29
|
|
|
if ( ! $options->is_excluded() ) { |
30
|
|
|
$post_type = MslsPostType::instance()->get_request(); |
31
|
|
|
|
32
|
|
|
if ( ! empty( $post_type ) ) { |
33
|
|
|
add_filter( "manage_{$post_type}_posts_columns", [ $obj, 'th' ] ); |
34
|
|
|
add_action( "manage_{$post_type}_posts_custom_column", [ $obj, 'td' ], 10, 2 ); |
35
|
|
|
add_action( 'trashed_post', [ $obj, 'delete' ] ); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $obj; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Table header |
44
|
|
|
* @param array $columns |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function th( $columns ) { |
48
|
|
|
$blogs = $this->collection->get(); |
49
|
|
|
if ( $blogs ) { |
|
|
|
|
50
|
|
|
$arr = []; |
51
|
|
|
foreach ( $blogs as $blog ) { |
52
|
|
|
$language = $blog->get_language(); |
53
|
|
|
|
54
|
|
|
$icon = new MslsAdminIcon( null ); |
55
|
|
|
$icon->set_language( $language )->set_icon_type( 'flag' ); |
56
|
|
|
|
57
|
|
|
if ( $post_id = get_the_ID() ) { |
58
|
|
|
$icon->set_id( $post_id ); |
59
|
|
|
$icon->set_origin_language( 'it_IT' ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$arr[] = $icon->get_icon(); |
63
|
|
|
} |
64
|
|
|
$columns['mslscol'] = implode( ' ', $arr ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $columns; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Table body |
72
|
|
|
* |
73
|
|
|
* @param string $column_name |
74
|
|
|
* @param int $item_id |
75
|
|
|
* |
76
|
|
|
* @codeCoverageIgnore |
77
|
|
|
*/ |
78
|
|
|
public function td( $column_name, $item_id ) { |
79
|
|
|
if ( 'mslscol' == $column_name ) { |
80
|
|
|
$blogs = $this->collection->get(); |
81
|
|
|
$origin_language = MslsBlogCollection::get_blog_language(); |
82
|
|
|
if ( $blogs ) { |
|
|
|
|
83
|
|
|
$mydata = MslsOptions::create( $item_id ); |
84
|
|
|
foreach ( $blogs as $blog ) { |
85
|
|
|
switch_to_blog( $blog->userblog_id ); |
86
|
|
|
|
87
|
|
|
$language = $blog->get_language(); |
88
|
|
|
|
89
|
|
|
$icon = MslsAdminIcon::create(); |
90
|
|
|
$icon->set_language( $language ); |
91
|
|
|
$icon->set_id( $item_id ); |
92
|
|
|
$icon->set_origin_language( $origin_language ); |
93
|
|
|
|
94
|
|
|
$icon->set_icon_type( 'action' ); |
95
|
|
|
|
96
|
|
|
if ( $mydata->has_value( $language ) ) { |
97
|
|
|
$icon->set_href( $mydata->$language ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
echo $icon->get_a(); |
101
|
|
|
|
102
|
|
|
restore_current_blog(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.