File: /www/wwwroot/1.scey.cn/wp-content/themes/Leading/admin/post/term-options.php
<?php
add_action('admin_head',function(){?>
<style type="text/css">
.thickbox-loading{width:700px!important;height:420px!important;margin-left:-350px!important}
#TB_ajaxContent{width:650px!important;height:362px!important}
<?php for ($i=1; $i<=6; $i++) { ?>
#label_list_type_<?php echo $i; ?>{background-image:url(<?php echo get_stylesheet_directory_uri().'/static/images/set/post-'.$i.'.png';?>);border:1px solid #e8e5e5;margin:0 0 15px 0;width:150px;height:90px;font-size:0;background-repeat:no-repeat;background-size:100% 100%;-moz-background-size:100% 100%; display: inline-block;}
#list_type_<?php echo $i; ?>:checked{border:3px solid #f33;width:150px;height:90px;display:block;margin-top:0;background-image:url(<?php echo get_stylesheet_directory_uri().'/static/images/set/post-'.$i.'.png';?>);border-radius:0;background-repeat:no-repeat;background-size:100% 100%;-moz-background-size:100% 100%}
#list_type_<?php echo $i; ?>,#list_type_<?php echo $i; ?>:checked:before{display:none}
<?php } ?>
</style>
<?php
});
add_filter($taxonomy.'_row_actions', function($actions, $term){
$color = get_term_meta($term->term_id, 'color', true);
if($color){
$actions['set_color'] = str_replace('>设置颜色<', '><span style="color:'.$color.'">设置颜色</span><', $actions['set_color']);
}
$list_type = get_term_meta($term->term_id, 'list_type', true) ?: 1;
$actions['set_list_type'] = str_replace('>列表样式<', '>列表样式('.$list_type.')<', $actions['set_list_type']);
$actions['set_banner'] = str_replace('>Banner设置<', '>Banner设置<', $actions['set_banner']);
return $actions;
},10,2);
add_action('wpjam_'.$taxonomy.'_terms_actions', function($actions, $taxonomy){
$actions['set_color'] = ['title'=>'设置颜色', 'submit_text'=>'保存', 'capability'=>get_taxonomy($taxonomy)->cap->edit_terms, 'tb_width'=>400];
$actions['set_list_type'] = ['title'=>'列表样式', 'submit_text'=>'保存', 'capability'=>get_taxonomy($taxonomy)->cap->edit_terms, 'tb_width'=>400];
$actions['set_banner'] = ['title'=>'Banner设置', 'submit_text'=>'保存', 'capability'=>get_taxonomy($taxonomy)->cap->edit_terms, 'tb_width'=>400];
return $actions;
}, 9, 2);
add_filter('wpjam_'.$taxonomy.'_terms_list_action', function($result, $list_action, $term_id, $data){
if($list_action == 'set_color'){
$color = $data['color'] ?? '';
if($color){
return update_term_meta($term_id, 'color', $color);
}else{
return delete_term_meta($term_id, 'color');
}
}elseif($list_action == 'set_list_type'){
$list_type = $data['list_type'] ?? 1;
return update_term_meta($term_id, 'list_type', $list_type);
}elseif($list_action == 'set_banner'){
$title_type = $data['title_type'] ?? 1;
$banner_title = $data['banner_title'] ?? '';
$banner_img = $data['banner_img'] ?? '';
$banner = update_term_meta($term_id, 'title_type', $title_type);
$banner = update_term_meta($term_id, 'banner_title', $banner_title);
$banner = update_term_meta($term_id, 'banner_img', $banner_img);
return $banner;
}
return $result;
}, 10, 4);
add_filter('wpjam_'.$taxonomy.'_terms_fields', function($fields, $action_key, $term_id, $taxonomy){
if($action_key == 'set_color'){
return [
'color' => ['title'=>'颜色', 'type'=>'color', 'value'=>get_term_meta($term_id, 'color', true)]
];
}elseif($action_key == 'set_list_type'){
return [
'list_type' => ['title'=>'列表样式', 'type'=>'radio', 'value'=>get_term_meta($term_id, 'list_type', true), 'options'=>[
'1'=>'样式-1',
'2'=>'样式-2',
'3'=>'样式-3',
'4'=>'样式-4',
'5'=>'样式-5',
'6'=>'样式-6']
]
];
}elseif($action_key == 'set_banner'){
return [
'banner_img' => ['title'=>'Banner图片', 'type'=>'img', 'value'=>get_term_meta($term_id, 'banner_img', true), 'item_type'=>'url', 'description'=>'非必选项,尺寸:1600x300'],
'banner_title' => ['title'=>'Banner标题', 'type'=>'text', 'value'=>get_term_meta($term_id, 'banner_title', true),],
'title_type' => ['title'=>'标题显示位置', 'type'=>'radio', 'value'=>get_term_meta($term_id, 'title_type', true), 'options'=>['1'=>'靠左对齐','2'=>'居中显示']]
];
}
return $fields;
}, 10, 4);
/*
add_filter('wpjam_term_options', function($term_options, $taxonomy){
global $pagenow;
if($pagenow == 'term.php'){
$term_options['banner_img'] = ['title'=>'Banner图片', 'type'=>'img', 'item_type'=>'url', 'description'=>'非必选项,尺寸:1600x300'];
$term_options['banner_title'] = ['title'=>'Banner标题', 'type'=>'text'];
$term_options['title_type'] = ['title'=>'标题显示位置', 'type'=>'radio', 'options'=>['1'=>'靠左对齐','2'=>'居中显示']];
$term_options['color'] = ['title'=>'颜色', 'type'=>'color'];
$term_options['list_type'] = ['title'=>'列表样式', 'type'=>'radio', 'options'=>[
'1'=>'样式-1',
'2'=>'样式-2',
'3'=>'样式-3',
'4'=>'样式-4',
'5'=>'样式-5',
'6'=>'样式-6']
];
}
return $term_options;
}, 99, 2);
*/
add_action('admin_head', function(){
?>
<script type="text/javascript">
jQuery(function($){
$('body').on('list_table_action_success', function(event, response){
if(response.list_action == 'set_color'){
$('body input.color').wpColorPicker();
}
});
});
</script>
<?php
});