Capture last db error. Pass it in WP_Error data when term inserts fail. Fix typo in WP_Ajax_Response
git-svn-id: http://svn.automattic.com/wordpress/trunk@7431 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4784e3bd97
commit
da37142561
|
@ -764,7 +764,7 @@ class WP_Ajax_Response {
|
||||||
$response .= "<wp_error_data code='$code'$class>";
|
$response .= "<wp_error_data code='$code'$class>";
|
||||||
|
|
||||||
if ( is_scalar($error_data) ) {
|
if ( is_scalar($error_data) ) {
|
||||||
$response .= "<![CDATA[$v]]>";
|
$response .= "<![CDATA[$error_data]]>";
|
||||||
} elseif ( is_array($error_data) ) {
|
} elseif ( is_array($error_data) ) {
|
||||||
foreach ( $error_data as $k => $v )
|
foreach ( $error_data as $k => $v )
|
||||||
$response .= "<$k><![CDATA[$v]]></$k>";
|
$response .= "<$k><![CDATA[$v]]></$k>";
|
||||||
|
|
|
@ -1153,14 +1153,14 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
|
||||||
|
|
||||||
if ( ! $term_id = is_term($slug) ) {
|
if ( ! $term_id = is_term($slug) ) {
|
||||||
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
|
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
|
||||||
return new WP_Error('db_insert_error', __('Could not insert term into the database'));
|
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
|
||||||
$term_id = (int) $wpdb->insert_id;
|
$term_id = (int) $wpdb->insert_id;
|
||||||
} else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) {
|
} else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) {
|
||||||
// If the taxonomy supports hierarchy and the term has a parent, make the slug unique
|
// If the taxonomy supports hierarchy and the term has a parent, make the slug unique
|
||||||
// by incorporating parent slugs.
|
// by incorporating parent slugs.
|
||||||
$slug = wp_unique_term_slug($slug, (object) $args);
|
$slug = wp_unique_term_slug($slug, (object) $args);
|
||||||
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
|
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
|
||||||
return new WP_Error('db_insert_error', __('Could not insert term into the database'));
|
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
|
||||||
$term_id = (int) $wpdb->insert_id;
|
$term_id = (int) $wpdb->insert_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ class wpdb {
|
||||||
|
|
||||||
var $show_errors = false;
|
var $show_errors = false;
|
||||||
var $suppress_errors = false;
|
var $suppress_errors = false;
|
||||||
|
var $last_error = '';
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
var $last_query;
|
var $last_query;
|
||||||
var $col_info;
|
var $col_info;
|
||||||
|
@ -278,7 +279,7 @@ class wpdb {
|
||||||
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
|
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
|
||||||
|
|
||||||
// If there is an error then take note of it..
|
// If there is an error then take note of it..
|
||||||
if ( mysql_error($this->dbh) ) {
|
if ( $this->last_error = mysql_error($this->dbh) ) {
|
||||||
$this->print_error();
|
$this->print_error();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue