get_default_comment_status

函式
get_default_comment_status ( $post_type = 'post', $comment_type = 'comment' )
引數
  • (string) $post_type Optional. Post type. Default 'post'.
    Required:
    Default: 'post'
  • (string) $comment_type Optional. Comment type. Default 'comment'.
    Required:
    Default: 'comment'
返回值
  • (string) Expected return value is 'open' or 'closed'.
定義位置
相關方法
get_comment_statuseswp_set_comment_statuswp_get_comment_statusget_default_block_editor_settingsget_comment_text
引入
4.3.0
棄用
-

get_default_comment_status: 這個函式返回WordPress中新文章的預設評論狀態。評論狀態可以設定為”開啟”、”關閉”或”繼承”(從文章的父級繼承該狀態)。

獲取一個文章型別的預設評論狀態。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >