wordpress相关代码

//页面小工具指定显示某个页面

function wp_list_pages_include($remove_args) {
$remove_args['include'] = $remove_args['exclude'];
$remove_args['exclude'] = '';
return $remove_args;
}
add_filter( 'widget_pages_args', 'wp_list_pages_include', 10, 1 );

//功能小工具中的wordpress链接去除

add_filter( 'widget_meta_poweredby', '__return_false' );

//文章别名为中文时替换为日期

add_action( 'wp_insert_post', 'use_date_in_slug' ,9999,2);
function use_date_in_slug($post_id, $post) {$title=urldecode($post->post_name);
if($post->post_type!=='post'||($title!==''&&preg_match('/[\x7f-\xff]/',$title)===0)){return false;}else{$title=''.date('Ymd').$post_id;}
wp_update_post(array('ID' => $post_id, 'post_name' => $title ));
}

//禁止非管理员进入后台

if ( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) {
$current_user = wp_get_current_user();
if($current_user->roles[0] !== 'administrator') {
wp_safe_redirect( home_url() );
exit();
}}

(中国梦 / )

发表评论

电子邮件地址不会被公开。

2 + 9 =