Habari\RewriteRules::sort_rules PHP Method

sort_rules() public static method

Required because plugins would insert their rules at the end of the array, which would allow any other rule (including the one that executes by default when no other rules work) to execute first.
public static sort_rules ( array $rewrite_rules ) : array
$rewrite_rules array An array of RewriteRules
return array Sorted rewrite rules by priority
    public static function sort_rules($rewrite_rules)
    {
        $pr = array();
        $max_priority = 0;
        foreach ($rewrite_rules as $r) {
            $priority = $r->priority;
            $pr[$priority][] = $r;
            $max_priority = max($max_priority, $priority);
        }
        $rewrite_rules = array();
        for ($z = 0; $z <= $max_priority; $z++) {
            if (isset($pr[$z])) {
                $rewrite_rules = array_merge($rewrite_rules, $pr[$z]);
            }
        }
        return $rewrite_rules;
    }