Make WordPress Core

Changeset 28464


Ignore:
Timestamp:
05/17/2014 02:15:40 PM (12 years ago)
Author:
wonderboymusic
Message:

Eliminate the use of extract() in wp_insert_term().

See #22400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r28461 r28464  
    23652365        global $wpdb;
    23662366
    2367         if ( ! taxonomy_exists($taxonomy) )
     2367        if ( ! taxonomy_exists($taxonomy) ) {
    23682368                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    2369 
     2369        }
    23702370        /**
    23712371         * Filter a term before it is sanitized and inserted into the database.
    … …  
    23772377         */
    23782378        $term = apply_filters( 'pre_insert_term', $term, $taxonomy );
    2379                 if ( is_wp_error( $term ) )
    2380                         return $term;
    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 ) {
    23832383                return new WP_Error('invalid_term_id', __('Invalid term ID'));
    2384 
    2385         if ( '' == trim($term) )
     2384        }
     2385        if ( '' == trim($term) ) {
    23862386                return new WP_Error('empty_term_name', __('A name is required for this term'));
    2387 
     2387        }
    23882388        $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
    23892389        $args = wp_parse_args($args, $defaults);
    … …  
    23912391        $args['taxonomy'] = $taxonomy;
    23922392        $args = sanitize_term($args, $taxonomy, 'db');
    2393         extract($args, EXTR_SKIP);
    23942393
    23952394        // 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'] );
    24002400        if ( ! $slug_provided ) {
    24012401                $slug = sanitize_title($name);
     2402        } else {
     2403                $slug = $args['slug'];
    24022404        }
    24032405
    24042406        $term_group = 0;
    2405         if ( $alias_of ) {
    2406                 $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_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'] ) );
    24072409                if ( $alias->term_group ) {
    24082410                        // The alias we want is already in a group, so let's use that one.
    … …  
    24402442                if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) {
    24412443                        // 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 ) );
    24432445                        if ( in_array($name, $siblings) ) {
    24442446                                if ( $slug_provided ) {
    … …  
    24492451                        } else {
    24502452                                $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' ) ) ) {
    24522454                                        return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
     2455                                }
    24532456                                $term_id = (int) $wpdb->insert_id;
    24542457                        }
    … …  
    24562459                        // We've got an existing term, with a different name, Create the new term.
    24572460                        $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' ) ) ) {
    24592462                                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
     2463                        }
    24602464                        $term_id = (int) $wpdb->insert_id;
    24612465                } elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) )  {
    … …  
    24662470                // This term does not exist at all in the database, Create it.
    24672471                $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' ) ) ) {
    24692473                        return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
     2474                }
    24702475                $term_id = (int) $wpdb->insert_id;
    24712476        }
    … …  
    24852490        $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 ) );
    24862491
    2487         if ( !empty($tt_id) )
     2492        if ( !empty($tt_id) ) {
    24882493                return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
    2489 
     2494        }
    24902495        $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) );
    24912496        $tt_id = (int) $wpdb->insert_id;
Note: See TracChangeset for help on using the changeset viewer.