Support » Plugin: Featured Image Column » Working updated lite version

  • Resolved Jonas Lundman

    (@jonas-lundman)


    Ive been using this plugin for many years. Compare to other plugins this one places the imge at the right spot, as directly to the checkbox on the left side of the table.

    However, the issues has become to many, and the author seems to have some time off. Meanwhile, we are using this replacement. I decided to share this to help out with analysing the problem(s) until an update is available.

    The cache is removed, any default featured image should be handle by has_post_thumbnail() not on column visibility tasks. There are updated plugins that do this matter the right way, and let them do so.

    The hooks and filters are calling in messed up order, why Quick edit doesnt render saved ajax calls correctly.

    The options are not thought through and many functions is not needed, we just use a simple filter to return any modifications of allowed post types, as product or attachments. We dont call a stylesheet for two lines of selector.

    In short, I like old ladies at the market, and this plugin has been around for a while and I rather see this keep on going, to show new contributors that WordPress doesnt always have to be re-published. Lets re-cycle!

    Well, here is the complete class, hope this posting doesnt break it. (Please WordPress: make previews on posted code)

    
    if(!defined('ABSPATH')) exit;
    
    if ( !class_exists( 'Featured_Image_Column' ) ) {
    	
    	class Featured_Image_Column {
    
    		function __construct() {
    			add_action('admin_init', array($this, 'init'));
    		}
    
    		function init(){
    
    			// Must return an array() 
    			$post_types = apply_filters('Featured_Image_Column_post_types', get_post_types(array('public' => true)));
    			if(empty($post_types)) return;
    
    			/* Print style */
    			add_action('admin_head', function(){ 
    				echo '<style>th#featured-image  { width: 40px; }</style>'."\r\n"; 
    			});
    			
    			/* Column manager */
    			foreach($post_types as $post_type){
    				if(!post_type_supports($post_type, 'thumbnail')) continue;
    				add_filter( "manage_{$post_type}_posts_columns", array($this, 'columns'));
    				add_action( "manage_{$post_type}_posts_custom_column", array($this, 'column_data'), 10, 2);
    			}
    		}
    
    		/**
    		 * Filter the image in before the 'title' column
    		 */
    		function columns($columns){
    			
    			if(!is_array($columns)) $columns = array();
    			$new = array();
    			foreach($columns as $key => $title){
    				if($key == 'title') $new['featured-image'] = __('Image', 'wordpress');
    				$new[$key] = $title;
    			}
    			return $new;
    		}
    		
    		/**
    		 * Output the image
    		 */
    		function column_data($column_name, $post_id) {
    			
    			if('featured-image' != $column_name) return;
    			$style = 'display: block; max-width: 42px; height: auto; border: 1px solid #e5e5e5;';
    			$style = apply_filters('Featured_Image_Column_image_style', $style);
    
    			if(has_post_thumbnail($post_id)){
    				$size = 'thumbnail';
    				echo get_the_post_thumbnail($post_id, $size, 'style='.$style);
    			} else {
    				echo '<img style="'. $style .'" src="'. esc_url(plugins_url( 'images/default.png', __FILE__ )) .'" />';
    			}	
    		}
    	}
    	
    	$featured_image_column = new Featured_Image_Column;
    	
    };
    

    Hope this is ok to post until update is running.

Viewing 1 replies (of 1 total)
  • Plugin Author Austin Passy

    (@austyfrosty)

    I tell you what @jonas-lundman, thanks for the lite version, but I think after 2 years it was time to give this plugin a fresh face. So I’ve updated it.

    Enjoy!

    • This reply was modified 2 years, 4 months ago by Austin Passy. Reason: spelling
Viewing 1 replies (of 1 total)
  • The topic ‘Working updated lite version’ is closed to new replies.