Don't let there be duplicate post_names
git-svn-id: http://svn.automattic.com/wordpress/trunk@2323 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
729562e1c2
commit
a622906bd5
|
@ -96,15 +96,30 @@ case 'post':
|
||||||
if ('' != $_POST['advanced']) $post_status = 'draft';
|
if ('' != $_POST['advanced']) $post_status = 'draft';
|
||||||
if ('' != $_POST['savepage']) $post_status = 'static';
|
if ('' != $_POST['savepage']) $post_status = 'static';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->posts'");
|
$id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->posts'");
|
||||||
$post_ID = $id_result->Auto_increment;
|
$post_ID = $id_result->Auto_increment;
|
||||||
|
|
||||||
if ( empty($post_name) ) {
|
if ( empty($post_name) ) {
|
||||||
$post_name = sanitize_title($post_title, $post_ID);
|
$post_name = sanitize_title($post_title, $post_ID);
|
||||||
} else {
|
} else {
|
||||||
$post_name = sanitize_title($post_name, $post_ID);
|
$post_name = sanitize_title($post_name, $post_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('publish' == $post_status) {
|
||||||
|
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||||
|
if ($post_name_check) {
|
||||||
|
$suffix = 2;
|
||||||
|
while ($post_name_check) {
|
||||||
|
$alt_post_name = $post_name . "-$suffix";
|
||||||
|
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||||
|
$suffix++;
|
||||||
|
}
|
||||||
|
$post_name = $alt_post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$postquery ="INSERT INTO $wpdb->posts
|
$postquery ="INSERT INTO $wpdb->posts
|
||||||
(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
|
(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -281,12 +296,6 @@ case 'editpost':
|
||||||
$post_parent = $_POST['parent_id'];
|
$post_parent = $_POST['parent_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($post_name)) {
|
|
||||||
$post_name = sanitize_title($post_title, $post_ID);
|
|
||||||
} else {
|
|
||||||
$post_name = sanitize_title($post_name, $post_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
$trackback = $_POST['trackback_url'];
|
$trackback = $_POST['trackback_url'];
|
||||||
// Format trackbacks
|
// Format trackbacks
|
||||||
$trackback = preg_replace('|\s+|', '\n', $trackback);
|
$trackback = preg_replace('|\s+|', '\n', $trackback);
|
||||||
|
@ -296,6 +305,25 @@ case 'editpost':
|
||||||
if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) && 2 != get_option('new_users_can_blog') )
|
if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) && 2 != get_option('new_users_can_blog') )
|
||||||
$post_status = 'draft';
|
$post_status = 'draft';
|
||||||
|
|
||||||
|
if (empty($post_name)) {
|
||||||
|
$post_name = sanitize_title($post_title, $post_ID);
|
||||||
|
} else {
|
||||||
|
$post_name = sanitize_title($post_name, $post_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('publish' == $post_status) {
|
||||||
|
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||||
|
if ($post_name_check) {
|
||||||
|
$suffix = 2;
|
||||||
|
while ($post_name_check) {
|
||||||
|
$alt_post_name = $post_name . "-$suffix";
|
||||||
|
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||||
|
$suffix++;
|
||||||
|
}
|
||||||
|
$post_name = $alt_post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
|
if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
|
||||||
$aa = $_POST['aa'];
|
$aa = $_POST['aa'];
|
||||||
$mm = $_POST['mm'];
|
$mm = $_POST['mm'];
|
||||||
|
|
|
@ -36,7 +36,20 @@ function wp_insert_post($postarr = array()) {
|
||||||
$ping_status = get_settings('default_ping_status');
|
$ping_status = get_settings('default_ping_status');
|
||||||
if ( empty($post_parent) )
|
if ( empty($post_parent) )
|
||||||
$post_parent = 0;
|
$post_parent = 0;
|
||||||
|
|
||||||
|
if ('publish' == $post_status) {
|
||||||
|
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||||
|
if ($post_name_check) {
|
||||||
|
$suffix = 2;
|
||||||
|
while ($post_name_check) {
|
||||||
|
$alt_post_name = $post_name . "-$suffix";
|
||||||
|
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||||
|
$suffix++;
|
||||||
|
}
|
||||||
|
$post_name = $alt_post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO $wpdb->posts
|
$sql = "INSERT INTO $wpdb->posts
|
||||||
(post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name, comment_status, ping_status, post_parent)
|
(post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name, comment_status, ping_status, post_parent)
|
||||||
VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_cat', '$post_status', '$post_name', '$comment_status', '$ping_status', '$post_parent')";
|
VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_cat', '$post_status', '$post_name', '$comment_status', '$ping_status', '$post_parent')";
|
||||||
|
|
Loading…
Reference in New Issue