Changeset 28464
- Timestamp:
- 05/17/2014 02:15:40 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r28461 r28464 2365 2365 global $wpdb; 2366 2366 2367 if ( ! taxonomy_exists($taxonomy) ) 2367 if ( ! taxonomy_exists($taxonomy) ) { 2368 2368 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 2369 2369 } 2370 2370 /** 2371 2371 * Filter a term before it is sanitized and inserted into the database. … … 2377 2377 */ 2378 2378 $term = apply_filters( 'pre_insert_term', $term, $taxonomy ); 2379 if ( is_wp_error( $term ) )2380 2381 2382 if ( is_int($term) && 0 == $term ) 2379 if ( is_wp_error( $term ) ) { 2380 return $term; 2381 } 2382 if ( is_int($term) && 0 == $term ) { 2383 2383 return new WP_Error('invalid_term_id', __('Invalid term ID')); 2384 2385 if ( '' == trim($term) ) 2384 } 2385 if ( '' == trim($term) ) { 2386 2386 return new WP_Error('empty_term_name', __('A name is required for this term')); 2387 2387 } 2388 2388 $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); 2389 2389 $args = wp_parse_args($args, $defaults); … … 2391 2391 $args['taxonomy'] = $taxonomy; 2392 2392 $args = sanitize_term($args, $taxonomy, 'db'); 2393 extract($args, EXTR_SKIP);2394 2393 2395 2394 // expected_slashed ($name) 2396 $name = wp_unslash($name); 2397 $description = wp_unslash($description); 2398 2399 $slug_provided = ! empty( $slug ); 2395 $name = wp_unslash( $args['name'] ); 2396 $description = wp_unslash( $args['description'] ); 2397 $parent = (int) $args['parent']; 2398 2399 $slug_provided = ! empty( $args['slug'] ); 2400 2400 if ( ! $slug_provided ) { 2401 2401 $slug = sanitize_title($name); 2402 } else { 2403 $slug = $args['slug']; 2402 2404 } 2403 2405 2404 2406 $term_group = 0; 2405 if ( $a lias_of) {2406 $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $a lias_of) );2407 if ( $args['alias_of'] ) { 2408 $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $args['alias_of'] ) ); 2407 2409 if ( $alias->term_group ) { 2408 2410 // The alias we want is already in a group, so let's use that one. … … 2440 2442 if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { 2441 2443 // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. 2442 $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );2444 $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => $parent ) ); 2443 2445 if ( in_array($name, $siblings) ) { 2444 2446 if ( $slug_provided ) { … … 2449 2451 } else { 2450 2452 $slug = wp_unique_term_slug($slug, (object) $args); 2451 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 2453 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2452 2454 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2455 } 2453 2456 $term_id = (int) $wpdb->insert_id; 2454 2457 } … … 2456 2459 // We've got an existing term, with a different name, Create the new term. 2457 2460 $slug = wp_unique_term_slug($slug, (object) $args); 2458 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 2461 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2459 2462 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2463 } 2460 2464 $term_id = (int) $wpdb->insert_id; 2461 2465 } elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) ) { … … 2466 2470 // This term does not exist at all in the database, Create it. 2467 2471 $slug = wp_unique_term_slug($slug, (object) $args); 2468 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 2472 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2469 2473 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2474 } 2470 2475 $term_id = (int) $wpdb->insert_id; 2471 2476 } … … 2485 2490 $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) ); 2486 2491 2487 if ( !empty($tt_id) ) 2492 if ( !empty($tt_id) ) { 2488 2493 return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); 2489 2494 } 2490 2495 $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) ); 2491 2496 $tt_id = (int) $wpdb->insert_id;
Note: See TracChangeset
for help on using the changeset viewer.