Question

I have a custom post type for service providers. Which is essentially a bio page for them. I have it set that they can only edit their own bio page, however to do this I had to grant them the ability to create their own bio page (Add New). Is there a way to remove the "Add New" ability once they have created their own page?

Was it helpful?

Solution

I wonder if this plugin might be helpful to you:

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

This plugin helps you to limit the number of posts/pages/custom post types each user can create on your site.

OTHER TIPS

I use the above plugin and it works great. Another 'rough' way would be to use one of the front end posting plugins and use the conditional code below to restrict the author if they already have a custom post published...

Make a page template for the specific page where the front end posting form is and add this where appropriate...

<?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 } ?>

You'd need to prevent them from gaining access to the back-end as well.

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' );

Hope this is your answer. Accept it if this your answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top