绿站
绿色文摘
今天是:

交流 | 搜索 | +发贴

WordPress限制用户投稿的文章数量
nydalu 2024年7月6日 20次

add_action(‘current_screen’, function($current_screen){
global $pagenow;
if($pagenow == ‘post-new.php’){
$post_type = $current_screen->post_type;

if($post_type == ‘product’){ // 这里可以改成你需要限制的日志类型
$counts = wp_count_posts($post_type);
$total = array_sum((array)$counts);

if($total > 99){
wp_die(‘发布上限为:99。’);
}
}
}
});

使用上面这段代码之后,再点击新增,就会出现:提示比如我只允许发布1篇
add_action(‘current_screen’, function($current_screen){
global $pagenow;
if($pagenow == ‘post-new.php’){
$post_type = $current_screen->post_type;

if($post_type == ‘post’){ // 这里可以改成你需要限制的日志类型
//$counts = wp_count_posts($post_type);
$counts = count_user_posts($user_id);
$total = array_sum((array)$counts);

if($total > 1){
wp_die(‘发布上限为:1。’);
}
}
}
});



关于 ·登录·管理
加载0.247 查询 15