<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

/***** 一覧にIDを表示 *****/
function haup_posts_columns_id($defaults){
	$defaults['haup_post_id'] = __('ID','hima-art-utility');
	return $defaults;
}
add_filter('manage_posts_columns', 'haup_posts_columns_id');
add_filter('manage_pages_columns', 'haup_posts_columns_id');
add_filter('manage_media_columns', 'haup_posts_columns_id');

function haup_posts_custom_id_columns($column_name, $id){
	if($column_name === 'haup_post_id'){
		echo esc_html($id);
	}
}
add_action('manage_posts_custom_column', 'haup_posts_custom_id_columns',10, 2);
add_action('manage_pages_custom_column', 'haup_posts_custom_id_columns',10, 2);
add_action('manage_media_custom_column', 'haup_posts_custom_id_columns',10, 2);

/***** カテゴリー・タグ一覧へIDを表示 *****/
function haup_add_category_columns( $columns ) {
	$columns['haup_cat_id'] = 'ID';
	return $columns;
}

function haup_custom_category_column( $content, $column_name, $term_id ) {
	if ( $column_name == 'haup_cat_id' ) {
	echo esc_html($term_id);
	}
}
add_filter( 'manage_edit-category_columns', 'haup_add_category_columns' );
add_action( 'manage_category_custom_column', 'haup_custom_category_column', 10, 3 );
add_filter( 'manage_edit-post_tag_columns', 'haup_add_category_columns' );
add_action( 'manage_post_tag_custom_column', 'haup_custom_category_column', 10, 3 );

/***** ユーザーIDを管理画面へ表示 *****/
function haup_add_user_columns($columns) {
	$columns['haup_user_id'] = 'ID';
	return $columns;
}

function haup_custom_user_column($value, $column_name, $user_id) {
	$user = get_userdata( $user_id );
	if ( 'haup_user_id' == $column_name )
		return $user_id;
	return $value;
}
add_filter('manage_users_columns', 'haup_add_user_columns');
add_action('manage_users_custom_column',  'haup_custom_user_column', 10, 3);

/* 管理画面上のスタイル */
function haup_admin_id_data_column_style_init(){
$custom_css_pre = hau_sanitize_css("
/* HAUP ID Column Width */
.column-haup_post_id{width:10%;}
.column-haup_cat_id{width:10%;}
.column-haup_user_id{width:10%;}
");

//タブを除去
$custom_css_deltab = preg_replace('/\t+/', '', $custom_css_pre);
//改行を除去
$custom_css = str_replace(PHP_EOL, '', $custom_css_deltab);
//インラインでCSS出力
	wp_add_inline_style( 'haup-only-admin-style', $custom_css );
}
add_action('admin_enqueue_scripts','haup_admin_id_data_column_style_init');