Changeset 7900
- Timestamp:
- 05/05/2008 11:19:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r7894 r7900 1110 1110 * @return int post ID or 0 on error 1111 1111 */ 1112 function wp_insert_post($postarr = array() ) {1112 function wp_insert_post($postarr = array(), $wp_error = false) { 1113 1113 global $wpdb, $wp_rewrite, $user_ID; 1114 1114 … … 1133 1133 } 1134 1134 1135 if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) ) 1136 return 0; 1135 if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) ) { 1136 if ( $wp_error ) 1137 return new WP_Error('empty_content', __('Content, title, and excerpt are empty.')); 1138 else 1139 return 0; 1140 } 1137 1141 1138 1142 // Make sure we set a valid category … … 1245 1249 if ($update) { 1246 1250 do_action( 'pre_post_update', $post_ID ); 1247 $wpdb->update( $wpdb->posts, $data, $where ); 1251 if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { 1252 if ( $wp_error ) 1253 return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); 1254 else 1255 return 0; 1256 } 1248 1257 } else { 1249 1258 $data['post_mime_type'] = stripslashes( $post_mime_type ); // This isn't in the update 1250 $wpdb->insert( $wpdb->posts, $data ); 1259 if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { 1260 if ( $wp_error ) 1261 return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error); 1262 else 1263 return 0; 1264 } 1251 1265 $post_ID = (int) $wpdb->insert_id; 1252 1266 … … 1265 1279 $current_guid = get_post_field( 'guid', $post_ID ); 1266 1280 1267 if ( 'page' == $post_type ) {1281 if ( 'page' == $post_type ) 1268 1282 clean_page_cache($post_ID); 1269 } else {1283 else 1270 1284 clean_post_cache($post_ID); 1271 }1272 1285 1273 1286 // Set GUID … … 1276 1289 1277 1290 $post = get_post($post_ID); 1278 if ( !empty($page_template) ) 1291 1292 if ( !empty($page_template) && 'page' == $post_type ) { 1279 1293 $post->page_template = $page_template; 1294 $page_templates = get_page_templates(); 1295 if ( ! in_array($page_template, $page_templates) ) { 1296 if ( $wp_error ) 1297 return new WP_Error('invalid_page_template', __('The page template is invalid.')); 1298 else 1299 return 0; 1300 } 1301 if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template) ) 1302 add_post_meta($post_ID, '_wp_page_template', $page_template, true); 1303 } 1280 1304 1281 1305 wp_transition_post_status($post_status, $previous_status, $post); … … 2898 2922 function _save_post_hook($post_id, $post) { 2899 2923 if ( $post->post_type == 'page' ) { 2900 if ( !empty($post->page_template) )2901 if ( ! update_post_meta($post_id, '_wp_page_template', $post->page_template))2902 add_post_meta($post_id, '_wp_page_template', $post->page_template, true);2903 2904 2924 clean_page_cache($post_id); 2905 2925 global $wp_rewrite;
Note: See TracChangeset
for help on using the changeset viewer.