/** * Converts the given set of old taxonomy options into the new format. * * @since 3.1 * @param array $array The array of old fields * @return array The new meta fields */ public static function convert_taxonomy_option( $arr ) { // Get the array data $tax = $arr['post_taxonomy']; $terms = $arr['post_terms']; $auto = $arr['post_auto_tax_terms']; $tags = $arr['post_tags']; $tags = $tags === 'false'? '' : $tags; // Construct the default taxonomy entry $default = array( 'taxonomy' => $tax, 'terms' => $terms, 'auto' => $auto ); // Generate the new option $new = array( $default ); // If the tags option is set, then we must save this as well, so that the user does not lose his/her settings if ( !empty($tags) ) { $tags = WPRSS_FTP_Utils::trim_explode(',', $tags); $new_tags = array(); // Create the tags foreach( $tags as $tag ) { $exists = term_exists( $tag, 'post_tag' ); if ( $exists === 0 || $exists === NULL ) { $exists = wp_insert_term( $tag, 'post_tag' ); } $tag_id = $exists['term_id']; $tag_obj = get_term_by( 'id', $tag_id, 'post_tag' ); $tag_slug = $tag_obj->slug; $new_tags[] = $tag_slug; } // Add another taxonomy entry for the tags $new[] = array( 'taxonomy' => 'post_tag', 'terms' => $new_tags, 'auto' => 'false' ); } return $new; }