Index: wp-includes/default-filters.php
===================================================================
--- wp-includes/default-filters.php	(revision 18753)
+++ wp-includes/default-filters.php	(working copy)
@@ -196,6 +196,7 @@
 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'        );
 add_filter( 'widget_text',              'shortcode_unautop'                   );
 add_filter( 'widget_text',              'do_shortcode'                        );
+add_filter( 'post_link_categories',     '_sort_terms_by_id'                   );
 
 // Actions
 add_action( 'wp_head',             'wp_enqueue_scripts',              1     );
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 18753)
+++ wp-includes/link-template.php	(working copy)
@@ -121,7 +121,7 @@
 		if ( strpos($permalink, '%category%') !== false ) {
 			$cats = get_the_category($post->ID);
 			if ( $cats ) {
-				usort($cats, '_usort_terms_by_ID'); // order by ID
+				$cats = apply_filters( 'post_link_categories', $cats );
 				$category = $cats[0]->slug;
 				if ( $parent = $cats[0]->parent )
 					$category = get_category_parents($parent, false, '/', true) . $category;
@@ -1128,7 +1128,7 @@
 			}
 
 			$excluded_categories = array_map( 'intval', $excluded_categories );
-				
+
 			if ( ! empty( $cat_array ) ) {
 				$excluded_categories = array_diff($excluded_categories, $cat_array);
 				$posts_in_ex_cats_sql = '';
@@ -1276,7 +1276,7 @@
 	$cat_array = array();
 	if( ! is_array( $excluded_categories ) )
 		$excluded_categories = explode( ',', $excluded_categories );
-		
+
 	if ( $in_same_cat || ! empty( $excluded_categories ) ) {
 		if ( $in_same_cat )
 			$cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) );
Index: wp-includes/category-template.php
===================================================================
--- wp-includes/category-template.php	(revision 18753)
+++ wp-includes/category-template.php	(working copy)
@@ -126,6 +126,23 @@
 }
 
 /**
+ * Sort terms by ID.
+ *
+ * Used with the post_link_categories filter.
+ *
+ * @since 3.3.0
+ * @access private
+ *
+ * @param array $terms
+ *
+ * @return array Sorted terms
+ */
+function _sort_terms_by_id ( $terms ) {
+	usort( $terms, '_usort_terms_by_ID' ); // order by ID
+	return $terms;
+}
+
+/**
  * Retrieve category name based on category ID.
  *
  * @since 0.71
