0

I have tryied all plugins.
I need a php code not a plugin cause im running a front end post creator.

I need a function or a php code which only allows a user to have 1 post only but if that post is deleted he can then make a new post.

closed as too broad by Michael, Krzysiek Dróżdż, bosco, Jacob Peattie, cjbj May 21 '18 at 8:47

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I'm voting to close this question as off-topic because you are explicitly asking for a coded solution without demonstrating research or implementation efforts on your own part. Please review the "How to Ask" page in our help center – bosco May 21 '18 at 3:53
0

You can use count_user_posts function. If the posts are getting saved as WordPress posts then it can be done by the snippet below:

if (is_user_logged_in()){
    $userPostCount = count_user_posts(get_current_user_id());
    if ($userPostCount > 1){
        $user = new WP_User(get_current_user_id());
        $user->add_cap('publish_posts',false);
    } else {
        $user->add_cap('publish_posts',true);
    }
}
  • Worked for dashboard but didnt work with front end poster ''DJD Site Post'' – ANdy May 20 '18 at 16:57
  • Is there a way to hide this without javascript for example? <button type="submit" class="send-button" id="submit"><?php echo ( $djd_options['djd-send-button'] ? $djd_options['djd-send-button'] : __('Publish', 'djd-site-post') ); ?></button> – ANdy May 20 '18 at 17:10
  • Sorry, I'm unfamiliar with "DJD Site Post" plugin. you can use CSS or add inline style, or you can add a condition in php to not echo if condition is not met. – Akshat May 20 '18 at 19:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.