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 do test if a post is a custom post type?
- Hook for post and page load
- How to enqueue scripts on custom post add/edit pages?
- How do you use a CPT as the default home page?
- Conditional for single-{post-type}.php
- Why are the comments disabled by default on my custom_post_types?
- Calling a Function After New Post Creation for a WordPress Custom Post Type?
- Why are comments and trackbacks still getting through for custom post types?
- How to Debug the ‘save_post’ Action?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- Display Authors Comments on Profile Page
- List all posts commented by current user
- get_query_var() not working in pre_get_posts
- Unregister post type from child theme
- Filter for “get_post_type_archive_link()”
- 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
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- Admin Post Update Redirection to Posts Screen
- How often do you need to register_post_type?
- is_singular() not working if called via callback function of admin-ajax.php
- modify all posts of a category to “no comments allowed”
- Custom comment status possible?
- feed links for custom post type pages
- How to create notification on frontend using heartbeat api for multiple custom post types
- functions.php conditional tag only for custom post type
- How to set a custom post type post as static front page?
- With what hook can I address all posts from all custom post types when they are published?
- Seperating custom post type comments from regular blog posts comments
- Exclude custom function content from certain pages
- 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?
- Hook when adding or editing a specific custom post type? [closed]
- Recent comments on author page?
- remove_action conditionally for Custom Post Type
- custom post type upcoming post and past post
- wp_query and comment_parent – select only posts with top level comments
- Comment moderation on custom post types
- 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
- Automatically check “Allow comments” for custom post type [duplicate]
- How to register custom post types in a plugin?
- Add information above a custom post type listing of all posts page
- Remove “Get Shortlink” button in admin of custom post type
- How could I create a ‘private comments’ section on a custom post type?
- Disable comments from showing up public for Custom Post Type
- is_page_template not working as expected
- Custom Post Type loops and Disqus
- Custom Blog Post Listing in Genesis Sample Child Theme
- “Allow Comments” box cannot be checked
- remove child post from custom post type archive
- Set a default category – if the user didn’t select one- before creating a post
- Can’t unregister parent theme’s CPT from my child theme
- 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]
- Hooking in to an archive page?
- 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
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Validate custom fields before save using WordPress Rest API
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- get_comments not working on custom post types
- Posts are duplicating on wp_post_update
- Custom Post Type Set Comments ON by default without show METABOX
- Register widget only page is a singular of custom post type
- Is there a conditional tag to determine whether the post is _any_ custom post type?
- 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
- Create another comment system for CPT
- 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
- Filter Posts from the Main Query
- Convert comments to Custom Post Type
- 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?
- How to assign classes to all elements?
- custom comments form for custom post type
- What functions does WordPress use for filtering / sanitizing comments?
- Categorise Custom Post Types
- How can I add a filter to a particular post format?
- 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?
- comment_notification_text filter for custom post type
- Add a custom text to admin footer in a Custom Post Type page