Title: WP_Hook::resort_active_iterations
Published: December 6, 2016
Last modified: May 20, 2026

---

# WP_Hook::resort_active_iterations( false|int $new_priority = false, bool $priority_existed = false )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Handles resetting callback priority keys mid-iteration.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#parameters)󠁿

 `$new_priority`false|intoptional

The priority of the new filter being added. Default false, for no priority being
added.

Default:`false`

`$priority_existed`booloptional

Flag for whether the priority already existed before the new filter was added.

Default:`false`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#source)󠁿

    ```php
    private function resort_active_iterations( $new_priority = false, $priority_existed = false ) {
    	$new_priorities = $this->priorities;

    	// If there are no remaining hooks, clear out all running iterations.
    	if ( ! $new_priorities ) {
    		foreach ( $this->iterations as $index => $iteration ) {
    			$this->iterations[ $index ] = $new_priorities;
    		}

    		return;
    	}

    	$min = min( $new_priorities );

    	foreach ( $this->iterations as $index => &$iteration ) {
    		$current = current( $iteration );

    		// If we're already at the end of this iteration, just leave the array pointer where it is.
    		if ( false === $current ) {
    			continue;
    		}

    		$iteration = $new_priorities;

    		if ( $current < $min ) {
    			array_unshift( $iteration, $current );
    			continue;
    		}

    		while ( current( $iteration ) < $current ) {
    			if ( false === next( $iteration ) ) {
    				break;
    			}
    		}

    		// If we have a new priority that didn't exist, but ::apply_filters() or ::do_action() thinks it's the current priority...
    		if ( $new_priority === $this->current_priority[ $index ] && ! $priority_existed ) {
    			/*
    			 * ...and the new priority is the same as what $this->iterations thinks is the previous
    			 * priority, we need to move back to it.
    			 */

    			if ( false === current( $iteration ) ) {
    				// If we've already moved off the end of the array, go back to the last element.
    				$prev = end( $iteration );
    			} else {
    				// Otherwise, just go back to the previous element.
    				$prev = prev( $iteration );
    			}

    			if ( false === $prev ) {
    				// Start of the array. Reset, and go about our day.
    				reset( $iteration );
    			} elseif ( $new_priority !== $prev ) {
    				// Previous wasn't the same. Move forward again.
    				next( $iteration );
    			}
    		}
    	}

    	unset( $iteration );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-hook.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-hook.php#L118)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-hook.php#L118-L179)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Hook::remove_all_filters()](https://developer.wordpress.org/reference/classes/wp_hook/remove_all_filters/)`wp-includes/class-wp-hook.php` |

Removes all callbacks from the current filter.

  | 
| [WP_Hook::add_filter()](https://developer.wordpress.org/reference/classes/wp_hook/add_filter/)`wp-includes/class-wp-hook.php` |

Adds a callback function to a filter hook.

  | 
| [WP_Hook::remove_filter()](https://developer.wordpress.org/reference/classes/wp_hook/remove_filter/)`wp-includes/class-wp-hook.php` |

Removes a callback function from a filter hook.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_hook/resort_active_iterations/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_hook%2Fresort_active_iterations%2F)
before being able to contribute a note or feedback.