Created
June 1, 2016 22:18
-
-
Save JustinSainton/002920bb0e9e7426bbdee6ad07ef232c to your computer and use it in GitHub Desktop.
Broken in trunk (4.6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpsc_get_terms_variation_sort_filter( $terms ) { | |
$new_terms = array(); | |
$unsorted = array(); | |
var_dump( $terms ); // in 4.5.2, returns an array of terms. In trunk (only in some contexts), returns a numeric string. | |
foreach ( $terms as $term ) { | |
if ( ! is_object( $term ) ) { | |
return $terms; | |
} | |
$term_order = ( $term->taxonomy == 'wpsc-variation' ) ? wpsc_get_meta( $term->term_id, 'sort_order', 'wpsc_variation' ) : null; | |
$term_order = (int) $term_order; | |
// unsorted categories should go to the top of the list | |
if ( $term_order == 0 ) { | |
$term->sort_order = $term_order; | |
$unsorted[] = $term; | |
continue; | |
} | |
while ( isset( $new_terms[ $term_order ] ) ) { | |
$term_order++; | |
} | |
$term->sort_order = $term_order; | |
$new_terms[ $term_order ] = $term; | |
} | |
if ( ! empty( $new_terms ) ) { | |
ksort( $new_terms ); | |
} | |
for ( $i = count( $unsorted ) - 1; $i >= 0; $i-- ) { | |
array_unshift( $new_terms, $unsorted[ $i ] ); | |
} | |
return array_values( $new_terms ); | |
} | |
add_filter( 'get_terms','wpsc_get_terms_variation_sort_filter' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment