One alternative is simply not to display the comment field if the current user isn’t logged in, using is_user_logged_in()
.
For example, inside your comments template:
<?php comment_form( $args ); ?>
Just wrap that in a conditional:
<?php
// Don't output the comment form if CPT and user isn't logged in
if ( 'debate' != get_post_type() || is_user_logged_in() ) {
comment_form( $args );
}
?>
Edit
Just put it into the template directly:
<?php
// If CPT and not logged in, display a message:
if ( 'debate' == get_post_type() && ! is_user_logged_in() ) {
echo '<p class="must-log-in">' . sprintf( __( 'You must be <a href="https://wordpress.stackexchange.com/questions/123157/%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>';
}
?>
Related Posts:
- changing default comment form arguments [duplicate]
- custom comments on specific post type
- add comments custom fields after user is logged in
- How to enqueue scripts on custom post add/edit pages?
- Conditional for single-{post-type}.php
- How to Debug the ‘save_post’ Action?
- List all posts commented by current user
- How to add a button to custom post type’s posts-page
- How to hook into the CPT’s title placeholder?
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Custom Comment Types
- Admin Post Update Redirection to Posts Screen
- modify all posts of a category to “no comments allowed”
- Custom comment status possible?
- functions.php conditional tag only for custom post type
- Get template part based on custom taxonomy term
- Add comments meta fields to comments metabox on post edit screen
- Exclude post_type from admin comments_list
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- If on term-page -> get the current term?
- remove_action conditionally for Custom Post Type
- What hook should be used to programmatically create a post only when master post is updated?
- Creating a function that receives the taxonomy terms that have been changed in a custom post type
- Remove “Get Shortlink” button in admin of custom post type
- Disable comments from showing up public for Custom Post Type
- Custom Post Type loops and Disqus
- Custom Blog Post Listing in Genesis Sample Child Theme
- Set a default category – if the user didn’t select one- before creating a post
- Separate comment section for post type in dashboard
- Modifying date filter on admin page for custom post type to link to custom field
- Count all comments of a custom post type
- if custom posts type exists and there are posts load script
- Need help targeting a custom post type with conditional tags
- Why would this IF statement not work? [closed]
- Excluding custom post types
- Insert data on comment post
- Add custom column in custom post type edit page
- Insert Multiple Post with Same Publish Button
- Validate custom fields before save using WordPress Rest API
- get_comments not working on custom post types
- Conditional Query of Custom Post Type and custom taxonomy
- WordPress comments_open for specific user role or post type
- Limit number of custom posts per taxonomy
- Add custom field in comments form
- How can the recipients and content for comment email notifications on a custom post type be changed?
- How to run filter only on custom post type edit screen
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- Custom Post Conditional for Parent & Child Single.php?
- What functions does WordPress use for filtering / sanitizing comments?
- Conditional for a Single Post That Belongs to a Category?
- Is there any way to get list of all possible filter hooks for all post types?
- How to show only the most recent post on my custom post type archive?
- Get rid of “trash can” for custom post type
- Use remove_meta_box conditionally on custom post type
- Conditional Tags for specific category of custom posts
- How do I amend form data before it is saved for a custom post type
- get comments by current user inside page template
- Move Genesis Single Page/Single Post Title
- How to check if post/page or taxonomy post is published by admin
- TinyMCE Buttons on Certain Post Type
- How check if a post is saved from backend or frontend?
- Display message if no posts in Custom Post Type loop
- WordPress hook which triggers on post import
- Before saving post hook
- Allow anonymous comments just in a custom post type
- Send email messages after comment was submitted
- Creating alternate meta box context locations
- Redirect to URL if x number of days passed
- If custom taxonomy else conditional [closed]
- Show specific content on parent custom post type and all children
- Get the latest comment from a custom post type where depth = 1?
- Use conditionals with wp_enqueue_style to attach stylesheet according to post type displayed
- Limiting actions only to edit.php page for specific custom post type
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- How to change the comments form title based on post type
- Plugin Development using classes – Public & Private Callbacks
- Store a value in global scope after init hook is fired
- Dynamic page for nav items used as filters
- Hook create / update post
- How to store additional data that is related to core data
- call a function when insert and update a custom post type
- How to create a discussion post when a custom post is created?
- Execute code only after user clicks ‘update’ button for CPT being edited
- do action inside a class is not working
- Custom post type updated to support comments, yet comments don’t appear
- Can not hook into custom post type template with: is_page() conditional?
- Hook only specific post type
- Turn off comments for given CPT checkbox?
- Conditional Tags If Custom Post Parent & Child?
- Author profile comments system
- Custom Post Query Combined with Conditional Tags
- Create action running on trashed_post hook to modify post_meta value
- Conditional statement checking two conditions for CPT and Custom Taxonomy [closed]
- strange conditional tag behaviour [duplicate]
- Comments are not working on Custom Post Type
- Error 403 when posting comments to a custom post type from a different page
- Custom post type is_singular condtional not working when managing sidebar display
- Redirect drafted post of custom post type to URL?
- Comments not working (error not allowed) on posts with custom post status
- Modifying post_type_link hook messing up edit function for a custom post