Ticket #31168: 31168.2.diff
File 31168.2.diff, 7.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index a26efec..db61564 100644
function wp_insert_post( $postarr, $wp_error = false ) { 3127 3127 3128 3128 $user_id = get_current_user_id(); 3129 3129 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 ); 3135 3149 3136 3150 $postarr = wp_parse_args($postarr, $defaults); 3137 3151 … … function wp_insert_post( $postarr, $wp_error = false ) { 3302 3316 } 3303 3317 } 3304 3318 3319 // Comment status. 3305 3320 if ( empty( $postarr['comment_status'] ) ) { 3306 3321 if ( $update ) { 3307 3322 $comment_status = 'closed'; 3308 3323 } else { 3309 $comment_status = get_ option('default_comment_status');3324 $comment_status = get_default_comment_status( $post_type ); 3310 3325 } 3311 3326 } else { 3312 3327 $comment_status = $postarr['comment_status']; … … function wp_insert_post( $postarr, $wp_error = false ) { 3315 3330 // These variables are needed by compact() later. 3316 3331 $post_content_filtered = $postarr['post_content_filtered']; 3317 3332 $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_ping_status( $post_type ) : $postarr['ping_status']; 3319 3334 $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; 3320 3335 $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; 3321 3336 $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0; … … function wp_transition_post_status( $new_status, $old_status, $post ) { 4056 4071 } 4057 4072 4058 4073 // 4059 // Trackbackand ping functions4074 // Comment, trackback, and ping functions 4060 4075 // 4061 4076 4062 4077 /** 4078 * Get the default comment or ping status. 4079 * 4080 * @since 4.3.0 4081 * @access private 4082 * 4083 * @param string $post_type Optional. Post type. Default 'post'. 4084 * @param bool $ping Optional. True for pings false for comments. Default 'false'. 4085 * @return string Expected return value is 'open' or 'closed'. 4086 */ 4087 function _get_default_status( $post_type = 'post', $ping = false ) { 4088 // Comments. 4089 $object = 'comment'; 4090 $supports = 'comments'; 4091 4092 // Ping/trackbacks. 4093 if ( true === $ping ) { 4094 $object = 'ping'; 4095 $supports = 'trackbacks'; 4096 } 4097 4098 // Set the status. 4099 if ( 'page' === $post_type ) { // @todo decide if this should be moved into its own function. 4100 $status = 'closed'; 4101 } elseif ( post_type_supports( $post_type, $supports ) ) { 4102 $status = get_option( "default_{$object}_status" ); 4103 } else { 4104 $status = 'closed'; 4105 } 4106 4107 /** 4108 * Filter the default comment or ping status for the given post_type. 4109 * 4110 * The dynamic portions of the hook name, `$post_type` & `$object`, refers to the 4111 * post type and whether this is a 'comment' or 'ping'. 4112 * 4113 * Some examples of filter hooks generated here include: 'get_post_default_comment_status', 4114 * 'get_page_default_comment_status', 'get_post_default_ping_status', 4115 * 'get_page_default_ping_status', etc. 4116 * 4117 * @since 4.3.0 4118 * 4119 * @param string $status Default status for the given post_type, either 'open' or 'closed'. 4120 */ 4121 return apply_filters( "get_{$post_type}_default_{$object}_status", $status ); 4122 } 4123 4124 /** 4125 * Get the default comment status. 4126 * 4127 * @since 4.3.0 4128 * 4129 * @param string $post_type Optional. Post type. Default 'post'. 4130 * @return string Expected return value is 'open' or 'closed'. 4131 */ 4132 function get_default_comment_status( $post_type = 'post' ) { 4133 return _get_default_status( $post_type ); 4134 } 4135 4136 /** 4137 * Get the default ping status. 4138 * 4139 * @since 4.3.0 4140 * 4141 * @param string $post_type Optional. Post type. Default 'post'. 4142 * @return string Expected return value is 'open' or 'closed'. 4143 */ 4144 function get_default_ping_status( $post_type = 'post' ) { 4145 return _get_default_status( $post_type, true ); 4146 } 4147 4148 /** 4063 4149 * Add a URL to those already pinged. 4064 4150 * 4065 4151 * @since 1.5.0 -
tests/phpunit/tests/post.php
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php index 2c80735..86810b9 100644
class Tests_Post extends WP_UnitTestCase { 950 950 $this->assertEquals( $value, $post->$field ); 951 951 } 952 952 } 953 954 /** 955 * @ticket 31168 956 */ 957 function test_wp_insert_post_default_comment_ping_status_open() { 958 $post_id = $this->factory->post->create( array( 959 'post_author' => $this->author_id, 960 'post_status' => 'public', 961 'post_content' => rand_str(), 962 'post_title' => rand_str(), 963 ) ); 964 $post = get_post( $post_id ); 965 966 $this->assertEquals( 'open', $post->comment_status ); 967 $this->assertEquals( 'open', $post->ping_status ); 968 } 969 970 /** 971 * @ticket 31168 972 */ 973 function test_wp_insert_post_page_default_comment_ping_status_closed() { 974 $post_id = $this->factory->post->create( array( 975 'post_author' => $this->author_id, 976 'post_status' => 'public', 977 'post_content' => rand_str(), 978 'post_title' => rand_str(), 979 'post_type' => 'page', 980 ) ); 981 $post = get_post( $post_id ); 982 983 $this->assertEquals( 'closed', $post->comment_status ); 984 $this->assertEquals( 'closed', $post->ping_status ); 985 } 986 987 /** 988 * @ticket 31168 989 */ 990 function test_wp_insert_post_cpt_default_comment_ping_status_open() { 991 $post_type = rand_str(20); 992 register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) ); 993 $post_id = $this->factory->post->create( array( 994 'post_author' => $this->author_id, 995 'post_status' => 'public', 996 'post_content' => rand_str(), 997 'post_title' => rand_str(), 998 'post_type' => $post_type, 999 ) ); 1000 $post = get_post( $post_id ); 1001 1002 $this->assertEquals( 'open', $post->comment_status ); 1003 $this->assertEquals( 'open', $post->ping_status ); 1004 _unregister_post_type( $post_type ); 1005 } 1006 1007 /** 1008 * @ticket 31168 1009 */ 1010 function test_wp_insert_post_cpt_default_comment_ping_status_closed() { 1011 $post_type = rand_str(20); 1012 register_post_type( $post_type ); 1013 $post_id = $this->factory->post->create( array( 1014 'post_author' => $this->author_id, 1015 'post_status' => 'public', 1016 'post_content' => rand_str(), 1017 'post_title' => rand_str(), 1018 'post_type' => $post_type, 1019 ) ); 1020 $post = get_post( $post_id ); 1021 1022 $this->assertEquals( 'closed', $post->comment_status ); 1023 $this->assertEquals( 'closed', $post->ping_status ); 1024 _unregister_post_type( $post_type ); 1025 } 953 1026 }