post_type) return $s->post_type; $screen = adminlane_list_ajax_screen(); return $screen !== '' ? substr($screen, 5) : 'post'; } add_action('admin_enqueue_scripts', function ($hook) { if ($hook !== 'edit.php' || !adminlane_list_active()) return; wp_enqueue_style('adl-list', ADMINLANE_URL . 'assets/list.css', ['adl-admin'], adminlane_ver('list.css')); wp_enqueue_script('adl-list', ADMINLANE_URL . 'assets/list.js', ['wp-i18n', 'adl-admin'], adminlane_ver('list.js'), true); wp_set_script_translations('adl-list', 'adminlane'); }, 21); /* --------------------------------------------------------------------- * Thumbnail column * ------------------------------------------------------------------- */ function adminlane_list_add_column(array $columns, string $post_type): array { if (!adminlane_list_context() || !post_type_supports($post_type, 'thumbnail')) return $columns; // The list already shows a picture of its own (WooCommerce's products and the like). foreach (array_keys($columns) as $key) { if (preg_match('/thumb|image|photo|featured/i', (string) $key)) return $columns; } $out = []; foreach ($columns as $key => $label) { $out[$key] = $label; if ($key === 'cb') $out['adminlane_thumb'] = '' . esc_html__('Image', 'adminlane') . ''; } if (!isset($out['adminlane_thumb'])) $out = ['adminlane_thumb' => esc_html__('Image', 'adminlane')] + $out; return $out; } // Added last, on the screen's own filter, so columns other plugins add are already there. function adminlane_list_hook_columns(string $screen_id, string $post_type): void { add_filter('manage_' . $screen_id . '_columns', function ($columns) use ($post_type) { return adminlane_list_add_column((array) $columns, $post_type); }, 99); } add_action('current_screen', function ($s) { if ($s instanceof WP_Screen && $s->base === 'edit' && $s->post_type !== '') adminlane_list_hook_columns($s->id, $s->post_type); }); add_action('admin_init', function () { $screen = adminlane_list_ajax_screen(); if ($screen !== '') adminlane_list_hook_columns($screen, substr($screen, 5)); }); function adminlane_list_thumb_cell(string $column, int $post_id): void { if ($column !== 'adminlane_thumb') return; $post = get_post($post_id); if (!$post) return; $thumb = get_post_thumbnail_id($post); $img = $thumb ? wp_get_attachment_image($thumb, [96, 96], false, ['class' => 'adl-thumb-img', 'loading' => 'lazy', 'decoding' => 'async', 'alt' => '']) : ''; if ($img === '') { $title = trim(wp_strip_all_tags(get_the_title($post))); $letter = $title !== '' ? mb_strtoupper(mb_substr($title, 0, 1)) : '·'; $img = '' . esc_html($letter) . ''; } $link = current_user_can('edit_post', $post_id) && $post->post_status !== 'trash' ? get_edit_post_link($post_id) : ''; $html = $link ? '' : '' . $img . ''; echo wp_kses($html, [ 'a' => ['class' => true, 'href' => true, 'tabindex' => true, 'aria-hidden' => true], 'span' => ['class' => true, 'title' => true], 'img' => ['src' => true, 'srcset' => true, 'sizes' => true, 'width' => true, 'height' => true, 'alt' => true, 'class' => true, 'loading' => true, 'decoding' => true, 'fetchpriority' => true], ]); } add_action('manage_posts_custom_column', 'adminlane_list_thumb_cell', 10, 2); add_action('manage_pages_custom_column', 'adminlane_list_thumb_cell', 10, 2); /* --------------------------------------------------------------------- * The status line under each title * Printed into the row's (hidden) Quick Edit data, then shown by list.js. * ------------------------------------------------------------------- */ /* * WordPress has no hook between a row's title and its actions. The closest one is * add_inline_data, which prints inside the row's hidden Quick Edit data, right * after the title. So, last of all (after every other plugin's Quick Edit fields), * the hidden box is closed, the status line printed, and an empty hidden box opened * for WordPress to close. The line is then in place from the first paint — the rows * don't grow after the page has loaded. */ add_action('add_inline_data', function ($post) { if (!adminlane_list_context() || !$post instanceof WP_Post) return; echo ''; echo wp_kses(adminlane_list_meta_line($post), [ 'div' => ['class' => true], 'span' => ['class' => true, 'aria-hidden' => true], ]); echo '