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

/***** 一覧にIDを表示 *****/
function haup_posts_columns_slug($columns){
	if(haup_is_single() || is_page()){
		$columns['HAUPPostPermalink'] = __('Permalink','hima-art-utility');
	}

	return $columns;
}
add_filter('manage_posts_columns', 'haup_posts_columns_slug');

function haup_pages_columns_slug($columns){
	$columns['HAUPPostPermalink'] = __('Permalink','hima-art-utility');

	return $columns;
}
add_filter('manage_pages_columns', 'haup_pages_columns_slug');

function haup_posts_custom_slug_columns($column_name, $id){
	//各ページのURLとホームのURLを取得
	$permalink = get_permalink();
	$home_url = home_url();

	//ホームのURLと直後の「/」を削除して$dataへ格納
		$data = str_replace( $home_url.'/' , "" , $permalink ); 

	//末尾に「/」があれば除去して$outputへ格納
	if(substr( $data , -1) == '/'){
		$output = str_replace( '/' , '' , $data );
	}else{
		$output = $data;
	}

	switch ( $column_name ) {
		case 'HAUPPostPermalink':
			echo esc_html($output);
			break;
	}

}
add_action('manage_posts_custom_column', 'haup_posts_custom_slug_columns',10, 2);
add_action('manage_pages_custom_column', 'haup_posts_custom_slug_columns',10, 2);

/* 管理画面上のスタイル */
function haup_admin_slug_data_column_style_init(){
$custom_css_pre = hau_sanitize_css("
/* HAUP Slug Data Column Width */
.column-HAUPPostPermalink{width:15%;}
");

//タブを除去
$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_slug_data_column_style_init');