summaryrefslogtreecommitdiffstats
path: root/wp-includes/post.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-06-10 14:08:54 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-06-10 14:08:54 +0000
commit310940b824eff4a116dcd72ccd339bb602021981 (patch)
tree19f6efc7b30b9456eebc26d578c5dc7e125bb6e7 /wp-includes/post.php
parent616f7399dc4c4f7c56951c7b87a7aa91b3e690a3 (diff)
downloadwordpress-mu-310940b824eff4a116dcd72ccd339bb602021981.tar.gz
wordpress-mu-310940b824eff4a116dcd72ccd339bb602021981.tar.xz
wordpress-mu-310940b824eff4a116dcd72ccd339bb602021981.zip
Merge with branches/2.5 in WordPress, revision 8066
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1324 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/post.php')
-rw-r--r--wp-includes/post.php54
1 files changed, 36 insertions, 18 deletions
diff --git a/wp-includes/post.php b/wp-includes/post.php
index 8219da6..cf76638 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -199,12 +199,11 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
* @subpackage Post
* @since 2.5
*
- * @param string $field {@internal Missing Description}}
- * @param int|object &$post post ID or post object
+ * @param int|object $post post ID or post object
* @return array of ancestor IDs
*/
function get_post_ancestors($post) {
- $post = get_post();
+ $post = get_post($post);
if ( !empty($post->ancestors) )
return $post->ancestors;
@@ -1164,7 +1163,7 @@ function wp_get_single_post($postid = 0, $mode = OBJECT) {
* @param array $postarr post contents
* @return int post ID or 0 on error
*/
-function wp_insert_post($postarr = array()) {
+function wp_insert_post($postarr = array(), $wp_error = false) {
global $wpdb, $wp_rewrite, $user_ID;
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
@@ -1187,8 +1186,12 @@ function wp_insert_post($postarr = array()) {
$previous_status = 'new';
}
- if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) )
- return 0;
+ if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) ) {
+ if ( $wp_error )
+ return new WP_Error('empty_content', __('Content, title, and excerpt are empty.'));
+ else
+ return 0;
+ }
// Make sure we set a valid category
if (0 == count($post_category) || !is_array($post_category)) {
@@ -1285,8 +1288,7 @@ function wp_insert_post($postarr = array()) {
$suffix = 2;
do {
$alt_post_name = substr($post_name, 0, 200-(strlen($suffix)+1)). "-$suffix";
- // expected_slashed ($alt_post_name, $post_name, $post_type)
- $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_type = '$post_type' AND ID != %d AND post_parent = %d LIMIT 1", $post_ID, $post_parent));
+ $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $alt_post_name, $post_type, $post_ID, $post_parent));
$suffix++;
} while ($post_name_check);
$post_name = $alt_post_name;
@@ -1300,10 +1302,20 @@ function wp_insert_post($postarr = array()) {
if ($update) {
do_action( 'pre_post_update', $post_ID );
- $wpdb->update( $wpdb->posts, $data, $where );
+ if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
+ if ( $wp_error )
+ return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
+ else
+ return 0;
+ }
} else {
$data['post_mime_type'] = stripslashes( $post_mime_type ); // This isn't in the update
- $wpdb->insert( $wpdb->posts, $data );
+ if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
+ if ( $wp_error )
+ return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
+ else
+ return 0;
+ }
$post_ID = (int) $wpdb->insert_id;
// use the newly generated $post_ID
@@ -1320,19 +1332,29 @@ function wp_insert_post($postarr = array()) {
$current_guid = get_post_field( 'guid', $post_ID );
- if ( 'page' == $post_type ) {
+ if ( 'page' == $post_type )
clean_page_cache($post_ID);
- } else {
+ else
clean_post_cache($post_ID);
- }
// Set GUID
if ( !$update && '' == $current_guid )
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where );
$post = get_post($post_ID);
- if ( !empty($page_template) )
+
+ if ( !empty($page_template) && 'page' == $post_type ) {
$post->page_template = $page_template;
+ $page_templates = get_page_templates();
+ if ( 'default' != $page_template && !in_array($page_template, $page_templates) ) {
+ if ( $wp_error )
+ return new WP_Error('invalid_page_template', __('The page template is invalid.'));
+ else
+ return 0;
+ }
+ if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template) )
+ add_post_meta($post_ID, '_wp_page_template', $page_template, true);
+ }
wp_transition_post_status($post_status, $previous_status, $post);
@@ -2943,10 +2965,6 @@ function _publish_post_hook($post_id) {
*/
function _save_post_hook($post_id, $post) {
if ( $post->post_type == 'page' ) {
- if ( !empty($post->page_template) )
- if ( ! update_post_meta($post_id, '_wp_page_template', $post->page_template))
- add_post_meta($post_id, '_wp_page_template', $post->page_template, true);
-
clean_page_cache($post_id);
global $wp_rewrite;
$wp_rewrite->flush_rules();