| 2055 | | if ( empty($slug) ) |
| 2056 | | $slug = sanitize_title($name); |
| | 2055 | if ( empty( $slug ) ) { |
| | 2056 | $name = trim( $name ); |
| | 2057 | |
| | 2058 | // check for a term like "$$$" so it isn't repeatedly added |
| | 2059 | if ( preg_match_all( '#[^:alnum:]#', $name, $matches ) && count( $matches[0] ) === strlen( $name ) ) { |
| | 2060 | $exists = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, slug FROM $wpdb->terms WHERE name = %s", $name ) ); |
| | 2061 | if ( ! empty( $exists ) ) { |
| | 2062 | if ( term_exists( $exists->term_id, $taxonomy ) ) |
| | 2063 | return new WP_Error( 'term_exists', __( 'A term with the name provided already exists.' ) ); |
| | 2064 | |
| | 2065 | // use the existing slug or the term will never match in term_exists |
| | 2066 | $slug = $exists->slug; |
| | 2067 | } |