3 回答
TA贡献1820条经验 获得超2个赞
我已经在你的函数中为你写了一些评论 - 但一切都应该有意义
function wpse67262_change_title( $data ) {
if( 'gd_place' != $data['post_type'] ){
return $data;
//This is for your pos type only?
}
$user = wp_get_current_user();
if(!is_admin() && !current_user_can('administrator')){
//So this makes sure, that the following does NOT run in the backend and also takes the admin role into account
$data['post_title'] = $user->first_name . ' ' . $user->last_name;
return $data;
} else {
//one of the conditions failed - So do nothing new
return $data;
}
}
add_filter( 'wp_insert_post_data', 'wpse67262_change_title' );
一个更清洁的功能可能是:
function wpse67262_change_title( $data ) {
if(!is_admin() && !current_user_can('administrator') && 'gd_place' == $data['post_type']){
//So this makes sure, that the following does NOT run in the backend and also takes the admin role into account, and checks the post type
$user = wp_get_current_user();
$data['post_title'] = $user->first_name . ' ' . $user->last_name;
return $data;
} else {
//one of the conditions failed - So do nothing new
return $data;
}
}
add_filter( 'wp_insert_post_data', 'wpse67262_change_title' );
TA贡献1877条经验 获得超6个赞
你可以试试这个来禁用帖子标题
jQuery(document).ready(function() {
post_status = /* your post status here */
if( post_status != "auto-draft" ) {
jQuery( "#title" ).attr( 'disabled', true );
});
- 3 回答
- 0 关注
- 111 浏览
添加回答
举报