Make WordPress Core


Ignore:
Timestamp:
07/02/2015 12:21:28 AM (9 years ago)
Author:
obenland
Message:

Turn of comments for pages by default.

Pages are static content, for which comments are not expected out of the box.

Props valendesigns, rachelbaker.
Fixes #31168.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r32881 r33041  
    31283128    $user_id = get_current_user_id();
    31293129
    3130     $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_id,
    3131         'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
    3132         'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
    3133         'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
    3134         'post_content' => '', 'post_title' => '', 'context' => '');
     3130    $defaults = array(
     3131        'post_author' => $user_id,
     3132        'post_content' => '',
     3133        'post_content_filtered' => '',
     3134        'post_title' => '',
     3135        'post_excerpt' => '',
     3136        'post_status' => 'draft',
     3137        'post_type' => 'post',
     3138        'comment_status' => '',
     3139        'ping_status' => '',
     3140        'post_password' => '',
     3141        'to_ping' =>  '',
     3142        'pinged' => '',
     3143        'post_parent' => 0,
     3144        'menu_order' => 0,
     3145        'guid' => '',
     3146        'import_id' => 0,
     3147        'context' => '',
     3148    );
    31353149
    31363150    $postarr = wp_parse_args($postarr, $defaults);
     
    33033317    }
    33043318
     3319    // Comment status.
    33053320    if ( empty( $postarr['comment_status'] ) ) {
    33063321        if ( $update ) {
    33073322            $comment_status = 'closed';
    33083323        } else {
    3309             $comment_status = get_option('default_comment_status');
     3324            $comment_status = get_default_comment_status( $post_type );
    33103325        }
    33113326    } else {
     
    33163331    $post_content_filtered = $postarr['post_content_filtered'];
    33173332    $post_author = empty( $postarr['post_author'] ) ? $user_id : $postarr['post_author'];
    3318     $ping_status = empty( $postarr['ping_status'] ) ? get_option( 'default_ping_status' ) : $postarr['ping_status'];
     3333    $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
    33193334    $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
    33203335    $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
     
    40574072
    40584073//
    4059 // Trackback and ping functions
     4074// Comment, trackback, and pingback functions.
    40604075//
     4076
     4077/**
     4078 * Get the default comment status for a post type.
     4079 *
     4080 * @since 4.3.0
     4081 *
     4082 * @param  string $post_type    Optional. Post type. Default 'post'.
     4083 * @param  string $comment_type Optional. Comment type. Default 'comment'.
     4084 * @return string Expected return value is 'open' or 'closed'.
     4085 */
     4086function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) {
     4087    switch ( $comment_type ) {
     4088        case 'pingback' :
     4089        case 'trackback' :
     4090            $supports = 'trackbacks';
     4091            $option = 'ping';
     4092            break;
     4093        default :
     4094            $supports = 'comments';
     4095            $option = 'comment';
     4096    }
     4097
     4098    // Set the status.
     4099    if ( 'page' === $post_type ) {
     4100        $status = 'closed';
     4101    } elseif ( post_type_supports( $post_type, $supports ) ) {
     4102        $status = get_option( "default_{$option}_status" );
     4103    } else {
     4104        $status = 'closed';
     4105    }
     4106
     4107    /**
     4108     * Filter the default comment status for the given post type.
     4109     *
     4110     * @since 4.3.0
     4111     *
     4112     * @param string $status       Default status for the given post type,
     4113     *                             either 'open' or 'closed'.
     4114     * @param string $comment_type Type of comment. Default is `comment`.
     4115     */
     4116    return apply_filters( "get_{$post_type}_default_comment_status", $status, $comment_type );
     4117}
    40614118
    40624119/**
Note: See TracChangeset for help on using the changeset viewer.