Добавляет ID в таблицу вывода медиафайлов.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'manage_media_columns', 'add_my_column_in_media_table' ); | |
add_action( 'manage_media_custom_column', 'fill_my_column_in_media_table', 10, 2 ); | |
/** | |
* Создает новую колонку. | |
* | |
* @param array $columns | |
* | |
* @return array | |
*/ | |
function add_my_column_in_media_table( $columns ) { | |
// Добавим хук, который в футере выведет стили для нашей колонки | |
add_action( 'admin_footer', 'add_my_column_in_media_table_css' ); | |
// Добавим колонку в начало | |
return [ 'id-image' => 'ID' ] + $columns; | |
} | |
/** | |
* Заполняет колонку данными. | |
* | |
* @param string $colname | |
* @param int $post_id | |
*/ | |
function fill_my_column_in_media_table( $colname, $post_id ) { | |
if ( $colname === 'id-image' ) { | |
echo (int) $post_id; | |
} | |
} | |
/** | |
* Выводит на экран стили для колонки "ID". | |
*/ | |
function add_my_column_in_media_table_css() { | |
?> | |
<style type="text/css"> | |
#id-image { | |
width: 40px; | |
} | |
</style> | |
<?php | |
} |
Author
campusboy87
commented
Sep 14, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment