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. git-svn-id: https://develop.svn.wordpress.org/trunk@33041 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
dd28f15179
commit
efdce1da51
@ -3127,11 +3127,25 @@ function wp_insert_post( $postarr, $wp_error = false ) {
|
|||||||
|
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
|
|
||||||
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_id,
|
$defaults = array(
|
||||||
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
|
'post_author' => $user_id,
|
||||||
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
|
'post_content' => '',
|
||||||
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
|
'post_content_filtered' => '',
|
||||||
'post_content' => '', 'post_title' => '', 'context' => '');
|
'post_title' => '',
|
||||||
|
'post_excerpt' => '',
|
||||||
|
'post_status' => 'draft',
|
||||||
|
'post_type' => 'post',
|
||||||
|
'comment_status' => '',
|
||||||
|
'ping_status' => '',
|
||||||
|
'post_password' => '',
|
||||||
|
'to_ping' => '',
|
||||||
|
'pinged' => '',
|
||||||
|
'post_parent' => 0,
|
||||||
|
'menu_order' => 0,
|
||||||
|
'guid' => '',
|
||||||
|
'import_id' => 0,
|
||||||
|
'context' => '',
|
||||||
|
);
|
||||||
|
|
||||||
$postarr = wp_parse_args($postarr, $defaults);
|
$postarr = wp_parse_args($postarr, $defaults);
|
||||||
|
|
||||||
@ -3302,11 +3316,12 @@ function wp_insert_post( $postarr, $wp_error = false ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comment status.
|
||||||
if ( empty( $postarr['comment_status'] ) ) {
|
if ( empty( $postarr['comment_status'] ) ) {
|
||||||
if ( $update ) {
|
if ( $update ) {
|
||||||
$comment_status = 'closed';
|
$comment_status = 'closed';
|
||||||
} else {
|
} else {
|
||||||
$comment_status = get_option('default_comment_status');
|
$comment_status = get_default_comment_status( $post_type );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$comment_status = $postarr['comment_status'];
|
$comment_status = $postarr['comment_status'];
|
||||||
@ -3315,7 +3330,7 @@ function wp_insert_post( $postarr, $wp_error = false ) {
|
|||||||
// These variables are needed by compact() later.
|
// These variables are needed by compact() later.
|
||||||
$post_content_filtered = $postarr['post_content_filtered'];
|
$post_content_filtered = $postarr['post_content_filtered'];
|
||||||
$post_author = empty( $postarr['post_author'] ) ? $user_id : $postarr['post_author'];
|
$post_author = empty( $postarr['post_author'] ) ? $user_id : $postarr['post_author'];
|
||||||
$ping_status = empty( $postarr['ping_status'] ) ? get_option( 'default_ping_status' ) : $postarr['ping_status'];
|
$ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
|
||||||
$to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
|
$to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
|
||||||
$pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
|
$pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
|
||||||
$import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
|
$import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
|
||||||
@ -4056,9 +4071,51 @@ function wp_transition_post_status( $new_status, $old_status, $post ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trackback and ping functions
|
// Comment, trackback, and pingback functions.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get 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 $comment_type Type of comment. Default is `comment`.
|
||||||
|
*/
|
||||||
|
return apply_filters( "get_{$post_type}_default_comment_status", $status, $comment_type );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a URL to those already pinged.
|
* Add a URL to those already pinged.
|
||||||
*
|
*
|
||||||
|
@ -950,4 +950,77 @@ class Tests_Post extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( $value, $post->$field );
|
$this->assertEquals( $value, $post->$field );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 31168
|
||||||
|
*/
|
||||||
|
function test_wp_insert_post_default_comment_ping_status_open() {
|
||||||
|
$post_id = $this->factory->post->create( array(
|
||||||
|
'post_author' => $this->author_id,
|
||||||
|
'post_status' => 'public',
|
||||||
|
'post_content' => rand_str(),
|
||||||
|
'post_title' => rand_str(),
|
||||||
|
) );
|
||||||
|
$post = get_post( $post_id );
|
||||||
|
|
||||||
|
$this->assertEquals( 'open', $post->comment_status );
|
||||||
|
$this->assertEquals( 'open', $post->ping_status );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 31168
|
||||||
|
*/
|
||||||
|
function test_wp_insert_post_page_default_comment_ping_status_closed() {
|
||||||
|
$post_id = $this->factory->post->create( array(
|
||||||
|
'post_author' => $this->author_id,
|
||||||
|
'post_status' => 'public',
|
||||||
|
'post_content' => rand_str(),
|
||||||
|
'post_title' => rand_str(),
|
||||||
|
'post_type' => 'page',
|
||||||
|
) );
|
||||||
|
$post = get_post( $post_id );
|
||||||
|
|
||||||
|
$this->assertEquals( 'closed', $post->comment_status );
|
||||||
|
$this->assertEquals( 'closed', $post->ping_status );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 31168
|
||||||
|
*/
|
||||||
|
function test_wp_insert_post_cpt_default_comment_ping_status_open() {
|
||||||
|
$post_type = rand_str(20);
|
||||||
|
register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) );
|
||||||
|
$post_id = $this->factory->post->create( array(
|
||||||
|
'post_author' => $this->author_id,
|
||||||
|
'post_status' => 'public',
|
||||||
|
'post_content' => rand_str(),
|
||||||
|
'post_title' => rand_str(),
|
||||||
|
'post_type' => $post_type,
|
||||||
|
) );
|
||||||
|
$post = get_post( $post_id );
|
||||||
|
|
||||||
|
$this->assertEquals( 'open', $post->comment_status );
|
||||||
|
$this->assertEquals( 'open', $post->ping_status );
|
||||||
|
_unregister_post_type( $post_type );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 31168
|
||||||
|
*/
|
||||||
|
function test_wp_insert_post_cpt_default_comment_ping_status_closed() {
|
||||||
|
$post_type = rand_str(20);
|
||||||
|
register_post_type( $post_type );
|
||||||
|
$post_id = $this->factory->post->create( array(
|
||||||
|
'post_author' => $this->author_id,
|
||||||
|
'post_status' => 'public',
|
||||||
|
'post_content' => rand_str(),
|
||||||
|
'post_title' => rand_str(),
|
||||||
|
'post_type' => $post_type,
|
||||||
|
) );
|
||||||
|
$post = get_post( $post_id );
|
||||||
|
|
||||||
|
$this->assertEquals( 'closed', $post->comment_status );
|
||||||
|
$this->assertEquals( 'closed', $post->ping_status );
|
||||||
|
_unregister_post_type( $post_type );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user