限制用户仅限创建一个自定义帖子类型帖子

问题描述 投票:2回答:3

我有一个服务提供商的自定义帖子类型。这本质上是他们的生物页面。我设置他们只能编辑自己的生物页面,但为了做到这一点,我必须授予他们创建自己的生物页面的能力(添加新的)。有没有办法在创建自己的页面后删除“添加新”功能?

wordpress custom-post-type capability
3个回答
3
投票

我想知道这个插件是否对您有所帮助:

http://wordpress.org/plugins/bainternet-posts-creation-limits/

此插件可帮助您限制每个用户可在您的网站上创建的帖子/页面/自定义帖子类型的数量。


0
投票

我使用上面的插件,效果很好。另一种“粗略”的方式是使用前端发布插件之一并使用下面的条件代码限制作者是否已经发布了自定义帖子...

为前端发布表单所在的特定页面制作页面模板,并在适当的位置添加...

<?php if (( 0 == count_user_posts( get_current_user_id(), "CUSTOM-POST-TYPE" ) && is_user_logged_in() && current_user_can('USER-ROLE-CAPABILITY') && !current_user_can( 'manage_options' ))) { ?>
    <?php the_content(); ?>
<?php } ?>

您还需要阻止他们访问后端。


0
投票
function post_published_limit() {
    $max_posts = 3; // change this or set it as an option that you can retrieve.
    $author = $post->post_author; // Post author ID.

    $count = count_user_posts( $author, 'CUSTOMPOSTTYPE'); // get author post count

    if ( $count > $max_posts ) {
        // count too high, let's set it to draft.

        $post = array('post_status' => 'draft');
        wp_update_post( $post );
    }
}
add_action( 'publish_CUSTOMPOSTTYPE', 'post_published_limit' );

希望这是你的答案。如果这是你的答案,请接受它。

© www.soinside.com 2019 - 2024. All rights reserved.