Hi there,
I implemented a custom admin column function following your documentation a while back and all has been working fine. But recently I noticed an "unserialize(): Error at offset 1347 of 2148 bytes" in my Query Monitor. The custom admin column displays fine and before the title as expected. If I remove this function completely the "unserialize(): Error" disappears.
MY CODE:
========
add_action( 'init', 'pl_add_custom_columns', 20 );
function pl_add_custom_columns() {
class Pl_Custom_Admin_Columns extends \MBAC\Post {
public function columns( $columns ) {
$columns = parent::columns( $columns );
$position = 'before';
$target = 'title';
$this->add( $columns, '_thumbnail_id', 'Featured Image', $position, $target );
return $columns;
}
public function show( $column, $post_id ) {
switch ( $column ) {
case '_thumbnail_id':
$img_url = wp_get_attachment_image_url( get_post_thumbnail_id( $post_id ), 'thumbnail' );
if( !empty( $img_url ) ) {
echo '<img class="admin-featured-img" src="' . $img_url . '" alt="'.get_the_title().'" title="'.get_the_title().'" />';
} else {
echo '<img class="admin-featured-img" src="'. esc_url(get_stylesheet_directory_uri()).'/img/img-fallback.svg" alt="No Featured Image" title="No Featured Image">';
}
break;
// More columns
}
}
}
new Pl_Custom_Admin_Columns( 'custom_post_type', array() );
}
* Note this method was used to display the featured image in the admin column because the _thumbnail_id
uses the 'type' => 'file_upload'
.
Q) Is my implementation correct?
Q) Is there a better method?
Q) Is this a known bug?
I look forward to your response 🙂