get_default_comment_status( string $post_type = 'post', string $comment_type = 'comment' )

Gets the default comment status for a post type.


Description Description


Parameters Parameters

$post_type

(string) (Optional) Post type.

Default value: 'post'

$comment_type

(string) (Optional) Comment type.

Default value: 'comment'


Top ↑

Return Return

(string) Expected return value is 'open' or 'closed'.


Top ↑

Source Source

File: wp-includes/comment.php

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

Top ↑

Changelog Changelog

Changelog
Version Description
4.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.