On this page
get_default_comment_status( string $post_type = 'post', string $comment_type = 'comment' ): string
Gets the default comment status for a post type.
Parameters
$post_typestring Optional-
Post type. Default
'post'.Default:
'post' $comment_typestring Optional-
Comment type. Default
'comment'.Default:
'comment'
Return
string Expected return value is 'open' or 'closed'.
Source
File: wp-includes/comment.php. View all references
function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) {
switch ( $comment_type ) {
case 'pingback':
case 'trackback':
$supports = 'trackbacks';
$option = 'ping';
break;
default:
$supports = 'comments';
$option = 'comment';
break;
}
// Set the status.
if ( 'page' === $post_type ) {
$status = 'closed';
} elseif ( post_type_supports( $post_type, $supports ) ) {
$status = get_option( "default_{$option}_status" );
} else {
$status = 'closed';
}
/**
* Filters the default comment status for the given post type.
*
* @since 4.3.0
*
* @param string $status Default status for the given post type,
* either 'open' or 'closed'.
* @param string $post_type Post type. Default is `post`.
* @param string $comment_type Type of comment. Default is `comment`.
*/
return apply_filters( 'get_default_comment_status', $status, $post_type, $comment_type );
}
Hooks
- apply_filters( 'get_default_comment_status',
string $status ,string $post_type ,string $comment_type ) -
Filters the default comment status for the given post type.
Related
Uses
| Uses | Description |
|---|---|
| post_type_supports() wp-includes/post.php | Checks a post type’s support for a given feature. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Used By
| Used By | Description |
|---|---|
| get_default_post_to_edit() wp-admin/includes/post.php | Returns default post information to use when populating the “Write Post” form. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| wp_xmlrpc_server::mw_editPost() wp-includes/class-wp-xmlrpc-server.php | Edit a post. |
| wp_xmlrpc_server::mw_newPost() wp-includes/class-wp-xmlrpc-server.php | Create a new post. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_default_comment_status