Ticket #6098: page_template_validation.diff
File page_template_validation.diff, 3.1 KB (added by , 17 years ago) |
---|
-
wp-includes/post.php
1109 1109 * @param array $postarr post contents 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 1115 1115 $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, … … 1132 1132 $previous_status = 'new'; 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 1139 1143 if (0 == count($post_category) || !is_array($post_category)) { … … 1244 1248 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 1253 1267 // use the newly generated $post_ID … … 1264 1278 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 1274 1287 if ( !$update && '' == $current_guid ) 1275 1288 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where ); 1276 1289 1290 if ( !empty($page_template) && 'page' == $post_type ) { 1291 $page_templates = get_page_templates(); 1292 if ( ! in_array($page_template, $page_templates) ) { 1293 if ( $wp_error ) 1294 return new WP_Error('invalid_page_template', __('The page template is invalid.')); 1295 else 1296 return 0; 1297 } 1298 if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template) ) 1299 add_post_meta($post_ID, '_wp_page_template', $page_template, true); 1300 } 1301 1277 1302 $post = get_post($post_ID); 1278 if ( !empty($page_template) )1279 $post->page_template = $page_template;1280 1303 1281 1304 wp_transition_post_status($post_status, $previous_status, $post); 1282 1305 … … 2897 2920 */ 2898 2921 function _save_post_hook($post_id, $post) { 2899 2922 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 2923 clean_page_cache($post_id); 2905 2924 global $wp_rewrite; 2906 2925 $wp_rewrite->flush_rules();