Skip to content

Instantly share code, notes, and snippets.

@campusboy87
Last active September 14, 2018 18:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Добавляет ID в таблицу вывода медиафайлов.
<?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
}
@campusboy87
Copy link
Author

add-id-image-for-table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment