1 | <?php |
||||
2 | /** |
||||
3 | * Plugin Name: Simple Featured Image Column |
||||
4 | * Plugin URI: https://github.com/dedevillela/Simple-Featured-Image-Column/ |
||||
5 | * Description: A simple plugin that displays the "Featured Image" column in admin post type listing. Supports Post, Pages and Custom Posts. |
||||
6 | * Version: 1.0.0 |
||||
7 | * Author: Andre Aguiar Villela |
||||
8 | * Author URI: https://dedevillela.com/ |
||||
9 | * License: GPLv2+ |
||||
10 | **/ |
||||
11 | |||||
12 | if ( !defined( 'ABSPATH' ) || preg_match('#' . basename( __FILE__ ) . '#', $_SERVER['PHP_SELF'])) { |
||||
13 | die( "Hey, dude! What are you doing here?" ); |
||||
14 | } |
||||
15 | |||||
16 | if ( !class_exists( 'Simple_Featured_Image_Column' ) ) { |
||||
17 | |||||
18 | class Simple_Featured_Image_Column { |
||||
19 | |||||
20 | function __construct() { |
||||
21 | add_action('admin_init', array($this, 'init')); |
||||
22 | } |
||||
23 | |||||
24 | function init(){ |
||||
25 | |||||
26 | $post_types = apply_filters('Simple_Featured_Image_Column_post_types', get_post_types(array('public' => true))); |
||||
27 | if(empty($post_types)) return; |
||||
28 | |||||
29 | add_action('admin_head', function(){ |
||||
30 | echo '<style>th#featured-image { width: 100px; }</style>'."\r\n"; |
||||
31 | }); |
||||
32 | |||||
33 | foreach($post_types as $post_type){ |
||||
34 | if(!post_type_supports($post_type, 'thumbnail')) continue; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
35 | add_filter( "manage_{$post_type}_posts_columns", array($this, 'columns')); |
||||
36 | add_action( "manage_{$post_type}_posts_custom_column", array($this, 'column_data'), 10, 2); |
||||
37 | } |
||||
38 | } |
||||
39 | |||||
40 | function columns($columns){ |
||||
41 | |||||
42 | if(!is_array($columns)) $columns = array(); |
||||
43 | $new = array(); |
||||
44 | foreach($columns as $key => $title){ |
||||
45 | if($key == 'title') $new['featured-image'] = __('Image', 'wordpress'); |
||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
46 | $new[$key] = $title; |
||||
47 | } |
||||
48 | return $new; |
||||
49 | } |
||||
50 | |||||
51 | function column_data($column_name, $post_id) { |
||||
52 | |||||
53 | if('featured-image' != $column_name) return; |
||||
54 | $style = 'display: block; max-width: 100px; height: auto; border: 1px solid #e5e5e5;'; |
||||
55 | $style = apply_filters('Simple_Featured_Image_Column_image_style', $style); |
||||
56 | |||||
57 | if(has_post_thumbnail($post_id)){ |
||||
58 | $size = 'thumbnail'; |
||||
59 | echo get_the_post_thumbnail($post_id, $size, 'style='.$style); |
||||
60 | } else { |
||||
61 | echo '<img style="'. $style .'" src="'. esc_url(plugins_url( 'images/default.png', __FILE__ )) .'" />'; |
||||
62 | } |
||||
63 | } |
||||
64 | } |
||||
65 | |||||
66 | $featured_image_column = new Simple_Featured_Image_Column; |
||||
67 | |||||
68 | }; |
||||
69 |