Make WordPress Core

Ticket #29291: 29291.patch

File 29291.patch, 1.1 KB (added by keraweb, 10 years ago)

Allow id ranges for post queries (defined with a hyphen: x-xx)

  • wp-includes/functions.php

     
    34313431 * @return array Sanitized array of IDs.
    34323432 */
    34333433function wp_parse_id_list( $list ) {
    3434         if ( !is_array($list) )
    3435                 $list = preg_split('/[\s,]+/', $list);
     3434        if ( ! is_array( $list ) )
     3435                $list = preg_split( '/[\s,]+/', $list );
    34363436
    3437         return array_unique(array_map('absint', $list));
     3437        /**
     3438         * Add support for id ranges separated with a hyphen (-)
     3439         * Respects the order of the list ids
     3440         *
     3441         * @since 4.7.0
     3442         */
     3443        for ( $key = 0, $length = count( $list ); $key < $length; $key++ ) {
     3444                if ( strpos( $list[ $key ], '-' ) !== false ) {
     3445                        $m = array_map( 'intval', explode( '-', $list[ $key ] ) );
     3446                        if ( count( $m ) > 1 && reset( $m ) != end( $m ) ) {
     3447                                unset( $list[ $key ] );
     3448                                array_splice( $list, $key, 0, range( reset( $m ), end( $m ) ) );
     3449                                $key = $key + ( end( $m ) - reset( $m ) );
     3450                                $length = count( $list );
     3451                        }
     3452                }
     3453        }
     3454
     3455        return array_unique( array_map( 'absint', $list ) );
    34383456}
    34393457
    34403458/**