WordPress 4.3 コメント

Comments are now turned off on pages by default

  • 4.3で、get_default_comment_status()が追加されて、
  • /**
     * Gets the default comment status for a post type.
     *
     * @since 4.3.0
     *
     * @param string $post_type Optional. Post type. Default 'post'.
     * @param string $comment_type Optional. Comment type. Default 'comment'.
     * @return string Expected return value is 'open' or 'closed'.
     */
    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';
    	}
    
    	// 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';
    	}
    
    	/**
    	 * Filter 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 wpdocs_open_comments_for_myposttype( $status, $post_type, $comment_type ) {
	
 return 'closed';
}
add_filter( 'get_default_comment_status', 'wpdocs_open_comments_for_myposttype', 11, 3 );

投稿も これでオフ、後は、投稿の許可のチェックボックスで表示非表示を設定すればいい

get_option( 'default_comment_status' )

ディスカッションのデフォルト値が変わる模様

[emulsion_relate_posts]