';
// 登録済カテゴリ取得。末端カテゴリ抽出
//$ancestors_cates:登録されている末端カテゴリからトップ親カテゴリまでを集約した配列
$registered_cates = wp_get_post_categories($post->ID);
$ancestors_cates = array();
foreach($registered_cates as $cat){
$flag = get_term_children($cat,'category');
if(empty( $flag )){
//if(get_category_children($cat) == ''){
$local = get_ancestors( $cat, 'category' );
array_unshift($local,$cat);
$ancestors_cates[] = array_reverse($local);
}
}
// 追加用のフォームの隠しデータ
echo '
';
$defolt_cates = get_categories('parent=0&hide_empty=0');
foreach($defolt_cates as $defo_cate){
echo '';
}
echo '
';
// ドロップダウン作成
// 新規投稿用
if( empty($registered_cates) or ($registered_cates[0] =='false') ){
echo '';
echo '';
echo '
';
$echo = ' 追加
';
echo $echo;
}
// 編集用
else{
$i=0;
foreach($ancestors_cates as $buddy => $cates ){
echo '';
$ii=0;
foreach($cates as $cate ){
$now_cate = get_categories('include='.$cate);
$parent_id = $now_cate[0];
$same_level_cate = get_categories('parent='.$parent_id->parent.'&hide_empty=0');
echo '';
$ii++;
}
echo '
';
$i++;
}
$echo = ' 追加
';
echo $echo;
}
}
/*********************************************
/* 保存処理
/*********************************************/
function ADC_save_postdata( $post_id ) {
if(!isset($_POST['ADC_noncename'])){
return $post_id;
}
// データが先ほど作った編集フォームのから適切な認証とともに送られてきたかどうかを確認。
if ( !wp_verify_nonce( $_POST['ADC_noncename'], plugin_basename(__FILE__) )) {
return $post_id;
}
// 自動保存ルーチンかどうかチェック。そうだった場合はフォームを送信しない(何もしない)
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
// パーミッションチェック
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
// 承認ができたのでデータを最適化
$add_cate = array();
if(isset($_POST['admin_dropdown_categories_']) ){
foreach( $_POST['admin_dropdown_categories_'] as $cate_id){
if(($cate_id!='false')&&(isset($cate_id))){
$add_cate[] = $cate_id;
}
}
}
// 保存
if($add_cate[0]!='false'){
wp_set_post_categories($post_id,$add_cate);
}
return $post_id;
}
/********************************************
/* jsonで結果を返す
/* GETで得たIDを元に子カテゴリを返す
/********************************************/
function my_category_retrun_child($parent_id = 0){
if(isset($_GET['admin_dropdown_categories_parent']) && ($_GET['admin_dropdown_categories_parent'] != null)){
$parent_id = $_GET['admin_dropdown_categories_parent'];
$list = get_categories('parent='.$parent_id);
$retrun_list = array();
foreach($list as $key => $val ){
if($val->parent == $parent_id){
$retrun_list[] = array('name' => $val->name , 'id' => $val->term_id);
} }
if(1 > count($retrun_list)){$retrun_list = false;}
@header('Content-Type: application/json; charset='. get_bloginfo('charset'));
echo json_encode($retrun_list);
exit;
}
}
?>